mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-23 17:09:21 +00:00
[Fix] Tripwire for sprinkler
This commit is contained in:
@@ -19,7 +19,13 @@ package net.momirealms.customcrops.api.common;
|
||||
|
||||
public interface Initable {
|
||||
|
||||
/**
|
||||
* init
|
||||
*/
|
||||
void init();
|
||||
|
||||
/**
|
||||
* disable
|
||||
*/
|
||||
void disable();
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package net.momirealms.customcrops.api.common;
|
||||
|
||||
public interface Property<T> {
|
||||
T get();
|
||||
void set(T value);
|
||||
}
|
||||
@@ -22,6 +22,12 @@ import net.momirealms.customcrops.api.mechanic.requirement.State;
|
||||
|
||||
public interface EventItem {
|
||||
|
||||
/**
|
||||
* Trigger events
|
||||
*
|
||||
* @param actionTrigger trigger
|
||||
* @param state state
|
||||
*/
|
||||
void trigger(ActionTrigger actionTrigger, State state);
|
||||
|
||||
}
|
||||
|
||||
@@ -19,5 +19,10 @@ package net.momirealms.customcrops.api.common.item;
|
||||
|
||||
public interface KeyItem {
|
||||
|
||||
/**
|
||||
* Get item's key
|
||||
*
|
||||
* @return key
|
||||
*/
|
||||
String getKey();
|
||||
}
|
||||
|
||||
@@ -94,16 +94,31 @@ public class BoneMealDispenseEvent extends Event implements Cancellable {
|
||||
return boneMealItem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the crop's data
|
||||
*
|
||||
* @return crop data
|
||||
*/
|
||||
@NotNull
|
||||
public WorldCrop getCrop() {
|
||||
return crop;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the bone meal's config
|
||||
*
|
||||
* @return bone meal config
|
||||
*/
|
||||
@NotNull
|
||||
public BoneMeal getBoneMeal() {
|
||||
return boneMeal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the dispenser block
|
||||
*
|
||||
* @return dispenser block
|
||||
*/
|
||||
@NotNull
|
||||
public Block getDispenser() {
|
||||
return dispenser;
|
||||
|
||||
@@ -77,6 +77,7 @@ public class BoneMealUseEvent extends Event implements Cancellable {
|
||||
|
||||
/**
|
||||
* Get the crop location
|
||||
*
|
||||
* @return location
|
||||
*/
|
||||
@NotNull
|
||||
@@ -87,6 +88,7 @@ public class BoneMealUseEvent extends Event implements Cancellable {
|
||||
/**
|
||||
* Get the item in player's hand
|
||||
* If there's nothing in hand, it would return AIR
|
||||
*
|
||||
* @return item in hand
|
||||
*/
|
||||
@NotNull
|
||||
@@ -94,11 +96,21 @@ public class BoneMealUseEvent extends Event implements Cancellable {
|
||||
return itemInHand;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the crop's data
|
||||
*
|
||||
* @return crop data
|
||||
*/
|
||||
@NotNull
|
||||
public WorldCrop getCrop() {
|
||||
return crop;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the bone meal config
|
||||
*
|
||||
* @return bone meal config
|
||||
*/
|
||||
@NotNull
|
||||
public BoneMeal getBoneMeal() {
|
||||
return boneMeal;
|
||||
|
||||
@@ -75,6 +75,7 @@ public class CropBreakEvent extends Event implements Cancellable {
|
||||
|
||||
/**
|
||||
* Get the crop's data, it might be null if it's spawned by other plugins in the wild
|
||||
*
|
||||
* @return crop data
|
||||
*/
|
||||
@Nullable
|
||||
@@ -84,6 +85,7 @@ public class CropBreakEvent extends Event implements Cancellable {
|
||||
|
||||
/**
|
||||
* Get the crop location
|
||||
*
|
||||
* @return location
|
||||
*/
|
||||
@NotNull
|
||||
@@ -91,6 +93,14 @@ public class CropBreakEvent extends Event implements Cancellable {
|
||||
return location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entity that triggered the event
|
||||
* This would be null if the crop is broken by respawn anchor
|
||||
* The breaker can be a TNT, creeper.
|
||||
* If the pot is a vanilla farmland, it can be trampled by entities
|
||||
*
|
||||
* @return entity
|
||||
*/
|
||||
@Nullable
|
||||
public Entity getEntity() {
|
||||
return entity;
|
||||
@@ -104,6 +114,11 @@ public class CropBreakEvent extends Event implements Cancellable {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the reason
|
||||
*
|
||||
* @return reason
|
||||
*/
|
||||
@NotNull
|
||||
public Reason getReason() {
|
||||
return reason;
|
||||
|
||||
@@ -73,6 +73,7 @@ public class CropInteractEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
/**
|
||||
* Get the crop location
|
||||
*
|
||||
* @return location
|
||||
*/
|
||||
@NotNull
|
||||
@@ -83,6 +84,7 @@ public class CropInteractEvent extends PlayerEvent implements Cancellable {
|
||||
/**
|
||||
* Get the item in player's hand
|
||||
* If there's nothing in hand, it would return AIR
|
||||
*
|
||||
* @return item in hand
|
||||
*/
|
||||
@NotNull
|
||||
@@ -92,6 +94,7 @@ public class CropInteractEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
/**
|
||||
* Get the crop's data, it might be null if it's spawned by other plugins in the wild
|
||||
*
|
||||
* @return crop data
|
||||
*/
|
||||
@Nullable
|
||||
|
||||
@@ -64,6 +64,7 @@ public class CropPlantEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
/**
|
||||
* Get the seed item
|
||||
*
|
||||
* @return seed item
|
||||
*/
|
||||
@NotNull
|
||||
|
||||
@@ -74,21 +74,41 @@ public class FertilizerUseEvent extends PlayerEvent implements Cancellable {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fertilizer item in hand
|
||||
*
|
||||
* @return item in hand
|
||||
*/
|
||||
@NotNull
|
||||
public ItemStack getItemInHand() {
|
||||
return itemInHand;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the pot's location
|
||||
*
|
||||
* @return location
|
||||
*/
|
||||
@NotNull
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the pot's data
|
||||
*
|
||||
* @return pot data
|
||||
*/
|
||||
@NotNull
|
||||
public WorldPot getPot() {
|
||||
return pot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fertilizer's config
|
||||
*
|
||||
* @return fertilizer config
|
||||
*/
|
||||
@NotNull
|
||||
public Fertilizer getFertilizer() {
|
||||
return fertilizer;
|
||||
|
||||
@@ -75,6 +75,7 @@ public class GreenhouseGlassBreakEvent extends Event implements Cancellable {
|
||||
|
||||
/**
|
||||
* Get the glass location
|
||||
*
|
||||
* @return location
|
||||
*/
|
||||
@NotNull
|
||||
@@ -100,6 +101,11 @@ public class GreenhouseGlassBreakEvent extends Event implements Cancellable {
|
||||
return reason;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the glass data
|
||||
*
|
||||
* @return glass data
|
||||
*/
|
||||
@NotNull
|
||||
public WorldGlass getGlass() {
|
||||
return glass;
|
||||
|
||||
@@ -64,6 +64,7 @@ public class GreenhouseGlassPlaceEvent extends PlayerEvent implements Cancellabl
|
||||
|
||||
/**
|
||||
* Get the glass location
|
||||
*
|
||||
* @return location
|
||||
*/
|
||||
@NotNull
|
||||
|
||||
@@ -75,6 +75,7 @@ public class PotBreakEvent extends Event implements Cancellable {
|
||||
|
||||
/**
|
||||
* Get the pot location
|
||||
*
|
||||
* @return location
|
||||
*/
|
||||
@NotNull
|
||||
@@ -85,6 +86,7 @@ public class PotBreakEvent extends Event implements Cancellable {
|
||||
|
||||
/**
|
||||
* Get the pot's data
|
||||
*
|
||||
* @return pot
|
||||
*/
|
||||
@NotNull
|
||||
|
||||
@@ -76,6 +76,7 @@ public class PotFillEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
/**
|
||||
* Get the pot location
|
||||
*
|
||||
* @return location
|
||||
*/
|
||||
@NotNull
|
||||
@@ -86,6 +87,7 @@ public class PotFillEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
/**
|
||||
* Get the pot's data
|
||||
*
|
||||
* @return pot
|
||||
*/
|
||||
@NotNull
|
||||
@@ -93,11 +95,21 @@ public class PotFillEvent extends PlayerEvent implements Cancellable {
|
||||
return pot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the item in hand
|
||||
*
|
||||
* @return item in hand
|
||||
*/
|
||||
@NotNull
|
||||
public ItemStack getItemInHand() {
|
||||
return itemInHand;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the passive fill method
|
||||
*
|
||||
* @return passive fill method
|
||||
*/
|
||||
@NotNull
|
||||
public PassiveFillMethod getFillMethod() {
|
||||
return fillMethod;
|
||||
|
||||
@@ -54,10 +54,6 @@ public class PotInteractEvent extends PlayerEvent implements Cancellable {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancelling this event would cancel PotInfoEvent too
|
||||
* @param cancel true if you wish to cancel this event
|
||||
*/
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
@@ -77,6 +73,7 @@ public class PotInteractEvent extends PlayerEvent implements Cancellable {
|
||||
/**
|
||||
* Get the item in player's hand
|
||||
* If there's nothing in hand, it would return AIR
|
||||
*
|
||||
* @return item in hand
|
||||
*/
|
||||
@NotNull
|
||||
@@ -86,6 +83,7 @@ public class PotInteractEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
/**
|
||||
* Get the pot location
|
||||
*
|
||||
* @return pot location
|
||||
*/
|
||||
@NotNull
|
||||
@@ -95,6 +93,7 @@ public class PotInteractEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
/**
|
||||
* Get the pot's data
|
||||
*
|
||||
* @return pot key
|
||||
*/
|
||||
@NotNull
|
||||
|
||||
@@ -68,6 +68,7 @@ public class PotPlaceEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
/**
|
||||
* Get the pot location
|
||||
*
|
||||
* @return location
|
||||
*/
|
||||
@NotNull
|
||||
@@ -77,6 +78,7 @@ public class PotPlaceEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
/**
|
||||
* Get the placed pot's config
|
||||
*
|
||||
* @return pot
|
||||
*/
|
||||
@NotNull
|
||||
|
||||
@@ -75,6 +75,7 @@ public class ScarecrowBreakEvent extends Event implements Cancellable {
|
||||
|
||||
/**
|
||||
* Get the scarecrow location
|
||||
*
|
||||
* @return location
|
||||
*/
|
||||
@NotNull
|
||||
|
||||
@@ -64,6 +64,7 @@ public class ScarecrowPlaceEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
/**
|
||||
* Get the scarecrow location
|
||||
*
|
||||
* @return location
|
||||
*/
|
||||
@NotNull
|
||||
|
||||
@@ -54,6 +54,7 @@ public class SeasonChangeEvent extends Event {
|
||||
|
||||
/**
|
||||
* Get the new season
|
||||
*
|
||||
* @return season
|
||||
*/
|
||||
@NotNull
|
||||
@@ -63,6 +64,7 @@ public class SeasonChangeEvent extends Event {
|
||||
|
||||
/**
|
||||
* Get the world
|
||||
*
|
||||
* @return world
|
||||
*/
|
||||
public World getWorld() {
|
||||
|
||||
@@ -75,6 +75,7 @@ public class SprinklerBreakEvent extends Event implements Cancellable {
|
||||
|
||||
/**
|
||||
* Get the sprinkler location
|
||||
*
|
||||
* @return location
|
||||
*/
|
||||
@NotNull
|
||||
@@ -84,6 +85,7 @@ public class SprinklerBreakEvent extends Event implements Cancellable {
|
||||
|
||||
/**
|
||||
* Get the sprinkler's data
|
||||
*
|
||||
* @return sprinkler
|
||||
*/
|
||||
@NotNull
|
||||
|
||||
@@ -76,6 +76,7 @@ public class SprinklerFillEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
/**
|
||||
* Get the item in player's hand
|
||||
*
|
||||
* @return item in hand
|
||||
*/
|
||||
@NotNull
|
||||
@@ -85,6 +86,7 @@ public class SprinklerFillEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
/**
|
||||
* Get the sprinkler location
|
||||
*
|
||||
* @return location
|
||||
*/
|
||||
@NotNull
|
||||
@@ -92,6 +94,11 @@ public class SprinklerFillEvent extends PlayerEvent implements Cancellable {
|
||||
return location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the passive fill method
|
||||
*
|
||||
* @return passive fill method
|
||||
*/
|
||||
@NotNull
|
||||
public PassiveFillMethod getFillMethod() {
|
||||
return fillMethod;
|
||||
|
||||
@@ -72,6 +72,7 @@ public class SprinklerInteractEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
/**
|
||||
* Get the sprinkler location
|
||||
*
|
||||
* @return location
|
||||
*/
|
||||
@NotNull
|
||||
@@ -81,6 +82,7 @@ public class SprinklerInteractEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
/**
|
||||
* Get the sprinkler's data
|
||||
*
|
||||
* @return sprinkler
|
||||
*/
|
||||
@NotNull
|
||||
@@ -90,6 +92,7 @@ public class SprinklerInteractEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
/**
|
||||
* Get the item in player's hand
|
||||
*
|
||||
* @return item in hand
|
||||
*/
|
||||
@NotNull
|
||||
|
||||
@@ -72,6 +72,7 @@ public class SprinklerPlaceEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
/**
|
||||
* Get the item in player's hand
|
||||
*
|
||||
* @return item in hand
|
||||
*/
|
||||
@NotNull
|
||||
@@ -81,6 +82,7 @@ public class SprinklerPlaceEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
/**
|
||||
* Get the sprinkler location
|
||||
*
|
||||
* @return location
|
||||
*/
|
||||
@NotNull
|
||||
@@ -90,6 +92,7 @@ public class SprinklerPlaceEvent extends PlayerEvent implements Cancellable {
|
||||
|
||||
/**
|
||||
* Get the sprinkler's config
|
||||
*
|
||||
* @return sprinkler
|
||||
*/
|
||||
@NotNull
|
||||
|
||||
@@ -74,21 +74,41 @@ public class WateringCanFillEvent extends PlayerEvent implements Cancellable {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the watering can item
|
||||
*
|
||||
* @return the watering can item
|
||||
*/
|
||||
@NotNull
|
||||
public ItemStack getItemInHand() {
|
||||
return itemInHand;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get watering can config
|
||||
*
|
||||
* @return watering can config
|
||||
*/
|
||||
@NotNull
|
||||
public WateringCan getWateringCan() {
|
||||
return wateringCan;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the positive fill method
|
||||
*
|
||||
* @return positive fill method
|
||||
*/
|
||||
@NotNull
|
||||
public PositiveFillMethod getFillMethod() {
|
||||
return fillMethod;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the location
|
||||
*
|
||||
* @return location
|
||||
*/
|
||||
@NotNull
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
|
||||
@@ -76,21 +76,41 @@ public class WateringCanWaterEvent extends PlayerEvent implements Cancellable {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the watering can item
|
||||
*
|
||||
* @return watering can item
|
||||
*/
|
||||
@NotNull
|
||||
public ItemStack getItemInHand() {
|
||||
return itemInHand;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the watering can's config
|
||||
*
|
||||
* @return watering can config
|
||||
*/
|
||||
@NotNull
|
||||
public WateringCan getWateringCan() {
|
||||
return wateringCan;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the locations that involved in this event
|
||||
*
|
||||
* @return locations
|
||||
*/
|
||||
@NotNull
|
||||
public Set<Location> getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the pot/sprinkler's data
|
||||
*
|
||||
* @return data
|
||||
*/
|
||||
@NotNull
|
||||
public CustomCropsBlock getPotOrSprinkler() {
|
||||
return potOrSprinkler;
|
||||
|
||||
@@ -22,9 +22,28 @@ import org.bukkit.inventory.ItemStack;
|
||||
|
||||
public interface ItemLibrary {
|
||||
|
||||
/**
|
||||
* Get the identification
|
||||
* for instance "CustomItems"
|
||||
*
|
||||
* @return identification
|
||||
*/
|
||||
String identification();
|
||||
|
||||
/**
|
||||
* Build an item instance for a player
|
||||
*
|
||||
* @param player player
|
||||
* @param id id
|
||||
* @return item
|
||||
*/
|
||||
ItemStack buildItem(Player player, String id);
|
||||
|
||||
/**
|
||||
* Get an item's id
|
||||
*
|
||||
* @param itemStack item
|
||||
* @return ID
|
||||
*/
|
||||
String getItemID(ItemStack itemStack);
|
||||
}
|
||||
|
||||
@@ -28,18 +28,71 @@ import java.util.HashMap;
|
||||
|
||||
public interface ActionManager extends Reloadable {
|
||||
|
||||
/**
|
||||
* Register a custom action type
|
||||
*
|
||||
* @param type type
|
||||
* @param actionFactory action factory
|
||||
* @return success or not
|
||||
*/
|
||||
boolean registerAction(String type, ActionFactory actionFactory);
|
||||
|
||||
/**
|
||||
* Unregister an action type by id
|
||||
*
|
||||
* @param type type
|
||||
* @return success or not
|
||||
*/
|
||||
boolean unregisterAction(String type);
|
||||
|
||||
/**
|
||||
* Build an action instance with Bukkit configs
|
||||
*
|
||||
* @param section bukkit config
|
||||
* @return action
|
||||
*/
|
||||
Action getAction(ConfigurationSection section);
|
||||
|
||||
/**
|
||||
* If an action type exists
|
||||
*
|
||||
* @param type type
|
||||
* @return exist or not
|
||||
*/
|
||||
default boolean hasAction(String type) {
|
||||
return getActionFactory(type) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an action map with Bukkit configs
|
||||
*
|
||||
* @param section bukkit config
|
||||
* @return action map
|
||||
*/
|
||||
HashMap<ActionTrigger, Action[]> getActionMap(ConfigurationSection section);
|
||||
|
||||
/**
|
||||
* Build actions with Bukkit configs
|
||||
*
|
||||
* @param section bukkit config
|
||||
* @return actions
|
||||
*/
|
||||
Action[] getActions(ConfigurationSection section);
|
||||
|
||||
/**
|
||||
* Get an action factory by type
|
||||
*
|
||||
* @param type type
|
||||
* @return action factory
|
||||
*/
|
||||
ActionFactory getActionFactory(String type);
|
||||
|
||||
/**
|
||||
* Trigger actions
|
||||
*
|
||||
* @param state state
|
||||
* @param actions actions
|
||||
*/
|
||||
static void triggerActions(State state, Action... actions) {
|
||||
if (actions != null)
|
||||
for (Action action : actions)
|
||||
|
||||
@@ -27,21 +27,73 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface ConditionManager extends Reloadable {
|
||||
|
||||
/**
|
||||
* Register a custom condition type
|
||||
*
|
||||
* @param type type
|
||||
* @param conditionFactory condition factory
|
||||
* @return success or not
|
||||
*/
|
||||
boolean registerCondition(String type, ConditionFactory conditionFactory);
|
||||
|
||||
/**
|
||||
* Unregister a condition type by id
|
||||
*
|
||||
* @param type type
|
||||
* @return success or not
|
||||
*/
|
||||
boolean unregisterCondition(String type);
|
||||
|
||||
boolean hasCondition(String type);
|
||||
/**
|
||||
* If a condition type exists
|
||||
*
|
||||
* @param type type
|
||||
* @return exist or not
|
||||
*/
|
||||
default boolean hasCondition(String type) {
|
||||
return getConditionFactory(type) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build conditions with Bukkit configs
|
||||
*
|
||||
* @param section bukkit config
|
||||
* @return conditions
|
||||
*/
|
||||
@NotNull
|
||||
Condition[] getConditions(ConfigurationSection section);
|
||||
|
||||
/**
|
||||
* Build a condition instance with Bukkit configs
|
||||
*
|
||||
* @param section bukkit config
|
||||
* @return condition
|
||||
*/
|
||||
Condition getCondition(ConfigurationSection section);
|
||||
|
||||
/**
|
||||
* Build a condition instance with Bukkit configs
|
||||
*
|
||||
* @return condition
|
||||
*/
|
||||
Condition getCondition(String key, Object args);
|
||||
|
||||
/**
|
||||
* Get a condition factory by type
|
||||
*
|
||||
* @param type type
|
||||
* @return condition factory
|
||||
*/
|
||||
@Nullable ConditionFactory getConditionFactory(String type);
|
||||
|
||||
/**
|
||||
* Are conditions met for a custom crops block
|
||||
*
|
||||
* @param block block
|
||||
* @param offline is the check for offline ticks
|
||||
* @param conditions conditions
|
||||
* @return meet or not
|
||||
*/
|
||||
static boolean isConditionMet(CustomCropsBlock block, boolean offline, Condition... conditions) {
|
||||
if (conditions == null) return true;
|
||||
for (Condition condition : conditions) {
|
||||
|
||||
@@ -20,8 +20,6 @@ package net.momirealms.customcrops.api.manager;
|
||||
import net.momirealms.customcrops.api.common.Initable;
|
||||
import net.momirealms.customcrops.api.integration.LevelInterface;
|
||||
import net.momirealms.customcrops.api.integration.SeasonInterface;
|
||||
import net.momirealms.customcrops.api.mechanic.world.season.Season;
|
||||
import org.bukkit.World;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface IntegrationManager extends Initable {
|
||||
@@ -51,9 +49,10 @@ public interface IntegrationManager extends Initable {
|
||||
*/
|
||||
@Nullable LevelInterface getLevelPlugin(String plugin);
|
||||
|
||||
/**
|
||||
* Get the SeasonInterface provided by a plugin.
|
||||
*
|
||||
* @return the season interface
|
||||
*/
|
||||
SeasonInterface getSeasonInterface();
|
||||
|
||||
Season getSeason(World world);
|
||||
|
||||
int getDate(World world);
|
||||
}
|
||||
|
||||
@@ -33,8 +33,20 @@ import java.util.Collection;
|
||||
|
||||
public interface ItemManager extends Reloadable {
|
||||
|
||||
/**
|
||||
* Register an item library
|
||||
*
|
||||
* @param itemLibrary item library
|
||||
* @return success or not
|
||||
*/
|
||||
boolean registerItemLibrary(@NotNull ItemLibrary itemLibrary);
|
||||
|
||||
/**
|
||||
* Unregister an item library by identification
|
||||
*
|
||||
* @param identification identification
|
||||
* @return success or not
|
||||
*/
|
||||
boolean unregisterItemLibrary(String identification);
|
||||
|
||||
String getItemID(ItemStack itemStack);
|
||||
|
||||
@@ -27,28 +27,81 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public interface RequirementManager extends Reloadable {
|
||||
|
||||
/**
|
||||
* Register a custom requirement type
|
||||
*
|
||||
* @param type type
|
||||
* @param requirementFactory requirement factory
|
||||
* @return success or not
|
||||
*/
|
||||
boolean registerRequirement(String type, RequirementFactory requirementFactory);
|
||||
|
||||
/**
|
||||
* Unregister a custom requirement by type
|
||||
*
|
||||
* @param type type
|
||||
* @return success or not
|
||||
*/
|
||||
boolean unregisterRequirement(String type);
|
||||
|
||||
/**
|
||||
* Build requirements with Bukkit configs
|
||||
*
|
||||
* @param section bukkit config
|
||||
* @param advanced check "not-met-actions" or not
|
||||
* @return requirements
|
||||
*/
|
||||
@Nullable
|
||||
Requirement[] getRequirements(ConfigurationSection section, boolean advanced);
|
||||
|
||||
boolean hasRequirement(String type);
|
||||
/**
|
||||
* If a requirement type exists
|
||||
*
|
||||
* @param type type
|
||||
* @return exist or not
|
||||
*/
|
||||
default boolean hasRequirement(String type) {
|
||||
return getRequirementFactory(type) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a requirement instance with Bukkit configs
|
||||
*
|
||||
* @param section bukkit config
|
||||
* @param advanced check "not-met-actions" or not
|
||||
* @return requirement
|
||||
*/
|
||||
@NotNull
|
||||
Requirement getRequirement(ConfigurationSection section, boolean advanced);
|
||||
|
||||
/**
|
||||
* Build a requirement instance with Bukkit configs
|
||||
*
|
||||
* @return requirement
|
||||
*/
|
||||
@NotNull
|
||||
Requirement getRequirement(String type, Object value);
|
||||
|
||||
/**
|
||||
* Get a requirement factory by type
|
||||
*
|
||||
* @param type type
|
||||
* @return requirement factory
|
||||
*/
|
||||
@Nullable
|
||||
RequirementFactory getRequirementFactory(String type);
|
||||
|
||||
static boolean isRequirementMet(State condition, Requirement... requirements) {
|
||||
/**
|
||||
* Are requirements met for a player
|
||||
*
|
||||
* @param state state
|
||||
* @param requirements requirements
|
||||
* @return meet or not
|
||||
*/
|
||||
static boolean isRequirementMet(State state, Requirement... requirements) {
|
||||
if (requirements == null) return true;
|
||||
for (Requirement requirement : requirements) {
|
||||
if (!requirement.isStateMet(condition)) {
|
||||
if (!requirement.isStateMet(state)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,6 +68,8 @@ public interface CustomCropsWorld {
|
||||
|
||||
void unloadChunk(ChunkPos chunkPos);
|
||||
|
||||
void deleteChunk(ChunkPos chunkPos);
|
||||
|
||||
void setInfoData(WorldInfoData infoData);
|
||||
|
||||
WorldInfoData getInfoData();
|
||||
|
||||
@@ -8,7 +8,7 @@ plugins {
|
||||
allprojects {
|
||||
|
||||
project.group = "net.momirealms"
|
||||
project.version = "3.4.4.3"
|
||||
project.version = "3.4.4.4"
|
||||
|
||||
apply<JavaPlugin>()
|
||||
apply(plugin = "java")
|
||||
|
||||
@@ -51,7 +51,7 @@ dependencies {
|
||||
implementation(project(":legacy-api"))
|
||||
implementation("net.kyori:adventure-api:4.15.0")
|
||||
implementation("net.kyori:adventure-platform-bukkit:4.3.2")
|
||||
implementation("com.github.Xiao-MoMi:AntiGriefLib:0.9.1")
|
||||
implementation("com.github.Xiao-MoMi:AntiGriefLib:0.10")
|
||||
implementation("com.github.Xiao-MoMi:BiomeAPI:0.3")
|
||||
|
||||
compileOnly("net.kyori:adventure-text-minimessage:4.15.0")
|
||||
|
||||
@@ -52,7 +52,6 @@ public class CustomCropsPluginImpl extends CustomCropsPlugin {
|
||||
private PacketManager packetManager;
|
||||
private CommandManager commandManager;
|
||||
private HologramManager hologramManager;
|
||||
private AntiGriefLib antiGriefLib;
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
@@ -71,11 +70,6 @@ public class CustomCropsPluginImpl extends CustomCropsPlugin {
|
||||
Dependency.BSTATS_BUKKIT
|
||||
)
|
||||
));
|
||||
|
||||
this.antiGriefLib = AntiGriefLib.builder(this)
|
||||
.silentLogs(true)
|
||||
.ignoreOP(true)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -91,14 +85,18 @@ public class CustomCropsPluginImpl extends CustomCropsPlugin {
|
||||
this.requirementManager = new RequirementManagerImpl(this);
|
||||
this.coolDownManager = new CoolDownManager(this);
|
||||
this.worldManager = new WorldManagerImpl(this);
|
||||
this.itemManager = new ItemManagerImpl(this, antiGriefLib);
|
||||
this.itemManager = new ItemManagerImpl(this,
|
||||
AntiGriefLib.builder(this)
|
||||
.silentLogs(true)
|
||||
.ignoreOP(true)
|
||||
.build()
|
||||
);
|
||||
this.messageManager = new MessageManagerImpl(this);
|
||||
this.packetManager = new PacketManager(this);
|
||||
this.commandManager = new CommandManager(this);
|
||||
this.placeholderManager = new PlaceholderManagerImpl(this);
|
||||
this.hologramManager = new HologramManager(this);
|
||||
this.commandManager.init();
|
||||
this.antiGriefLib.init();
|
||||
this.integrationManager.init();
|
||||
this.disableNBTAPILogs();
|
||||
Migration.tryUpdating();
|
||||
|
||||
@@ -17,12 +17,10 @@
|
||||
|
||||
package net.momirealms.customcrops.compatibility;
|
||||
|
||||
import com.gamingmesh.jobs.Jobs;
|
||||
import net.momirealms.customcrops.api.CustomCropsPlugin;
|
||||
import net.momirealms.customcrops.api.integration.LevelInterface;
|
||||
import net.momirealms.customcrops.api.integration.SeasonInterface;
|
||||
import net.momirealms.customcrops.api.manager.IntegrationManager;
|
||||
import net.momirealms.customcrops.api.mechanic.world.season.Season;
|
||||
import net.momirealms.customcrops.api.util.LogUtils;
|
||||
import net.momirealms.customcrops.compatibility.item.MMOItemsItemImpl;
|
||||
import net.momirealms.customcrops.compatibility.item.MythicMobsItemImpl;
|
||||
@@ -32,7 +30,6 @@ import net.momirealms.customcrops.compatibility.level.*;
|
||||
import net.momirealms.customcrops.compatibility.season.AdvancedSeasonsImpl;
|
||||
import net.momirealms.customcrops.compatibility.season.InBuiltSeason;
|
||||
import net.momirealms.customcrops.compatibility.season.RealisticSeasonsImpl;
|
||||
import org.bukkit.World;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -110,13 +107,6 @@ public class IntegrationManagerImpl implements IntegrationManager {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a level plugin with the specified name.
|
||||
*
|
||||
* @param plugin The name of the level plugin.
|
||||
* @param level The implementation of the LevelInterface.
|
||||
* @return true if the registration was successful, false if the plugin name is already registered.
|
||||
*/
|
||||
@Override
|
||||
public boolean registerLevelPlugin(String plugin, LevelInterface level) {
|
||||
if (levelPluginMap.containsKey(plugin)) return false;
|
||||
@@ -124,12 +114,6 @@ public class IntegrationManagerImpl implements IntegrationManager {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregisters a level plugin with the specified name.
|
||||
*
|
||||
* @param plugin The name of the level plugin to unregister.
|
||||
* @return true if the unregistration was successful, false if the plugin name is not found.
|
||||
*/
|
||||
@Override
|
||||
public boolean unregisterLevelPlugin(String plugin) {
|
||||
return levelPluginMap.remove(plugin) != null;
|
||||
@@ -139,12 +123,6 @@ public class IntegrationManagerImpl implements IntegrationManager {
|
||||
LogUtils.info( plugin + " hooked!");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the LevelInterface provided by a plugin.
|
||||
*
|
||||
* @param plugin The name of the plugin providing the LevelInterface.
|
||||
* @return The LevelInterface provided by the specified plugin, or null if the plugin is not registered.
|
||||
*/
|
||||
@Override
|
||||
@Nullable
|
||||
public LevelInterface getLevelPlugin(String plugin) {
|
||||
@@ -155,14 +133,4 @@ public class IntegrationManagerImpl implements IntegrationManager {
|
||||
public SeasonInterface getSeasonInterface() {
|
||||
return seasonInterface;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Season getSeason(World world) {
|
||||
return seasonInterface.getSeason(world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDate(World world) {
|
||||
return seasonInterface.getDate(world);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
package net.momirealms.customcrops.compatibility.level;
|
||||
|
||||
import com.archyx.aureliumskills.api.AureliumAPI;
|
||||
import com.archyx.aureliumskills.leveler.Leveler;
|
||||
import net.momirealms.customcrops.api.integration.LevelInterface;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
||||
@@ -74,10 +74,10 @@ public class CCPapi extends PlaceholderExpansion {
|
||||
switch (split[0]) {
|
||||
case "season" -> {
|
||||
if (split.length == 1) {
|
||||
return MessageManager.seasonTranslation(plugin.getIntegrationManager().getSeason(player.getWorld()));
|
||||
return MessageManager.seasonTranslation(plugin.getIntegrationManager().getSeasonInterface().getSeason(player.getWorld()));
|
||||
} else {
|
||||
try {
|
||||
return MessageManager.seasonTranslation(plugin.getIntegrationManager().getSeason(Bukkit.getWorld(split[1])));
|
||||
return MessageManager.seasonTranslation(plugin.getIntegrationManager().getSeasonInterface().getSeason(Bukkit.getWorld(split[1])));
|
||||
} catch (NullPointerException e) {
|
||||
LogUtils.severe("World " + split[1] + " does not exist");
|
||||
e.printStackTrace();
|
||||
@@ -86,10 +86,10 @@ public class CCPapi extends PlaceholderExpansion {
|
||||
}
|
||||
case "date" -> {
|
||||
if (split.length == 1) {
|
||||
return String.valueOf(plugin.getIntegrationManager().getDate(player.getWorld()));
|
||||
return String.valueOf(plugin.getIntegrationManager().getSeasonInterface().getDate(player.getWorld()));
|
||||
} else {
|
||||
try {
|
||||
return String.valueOf(plugin.getIntegrationManager().getDate(Bukkit.getWorld(split[1])));
|
||||
return String.valueOf(plugin.getIntegrationManager().getSeasonInterface().getDate(Bukkit.getWorld(split[1])));
|
||||
} catch (NullPointerException e) {
|
||||
LogUtils.severe("World " + split[1] + " does not exist");
|
||||
e.printStackTrace();
|
||||
|
||||
@@ -24,9 +24,11 @@ import dev.jorel.commandapi.arguments.StringArgument;
|
||||
import net.momirealms.customcrops.api.CustomCropsPlugin;
|
||||
import net.momirealms.customcrops.api.common.Initable;
|
||||
import net.momirealms.customcrops.api.integration.SeasonInterface;
|
||||
import net.momirealms.customcrops.api.manager.AdventureManager;
|
||||
import net.momirealms.customcrops.api.manager.ConfigManager;
|
||||
import net.momirealms.customcrops.api.manager.MessageManager;
|
||||
import net.momirealms.customcrops.api.mechanic.item.ItemType;
|
||||
import net.momirealms.customcrops.api.mechanic.world.ChunkPos;
|
||||
import net.momirealms.customcrops.api.mechanic.world.CustomCropsBlock;
|
||||
import net.momirealms.customcrops.api.mechanic.world.level.CustomCropsChunk;
|
||||
import net.momirealms.customcrops.api.mechanic.world.level.CustomCropsSection;
|
||||
@@ -61,7 +63,8 @@ public class CommandManager implements Initable {
|
||||
getAboutCommand(),
|
||||
getSeasonCommand(),
|
||||
getDateCommand(),
|
||||
getForceTickCommand()
|
||||
getForceTickCommand(),
|
||||
getUnsafeCommand()
|
||||
)
|
||||
.register();
|
||||
}
|
||||
@@ -81,6 +84,23 @@ public class CommandManager implements Initable {
|
||||
});
|
||||
}
|
||||
|
||||
private CommandAPICommand getUnsafeCommand() {
|
||||
return new CommandAPICommand("unsafe")
|
||||
.withSubcommands(
|
||||
new CommandAPICommand("delete-chunk-data").executesPlayer((player, args) -> {
|
||||
CustomCropsPlugin.get().getWorldManager().getCustomCropsWorld(player.getWorld()).ifPresent(customCropsWorld -> {
|
||||
var optionalChunk = customCropsWorld.getLoadedChunkAt(ChunkPos.getByBukkitChunk(player.getChunk()));
|
||||
if (optionalChunk.isEmpty()) {
|
||||
AdventureManager.getInstance().sendMessageWithPrefix(player, "<white>This chunk doesn't have any data.");
|
||||
return;
|
||||
}
|
||||
customCropsWorld.deleteChunk(ChunkPos.getByBukkitChunk(player.getChunk()));
|
||||
AdventureManager.getInstance().sendMessageWithPrefix(player, "<white>Done.");
|
||||
});
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
private CommandAPICommand getAboutCommand() {
|
||||
return new CommandAPICommand("about").executes((sender, args) -> {
|
||||
plugin.getAdventure().sendMessage(sender, "<#FFA500>⛈ CustomCrops <gray>- <#87CEEB>" + CustomCropsPlugin.getInstance().getVersionManager().getPluginVersion());
|
||||
@@ -138,7 +158,7 @@ public class CommandManager implements Initable {
|
||||
plugin.getAdventure().sendMessageWithPrefix(sender, "CustomCrops is not enabled in that world");
|
||||
return;
|
||||
}
|
||||
plugin.getAdventure().sendMessageWithPrefix(sender, String.valueOf(plugin.getIntegrationManager().getDate(world)));
|
||||
plugin.getAdventure().sendMessageWithPrefix(sender, String.valueOf(plugin.getIntegrationManager().getSeasonInterface().getDate(world)));
|
||||
}),
|
||||
new CommandAPICommand("set")
|
||||
.withArguments(new StringArgument("world").replaceSuggestions(ArgumentSuggestions.strings(commandSenderSuggestionInfo -> plugin.getWorldManager().getCustomCropsWorlds().stream()
|
||||
@@ -196,7 +216,7 @@ public class CommandManager implements Initable {
|
||||
plugin.getAdventure().sendMessageWithPrefix(sender, "CustomCrops is not enabled in that world");
|
||||
return;
|
||||
}
|
||||
plugin.getAdventure().sendMessageWithPrefix(sender, MessageManager.seasonTranslation(plugin.getIntegrationManager().getSeason(world)));
|
||||
plugin.getAdventure().sendMessageWithPrefix(sender, MessageManager.seasonTranslation(plugin.getIntegrationManager().getSeasonInterface().getSeason(world)));
|
||||
}),
|
||||
new CommandAPICommand("set")
|
||||
.withArguments(new StringArgument("world").replaceSuggestions(ArgumentSuggestions.strings(commandSenderSuggestionInfo -> {
|
||||
|
||||
@@ -111,11 +111,6 @@ public class ConditionManagerImpl implements ConditionManager {
|
||||
return this.conditionBuilderMap.remove(type) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCondition(String type) {
|
||||
return conditionBuilderMap.containsKey(type);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull Condition[] getConditions(ConfigurationSection section) {
|
||||
ArrayList<Condition> conditions = new ArrayList<>();
|
||||
@@ -578,7 +573,7 @@ public class ConditionManagerImpl implements ConditionManager {
|
||||
registerCondition("suitable_season", (args) -> {
|
||||
HashSet<String> seasons = new HashSet<>(ConfigUtils.stringListArgs(args).stream().map(it -> it.toUpperCase(Locale.ENGLISH)).toList());
|
||||
return (block, offline) -> {
|
||||
Season season = plugin.getIntegrationManager().getSeason(block.getLocation().getBukkitWorld());
|
||||
Season season = plugin.getIntegrationManager().getSeasonInterface().getSeason(block.getLocation().getBukkitWorld());
|
||||
if (season == null) {
|
||||
return true;
|
||||
}
|
||||
@@ -602,7 +597,7 @@ public class ConditionManagerImpl implements ConditionManager {
|
||||
registerCondition("unsuitable_season", (args) -> {
|
||||
HashSet<String> seasons = new HashSet<>(ConfigUtils.stringListArgs(args).stream().map(it -> it.toUpperCase(Locale.ENGLISH)).toList());
|
||||
return (block, offline) -> {
|
||||
Season season = plugin.getIntegrationManager().getSeason(block.getLocation().getBukkitWorld());
|
||||
Season season = plugin.getIntegrationManager().getSeasonInterface().getSeason(block.getLocation().getBukkitWorld());
|
||||
if (season == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -742,6 +742,79 @@ public class ItemManagerImpl implements ItemManager {
|
||||
}
|
||||
|
||||
this.registerItemFunction(itemID, FunctionTrigger.INTERACT_AT,
|
||||
/*
|
||||
* Handle clicking sprinkler with a watering can
|
||||
*/
|
||||
new CFunction(conditionWrapper -> {
|
||||
if (!(conditionWrapper instanceof InteractBlockWrapper blockWrapper)) {
|
||||
return FunctionResult.PASS;
|
||||
}
|
||||
// is a pot
|
||||
Block block = blockWrapper.getClickedBlock();
|
||||
Sprinkler sprinkler = getSprinklerBy3DItemID(customProvider.getBlockID(block));
|
||||
if (sprinkler == null) {
|
||||
return FunctionResult.PASS;
|
||||
}
|
||||
final Player player = blockWrapper.getPlayer();
|
||||
final ItemStack itemInHand = blockWrapper.getItemInHand();
|
||||
final Location clicked = block.getLocation();
|
||||
State state = new State(player, itemInHand, clicked);
|
||||
// check watering-can requirements
|
||||
if (!RequirementManager.isRequirementMet(state, wateringCan.getRequirements())) {
|
||||
return FunctionResult.RETURN;
|
||||
}
|
||||
// check whitelist
|
||||
if (!wateringCan.getSprinklerWhitelist().contains(sprinkler.getKey())) {
|
||||
wateringCan.trigger(ActionTrigger.WRONG_SPRINKLER, state);
|
||||
return FunctionResult.RETURN;
|
||||
}
|
||||
// get water in can
|
||||
int waterInCan = wateringCan.getCurrentWater(itemInHand);
|
||||
|
||||
// check sprinkler requirements
|
||||
if (!RequirementManager.isRequirementMet(state, sprinkler.getUseRequirements())) {
|
||||
return FunctionResult.RETURN;
|
||||
}
|
||||
// check whitelist
|
||||
if (!wateringCan.getSprinklerWhitelist().contains(sprinkler.getKey())) {
|
||||
wateringCan.trigger(ActionTrigger.WRONG_SPRINKLER, state);
|
||||
return FunctionResult.RETURN;
|
||||
}
|
||||
// check amount of water
|
||||
if (waterInCan > 0 || wateringCan.isInfinite()) {
|
||||
// get sprinkler data
|
||||
SimpleLocation simpleLocation = SimpleLocation.of(clicked);
|
||||
Optional<WorldSprinkler> worldSprinkler = plugin.getWorldManager().getSprinklerAt(simpleLocation);
|
||||
if (worldSprinkler.isEmpty()) {
|
||||
plugin.debug("Player " + player.getName() + " tried to interact a sprinkler which not exists in memory. Fixing the data...");
|
||||
WorldSprinkler sp = new MemorySprinkler(simpleLocation, sprinkler.getKey(), 0);
|
||||
plugin.getWorldManager().addSprinklerAt(sp, simpleLocation);
|
||||
worldSprinkler = Optional.of(sp);
|
||||
} else {
|
||||
if (sprinkler.getStorage() <= worldSprinkler.get().getWater()) {
|
||||
return FunctionResult.RETURN;
|
||||
}
|
||||
}
|
||||
|
||||
// fire the event
|
||||
WateringCanWaterEvent waterEvent = new WateringCanWaterEvent(player, itemInHand, new HashSet<>(Set.of(clicked)), wateringCan, worldSprinkler.get());
|
||||
if (EventUtils.fireAndCheckCancel(waterEvent))
|
||||
return FunctionResult.CANCEL_EVENT_AND_RETURN;
|
||||
|
||||
state.setArg("{storage}", String.valueOf(wateringCan.getStorage()));
|
||||
state.setArg("{current}", String.valueOf(waterInCan - 1));
|
||||
state.setArg("{water_bar}", wateringCan.getWaterBar() == null ? "" : wateringCan.getWaterBar().getWaterBar(waterInCan - 1, wateringCan.getStorage()));
|
||||
wateringCan.updateItem(player, itemInHand, waterInCan - 1, state.getArgs());
|
||||
wateringCan.trigger(ActionTrigger.CONSUME_WATER, state);
|
||||
plugin.getWorldManager().addWaterToSprinkler(sprinkler, simpleLocation, 1);
|
||||
} else {
|
||||
state.setArg("{storage}", String.valueOf(wateringCan.getStorage()));
|
||||
state.setArg("{current}", "0");
|
||||
state.setArg("{water_bar}", wateringCan.getWaterBar() == null ? "" : wateringCan.getWaterBar().getWaterBar(0, wateringCan.getStorage()));
|
||||
wateringCan.trigger(ActionTrigger.NO_WATER, state);
|
||||
}
|
||||
return FunctionResult.RETURN;
|
||||
}, CFunction.FunctionPriority.HIGH),
|
||||
/*
|
||||
* Handle clicking pot with a watering can
|
||||
*/
|
||||
@@ -893,6 +966,9 @@ public class ItemManagerImpl implements ItemManager {
|
||||
}
|
||||
return FunctionResult.RETURN;
|
||||
}, CFunction.FunctionPriority.NORMAL),
|
||||
/*
|
||||
* Handle clicking crop with a watering can
|
||||
*/
|
||||
new CFunction(conditionWrapper -> {
|
||||
if (!(conditionWrapper instanceof InteractFurnitureWrapper furnitureWrapper)) {
|
||||
return FunctionResult.PASS;
|
||||
@@ -1316,12 +1392,12 @@ public class ItemManagerImpl implements ItemManager {
|
||||
* Interact the sprinkler
|
||||
*/
|
||||
new CFunction(conditionWrapper -> {
|
||||
if (!(conditionWrapper instanceof InteractFurnitureWrapper interactFurnitureWrapper)) {
|
||||
if (!(conditionWrapper instanceof InteractWrapper interactWrapper)) {
|
||||
return FunctionResult.PASS;
|
||||
}
|
||||
ItemStack itemInHand = interactFurnitureWrapper.getItemInHand();
|
||||
Player player = interactFurnitureWrapper.getPlayer();
|
||||
Location location = interactFurnitureWrapper.getLocation();
|
||||
ItemStack itemInHand = interactWrapper.getItemInHand();
|
||||
Player player = interactWrapper.getPlayer();
|
||||
Location location = interactWrapper.getLocation();
|
||||
// check use requirements
|
||||
State state = new State(player, itemInHand, location);
|
||||
if (!RequirementManager.isRequirementMet(state, sprinkler.getUseRequirements())) {
|
||||
@@ -1381,6 +1457,7 @@ public class ItemManagerImpl implements ItemManager {
|
||||
state.setArg("{current}", String.valueOf(sprinkler.getStorage()));
|
||||
state.setArg("{water_bar}", sprinkler.getWaterBar() == null ? "" : sprinkler.getWaterBar().getWaterBar(sprinkler.getStorage(), sprinkler.getStorage()));
|
||||
sprinkler.trigger(ActionTrigger.FULL, state);
|
||||
return FunctionResult.CANCEL_EVENT_AND_RETURN;
|
||||
}
|
||||
}
|
||||
return FunctionResult.RETURN;
|
||||
@@ -1394,14 +1471,14 @@ public class ItemManagerImpl implements ItemManager {
|
||||
|
||||
this.registerItemFunction(new String[]{sprinkler.get3DItemID(), sprinkler.get3DItemWithWater()}, FunctionTrigger.BE_INTERACTED,
|
||||
new CFunction(conditionWrapper -> {
|
||||
if (!(conditionWrapper instanceof InteractFurnitureWrapper interactFurnitureWrapper)) {
|
||||
if (!(conditionWrapper instanceof InteractWrapper interactWrapper)) {
|
||||
return FunctionResult.PASS;
|
||||
}
|
||||
|
||||
Location location = interactFurnitureWrapper.getLocation();
|
||||
Location location = interactWrapper.getLocation();
|
||||
// trigger interact actions
|
||||
plugin.getScheduler().runTaskSyncLater(() -> {
|
||||
State state = new State(interactFurnitureWrapper.getPlayer(), interactFurnitureWrapper.getItemInHand(), location);
|
||||
State state = new State(interactWrapper.getPlayer(), interactWrapper.getItemInHand(), location);
|
||||
Optional<WorldSprinkler> optionalSprinkler = plugin.getWorldManager().getSprinklerAt(SimpleLocation.of(location));
|
||||
if (optionalSprinkler.isEmpty()) {
|
||||
return;
|
||||
@@ -2071,6 +2148,7 @@ public class ItemManagerImpl implements ItemManager {
|
||||
plugin.getWorldManager().addWaterToPot(pot, simpleLocation, method.getAmount());
|
||||
} else {
|
||||
pot.trigger(ActionTrigger.FULL, state);
|
||||
return FunctionResult.CANCEL_EVENT_AND_RETURN;
|
||||
}
|
||||
}
|
||||
return FunctionResult.RETURN;
|
||||
|
||||
@@ -145,9 +145,15 @@ public abstract class AbstractCustomListener implements Listener {
|
||||
|
||||
@EventHandler (ignoreCancelled = true)
|
||||
public void onPlaceBlock(BlockPlaceEvent event) {
|
||||
onPlaceBlock(
|
||||
final Block block = event.getBlock();
|
||||
// prevent players from placing blocks on entities (crops/sprinklers)
|
||||
if (CustomCropsPlugin.get().getWorldManager().getBlockAt(SimpleLocation.of(block.getLocation())).isPresent()) {
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
this.onPlaceBlock(
|
||||
event.getPlayer(),
|
||||
event.getBlock(),
|
||||
block,
|
||||
event.getBlockPlaced().getType().name(),
|
||||
event
|
||||
);
|
||||
|
||||
@@ -146,11 +146,6 @@ public class RequirementManagerImpl implements RequirementManager {
|
||||
return requirements.toArray(new Requirement[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasRequirement(String type) {
|
||||
return requirementBuilderMap.containsKey(type);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Requirement getRequirement(ConfigurationSection section, boolean advanced) {
|
||||
|
||||
@@ -276,6 +276,11 @@ public class CWorld implements CustomCropsWorld {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteChunk(ChunkPos chunkPos) {
|
||||
CChunk chunk = loadedChunks.remove(chunkPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInfoData(WorldInfoData infoData) {
|
||||
this.infoData = infoData;
|
||||
|
||||
Reference in New Issue
Block a user