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 35d22be..d934439 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 @@ -359,7 +359,7 @@ public class PotBlock extends AbstractCustomCropsBlock { future.thenAcceptAsync((run) -> { if (!run) return; // work as vanilla farmland - if (config.vanillaFarmland()) return; + if (config.disablePluginMechanism()) return; boolean hasNaturalWater = false; boolean waterChanged = false; @@ -620,7 +620,7 @@ public class PotBlock extends AbstractCustomCropsBlock { } public void updateBlockAppearance(Location location, PotConfig config, boolean hasWater, @Nullable Fertilizer fertilizer) { - if (config.vanillaFarmland()) return; + if (config.disablePluginMechanism()) return; String appearance = config.getPotAppearance(hasWater, fertilizer == null ? null : fertilizer.type()); BukkitCustomCropsPlugin.getInstance().getItemManager().placeBlock(location, appearance); } diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/block/SprinklerBlock.java b/api/src/main/java/net/momirealms/customcrops/api/core/block/SprinklerBlock.java index f195fa0..008d7fb 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/block/SprinklerBlock.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/block/SprinklerBlock.java @@ -49,7 +49,6 @@ import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; import java.util.Optional; -import java.util.concurrent.CompletableFuture; public class SprinklerBlock extends AbstractCustomCropsBlock { @@ -295,7 +294,7 @@ public class SprinklerBlock extends AbstractCustomCropsBlock { CustomCropsBlockState anotherState = optionalState.get(); if (anotherState.type() instanceof PotBlock potBlock) { PotConfig potConfig = potBlock.config(anotherState); - if (!potConfig.vanillaFarmland()) { + if (!potConfig.disablePluginMechanism()) { if (config.potWhitelist().contains(potConfig.id())) { if (potBlock.addWater(anotherState, potConfig, config.wateringAmount())) { BukkitCustomCropsPlugin.getInstance().getScheduler().sync().run( 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 b50ff6e..aa8d88e 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 @@ -82,6 +82,9 @@ public class FertilizerItem extends AbstractCustomCropsItem { // if the clicked block is a pot PotConfig potConfig = Registries.ITEM_TO_POT.get(targetBlockID); if (potConfig != null) { + if (potConfig.disablePluginMechanism()) { + return InteractionResult.COMPLETE; + } // check pot whitelist if (!fertilizerConfig.whitelistPots().contains(potConfig.id())) { ActionManager.trigger(context, fertilizerConfig.wrongPotActions()); @@ -115,7 +118,7 @@ public class FertilizerItem extends AbstractCustomCropsItem { .id(fertilizerConfig.id()) .build(); CustomCropsBlockState potState = potBlock.fixOrGetState(world, Pos3.from(targetLocation), potConfig, event.relatedID()); - if (!potBlock.canApplyFertilizer(potState,fertilizer)) { + if (!potBlock.canApplyFertilizer(potState, fertilizer)) { ActionManager.trigger(context, potConfig.maxFertilizerActions()); return InteractionResult.COMPLETE; } 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 41f99a6..69c268c 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 @@ -286,7 +286,7 @@ public class WateringCanItem extends AbstractCustomCropsItem { PotConfig potConfig = Registries.ITEM_TO_POT.get(targetBlockID); if (potConfig != null) { - if (potConfig.vanillaFarmland()) + if (potConfig.disablePluginMechanism()) return InteractionResult.COMPLETE; // need to click the upper face if (blockFace != BlockFace.UP) diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/mechanic/pot/PotConfig.java b/api/src/main/java/net/momirealms/customcrops/api/core/mechanic/pot/PotConfig.java index c4b0475..a619f8d 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/mechanic/pot/PotConfig.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/mechanic/pot/PotConfig.java @@ -27,6 +27,7 @@ import net.momirealms.customcrops.common.util.Pair; import org.bukkit.entity.Player; import java.util.HashMap; +import java.util.List; import java.util.Set; /** @@ -67,7 +68,7 @@ public interface PotConfig { * * @return True if disabled */ - boolean vanillaFarmland(); + boolean disablePluginMechanism(); /** * Gets the methods available for watering the pot. @@ -236,6 +237,14 @@ public interface PotConfig { */ Builder vanillaFarmland(boolean vanillaFarmland); + /** + * Mark this pot as a vanilla one and disable plugin mechanisms + * + * @param vanillaPots pots + * @return The current instance of the Builder. + */ + Builder vanillaPots(List vanillaPots); + /** * Sets whether the pot can accept rain as a source of water. * diff --git a/api/src/main/java/net/momirealms/customcrops/api/core/mechanic/pot/PotConfigImpl.java b/api/src/main/java/net/momirealms/customcrops/api/core/mechanic/pot/PotConfigImpl.java index 8edb196..3bc486c 100644 --- a/api/src/main/java/net/momirealms/customcrops/api/core/mechanic/pot/PotConfigImpl.java +++ b/api/src/main/java/net/momirealms/customcrops/api/core/mechanic/pot/PotConfigImpl.java @@ -24,16 +24,17 @@ import net.momirealms.customcrops.api.misc.water.WaterBar; import net.momirealms.customcrops.api.misc.water.WateringMethod; import net.momirealms.customcrops.api.requirement.Requirement; import net.momirealms.customcrops.common.util.Pair; +import org.bukkit.Material; +import org.bukkit.block.data.type.Farmland; import org.bukkit.entity.Player; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Set; +import java.util.*; public class PotConfigImpl implements PotConfig { private final String id; private final boolean vanillaFarmland; + private final boolean disablePluginSystem; private final Pair basicAppearance; private final HashMap> potAppearanceMap; private final Set blocks = new HashSet<>(); @@ -77,7 +78,8 @@ public class PotConfigImpl implements PotConfig { Action[] breakActions, Action[] addWaterActions, Action[] fullWaterActions, - Action[] maxFertilizerActions + Action[] maxFertilizerActions, + List vanillaPots ) { this.id = id; this.vanillaFarmland = vanillaFarmland; @@ -109,10 +111,19 @@ public class PotConfigImpl implements PotConfig { this.wetBlocks.add(pair.right()); } if (vanillaFarmland) { + disablePluginSystem = true; this.blocks.clear(); for (int i = 0; i <= 7; i++) { - this.blocks.add("minecraft:farmland[moisture=" + i +"]"); + Farmland data = (Farmland) Material.FARMLAND.createBlockData(); + data.setMoisture(i); + this.blocks.add(data.getAsString()); } + } else if (vanillaPots != null && !vanillaPots.isEmpty()) { + disablePluginSystem = true; + this.blocks.clear(); + this.blocks.addAll(vanillaPots); + } else { + disablePluginSystem = false; } } @@ -123,28 +134,28 @@ public class PotConfigImpl implements PotConfig { @Override public int storage() { - if (vanillaFarmland()) return 0; + if (disablePluginMechanism()) return 0; return storage; } @Override public boolean isRainDropAccepted() { - return isRainDropAccepted && !vanillaFarmland(); + return isRainDropAccepted && !disablePluginMechanism(); } @Override public boolean isNearbyWaterAccepted() { - return isNearbyWaterAccepted && !vanillaFarmland(); + return isNearbyWaterAccepted && !disablePluginMechanism(); } @Override - public boolean vanillaFarmland() { - return vanillaFarmland; + public boolean disablePluginMechanism() { + return disablePluginSystem; } @Override public WateringMethod[] wateringMethods() { - if (vanillaFarmland()) return new WateringMethod[0]; + if (disablePluginMechanism()) return new WateringMethod[0]; return wateringMethods; } @@ -155,18 +166,19 @@ public class PotConfigImpl implements PotConfig { @Override public boolean isWet(String blockID) { - if (vanillaFarmland()) return false; + if (disablePluginMechanism()) return false; return wetBlocks.contains(blockID); } @Override public WaterBar waterBar() { + if (disablePluginMechanism()) return null; return waterBar; } @Override public int maxFertilizers() { - if (vanillaFarmland) return 0; + if (disablePluginMechanism()) return 0; return maxFertilizers; } @@ -259,10 +271,11 @@ public class PotConfigImpl implements PotConfig { private Action[] addWaterActions; private Action[] fullWaterActions; private Action[] maxFertilizerActions; + private List vanillaPots = new ArrayList<>(); @Override public PotConfig build() { - return new PotConfigImpl(id, vanillaFarmland, basicAppearance, potAppearanceMap, storage, isRainDropAccepted, isNearbyWaterAccepted, wateringMethods, waterBar, maxFertilizers, placeRequirements, breakRequirements, useRequirements, tickActions, reachLimitActions, interactActions, placeActions, breakActions, addWaterActions, fullWaterActions, maxFertilizerActions); + return new PotConfigImpl(id, vanillaFarmland, basicAppearance, potAppearanceMap, storage, isRainDropAccepted, isNearbyWaterAccepted, wateringMethods, waterBar, maxFertilizers, placeRequirements, breakRequirements, useRequirements, tickActions, reachLimitActions, interactActions, placeActions, breakActions, addWaterActions, fullWaterActions, maxFertilizerActions, vanillaPots); } @Override @@ -283,6 +296,12 @@ public class PotConfigImpl implements PotConfig { return this; } + @Override + public Builder vanillaPots(List vanillaPots) { + this.vanillaPots = vanillaPots; + return this; + } + @Override public Builder isRainDropAccepted(boolean isRainDropAccepted) { this.isRainDropAccepted = isRainDropAccepted; diff --git a/common/src/main/java/net/momirealms/customcrops/common/util/ListUtils.java b/common/src/main/java/net/momirealms/customcrops/common/util/ListUtils.java index 7c31884..d35f872 100644 --- a/common/src/main/java/net/momirealms/customcrops/common/util/ListUtils.java +++ b/common/src/main/java/net/momirealms/customcrops/common/util/ListUtils.java @@ -38,6 +38,9 @@ public class ListUtils { */ @SuppressWarnings("unchecked") public static List toList(final Object obj) { + if (obj == null) { + return List.of(); + } if (obj instanceof String s) { return List.of(s); } else if (obj instanceof List list) { diff --git a/plugin/src/main/java/net/momirealms/customcrops/bukkit/command/feature/DebugDataCommand.java b/plugin/src/main/java/net/momirealms/customcrops/bukkit/command/feature/DebugDataCommand.java index 8ce6c5c..928f1c6 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/bukkit/command/feature/DebugDataCommand.java +++ b/plugin/src/main/java/net/momirealms/customcrops/bukkit/command/feature/DebugDataCommand.java @@ -65,8 +65,9 @@ public class DebugDataCommand extends BukkitCommandFeature { .sendMessage(AdventureHelper.miniMessage("CustomCrops Data not found")); } }); + String bData = block.getBlockData().getAsString(); BukkitCustomCropsPlugin.getInstance().getSenderFactory().wrap(player) - .sendMessage(AdventureHelper.miniMessage("Vanilla crop data: " + block.getBlockData().getAsString())); + .sendMessage(AdventureHelper.miniMessage("Vanilla crop data: Copy'>" + bData + "")); }); } 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 71194c0..38bbacd 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 @@ -36,6 +36,7 @@ import net.momirealms.customcrops.api.core.world.CustomCropsBlockState; import net.momirealms.customcrops.api.misc.value.TextValue; import net.momirealms.customcrops.api.misc.water.WaterBar; import net.momirealms.customcrops.api.requirement.RequirementManager; +import net.momirealms.customcrops.common.util.ListUtils; import net.momirealms.customcrops.common.util.Pair; import net.momirealms.customcrops.common.util.TriFunction; import org.bukkit.entity.Player; @@ -116,6 +117,7 @@ public class ConfigType { PotConfig config = PotConfig.builder() .id(id) .vanillaFarmland(section.getBoolean("vanilla-farmland", false)) + .vanillaPots(ListUtils.toList(section.get("vanilla-blocks"))) .storage(section.getInt("storage", 5)) .isRainDropAccepted(section.getBoolean("absorb-rainwater", false)) .isNearbyWaterAccepted(section.getBoolean("absorb-nearby-water", false))