From 139cd9649d07dfd70af87da36c9579928978c7de Mon Sep 17 00:00:00 2001 From: XiaoMoMi <70987828+Xiao-MoMi@users.noreply.github.com> Date: Sun, 1 Sep 2024 01:39:51 +0800 Subject: [PATCH] implement watering can --- .../customcrops/api/context/ContextKeys.java | 3 + .../api/core/AbstractCustomEventListener.java | 3 +- .../customcrops/api/core/ConfigManager.java | 2 +- .../api/core/InteractionResult.java | 3 +- .../customcrops/api/core/ItemManager.java | 3 +- .../customcrops/api/core/Registries.java | 1 + .../api/core/SynchronizedCompoundMap.java | 2 +- .../customcrops/api/core/block/BoneMeal.java | 2 +- .../customcrops/api/core/block/CropBlock.java | 10 +- .../api/core/block/CrowAttack.java | 2 +- .../customcrops/api/core/block/PotBlock.java | 13 +- .../api/core/block/VariationData.java | 2 +- .../api/core/item/FertilizerItem.java | 16 +-- .../api/core/item/FertilizerType.java | 2 +- .../customcrops/api/core/item/SeedItem.java | 40 +++--- .../api/core/item/SprinklerItem.java | 10 +- .../api/core/item/WateringCanItem.java | 121 +++++++++++------- .../customcrops/api/core/world/BlockPos.java | 2 +- .../customcrops/api/core/world/ChunkPos.java | 2 +- .../api/core/world/CustomCropsChunk.java | 2 +- .../api/core/world/CustomCropsRegion.java | 2 +- .../api/core/world/CustomCropsSection.java | 2 +- .../api/core/world/CustomCropsWorld.java | 2 +- .../customcrops/api/core/world/DataBlock.java | 2 +- .../api/core/world/DelayedTickTask.java | 2 +- .../customcrops/api/core/world/RegionPos.java | 2 +- .../customcrops/api/core/world/Season.java | 2 +- .../api/core/world/SerializableChunk.java | 2 +- .../api/core/world/SerializableSection.java | 2 +- .../api/core/world/WorldExtraData.java | 2 +- .../api/core/world/WorldSetting.java | 2 +- .../api/event/BoneMealUseEvent.java | 2 +- .../customcrops/api/event/CropBreakEvent.java | 2 +- .../api/event/CropInteractEvent.java | 2 +- .../customcrops/api/event/CropPlantEvent.java | 2 +- .../api/event/FertilizerUseEvent.java | 2 +- .../api/event/GreenhouseGlassBreakEvent.java | 2 +- .../event/GreenhouseGlassInteractEvent.java | 2 +- .../api/event/GreenhouseGlassPlaceEvent.java | 2 +- .../customcrops/api/event/PotBreakEvent.java | 2 +- .../customcrops/api/event/PotFillEvent.java | 2 +- .../api/event/PotInteractEvent.java | 2 +- .../customcrops/api/event/PotPlaceEvent.java | 2 +- .../api/event/ScarecrowBreakEvent.java | 2 +- .../api/event/ScarecrowInteractEvent.java | 2 +- .../api/event/ScarecrowPlaceEvent.java | 2 +- .../api/event/SprinklerBreakEvent.java | 2 +- .../api/event/SprinklerFillEvent.java | 2 +- .../api/event/SprinklerInteractEvent.java | 2 +- .../api/event/SprinklerPlaceEvent.java | 2 +- .../api/event/WateringCanFillEvent.java | 2 +- .../api/event/WateringCanWaterPotEvent.java | 2 +- .../event/WateringCanWaterSprinklerEvent.java | 2 +- .../api/misc/water/AbstractMethod.java | 2 +- .../api/misc/water/FillMethod.java | 2 +- .../customcrops/api/misc/water/WaterBar.java | 2 +- .../api/misc/water/WateringMethod.java | 2 +- build.gradle.kts | 21 ++- .../bukkit/config/BukkitConfigManager.java | 1 + .../customcrops/bukkit/config/ConfigType.java | 4 +- .../bukkit/item/BukkitItemManager.java | 13 +- .../bukkit/misc/HologramManager.java | 2 +- 62 files changed, 210 insertions(+), 146 deletions(-) diff --git a/api/src/main/java/net/momirealms/customcrops/api/context/ContextKeys.java b/api/src/main/java/net/momirealms/customcrops/api/context/ContextKeys.java index 9c69bb4..da123e3 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/context/ContextKeys.java +++ b/api/src/main/java/net/momirealms/customcrops/api/context/ContextKeys.java @@ -30,6 +30,9 @@ import java.util.Objects; public class ContextKeys { public static final ContextKeys LOCATION = of("location", Location.class); + public static final ContextKeys WATER_BAR = of("water_bar", String.class); + public static final ContextKeys CURRENT_WATER = of("current", Integer.class); + public static final ContextKeys STORAGE = of("storage", Integer.class); public static final ContextKeys X = of("x", Integer.class); public static final ContextKeys Y = of("y", Integer.class); public static final ContextKeys Z = of("z", Integer.class); diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/AbstractCustomEventListener.java b/api/src/main/java/net/momirealms/customcrops/api/core/AbstractCustomEventListener.java index 172f783..58f57d2 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/AbstractCustomEventListener.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/AbstractCustomEventListener.java @@ -69,7 +69,8 @@ public abstract class AbstractCustomEventListener implements Listener { return; this.itemManager.handlePlayerInteractAir( event.getPlayer(), - event.getHand(), event.getItem() + event.getHand(), + event.getItem() ); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/ConfigManager.java b/api/src/main/java/net/momirealms/customcrops/api/core/ConfigManager.java index 915614c..7d03bc5 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/ConfigManager.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/ConfigManager.java @@ -57,7 +57,7 @@ public abstract class ConfigManager implements ConfigLoader, Reloadable { protected boolean syncSeasons; protected String referenceWorld; - protected String[] itemDetectOrder; + protected String[] itemDetectOrder = new String[0]; protected double[] defaultQualityRatio; diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/InteractionResult.java b/api/src/main/java/net/momirealms/customcrops/api/core/InteractionResult.java index 8c5c86b..8cf408a 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/InteractionResult.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/InteractionResult.java @@ -19,7 +19,6 @@ package net.momirealms.customcrops.api.core; public enum InteractionResult { - SUCCESS, - FAIL, + COMPLETE, PASS } diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/ItemManager.java b/api/src/main/java/net/momirealms/customcrops/api/core/ItemManager.java index e667237..41bfacc 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/ItemManager.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/ItemManager.java @@ -18,6 +18,7 @@ package net.momirealms.customcrops.api.core; import net.momirealms.customcrops.common.item.Item; +import net.momirealms.customcrops.common.plugin.feature.Reloadable; import org.bukkit.Location; import org.bukkit.block.Block; import org.bukkit.entity.Entity; @@ -26,7 +27,7 @@ import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -public interface ItemManager { +public interface ItemManager extends Reloadable { void place(@NotNull Location location, @NotNull ExistenceForm form, @NotNull String id, FurnitureRotation rotation); diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/Registries.java b/api/src/main/java/net/momirealms/customcrops/api/core/Registries.java index d189432..d9a7884 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/Registries.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/Registries.java @@ -56,4 +56,5 @@ public class Registries { public static final ClearableRegistry ITEM_TO_FERTILIZER = new ClearableMappedRegistry<>(Key.key("fast_lookup", "item_to_fertilizer")); public static final ClearableRegistry ITEM_TO_POT = new ClearableMappedRegistry<>(Key.key("fast_lookup", "item_to_pot")); public static final ClearableRegistry ITEM_TO_SPRINKLER = new ClearableMappedRegistry<>(Key.key("fast_lookup", "item_to_sprinkler")); + public static final ClearableRegistry ITEM_TO_WATERING_CAN = new ClearableMappedRegistry<>(Key.key("fast_lookup", "item_to_wateringcan")); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/SynchronizedCompoundMap.java b/api/src/main/java/net/momirealms/customcrops/api/core/SynchronizedCompoundMap.java index 55fd979..e0a3dbf 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/SynchronizedCompoundMap.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/SynchronizedCompoundMap.java @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/block/BoneMeal.java b/api/src/main/java/net/momirealms/customcrops/api/core/block/BoneMeal.java index 2dc206d..d74f05f 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/block/BoneMeal.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/block/BoneMeal.java @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/block/CropBlock.java b/api/src/main/java/net/momirealms/customcrops/api/core/block/CropBlock.java index 616d490..4b74f9a 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/block/CropBlock.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/block/CropBlock.java @@ -21,6 +21,7 @@ import com.flowpowered.nbt.IntTag; import net.momirealms.customcrops.api.BukkitCustomCropsPlugin; import net.momirealms.customcrops.api.action.ActionManager; import net.momirealms.customcrops.api.context.Context; +import net.momirealms.customcrops.api.context.ContextKeys; import net.momirealms.customcrops.api.core.*; import net.momirealms.customcrops.api.core.item.Fertilizer; import net.momirealms.customcrops.api.core.item.FertilizerConfig; @@ -35,6 +36,7 @@ import net.momirealms.customcrops.api.event.CropBreakEvent; import net.momirealms.customcrops.api.event.CropInteractEvent; import net.momirealms.customcrops.api.requirement.RequirementManager; import net.momirealms.customcrops.api.util.EventUtils; +import net.momirealms.customcrops.api.util.LocationUtils; import net.momirealms.customcrops.api.util.PlayerUtils; import org.bukkit.GameMode; import org.bukkit.Location; @@ -185,6 +187,7 @@ public class CropBlock extends AbstractCustomCropsBlock { String blockBelowID = BukkitCustomCropsPlugin.getInstance().getItemManager().blockID(potLocation.getBlock()); PotConfig potConfig = Registries.ITEM_TO_POT.get(blockBelowID); if (potConfig != null) { + context.arg(ContextKeys.LOCATION, LocationUtils.toBlockLocation(potLocation)); PotBlock potBlock = (PotBlock) BuiltInBlockMechanics.POT.mechanic(); assert potBlock != null; // fix or get data @@ -193,6 +196,7 @@ public class CropBlock extends AbstractCustomCropsBlock { return; } + context.arg(ContextKeys.LOCATION, LocationUtils.toBlockLocation(location)); if (point < cropConfig.maxPoints()) { for (BoneMeal boneMeal : cropConfig.boneMeals()) { if (boneMeal.requiredItem().equals(event.itemID()) && boneMeal.amountOfRequiredItem() <= itemInHand.getAmount()) { @@ -231,6 +235,7 @@ public class CropBlock extends AbstractCustomCropsBlock { Objects.requireNonNull(afterStage); Context blockContext = Context.block(state); + blockContext.arg(ContextKeys.LOCATION, LocationUtils.toBlockLocation(location)); for (int i = point + 1; i <= afterPoints; i++) { CropStageConfig stage = cropConfig.stageByPoint(i); if (stage != null) { @@ -307,9 +312,10 @@ public class CropBlock extends AbstractCustomCropsBlock { } Context context = Context.block(state); + Location bukkitLocation = location.toLocation(bukkitWorld); + context.arg(ContextKeys.LOCATION, bukkitLocation); for (DeathCondition deathCondition : config.deathConditions()) { if (deathCondition.isMet(context)) { - Location bukkitLocation = location.toLocation(bukkitWorld); BukkitCustomCropsPlugin.getInstance().getScheduler().sync().runLater(() -> { FurnitureRotation rotation = BukkitCustomCropsPlugin.getInstance().getItemManager().remove(bukkitLocation, ExistenceForm.ANY); world.removeBlockState(location); @@ -375,8 +381,6 @@ public class CropBlock extends AbstractCustomCropsBlock { tempPoints = after.point() - 1; } - Location bukkitLocation = location.toLocation(bukkitWorld); - final String finalPreStage = preStage; final String finalAfterStage = afterStage; final ExistenceForm finalAfterForm = afterForm; diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/block/CrowAttack.java b/api/src/main/java/net/momirealms/customcrops/api/core/block/CrowAttack.java index cd06a01..bb95d4f 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/block/CrowAttack.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/block/CrowAttack.java @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/block/PotBlock.java b/api/src/main/java/net/momirealms/customcrops/api/core/block/PotBlock.java index 4a12594..82672f2 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/block/PotBlock.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/block/PotBlock.java @@ -21,6 +21,7 @@ import com.flowpowered.nbt.*; import net.momirealms.customcrops.api.BukkitCustomCropsPlugin; import net.momirealms.customcrops.api.action.ActionManager; import net.momirealms.customcrops.api.context.Context; +import net.momirealms.customcrops.api.context.ContextKeys; import net.momirealms.customcrops.api.core.*; import net.momirealms.customcrops.api.core.item.Fertilizer; import net.momirealms.customcrops.api.core.item.FertilizerConfig; @@ -34,6 +35,7 @@ import net.momirealms.customcrops.api.core.wrapper.WrappedPlaceEvent; import net.momirealms.customcrops.api.event.*; import net.momirealms.customcrops.api.requirement.RequirementManager; import net.momirealms.customcrops.api.util.EventUtils; +import net.momirealms.customcrops.api.util.LocationUtils; import net.momirealms.customcrops.api.util.PlayerUtils; import net.momirealms.customcrops.api.util.StringUtils; import org.bukkit.GameMode; @@ -220,6 +222,8 @@ public class PotBlock extends AbstractCustomCropsBlock { final Player player = event.player(); Context context = Context.player(player); + context.arg(ContextKeys.LOCATION, LocationUtils.toBlockLocation(location)); + // check use requirements if (!RequirementManager.isSatisfied(context, potConfig.useRequirements())) { return; @@ -258,6 +262,9 @@ public class PotBlock extends AbstractCustomCropsBlock { } } } + if (addWater(state, method.amountOfWater())) { + updateBlockAppearance(potLocation, potConfig, true, fertilizers(state)); + } method.triggerActions(context); ActionManager.trigger(context, potConfig.addWaterActions()); } @@ -361,7 +368,11 @@ public class PotBlock extends AbstractCustomCropsBlock { boolean fertilizerChanged = tickFertilizer(state); if (fertilizerChanged || waterChanged) { - updateBlockAppearance(location.toLocation(bukkitWorld), config, hasNaturalWater, fertilizers(state)); + boolean finalHasNaturalWater = hasNaturalWater; + Location bukkitLocation = location.toLocation(bukkitWorld); + BukkitCustomCropsPlugin.getInstance().getScheduler().sync().run(() -> { + updateBlockAppearance(bukkitLocation, config, finalHasNaturalWater, fertilizers(state)); + }, bukkitLocation); } } diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/block/VariationData.java b/api/src/main/java/net/momirealms/customcrops/api/core/block/VariationData.java index dd8f30c..8afd763 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/block/VariationData.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/block/VariationData.java @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/item/FertilizerItem.java b/api/src/main/java/net/momirealms/customcrops/api/core/item/FertilizerItem.java index 82bdfcb..10505bd 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/item/FertilizerItem.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/item/FertilizerItem.java @@ -53,7 +53,7 @@ public class FertilizerItem extends AbstractCustomCropsItem { public InteractionResult interactAt(WrappedInteractEvent event) { FertilizerConfig fertilizerConfig = Registries.FERTILIZER.get(event.itemID()); if (fertilizerConfig == null) { - return InteractionResult.FAIL; + return InteractionResult.COMPLETE; } final Player player = event.player(); @@ -77,14 +77,14 @@ public class FertilizerItem extends AbstractCustomCropsItem { // check pot whitelist if (!fertilizerConfig.whitelistPots().contains(potConfig.id())) { ActionManager.trigger(context, fertilizerConfig.wrongPotActions()); - return InteractionResult.FAIL; + return InteractionResult.COMPLETE; } // check requirements if (!RequirementManager.isSatisfied(context, fertilizerConfig.requirements())) { - return InteractionResult.FAIL; + return InteractionResult.COMPLETE; } if (!RequirementManager.isSatisfied(context, potConfig.useRequirements())) { - return InteractionResult.FAIL; + return InteractionResult.COMPLETE; } // check "before-plant" if (fertilizerConfig.beforePlant()) { @@ -94,7 +94,7 @@ public class FertilizerItem extends AbstractCustomCropsItem { CustomCropsBlockState blockState = state.get(); if (blockState.type() instanceof CropBlock) { ActionManager.trigger(context, fertilizerConfig.beforePlantActions()); - return InteractionResult.FAIL; + return InteractionResult.COMPLETE; } } } @@ -108,12 +108,12 @@ public class FertilizerItem extends AbstractCustomCropsItem { .build(); CustomCropsBlockState potState = potBlock.fixOrGetState(world, Pos3.from(targetLocation), potConfig, event.relatedID()); if (!potBlock.canApplyFertilizer(potState,fertilizer)) { - return InteractionResult.FAIL; + return InteractionResult.COMPLETE; } // trigger event FertilizerUseEvent useEvent = new FertilizerUseEvent(player, itemInHand, fertilizer, targetLocation, potState, event.hand(), potConfig); if (EventUtils.fireAndCheckCancel(useEvent)) - return InteractionResult.FAIL; + return InteractionResult.COMPLETE; // add the fertilizer if (potBlock.addFertilizer(potState, fertilizer)) { potBlock.updateBlockAppearance(targetLocation, potState, potBlock.fertilizers(potState)); @@ -122,7 +122,7 @@ public class FertilizerItem extends AbstractCustomCropsItem { itemInHand.setAmount(itemInHand.getAmount() - 1); } ActionManager.trigger(context, fertilizerConfig.useActions()); - return InteractionResult.SUCCESS; + return InteractionResult.COMPLETE; } return InteractionResult.PASS; diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/item/FertilizerType.java b/api/src/main/java/net/momirealms/customcrops/api/core/item/FertilizerType.java index 4642652..0868408 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/item/FertilizerType.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/item/FertilizerType.java @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/item/SeedItem.java b/api/src/main/java/net/momirealms/customcrops/api/core/item/SeedItem.java index 9cd844a..3ddb0f5 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/item/SeedItem.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/item/SeedItem.java @@ -45,12 +45,11 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import java.util.Collection; -import java.util.Map; public class SeedItem extends AbstractCustomCropsItem { public SeedItem() { - super(BuiltInBlockMechanics.CROP.key()); + super(BuiltInItemMechanics.SEED.key()); } @Override @@ -60,11 +59,10 @@ public class SeedItem extends AbstractCustomCropsItem { if (potConfig == null) return InteractionResult.PASS; // check if the crop exists CropConfig cropConfig = Registries.SEED_TO_CROP.get(event.itemID()); - if (cropConfig == null) return InteractionResult.FAIL; + if (cropConfig == null) return InteractionResult.COMPLETE; // check the block face if (event.clickedBlockFace() != BlockFace.UP) return InteractionResult.PASS; - final Player player = event.player(); Context context = Context.player(player); // check pot whitelist @@ -73,20 +71,21 @@ public class SeedItem extends AbstractCustomCropsItem { } // check plant requirements if (!RequirementManager.isSatisfied(context, cropConfig.plantRequirements())) { - return InteractionResult.FAIL; + return InteractionResult.COMPLETE; } // check if the block is empty - if (!suitableForSeed(event.location())) { - return InteractionResult.FAIL; + Location seedLocation = event.location().add(0, 1, 0); + if (!suitableForSeed(seedLocation)) { + return InteractionResult.COMPLETE; } CustomCropsWorld world = event.world(); - Location seedLocation = event.location().add(0, 1, 0); + Pos3 pos3 = Pos3.from(seedLocation); // check limitation if (world.setting().cropPerChunk() >= 0) { if (world.testChunkLimitation(pos3, CropBlock.class, world.setting().cropPerChunk())) { ActionManager.trigger(context, cropConfig.reachLimitActions()); - return InteractionResult.FAIL; + return InteractionResult.COMPLETE; } } final ItemStack itemInHand = event.itemInHand(); @@ -97,24 +96,17 @@ public class SeedItem extends AbstractCustomCropsItem { // trigger event CropPlantEvent plantEvent = new CropPlantEvent(player, itemInHand, event.hand(), seedLocation, cropConfig, state, 0); if (EventUtils.fireAndCheckCancel(plantEvent)) { - return InteractionResult.FAIL; + return InteractionResult.COMPLETE; } int point = plantEvent.getPoint(); - int temp = point; - ExistenceForm form = null; - String stageID = null; - while (temp >= 0) { - Map.Entry entry = cropConfig.getFloorStageEntry(temp); - CropStageConfig stageConfig = entry.getValue(); - if (stageConfig.stageID() != null) { - form = stageConfig.existenceForm(); - stageID = stageConfig.stageID(); - break; - } - temp = stageConfig.point() - 1; + CropStageConfig stageConfig = cropConfig.stageWithModelByPoint(point); + if (stageConfig == null) { + return InteractionResult.COMPLETE; } + String stageID = stageConfig.stageID(); + ExistenceForm form = stageConfig.existenceForm(); if (stageID == null || form == null) { - return InteractionResult.FAIL; + return InteractionResult.COMPLETE; } // reduce item if (player.getGameMode() != GameMode.CREATIVE) @@ -133,7 +125,7 @@ public class SeedItem extends AbstractCustomCropsItem { context.arg(ContextKeys.SLOT, event.hand()); // trigger plant actions ActionManager.trigger(context, cropConfig.plantActions()); - return InteractionResult.SUCCESS; + return InteractionResult.COMPLETE; } private boolean suitableForSeed(Location location) { diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/item/SprinklerItem.java b/api/src/main/java/net/momirealms/customcrops/api/core/item/SprinklerItem.java index 93cf1ca..96ecae8 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/item/SprinklerItem.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/item/SprinklerItem.java @@ -56,7 +56,7 @@ public class SprinklerItem extends AbstractCustomCropsItem { return InteractionResult.PASS; SprinklerConfig config = Registries.SPRINKLER.get(event.itemID()); if (config == null) { - return InteractionResult.FAIL; + return InteractionResult.COMPLETE; } Block clicked = event.location().getBlock(); @@ -79,7 +79,7 @@ public class SprinklerItem extends AbstractCustomCropsItem { Context context = Context.player(player); // check requirements if (!RequirementManager.isSatisfied(context, config.placeRequirements())) { - return InteractionResult.FAIL; + return InteractionResult.COMPLETE; } final CustomCropsWorld world = event.world(); @@ -88,7 +88,7 @@ public class SprinklerItem extends AbstractCustomCropsItem { if (world.setting().sprinklerPerChunk() >= 0) { if (world.testChunkLimitation(pos3, SprinklerBlock.class, world.setting().sprinklerPerChunk())) { ActionManager.trigger(context, config.reachLimitActions()); - return InteractionResult.FAIL; + return InteractionResult.COMPLETE; } } // generate state @@ -99,7 +99,7 @@ public class SprinklerItem extends AbstractCustomCropsItem { // trigger event SprinklerPlaceEvent placeEvent = new SprinklerPlaceEvent(player, itemInHand, event.hand(), targetLocation.clone(), config, state); if (EventUtils.fireAndCheckCancel(placeEvent)) - return InteractionResult.FAIL; + return InteractionResult.COMPLETE; // clear replaceable block targetLocation.getBlock().setType(Material.AIR, false); if (player.getGameMode() != GameMode.CREATIVE) @@ -114,7 +114,7 @@ public class SprinklerItem extends AbstractCustomCropsItem { ); }); ActionManager.trigger(context, config.placeActions()); - return InteractionResult.SUCCESS; + return InteractionResult.COMPLETE; } private boolean suitableForSprinkler(Location location) { diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/item/WateringCanItem.java b/api/src/main/java/net/momirealms/customcrops/api/core/item/WateringCanItem.java index 2d5218c..647a650 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/item/WateringCanItem.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/item/WateringCanItem.java @@ -49,6 +49,8 @@ import org.bukkit.block.BlockFace; import org.bukkit.block.data.Waterlogged; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import org.bukkit.util.RayTraceResult; +import org.bukkit.util.Vector; import java.util.ArrayList; import java.util.List; @@ -71,7 +73,7 @@ public class WateringCanItem extends AbstractCustomCropsItem { Item wrapped = BukkitCustomCropsPlugin.getInstance().getItemManager().wrap(itemStack); int realWater = Math.min(config.storage(), water); if (!config.infinite()) { - wrapped.setTag("CustomCrops", "water", realWater); + wrapped.setTag(realWater, "CustomCrops", "water"); wrapped.maxDamage().ifPresent(max -> { if (max <= 0) return; int damage = (int) (max * (((double) config.storage() - realWater) / config.storage())); @@ -104,23 +106,27 @@ public class WateringCanItem extends AbstractCustomCropsItem { @Override public void interactAir(WrappedInteractAirEvent event) { - WateringCanConfig config = Registries.WATERING_CAN.get(event.itemID()); + WateringCanConfig config = Registries.ITEM_TO_WATERING_CAN.get(event.itemID()); if (config == null) return; final Player player = event.player();; Context context = Context.player(player); // check requirements - if (!RequirementManager.isSatisfied(context, config.requirements())) { + if (!RequirementManager.isSatisfied(context, config.requirements())) return; - } // ignore infinite if (config.infinite()) return; - // get target block - Block targetBlock = player.getTargetBlockExact(5, FluidCollisionMode.ALWAYS); + RayTraceResult result = player.getWorld().rayTraceBlocks(player.getEyeLocation(), player.getLocation().getDirection(), 5, FluidCollisionMode.ALWAYS); + if (result == null) + return; + Block targetBlock = result.getHitBlock(); if (targetBlock == null) return; + final Vector vector = result.getHitPosition(); + // for old config compatibility + context.arg(ContextKeys.LOCATION, new Location(player.getWorld(), vector.getX() - 0.5,vector.getY() - 1, vector.getZ() - 0.5)); final ItemStack itemInHand = event.itemInHand(); int water = getCurrentWater(itemInHand); @@ -140,6 +146,10 @@ public class WateringCanItem extends AbstractCustomCropsItem { WateringCanFillEvent fillEvent = new WateringCanFillEvent(player, event.hand(), itemInHand, targetBlock.getLocation(), config, method); if (EventUtils.fireAndCheckCancel(fillEvent)) return; + int current = Math.min(water + method.amountOfWater(), config.storage()); + context.arg(ContextKeys.WATER_BAR, Optional.ofNullable(config.waterBar()).map(bar -> bar.getWaterBar(current, config.storage())).orElse("")); + context.arg(ContextKeys.STORAGE, config.storage()); + context.arg(ContextKeys.CURRENT_WATER, current); setCurrentWater(itemInHand, config, water + method.amountOfWater(), context); method.triggerActions(context); ActionManager.trigger(context, config.addWaterActions()); @@ -151,16 +161,16 @@ public class WateringCanItem extends AbstractCustomCropsItem { @Override public InteractionResult interactAt(WrappedInteractEvent event) { - WateringCanConfig wateringCanConfig = Registries.WATERING_CAN.get(event.itemID()); + WateringCanConfig wateringCanConfig = Registries.ITEM_TO_WATERING_CAN.get(event.itemID()); if (wateringCanConfig == null) - return InteractionResult.FAIL; + return InteractionResult.COMPLETE; final Player player = event.player(); final Context context = Context.player(player); // check watering can requirements if (!RequirementManager.isSatisfied(context, wateringCanConfig.requirements())) { - return InteractionResult.FAIL; + return InteractionResult.COMPLETE; } final CustomCropsWorld world = event.world(); @@ -175,21 +185,21 @@ public class WateringCanItem extends AbstractCustomCropsItem { if (sprinklerConfig != null) { // ignore infinite sprinkler if (sprinklerConfig.infinite()) { - return InteractionResult.FAIL; + return InteractionResult.COMPLETE; } // check requirements if (!RequirementManager.isSatisfied(context, sprinklerConfig.useRequirements())) { - return InteractionResult.FAIL; + return InteractionResult.COMPLETE; } // check water if (waterInCan <= 0 && !wateringCanConfig.infinite()) { ActionManager.trigger(context, wateringCanConfig.runOutOfWaterActions()); - return InteractionResult.FAIL; + return InteractionResult.COMPLETE; } // check whitelist if (!wateringCanConfig.whitelistSprinklers().contains(sprinklerConfig.id())) { ActionManager.trigger(context, wateringCanConfig.wrongSprinklerActions()); - return InteractionResult.FAIL; + return InteractionResult.COMPLETE; } SprinklerBlock sprinklerBlock = (SprinklerBlock) BuiltInBlockMechanics.SPRINKLER.mechanic(); @@ -198,14 +208,19 @@ public class WateringCanItem extends AbstractCustomCropsItem { // check full if (sprinklerBlock.water(sprinklerState) >= sprinklerConfig.storage()) { ActionManager.trigger(context, sprinklerConfig.fullWaterActions()); - return InteractionResult.FAIL; + return InteractionResult.COMPLETE; } // trigger event WateringCanWaterSprinklerEvent waterSprinklerEvent = new WateringCanWaterSprinklerEvent(player, itemInHand, event.hand(), wateringCanConfig, sprinklerConfig, sprinklerState, targetLocation); if (EventUtils.fireAndCheckCancel(waterSprinklerEvent)) { - return InteractionResult.FAIL; + return InteractionResult.COMPLETE; } + + context.arg(ContextKeys.WATER_BAR, Optional.ofNullable(wateringCanConfig.waterBar()).map(bar -> bar.getWaterBar(waterInCan - 1, wateringCanConfig.storage())).orElse("")); + context.arg(ContextKeys.STORAGE, wateringCanConfig.storage()); + context.arg(ContextKeys.CURRENT_WATER, waterInCan - 1); + // add water if (sprinklerBlock.addWater(sprinklerState, sprinklerConfig, wateringCanConfig.wateringAmount())) { if (!sprinklerConfig.threeDItem().equals(sprinklerConfig.threeDItemWithWater())) { @@ -215,26 +230,7 @@ public class WateringCanItem extends AbstractCustomCropsItem { ActionManager.trigger(context, wateringCanConfig.consumeWaterActions()); setCurrentWater(itemInHand, wateringCanConfig, waterInCan - 1, context); - return InteractionResult.SUCCESS; - } - - // try filling the watering can - for (FillMethod method : wateringCanConfig.fillMethods()) { - if (method.getID().equals(event.relatedID())) { - if (method.checkRequirements(context)) { - if (waterInCan >= wateringCanConfig.storage()) { - ActionManager.trigger(context, wateringCanConfig.fullActions()); - return InteractionResult.FAIL; - } - WateringCanFillEvent fillEvent = new WateringCanFillEvent(player, event.hand(), itemInHand, targetLocation, wateringCanConfig, method); - if (EventUtils.fireAndCheckCancel(fillEvent)) - return InteractionResult.FAIL; - setCurrentWater(itemInHand, wateringCanConfig, waterInCan + method.amountOfWater(), context); - method.triggerActions(context); - ActionManager.trigger(context, wateringCanConfig.addWaterActions()); - } - return InteractionResult.SUCCESS; - } + return InteractionResult.COMPLETE; } // if the clicked block is a crop, correct the target block @@ -254,12 +250,12 @@ public class WateringCanItem extends AbstractCustomCropsItem { // check whitelist if (!wateringCanConfig.whitelistPots().contains(potConfig.id())) { ActionManager.trigger(context, wateringCanConfig.wrongPotActions()); - return InteractionResult.FAIL; + return InteractionResult.COMPLETE; } // check water if (waterInCan <= 0 && !wateringCanConfig.infinite()) { ActionManager.trigger(context, wateringCanConfig.runOutOfWaterActions()); - return InteractionResult.FAIL; + return InteractionResult.COMPLETE; } World bukkitWorld = targetLocation.getWorld(); @@ -267,26 +263,65 @@ public class WateringCanItem extends AbstractCustomCropsItem { WateringCanWaterPotEvent waterPotEvent = new WateringCanWaterPotEvent(player, itemInHand, event.hand(), wateringCanConfig, potConfig, pots); if (EventUtils.fireAndCheckCancel(waterPotEvent)) { - return InteractionResult.FAIL; + return InteractionResult.COMPLETE; } + context.arg(ContextKeys.WATER_BAR, Optional.ofNullable(wateringCanConfig.waterBar()).map(bar -> bar.getWaterBar(waterInCan - 1, wateringCanConfig.storage())).orElse("")); + context.arg(ContextKeys.STORAGE, wateringCanConfig.storage()); + context.arg(ContextKeys.CURRENT_WATER, waterInCan - 1); + PotBlock potBlock = (PotBlock) BuiltInBlockMechanics.POT.mechanic(); for (Pair pair : waterPotEvent.getPotWithIDs()) { CustomCropsBlockState potState = potBlock.fixOrGetState(world,pair.left(), potConfig, pair.right()); + Location temp = pair.left().toLocation(bukkitWorld); if (potBlock.addWater(potState, potConfig, wateringCanConfig.wateringAmount())) { - Location temp = pair.left().toLocation(bukkitWorld); potBlock.updateBlockAppearance(temp, potConfig, true, potBlock.fertilizers(potState)); - context.arg(ContextKeys.LOCATION, temp); - ActionManager.trigger(context, potConfig.addWaterActions()); } + context.arg(ContextKeys.LOCATION, temp); + ActionManager.trigger(context, potConfig.addWaterActions()); } ActionManager.trigger(context, wateringCanConfig.consumeWaterActions()); setCurrentWater(itemInHand, wateringCanConfig, waterInCan - 1, context); - return InteractionResult.SUCCESS; + return InteractionResult.COMPLETE; } - return InteractionResult.PASS; + RayTraceResult result = player.getWorld().rayTraceBlocks(player.getEyeLocation(), player.getLocation().getDirection(), 5, FluidCollisionMode.ALWAYS); + if (result == null) + return InteractionResult.COMPLETE; + Block targetBlock = result.getHitBlock(); + if (targetBlock == null) + return InteractionResult.COMPLETE; + final Vector vector = result.getHitPosition(); + // for old config compatibility + context.arg(ContextKeys.LOCATION, new Location(player.getWorld(), vector.getX() - 0.5,vector.getY() - 1, vector.getZ() - 0.5)); + String blockID = BukkitCustomCropsPlugin.getInstance().getItemManager().blockID(targetBlock); + if (targetBlock.getBlockData() instanceof Waterlogged waterlogged && waterlogged.isWaterlogged()) { + blockID = "WATER"; + } + for (FillMethod method : wateringCanConfig.fillMethods()) { + if (method.getID().equals(blockID)) { + if (method.checkRequirements(context)) { + if (waterInCan >= wateringCanConfig.storage()) { + ActionManager.trigger(context, wateringCanConfig.fullActions()); + return InteractionResult.COMPLETE; + } + WateringCanFillEvent fillEvent = new WateringCanFillEvent(player, event.hand(), itemInHand, targetBlock.getLocation(), wateringCanConfig, method); + if (EventUtils.fireAndCheckCancel(fillEvent)) + return InteractionResult.COMPLETE; + int current = Math.min(waterInCan + method.amountOfWater(), wateringCanConfig.storage()); + context.arg(ContextKeys.WATER_BAR, Optional.ofNullable(wateringCanConfig.waterBar()).map(bar -> bar.getWaterBar(current, wateringCanConfig.storage())).orElse("")); + context.arg(ContextKeys.STORAGE, wateringCanConfig.storage()); + context.arg(ContextKeys.CURRENT_WATER, current); + setCurrentWater(itemInHand, wateringCanConfig, waterInCan + method.amountOfWater(), context); + method.triggerActions(context); + ActionManager.trigger(context, wateringCanConfig.addWaterActions()); + } + return InteractionResult.COMPLETE; + } + } + + return InteractionResult.COMPLETE; } public ArrayList> potInRange(World world, Pos3 pos3, int width, int length, float yaw, PotConfig config) { diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/world/BlockPos.java b/api/src/main/java/net/momirealms/customcrops/api/core/world/BlockPos.java index c3bf17a..d91a1e1 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/world/BlockPos.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/world/BlockPos.java @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/world/ChunkPos.java b/api/src/main/java/net/momirealms/customcrops/api/core/world/ChunkPos.java index fe43a88..044f017 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/world/ChunkPos.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/world/ChunkPos.java @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/world/CustomCropsChunk.java b/api/src/main/java/net/momirealms/customcrops/api/core/world/CustomCropsChunk.java index 9d7894c..16f66cc 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/world/CustomCropsChunk.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/world/CustomCropsChunk.java @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/world/CustomCropsRegion.java b/api/src/main/java/net/momirealms/customcrops/api/core/world/CustomCropsRegion.java index d8f8302..1746bcf 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/world/CustomCropsRegion.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/world/CustomCropsRegion.java @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/world/CustomCropsSection.java b/api/src/main/java/net/momirealms/customcrops/api/core/world/CustomCropsSection.java index e44d4a4..0a6b22e 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/world/CustomCropsSection.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/world/CustomCropsSection.java @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/world/CustomCropsWorld.java b/api/src/main/java/net/momirealms/customcrops/api/core/world/CustomCropsWorld.java index f4438ec..33e5cc4 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/world/CustomCropsWorld.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/world/CustomCropsWorld.java @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/world/DataBlock.java b/api/src/main/java/net/momirealms/customcrops/api/core/world/DataBlock.java index f063ffb..227a7ce 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/world/DataBlock.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/world/DataBlock.java @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/world/DelayedTickTask.java b/api/src/main/java/net/momirealms/customcrops/api/core/world/DelayedTickTask.java index 2526dfd..99cece5 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/world/DelayedTickTask.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/world/DelayedTickTask.java @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/world/RegionPos.java b/api/src/main/java/net/momirealms/customcrops/api/core/world/RegionPos.java index ac0cf69..e4d530c 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/world/RegionPos.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/world/RegionPos.java @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/world/Season.java b/api/src/main/java/net/momirealms/customcrops/api/core/world/Season.java index f6a0398..8fbb4fc 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/world/Season.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/world/Season.java @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/world/SerializableChunk.java b/api/src/main/java/net/momirealms/customcrops/api/core/world/SerializableChunk.java index 4b9d496..441e4ae 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/world/SerializableChunk.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/world/SerializableChunk.java @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/world/SerializableSection.java b/api/src/main/java/net/momirealms/customcrops/api/core/world/SerializableSection.java index 5204eb2..6d170f7 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/world/SerializableSection.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/world/SerializableSection.java @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/world/WorldExtraData.java b/api/src/main/java/net/momirealms/customcrops/api/core/world/WorldExtraData.java index ecfa0c7..650eafc 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/world/WorldExtraData.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/world/WorldExtraData.java @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/world/WorldSetting.java b/api/src/main/java/net/momirealms/customcrops/api/core/world/WorldSetting.java index 6df176d..55737bb 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/world/WorldSetting.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/world/WorldSetting.java @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 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 17a8c8e..37e4011 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 @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 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 03b09d2..1d2daef 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 @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 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 8f89ee3..636ec03 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 @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 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 21d15d6..98379b6 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 @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 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 85a276c..25b3792 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 @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 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 b898716..b14a3a2 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 @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 diff --git a/api/src/main/java/net/momirealms/customcrops/api/event/GreenhouseGlassInteractEvent.java b/api/src/main/java/net/momirealms/customcrops/api/event/GreenhouseGlassInteractEvent.java index df0a46b..c8886ef 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/event/GreenhouseGlassInteractEvent.java +++ b/api/src/main/java/net/momirealms/customcrops/api/event/GreenhouseGlassInteractEvent.java @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 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 a5cfc21..b77b306 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 @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 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 d443f4e..1bf00d0 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 @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 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 3d5141c..78379ce 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 @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 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 fc59d6c..ebc2796 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 @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 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 23e2f94..d106667 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 @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 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 65b8ac1..43a153b 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 @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 diff --git a/api/src/main/java/net/momirealms/customcrops/api/event/ScarecrowInteractEvent.java b/api/src/main/java/net/momirealms/customcrops/api/event/ScarecrowInteractEvent.java index c84cdde..e8f7acd 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/event/ScarecrowInteractEvent.java +++ b/api/src/main/java/net/momirealms/customcrops/api/event/ScarecrowInteractEvent.java @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 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 c55657d..18f859d 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 @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 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 dfa508d..dee448b 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 @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 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 ace165e..08a64c1 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 @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 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 7aaf4b2..f3d5da3 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 @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 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 e2b1494..f1cead1 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 @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 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 6dce329..ffadfaf 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 @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 diff --git a/api/src/main/java/net/momirealms/customcrops/api/event/WateringCanWaterPotEvent.java b/api/src/main/java/net/momirealms/customcrops/api/event/WateringCanWaterPotEvent.java index e1e45f2..d504dc2 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/event/WateringCanWaterPotEvent.java +++ b/api/src/main/java/net/momirealms/customcrops/api/event/WateringCanWaterPotEvent.java @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 diff --git a/api/src/main/java/net/momirealms/customcrops/api/event/WateringCanWaterSprinklerEvent.java b/api/src/main/java/net/momirealms/customcrops/api/event/WateringCanWaterSprinklerEvent.java index 5d31bbf..9cf0aa2 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/event/WateringCanWaterSprinklerEvent.java +++ b/api/src/main/java/net/momirealms/customcrops/api/event/WateringCanWaterSprinklerEvent.java @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 diff --git a/api/src/main/java/net/momirealms/customcrops/api/misc/water/AbstractMethod.java b/api/src/main/java/net/momirealms/customcrops/api/misc/water/AbstractMethod.java index 1504598..ee1c2de 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/misc/water/AbstractMethod.java +++ b/api/src/main/java/net/momirealms/customcrops/api/misc/water/AbstractMethod.java @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 diff --git a/api/src/main/java/net/momirealms/customcrops/api/misc/water/FillMethod.java b/api/src/main/java/net/momirealms/customcrops/api/misc/water/FillMethod.java index a514ae2..4d8c5f1 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/misc/water/FillMethod.java +++ b/api/src/main/java/net/momirealms/customcrops/api/misc/water/FillMethod.java @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 diff --git a/api/src/main/java/net/momirealms/customcrops/api/misc/water/WaterBar.java b/api/src/main/java/net/momirealms/customcrops/api/misc/water/WaterBar.java index db04298..bf92074 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/misc/water/WaterBar.java +++ b/api/src/main/java/net/momirealms/customcrops/api/misc/water/WaterBar.java @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 diff --git a/api/src/main/java/net/momirealms/customcrops/api/misc/water/WateringMethod.java b/api/src/main/java/net/momirealms/customcrops/api/misc/water/WateringMethod.java index 5fccaf5..bc7e37a 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/misc/water/WateringMethod.java +++ b/api/src/main/java/net/momirealms/customcrops/api/misc/water/WateringMethod.java @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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 diff --git a/build.gradle.kts b/build.gradle.kts index d72e8d7..a3ec23b 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,4 @@ +import org.gradle.process.internal.ExecException import java.io.ByteArrayOutputStream plugins { @@ -32,18 +33,26 @@ subprojects { fun versionBanner(): String { val os = ByteArrayOutputStream() - project.exec { - commandLine = "git rev-parse --short=8 HEAD".split(" ") - standardOutput = os + try { + project.exec { + commandLine = "git rev-parse --short=8 HEAD".split(" ") + standardOutput = os + } + } catch (e: ExecException) { + return "Unknown" } return String(os.toByteArray()).trim() } fun builder(): String { val os = ByteArrayOutputStream() - project.exec { - commandLine = "git config user.name".split(" ") - standardOutput = os + try { + project.exec { + commandLine = "git config user.name".split(" ") + standardOutput = os + } + } catch (e: ExecException) { + return "Unknown" } return String(os.toByteArray()).trim() } \ No newline at end of file diff --git a/plugin/src/main/java/net/momirealms/customcrops/bukkit/config/BukkitConfigManager.java b/plugin/src/main/java/net/momirealms/customcrops/bukkit/config/BukkitConfigManager.java index f4d3639..0049ef5 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/bukkit/config/BukkitConfigManager.java +++ b/plugin/src/main/java/net/momirealms/customcrops/bukkit/config/BukkitConfigManager.java @@ -213,6 +213,7 @@ public class BukkitConfigManager extends ConfigManager { @Override public void registerWateringCanConfig(WateringCanConfig config) { Registries.WATERING_CAN.register(config.id(), config); + Registries.ITEM_TO_WATERING_CAN.register(config.itemID(), config); Registries.ITEMS.register(config.itemID(), BuiltInItemMechanics.WATERING_CAN.mechanic()); } diff --git a/plugin/src/main/java/net/momirealms/customcrops/bukkit/config/ConfigType.java b/plugin/src/main/java/net/momirealms/customcrops/bukkit/config/ConfigType.java index 26fa0ed..3ebe695 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/bukkit/config/ConfigType.java +++ b/plugin/src/main/java/net/momirealms/customcrops/bukkit/config/ConfigType.java @@ -66,7 +66,7 @@ public class ConfigType { .length(section.getInt("effective-range.length", 1)) .potWhitelist(new HashSet<>(section.getStringList("pot-whitelist"))) .sprinklerWhitelist(new HashSet<>(section.getStringList("sprinkler-whitelist"))) - .dynamicLore(section.getBoolean("dynamic-lore")) + .dynamicLore(section.getBoolean("dynamic-lore.enable")) .lore(section.getStringList("dynamic-lore.lore").stream().map(TextValue::auto).toList()) .fillMethods(manager.getFillMethods(section.getSection("fill-method"))) .requirements(BukkitCustomCropsPlugin.getInstance().getRequirementManager(Player.class).parseRequirements(section.getSection("requirements"), true)) @@ -115,6 +115,7 @@ public class ConfigType { PotConfig config = PotConfig.builder() .id(id) + .storage(section.getInt("storage", 5)) .isRainDropAccepted(section.getBoolean("absorb-rainwater", false)) .isNearbyWaterAccepted(section.getBoolean("absorb-nearby-water", false)) .maxFertilizers(section.getInt("max-fertilizers", 1)) @@ -187,6 +188,7 @@ public class ConfigType { int point = Integer.parseInt(entry.getKey()); CropStageConfig.Builder builder = CropStageConfig.builder() .point(point) + .existenceForm(inner.contains("type") ? CustomForm.valueOf(inner.getString("type").toUpperCase(Locale.ENGLISH)).existenceForm() : form) .displayInfoOffset(inner.getDouble("hologram-offset-correction")) .stageID(inner.getString("model")) .breakRequirements(prm.parseRequirements(inner.getSection("requirements.break"), true)) diff --git a/plugin/src/main/java/net/momirealms/customcrops/bukkit/item/BukkitItemManager.java b/plugin/src/main/java/net/momirealms/customcrops/bukkit/item/BukkitItemManager.java index 3241abe..e658448 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/bukkit/item/BukkitItemManager.java +++ b/plugin/src/main/java/net/momirealms/customcrops/bukkit/item/BukkitItemManager.java @@ -80,6 +80,11 @@ public class BukkitItemManager extends AbstractItemManager { this.factory = BukkitItemFactory.create(plugin); } + @Override + public void load() { + this.resetItemDetectionOrder(); + } + @Override public void setCustomEventListener(@NotNull AbstractCustomEventListener listener) { Objects.requireNonNull(listener, "listener cannot be null"); @@ -392,7 +397,7 @@ public class BukkitItemManager extends AbstractItemManager { CustomCropsWorld world = optionalWorld.get(); WrappedInteractEvent wrapped = new WrappedInteractEvent(ExistenceForm.BLOCK, player, world, block.getLocation(), blockID, itemInHand, itemID, hand, blockFace, event); - handleInteractEvent(blockID, itemID, wrapped); + handleInteractEvent(blockID, wrapped); } @Override @@ -406,11 +411,11 @@ public class BukkitItemManager extends AbstractItemManager { CustomCropsWorld world = optionalWorld.get(); WrappedInteractEvent wrapped = new WrappedInteractEvent(ExistenceForm.FURNITURE, player, world, location, furnitureID, itemInHand, itemID, hand, null, event); - handleInteractEvent(furnitureID, itemID, wrapped); + handleInteractEvent(furnitureID, wrapped); } - private void handleInteractEvent(String blockID, String itemID, WrappedInteractEvent wrapped) { - CustomCropsItem customCropsItem = Registries.ITEMS.get(itemID); + private void handleInteractEvent(String blockID, WrappedInteractEvent wrapped) { + CustomCropsItem customCropsItem = Registries.ITEMS.get(wrapped.itemID()); if (customCropsItem != null) { InteractionResult result = customCropsItem.interactAt(wrapped); if (result != InteractionResult.PASS) diff --git a/plugin/src/main/java/net/momirealms/customcrops/bukkit/misc/HologramManager.java b/plugin/src/main/java/net/momirealms/customcrops/bukkit/misc/HologramManager.java index 69db254..04aa6f0 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/bukkit/misc/HologramManager.java +++ b/plugin/src/main/java/net/momirealms/customcrops/bukkit/misc/HologramManager.java @@ -1,5 +1,5 @@ /* - * Copyright (C) <2022> + * Copyright (C) <2024> * * 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