diff --git a/api/src/main/java/net/momirealms/customcrops/api/common/Initable.java b/api/src/main/java/net/momirealms/customcrops/api/common/Initable.java index 792ce4e..15ff32b 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/common/Initable.java +++ b/api/src/main/java/net/momirealms/customcrops/api/common/Initable.java @@ -19,7 +19,13 @@ package net.momirealms.customcrops.api.common; public interface Initable { + /** + * init + */ void init(); + /** + * disable + */ void disable(); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/common/Property.java b/api/src/main/java/net/momirealms/customcrops/api/common/Property.java deleted file mode 100644 index f75361b..0000000 --- a/api/src/main/java/net/momirealms/customcrops/api/common/Property.java +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (C) <2022> - * - * 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 . - */ - -package net.momirealms.customcrops.api.common; - -public interface Property { - T get(); - void set(T value); -} \ No newline at end of file diff --git a/api/src/main/java/net/momirealms/customcrops/api/common/item/EventItem.java b/api/src/main/java/net/momirealms/customcrops/api/common/item/EventItem.java index 9910df0..8ef98ab 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/common/item/EventItem.java +++ b/api/src/main/java/net/momirealms/customcrops/api/common/item/EventItem.java @@ -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); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/common/item/KeyItem.java b/api/src/main/java/net/momirealms/customcrops/api/common/item/KeyItem.java index 18b3448..92d06af 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/common/item/KeyItem.java +++ b/api/src/main/java/net/momirealms/customcrops/api/common/item/KeyItem.java @@ -19,5 +19,10 @@ package net.momirealms.customcrops.api.common.item; public interface KeyItem { + /** + * Get item's key + * + * @return key + */ String getKey(); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/event/BoneMealDispenseEvent.java b/api/src/main/java/net/momirealms/customcrops/api/event/BoneMealDispenseEvent.java index 8d2ca69..ed4ed54 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/event/BoneMealDispenseEvent.java +++ b/api/src/main/java/net/momirealms/customcrops/api/event/BoneMealDispenseEvent.java @@ -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; diff --git a/api/src/main/java/net/momirealms/customcrops/api/event/BoneMealUseEvent.java b/api/src/main/java/net/momirealms/customcrops/api/event/BoneMealUseEvent.java index 2c0e4ef..6216a37 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/event/BoneMealUseEvent.java +++ b/api/src/main/java/net/momirealms/customcrops/api/event/BoneMealUseEvent.java @@ -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; diff --git a/api/src/main/java/net/momirealms/customcrops/api/event/CropBreakEvent.java b/api/src/main/java/net/momirealms/customcrops/api/event/CropBreakEvent.java index 80791f5..9a2bb76 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/event/CropBreakEvent.java +++ b/api/src/main/java/net/momirealms/customcrops/api/event/CropBreakEvent.java @@ -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; diff --git a/api/src/main/java/net/momirealms/customcrops/api/event/CropInteractEvent.java b/api/src/main/java/net/momirealms/customcrops/api/event/CropInteractEvent.java index 4f1fe41..8e55b85 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/event/CropInteractEvent.java +++ b/api/src/main/java/net/momirealms/customcrops/api/event/CropInteractEvent.java @@ -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 diff --git a/api/src/main/java/net/momirealms/customcrops/api/event/CropPlantEvent.java b/api/src/main/java/net/momirealms/customcrops/api/event/CropPlantEvent.java index 2d55ab1..3b04f9d 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/event/CropPlantEvent.java +++ b/api/src/main/java/net/momirealms/customcrops/api/event/CropPlantEvent.java @@ -64,6 +64,7 @@ public class CropPlantEvent extends PlayerEvent implements Cancellable { /** * Get the seed item + * * @return seed item */ @NotNull diff --git a/api/src/main/java/net/momirealms/customcrops/api/event/FertilizerUseEvent.java b/api/src/main/java/net/momirealms/customcrops/api/event/FertilizerUseEvent.java index 2154799..4376d9c 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/event/FertilizerUseEvent.java +++ b/api/src/main/java/net/momirealms/customcrops/api/event/FertilizerUseEvent.java @@ -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; diff --git a/api/src/main/java/net/momirealms/customcrops/api/event/GreenhouseGlassBreakEvent.java b/api/src/main/java/net/momirealms/customcrops/api/event/GreenhouseGlassBreakEvent.java index 1423b54..9a5c8bf 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/event/GreenhouseGlassBreakEvent.java +++ b/api/src/main/java/net/momirealms/customcrops/api/event/GreenhouseGlassBreakEvent.java @@ -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; diff --git a/api/src/main/java/net/momirealms/customcrops/api/event/GreenhouseGlassPlaceEvent.java b/api/src/main/java/net/momirealms/customcrops/api/event/GreenhouseGlassPlaceEvent.java index 59cc4f6..f161335 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/event/GreenhouseGlassPlaceEvent.java +++ b/api/src/main/java/net/momirealms/customcrops/api/event/GreenhouseGlassPlaceEvent.java @@ -64,6 +64,7 @@ public class GreenhouseGlassPlaceEvent extends PlayerEvent implements Cancellabl /** * Get the glass location + * * @return location */ @NotNull diff --git a/api/src/main/java/net/momirealms/customcrops/api/event/PotBreakEvent.java b/api/src/main/java/net/momirealms/customcrops/api/event/PotBreakEvent.java index a0ea77b..a5cbb08 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/event/PotBreakEvent.java +++ b/api/src/main/java/net/momirealms/customcrops/api/event/PotBreakEvent.java @@ -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 diff --git a/api/src/main/java/net/momirealms/customcrops/api/event/PotFillEvent.java b/api/src/main/java/net/momirealms/customcrops/api/event/PotFillEvent.java index 1319608..7a947e7 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/event/PotFillEvent.java +++ b/api/src/main/java/net/momirealms/customcrops/api/event/PotFillEvent.java @@ -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; diff --git a/api/src/main/java/net/momirealms/customcrops/api/event/PotInteractEvent.java b/api/src/main/java/net/momirealms/customcrops/api/event/PotInteractEvent.java index 52b947a..f1f5c65 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/event/PotInteractEvent.java +++ b/api/src/main/java/net/momirealms/customcrops/api/event/PotInteractEvent.java @@ -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 diff --git a/api/src/main/java/net/momirealms/customcrops/api/event/PotPlaceEvent.java b/api/src/main/java/net/momirealms/customcrops/api/event/PotPlaceEvent.java index 875b1e3..4f8570f 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/event/PotPlaceEvent.java +++ b/api/src/main/java/net/momirealms/customcrops/api/event/PotPlaceEvent.java @@ -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 diff --git a/api/src/main/java/net/momirealms/customcrops/api/event/ScarecrowBreakEvent.java b/api/src/main/java/net/momirealms/customcrops/api/event/ScarecrowBreakEvent.java index 57e412d..d9a2a00 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/event/ScarecrowBreakEvent.java +++ b/api/src/main/java/net/momirealms/customcrops/api/event/ScarecrowBreakEvent.java @@ -75,6 +75,7 @@ public class ScarecrowBreakEvent extends Event implements Cancellable { /** * Get the scarecrow location + * * @return location */ @NotNull diff --git a/api/src/main/java/net/momirealms/customcrops/api/event/ScarecrowPlaceEvent.java b/api/src/main/java/net/momirealms/customcrops/api/event/ScarecrowPlaceEvent.java index b65a4bc..981aa8b 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/event/ScarecrowPlaceEvent.java +++ b/api/src/main/java/net/momirealms/customcrops/api/event/ScarecrowPlaceEvent.java @@ -64,6 +64,7 @@ public class ScarecrowPlaceEvent extends PlayerEvent implements Cancellable { /** * Get the scarecrow location + * * @return location */ @NotNull diff --git a/api/src/main/java/net/momirealms/customcrops/api/event/SeasonChangeEvent.java b/api/src/main/java/net/momirealms/customcrops/api/event/SeasonChangeEvent.java index dfc4641..6a67aa1 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/event/SeasonChangeEvent.java +++ b/api/src/main/java/net/momirealms/customcrops/api/event/SeasonChangeEvent.java @@ -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() { diff --git a/api/src/main/java/net/momirealms/customcrops/api/event/SprinklerBreakEvent.java b/api/src/main/java/net/momirealms/customcrops/api/event/SprinklerBreakEvent.java index 586be8f..34c797c 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/event/SprinklerBreakEvent.java +++ b/api/src/main/java/net/momirealms/customcrops/api/event/SprinklerBreakEvent.java @@ -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 diff --git a/api/src/main/java/net/momirealms/customcrops/api/event/SprinklerFillEvent.java b/api/src/main/java/net/momirealms/customcrops/api/event/SprinklerFillEvent.java index 56db0f7..32a26a2 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/event/SprinklerFillEvent.java +++ b/api/src/main/java/net/momirealms/customcrops/api/event/SprinklerFillEvent.java @@ -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; diff --git a/api/src/main/java/net/momirealms/customcrops/api/event/SprinklerInteractEvent.java b/api/src/main/java/net/momirealms/customcrops/api/event/SprinklerInteractEvent.java index f8ae29d..d671fe3 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/event/SprinklerInteractEvent.java +++ b/api/src/main/java/net/momirealms/customcrops/api/event/SprinklerInteractEvent.java @@ -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 diff --git a/api/src/main/java/net/momirealms/customcrops/api/event/SprinklerPlaceEvent.java b/api/src/main/java/net/momirealms/customcrops/api/event/SprinklerPlaceEvent.java index dec4943..d1469d8 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/event/SprinklerPlaceEvent.java +++ b/api/src/main/java/net/momirealms/customcrops/api/event/SprinklerPlaceEvent.java @@ -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 diff --git a/api/src/main/java/net/momirealms/customcrops/api/event/WateringCanFillEvent.java b/api/src/main/java/net/momirealms/customcrops/api/event/WateringCanFillEvent.java index 4275aee..9c4e3a3 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/event/WateringCanFillEvent.java +++ b/api/src/main/java/net/momirealms/customcrops/api/event/WateringCanFillEvent.java @@ -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; diff --git a/api/src/main/java/net/momirealms/customcrops/api/event/WateringCanWaterEvent.java b/api/src/main/java/net/momirealms/customcrops/api/event/WateringCanWaterEvent.java index 37b8e30..20efead 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/event/WateringCanWaterEvent.java +++ b/api/src/main/java/net/momirealms/customcrops/api/event/WateringCanWaterEvent.java @@ -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 getLocation() { return location; } + /** + * Get the pot/sprinkler's data + * + * @return data + */ @NotNull public CustomCropsBlock getPotOrSprinkler() { return potOrSprinkler; diff --git a/api/src/main/java/net/momirealms/customcrops/api/integration/ItemLibrary.java b/api/src/main/java/net/momirealms/customcrops/api/integration/ItemLibrary.java index 0293d59..66a49b0 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/integration/ItemLibrary.java +++ b/api/src/main/java/net/momirealms/customcrops/api/integration/ItemLibrary.java @@ -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); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/manager/ActionManager.java b/api/src/main/java/net/momirealms/customcrops/api/manager/ActionManager.java index 2e94c26..47d4b34 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/manager/ActionManager.java +++ b/api/src/main/java/net/momirealms/customcrops/api/manager/ActionManager.java @@ -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 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) diff --git a/api/src/main/java/net/momirealms/customcrops/api/manager/ConditionManager.java b/api/src/main/java/net/momirealms/customcrops/api/manager/ConditionManager.java index 59c0b70..91ce5a1 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/manager/ConditionManager.java +++ b/api/src/main/java/net/momirealms/customcrops/api/manager/ConditionManager.java @@ -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) { diff --git a/api/src/main/java/net/momirealms/customcrops/api/manager/IntegrationManager.java b/api/src/main/java/net/momirealms/customcrops/api/manager/IntegrationManager.java index b983eb8..aa2e90f 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/manager/IntegrationManager.java +++ b/api/src/main/java/net/momirealms/customcrops/api/manager/IntegrationManager.java @@ -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); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/manager/ItemManager.java b/api/src/main/java/net/momirealms/customcrops/api/manager/ItemManager.java index a1708df..f57ae6b 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/manager/ItemManager.java +++ b/api/src/main/java/net/momirealms/customcrops/api/manager/ItemManager.java @@ -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); diff --git a/api/src/main/java/net/momirealms/customcrops/api/manager/RequirementManager.java b/api/src/main/java/net/momirealms/customcrops/api/manager/RequirementManager.java index dc6eabe..b4f6efb 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/manager/RequirementManager.java +++ b/api/src/main/java/net/momirealms/customcrops/api/manager/RequirementManager.java @@ -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; } } diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/CustomCropsWorld.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/CustomCropsWorld.java index ab70de7..523908f 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/CustomCropsWorld.java +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/world/level/CustomCropsWorld.java @@ -68,6 +68,8 @@ public interface CustomCropsWorld { void unloadChunk(ChunkPos chunkPos); + void deleteChunk(ChunkPos chunkPos); + void setInfoData(WorldInfoData infoData); WorldInfoData getInfoData(); diff --git a/build.gradle.kts b/build.gradle.kts index c773d22..5e62fbf 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ plugins { allprojects { project.group = "net.momirealms" - project.version = "3.4.4.3" + project.version = "3.4.4.4" apply() apply(plugin = "java") diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts index 825bbba..28e6696 100644 --- a/plugin/build.gradle.kts +++ b/plugin/build.gradle.kts @@ -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") diff --git a/plugin/src/main/java/net/momirealms/customcrops/CustomCropsPluginImpl.java b/plugin/src/main/java/net/momirealms/customcrops/CustomCropsPluginImpl.java index afbc139..3d7e1ed 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/CustomCropsPluginImpl.java +++ b/plugin/src/main/java/net/momirealms/customcrops/CustomCropsPluginImpl.java @@ -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(); diff --git a/plugin/src/main/java/net/momirealms/customcrops/compatibility/IntegrationManagerImpl.java b/plugin/src/main/java/net/momirealms/customcrops/compatibility/IntegrationManagerImpl.java index 02d585c..1243e73 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/compatibility/IntegrationManagerImpl.java +++ b/plugin/src/main/java/net/momirealms/customcrops/compatibility/IntegrationManagerImpl.java @@ -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); - } } diff --git a/plugin/src/main/java/net/momirealms/customcrops/compatibility/level/AureliumSkillsImpl.java b/plugin/src/main/java/net/momirealms/customcrops/compatibility/level/AureliumSkillsImpl.java index e81cc86..b9eb4bb 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/compatibility/level/AureliumSkillsImpl.java +++ b/plugin/src/main/java/net/momirealms/customcrops/compatibility/level/AureliumSkillsImpl.java @@ -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; diff --git a/plugin/src/main/java/net/momirealms/customcrops/compatibility/papi/CCPapi.java b/plugin/src/main/java/net/momirealms/customcrops/compatibility/papi/CCPapi.java index caff5e2..1150848 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/compatibility/papi/CCPapi.java +++ b/plugin/src/main/java/net/momirealms/customcrops/compatibility/papi/CCPapi.java @@ -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(); diff --git a/plugin/src/main/java/net/momirealms/customcrops/manager/CommandManager.java b/plugin/src/main/java/net/momirealms/customcrops/manager/CommandManager.java index 67a71dd..8077944 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/manager/CommandManager.java +++ b/plugin/src/main/java/net/momirealms/customcrops/manager/CommandManager.java @@ -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, "This chunk doesn't have any data."); + return; + } + customCropsWorld.deleteChunk(ChunkPos.getByBukkitChunk(player.getChunk())); + AdventureManager.getInstance().sendMessageWithPrefix(player, "Done."); + }); + }) + ); + } + private CommandAPICommand getAboutCommand() { return new CommandAPICommand("about").executes((sender, args) -> { plugin.getAdventure().sendMessage(sender, "<#FFA500>⛈ CustomCrops - <#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 -> { diff --git a/plugin/src/main/java/net/momirealms/customcrops/mechanic/condition/ConditionManagerImpl.java b/plugin/src/main/java/net/momirealms/customcrops/mechanic/condition/ConditionManagerImpl.java index 19356a7..597c8c0 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/mechanic/condition/ConditionManagerImpl.java +++ b/plugin/src/main/java/net/momirealms/customcrops/mechanic/condition/ConditionManagerImpl.java @@ -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 conditions = new ArrayList<>(); @@ -578,7 +573,7 @@ public class ConditionManagerImpl implements ConditionManager { registerCondition("suitable_season", (args) -> { HashSet 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 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; } diff --git a/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/ItemManagerImpl.java b/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/ItemManagerImpl.java index 5899528..1bc8b2a 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/ItemManagerImpl.java +++ b/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/ItemManagerImpl.java @@ -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 = 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 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; diff --git a/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/custom/AbstractCustomListener.java b/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/custom/AbstractCustomListener.java index 6a27fef..5f20cb7 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/custom/AbstractCustomListener.java +++ b/plugin/src/main/java/net/momirealms/customcrops/mechanic/item/custom/AbstractCustomListener.java @@ -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 ); diff --git a/plugin/src/main/java/net/momirealms/customcrops/mechanic/requirement/RequirementManagerImpl.java b/plugin/src/main/java/net/momirealms/customcrops/mechanic/requirement/RequirementManagerImpl.java index 1e0ee34..2756161 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/mechanic/requirement/RequirementManagerImpl.java +++ b/plugin/src/main/java/net/momirealms/customcrops/mechanic/requirement/RequirementManagerImpl.java @@ -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) { diff --git a/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/CWorld.java b/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/CWorld.java index a43884d..9211296 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/CWorld.java +++ b/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/CWorld.java @@ -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;