diff --git a/build.gradle b/build.gradle index d363b4f..cb1df75 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group = 'net.momirealms' -version = '2.0.12' +version = '2.0.13' repositories { mavenCentral() @@ -48,6 +48,10 @@ repositories { name = 'glaremasters repo' url = 'https://repo.glaremasters.me/repository/towny/' } + maven { + name = 'superior skyblock repo' + url 'https://repo.bg-software.com/repository/api/' + } } dependencies { @@ -73,7 +77,7 @@ dependencies { implementation("org.bstats:bstats-bukkit:3.0.0") } -def targetJavaVersion = 16 +def targetJavaVersion = 17 java { def javaVersion = JavaVersion.toVersion(targetJavaVersion) sourceCompatibility = javaVersion diff --git a/src/main/java/net/momirealms/customcrops/integrations/customplugin/CustomInterface.java b/src/main/java/net/momirealms/customcrops/integrations/customplugin/CustomInterface.java index 72a3464..94a7937 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/customplugin/CustomInterface.java +++ b/src/main/java/net/momirealms/customcrops/integrations/customplugin/CustomInterface.java @@ -17,6 +17,7 @@ package net.momirealms.customcrops.integrations.customplugin; +import net.momirealms.customcrops.api.crop.Crop; import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.entity.ItemFrame; @@ -47,4 +48,12 @@ public interface CustomInterface { boolean doesExist(String itemID); + boolean hasNextStage(String id); + + String getNextStage(String id); + + @Nullable + Crop getCropFromID(String id); + + Location getFrameCropLocation(Location seedLoc); } diff --git a/src/main/java/net/momirealms/customcrops/integrations/customplugin/HandlerP.java b/src/main/java/net/momirealms/customcrops/integrations/customplugin/HandlerP.java index cec0ed3..0c860c6 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/customplugin/HandlerP.java +++ b/src/main/java/net/momirealms/customcrops/integrations/customplugin/HandlerP.java @@ -314,18 +314,6 @@ public abstract class HandlerP extends Function { return false; } - public boolean hasNextStage(String id) { - String[] crop = StringUtils.split(id,"_"); - int nextStage = Integer.parseInt(crop[2]) + 1; - return customInterface.doesExist(crop[0] + "_" + crop[1] + "_" + nextStage); - } - - public String getNextStage(String id) { - String[] crop = StringUtils.split(id,"_"); - int nextStage = Integer.parseInt(crop[2]) + 1; - return crop[0] + "_" + crop[1] + "_" + nextStage; - } - public boolean fillWaterCan(String id, NBTItem nbtItem, ItemStack itemStack, Player player) { WaterCan config = WaterCanConfig.CANS.get(id); if (config != null) { @@ -547,17 +535,6 @@ public abstract class HandlerP extends Function { return !preActionEvent.isCancelled(); } - public Crop getCropFromID(String id) { - String crop; - if (id.contains(":")) { - crop = id.split(":")[1].split("_")[0]; - } - else { - crop = id.split("_")[0]; - } - return CropConfig.CROPS.get(crop); - } - protected boolean onInteractRipeCrop(Location location, Crop crop, Player player) { CustomWorld customWorld = cropManager.getCustomWorld(location.getWorld()); @@ -582,16 +559,15 @@ public abstract class HandlerP extends Function { CustomWorld customWorld = cropManager.getCustomWorld(seedLoc.getWorld()); if (customWorld == null) return false; - if (!MainConfig.OraxenHook) { - if (FurnitureUtil.hasFurniture(seedLoc.clone().add(0.5,0.5,0.5))) return false; - } - else { - if (FurnitureUtil.hasFurniture(seedLoc.clone().add(0.5,0.03125,0.5))) return false; - } - + if (FurnitureUtil.hasFurniture(customInterface.getFrameCropLocation(seedLoc))) return false; if (seedLoc.getBlock().getType() != Material.AIR) return false; if (player != null) { + + long time = System.currentTimeMillis(); + if (time - (coolDown.getOrDefault(player, time - 100)) < 100) return false; + coolDown.put(player, time); + PlantingCondition plantingCondition = new PlantingCondition(seedLoc, player); if (crop.getRequirements() != null) { for (RequirementInterface requirement : crop.getRequirements()) { @@ -617,13 +593,17 @@ public abstract class HandlerP extends Function { } if (MainConfig.limitation) { - if (MainConfig.cropMode && LimitationUtil.reachWireLimit(seedLoc)) { - if (player != null) AdventureUtil.playerMessage(player, MessageConfig.prefix + MessageConfig.limitWire.replace("{max}", String.valueOf(MainConfig.wireAmount))); - return false; + if (MainConfig.cropMode) { + if (LimitationUtil.reachWireLimit(seedLoc)) { + if (player != null) AdventureUtil.playerMessage(player, MessageConfig.prefix + MessageConfig.limitWire.replace("{max}", String.valueOf(MainConfig.wireAmount))); + return false; + } } - if (!MainConfig.cropMode && LimitationUtil.reachFrameLimit(seedLoc)) { - if (player != null) AdventureUtil.playerMessage(player, MessageConfig.prefix + MessageConfig.limitFrame.replace("{max}", String.valueOf(MainConfig.frameAmount))); - return false; + else { + if (LimitationUtil.reachFrameLimit(seedLoc)) { + if (player != null) AdventureUtil.playerMessage(player, MessageConfig.prefix + MessageConfig.limitFrame.replace("{max}", String.valueOf(MainConfig.frameAmount))); + return false; + } } } diff --git a/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderFrameCropImpl.java b/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderFrameCropImpl.java index 48a025e..cb3e296 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderFrameCropImpl.java +++ b/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderFrameCropImpl.java @@ -52,71 +52,57 @@ public class ItemsAdderFrameCropImpl implements CropModeInterface { Chunk chunk = location.getChunk(); - if (chunk.isEntitiesLoaded()) { - Location cropLoc = location.clone().add(0.5,0.5,0.5); - ItemFrame itemFrame = FurnitureUtil.getItemFrame(cropLoc); - if (itemFrame == null) return true; - String id = customInterface.getItemID(itemFrame.getItem()); - if (id == null) return true; - if (id.equals(BasicItemConfig.deadCrop)) return true; + if (chunk.isEntitiesLoaded()) return false; + ItemFrame itemFrame = FurnitureUtil.getItemFrame(customInterface.getFrameCropLocation(location)); + if (itemFrame == null) return true; - String cropId = StringUtils.split(id, ":")[1]; - String[] cropNameList = StringUtils.split(cropId, "_"); - String cropKey = cropNameList[0]; + String id = customInterface.getItemID(itemFrame.getItem()); + if (id == null || id.equals(BasicItemConfig.deadCrop)) return true; - Crop crop = CropConfig.CROPS.get(cropKey); - if (crop == null) return true; - if (MainConfig.needSkyLight && location.getBlock().getLightFromSky() < MainConfig.skyLightLevel) { - itemFrame.setItem(customInterface.getItemStack(BasicItemConfig.deadCrop), false); - return true; - } - if (cropManager.isWrongSeason(location, crop.getSeasons())) { - itemFrame.setItem(customInterface.getItemStack(BasicItemConfig.deadCrop), false); - return true; - } - Location potLoc = location.clone().subtract(0,1,0); - String potID = customInterface.getBlockID(potLoc); - if (potID == null) return true; - Fertilizer fertilizer = cropManager.getFertilizer(potLoc); - boolean certainGrow = potID.equals(BasicItemConfig.wetPot); - int nextStage = Integer.parseInt(cropNameList[2]) + 1; - String temp = id.substring(0, id.length() - cropNameList[2].length()); - - if (customInterface.doesExist(temp + nextStage)) { - if (MainConfig.enableCrow && cropManager.crowJudge(location, itemFrame)) return true; - if (fertilizer instanceof SpeedGrow speedGrow && Math.random() < speedGrow.getChance()) { - if (customInterface.doesExist(temp + (nextStage+1))) { - addStage(itemFrame, temp + (nextStage+1), crop.canRotate()); - } - } - else if (certainGrow || Math.random() < MainConfig.dryGrowChance) { - addStage(itemFrame, temp + nextStage, crop.canRotate()); - } - } - else { - if (MainConfig.enableCrow && cropManager.crowJudge(location, itemFrame)) return true; - GiganticCrop giganticCrop = crop.getGiganticCrop(); - if (giganticCrop != null) { - double chance = giganticCrop.getChance(); - if (fertilizer instanceof Gigantic gigantic) { - chance += gigantic.getChance(); - } - if (Math.random() < chance) { - Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> { - customInterface.removeFurniture(itemFrame); - if (giganticCrop.isBlock()) { - customInterface.placeWire(location, giganticCrop.getBlockID()); - } - else { - customInterface.placeFurniture(location, giganticCrop.getBlockID()); - } - }); - } - } - return true; - } + String[] cropNameList = StringUtils.split(StringUtils.split(id, ":")[1], "_"); + Crop crop = CropConfig.CROPS.get(cropNameList[0]); + if (crop == null) return true; + if ((MainConfig.needSkyLight && location.getBlock().getLightFromSky() < MainConfig.skyLightLevel) || cropManager.isWrongSeason(location, crop.getSeasons())) { + itemFrame.setItem(customInterface.getItemStack(BasicItemConfig.deadCrop), false); + return true; + } + + Location potLoc = location.clone().subtract(0,1,0); + String potID = customInterface.getBlockID(potLoc); + if (potID == null || (!potID.equals(BasicItemConfig.wetPot) && !potID.equals(BasicItemConfig.dryPot))) return true; + + if (MainConfig.enableCrow && cropManager.crowJudge(location, itemFrame)) return true; + + Fertilizer fertilizer = cropManager.getFertilizer(potLoc); + boolean certainGrow = potID.equals(BasicItemConfig.wetPot); + int nextStage = Integer.parseInt(cropNameList[2]) + 1; + String temp = id.substring(0, id.length() - cropNameList[2].length()); + + if (customInterface.doesExist(temp + nextStage)) { + if (fertilizer instanceof SpeedGrow speedGrow + && Math.random() < speedGrow.getChance() + && customInterface.doesExist(temp + (nextStage+1)) + ) + addStage(itemFrame, temp + (nextStage+1), crop.canRotate()); + else if (certainGrow || Math.random() < MainConfig.dryGrowChance) + addStage(itemFrame, temp + nextStage, crop.canRotate()); + return false; + } + else { + GiganticCrop giganticCrop = crop.getGiganticCrop(); + if (giganticCrop != null) { + double chance = giganticCrop.getChance(); + if (fertilizer instanceof Gigantic gigantic) chance += gigantic.getChance(); + if (Math.random() < chance) { + Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> { + customInterface.removeFurniture(itemFrame); + if (giganticCrop.isBlock()) customInterface.placeWire(location, giganticCrop.getBlockID()); + else customInterface.placeFurniture(location, giganticCrop.getBlockID()); + }); + } + } + return true; } - return false; } private void addStage(ItemFrame itemFrame, String stage, boolean rotate) { diff --git a/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderFrameHandler.java b/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderFrameHandler.java index dfad40e..d7519ce 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderFrameHandler.java +++ b/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderFrameHandler.java @@ -69,45 +69,44 @@ public class ItemsAdderFrameHandler extends ItemsAdderHandler { return; } - if (namespacedID.contains("_stage_")) { - if (!canProceedAction(player, location)) return; - if (!namespacedID.equals(BasicItemConfig.deadCrop)) { - ItemStack itemInHand = player.getInventory().getItemInMainHand(); - if (!hasNextStage(namespacedID)) { - if (MainConfig.canRightClickHarvest && !(MainConfig.emptyHand && itemInHand.getType() != Material.AIR)) { - if (!AntiGrief.testBreak(player, entity.getLocation())) return; - if (!canProceedAction(player, entity.getLocation())) return; - CustomFurniture.remove(entity, false); - if (entity.isValid()) entity.remove(); - this.onInteractRipeCrop(location, namespacedID, player); - return; - } - } - //has next stage - else if (MainConfig.enableBoneMeal && itemInHand.getType() == Material.BONE_MEAL) { - if (!AntiGrief.testPlace(player, location)) return; - if (player.getGameMode() != GameMode.CREATIVE) itemInHand.setAmount(itemInHand.getAmount() - 1); - if (Math.random() < MainConfig.boneMealChance) { - entity.getWorld().spawnParticle(MainConfig.boneMealSuccess, location.clone().add(0,0.5, 0),3,0.2,0.2,0.2); - if (SoundConfig.boneMeal.isEnable()) { - AdventureUtil.playerSound( - player, - SoundConfig.boneMeal.getSource(), - SoundConfig.boneMeal.getKey(), - 1,1 - ); - } - CustomFurniture.remove(entity, false); - CustomFurniture.spawn(getNextStage(namespacedID), location.getBlock()); - } + if (!namespacedID.contains("_stage_")) return; + if (!canProceedAction(player, location)) return; + if (!namespacedID.equals(BasicItemConfig.deadCrop)) { + ItemStack itemInHand = player.getInventory().getItemInMainHand(); + if (!customInterface.hasNextStage(namespacedID)) { + if (MainConfig.canRightClickHarvest && !(MainConfig.emptyHand && itemInHand.getType() != Material.AIR)) { + if (!AntiGrief.testBreak(player, entity.getLocation())) return; + if (!canProceedAction(player, entity.getLocation())) return; + customInterface.removeFurniture(entity); + if (entity.isValid()) entity.remove(); + this.onInteractRipeCrop(location, namespacedID, player); return; } } - - if (!AntiGrief.testPlace(player, location)) return; - Location potLoc = location.clone().subtract(0, 1, 0).getBlock().getLocation(); - super.tryMisc(player, player.getInventory().getItemInMainHand(), potLoc); + //has next stage + else if (MainConfig.enableBoneMeal && itemInHand.getType() == Material.BONE_MEAL) { + if (!AntiGrief.testPlace(player, location)) return; + if (player.getGameMode() != GameMode.CREATIVE) itemInHand.setAmount(itemInHand.getAmount() - 1); + if (Math.random() < MainConfig.boneMealChance) { + entity.getWorld().spawnParticle(MainConfig.boneMealSuccess, location.clone().add(0,0.5, 0),3,0.2,0.2,0.2); + if (SoundConfig.boneMeal.isEnable()) { + AdventureUtil.playerSound( + player, + SoundConfig.boneMeal.getSource(), + SoundConfig.boneMeal.getKey(), + 1,1 + ); + } + customInterface.removeFurniture(entity); + customInterface.placeFurniture(location, customInterface.getNextStage(namespacedID)); + } + return; + } } + + if (!AntiGrief.testPlace(player, location)) return; + Location potLoc = location.clone().subtract(0, 1, 0).getBlock().getLocation(); + super.tryMisc(player, player.getInventory().getItemInMainHand(), potLoc); } public void onBreakFurniture(FurnitureBreakEvent event) { @@ -132,7 +131,7 @@ public class ItemsAdderFrameHandler extends ItemsAdderHandler { if (namespacedId.contains("_stage_")) { if (namespacedId.equals(BasicItemConfig.deadCrop)) return; - if (hasNextStage(namespacedId)) { + if (customInterface.hasNextStage(namespacedId)) { super.onBreakUnripeCrop(location); return; } @@ -140,17 +139,6 @@ public class ItemsAdderFrameHandler extends ItemsAdderHandler { } } -// Broken -// //This can only be pot -// public void onInteractBlock(CustomBlockInteractEvent event) { -// if (event.isCancelled()) return; -// String blockID = event.getNamespacedID(); -// if (blockID.equals(BasicItemConfig.dryPot) || blockID.equals(BasicItemConfig.wetPot)) { -// Location potLoc = event.getBlockClicked().getLocation(); -// super.tryMisc(event.getPlayer(), event.getItem(), potLoc); -// } -// } - @Override public void onPlayerInteract(PlayerInteractEvent event) { @@ -209,17 +197,13 @@ public class ItemsAdderFrameHandler extends ItemsAdderHandler { Player player = event.getPlayer(); Location location = event.getBlock().getLocation(); - if (!AntiGrief.testBreak(player, location)) { - return; - } - + if (!AntiGrief.testBreak(player, location)) return; if (!canProceedAction(player, location)) return; if (namespacedId.equals(BasicItemConfig.dryPot) - || namespacedId.equals(BasicItemConfig.wetPot)) { - + || namespacedId.equals(BasicItemConfig.wetPot) + ) { super.onBreakPot(location); - //Check if there's crop above Location seedLocation = location.clone().add(0.5,1.5,0.5); @@ -232,7 +216,7 @@ public class ItemsAdderFrameHandler extends ItemsAdderHandler { CustomFurniture.remove(itemFrame, false); if (itemFrame.isValid()) itemFrame.remove(); if (seedID.equals(BasicItemConfig.deadCrop)) return; - if (hasNextStage(seedID)) { + if (customInterface.hasNextStage(seedID)) { super.onBreakUnripeCrop(location); return; } @@ -242,14 +226,12 @@ public class ItemsAdderFrameHandler extends ItemsAdderHandler { } private void onInteractRipeCrop(Location location, String id, Player player) { - Crop crop = getCropFromID(id); + Crop crop = customInterface.getCropFromID(id); if (crop == null) return; if (super.onInteractRipeCrop(location, crop, player)) return; - CustomFurniture customFurniture = CustomFurniture.spawn(crop.getReturnStage(), location.getBlock()); - if (crop.canRotate() && customFurniture != null) { - if (customFurniture instanceof ItemFrame itemFrame) { - itemFrame.setRotation(FurnitureUtil.getRandomRotation()); - } + if (crop.getReturnStage() != null) { + CustomFurniture customFurniture = CustomFurniture.spawn(crop.getReturnStage(), location.getBlock()); + if (crop.canRotate() && customFurniture instanceof ItemFrame itemFrame) itemFrame.setRotation(FurnitureUtil.getRandomRotation()); } } } diff --git a/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderHandler.java b/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderHandler.java index 9221ffb..efb37ca 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderHandler.java +++ b/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderHandler.java @@ -20,12 +20,17 @@ package net.momirealms.customcrops.integrations.customplugin.itemsadder; import de.tr7zw.changeme.nbtapi.NBTCompound; import de.tr7zw.changeme.nbtapi.NBTItem; import dev.lone.itemsadder.api.CustomStack; -import dev.lone.itemsadder.api.Events.*; +import dev.lone.itemsadder.api.Events.CustomBlockBreakEvent; +import dev.lone.itemsadder.api.Events.FurnitureBreakEvent; +import dev.lone.itemsadder.api.Events.FurnitureInteractEvent; +import dev.lone.itemsadder.api.Events.FurniturePlaceSuccessEvent; import net.kyori.adventure.key.Key; import net.momirealms.customcrops.CustomCrops; -import net.momirealms.customcrops.api.crop.Crop; import net.momirealms.customcrops.api.event.WaterPotEvent; -import net.momirealms.customcrops.config.*; +import net.momirealms.customcrops.config.BasicItemConfig; +import net.momirealms.customcrops.config.MainConfig; +import net.momirealms.customcrops.config.SoundConfig; +import net.momirealms.customcrops.config.WaterCanConfig; import net.momirealms.customcrops.integrations.AntiGrief; import net.momirealms.customcrops.integrations.customplugin.HandlerP; import net.momirealms.customcrops.integrations.customplugin.itemsadder.listeners.ItemsAdderBlockListener; @@ -34,7 +39,6 @@ import net.momirealms.customcrops.managers.CropManager; import net.momirealms.customcrops.managers.CustomWorld; import net.momirealms.customcrops.objects.WaterCan; import net.momirealms.customcrops.utils.AdventureUtil; -import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -208,20 +212,10 @@ public abstract class ItemsAdderHandler extends HandlerP { return true; } - @Override - public Crop getCropFromID(String namespacedID) { - String[] cropNameList = StringUtils.split(StringUtils.split(namespacedID, ":")[1], "_"); - return CropConfig.CROPS.get(cropNameList[0]); - } - public void onBreakBlock(CustomBlockBreakEvent event) { //null } - public void onInteractBlock(CustomBlockInteractEvent event) { - //null - } - public void onInteractFurniture(FurnitureInteractEvent event) { //null } diff --git a/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderHook.java b/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderHook.java index 37c689a..6183a02 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderHook.java +++ b/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderHook.java @@ -22,7 +22,10 @@ import de.tr7zw.changeme.nbtapi.NBTItem; import dev.lone.itemsadder.api.CustomBlock; import dev.lone.itemsadder.api.CustomFurniture; import dev.lone.itemsadder.api.CustomStack; +import net.momirealms.customcrops.api.crop.Crop; +import net.momirealms.customcrops.config.CropConfig; import net.momirealms.customcrops.integrations.customplugin.CustomInterface; +import org.apache.commons.lang.StringUtils; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.entity.Entity; @@ -98,4 +101,27 @@ public class ItemsAdderHook implements CustomInterface { return CustomStack.getInstance(itemID) != null; } + @Override + public boolean hasNextStage(String id) { + return doesExist(getNextStage(id)); + } + + @Override + public String getNextStage(String id) { + String[] split = StringUtils.split(id, ":"); + String[] crop = StringUtils.split(split[1], "_"); + int nextStage = Integer.parseInt(crop[2]) + 1; + return split[0] + ":" + crop[0] + "_" + crop[1] + "_" + nextStage; + } + + @Override + public @Nullable Crop getCropFromID(String id) { + String[] cropNameList = StringUtils.split(StringUtils.split(id, ":")[1], "_"); + return CropConfig.CROPS.get(cropNameList[0]); + } + + @Override + public Location getFrameCropLocation(Location seedLoc) { + return seedLoc.clone().add(0.5,0.5,0.5); + } } diff --git a/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderWireCropImpl.java b/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderWireCropImpl.java index ea76333..78dcd0b 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderWireCropImpl.java +++ b/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderWireCropImpl.java @@ -46,17 +46,13 @@ public class ItemsAdderWireCropImpl implements CropModeInterface { @Override public boolean growJudge(Location location) { String blockID = customInterface.getBlockID(location); - if (blockID == null) return true; - if (!blockID.contains("_stage_")) return true; + if (blockID == null || !blockID.contains("_stage_")) return true; - String cropId = StringUtils.split(blockID, ":")[1]; - String[] cropNameList = StringUtils.split(cropId, "_"); - String cropKey = cropNameList[0]; - - Crop crop = CropConfig.CROPS.get(cropKey); + String[] cropNameList = StringUtils.split(StringUtils.split(blockID, ":")[1], "_"); + Crop crop = CropConfig.CROPS.get(cropNameList[0]); if (crop == null) return true; - if (MainConfig.needSkyLight && location.getBlock().getLightFromSky() < MainConfig.skyLightLevel) { + if ((MainConfig.needSkyLight && location.getBlock().getLightFromSky() < MainConfig.skyLightLevel) || cropManager.isWrongSeason(location, crop.getSeasons())) { Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> { customInterface.removeBlock(location); customInterface.placeWire(location, BasicItemConfig.deadCrop); @@ -64,56 +60,42 @@ public class ItemsAdderWireCropImpl implements CropModeInterface { return true; } - if (cropManager.isWrongSeason(location, crop.getSeasons())) { - Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> { - customInterface.removeBlock(location); - customInterface.placeWire(location, BasicItemConfig.deadCrop); - }); - return true; - } Location potLoc = location.clone().subtract(0,1,0); String potID = customInterface.getBlockID(potLoc); - if (potID == null) return true; + if (potID == null || (!potID.equals(BasicItemConfig.wetPot) && !potID.equals(BasicItemConfig.dryPot))) return true; + + if (MainConfig.enableCrow && cropManager.crowJudge(location)) return true; Fertilizer fertilizer = cropManager.getFertilizer(potLoc); boolean certainGrow = potID.equals(BasicItemConfig.wetPot); int nextStage = Integer.parseInt(cropNameList[2]) + 1; - String temp = blockID.substring(0, blockID.length() - cropNameList[2].length()); + String temp = blockID.substring(0, blockID.length() - cropNameList[2].length()); if (customInterface.doesExist(temp + nextStage)) { - if (MainConfig.enableCrow && cropManager.crowJudge(location)) return true; - if (fertilizer instanceof SpeedGrow speedGrow && Math.random() < speedGrow.getChance()) { - if (customInterface.doesExist(temp + (nextStage+1))) { - addStage(location, temp + (nextStage+1)); - } - } - else if (certainGrow || Math.random() < MainConfig.dryGrowChance) { + if (fertilizer instanceof SpeedGrow speedGrow + && Math.random() < speedGrow.getChance() + && customInterface.doesExist(temp + (nextStage+1)) + ) + addStage(location, temp + (nextStage+1)); + else if (certainGrow || Math.random() < MainConfig.dryGrowChance) addStage(location, temp + nextStage); - } + return false; } else { - if (MainConfig.enableCrow && cropManager.crowJudge(location)) return true; GiganticCrop giganticCrop = crop.getGiganticCrop(); if (giganticCrop != null) { double chance = giganticCrop.getChance(); - if (fertilizer instanceof Gigantic gigantic) { - chance += gigantic.getChance(); - } + if (fertilizer instanceof Gigantic gigantic) chance += gigantic.getChance(); if (Math.random() < chance) { Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> { customInterface.removeBlock(location); - if (giganticCrop.isBlock()) { - customInterface.placeWire(location, giganticCrop.getBlockID()); - } - else { - customInterface.placeFurniture(location, giganticCrop.getBlockID()); - } + if (giganticCrop.isBlock()) customInterface.placeWire(location, giganticCrop.getBlockID()); + else customInterface.placeFurniture(location, giganticCrop.getBlockID()); }); } } return true; } - return false; } private void addStage(Location seedLoc, String stage) { diff --git a/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderWireHandler.java b/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderWireHandler.java index 12cda50..1c3f470 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderWireHandler.java +++ b/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/ItemsAdderWireHandler.java @@ -20,7 +20,6 @@ package net.momirealms.customcrops.integrations.customplugin.itemsadder; import dev.lone.itemsadder.api.CustomBlock; import dev.lone.itemsadder.api.CustomStack; import dev.lone.itemsadder.api.Events.CustomBlockBreakEvent; -import dev.lone.itemsadder.api.Events.CustomBlockInteractEvent; import dev.lone.itemsadder.api.Events.FurnitureBreakEvent; import dev.lone.itemsadder.api.Events.FurnitureInteractEvent; import net.momirealms.customcrops.api.crop.Crop; @@ -114,12 +113,11 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler { ItemStack itemInHand = event.getItem(); if (!blockID.equals(BasicItemConfig.deadCrop)) { - if (!hasNextStage(blockID)) { + if (!customInterface.hasNextStage(blockID)) { ItemStack mainHand = player.getInventory().getItemInMainHand(); ItemStack offHand = player.getInventory().getItemInOffHand(); if (MainConfig.canRightClickHarvest && !(MainConfig.emptyHand && (mainHand.getType() != Material.AIR || offHand.getType() != Material.AIR))) { if (!AntiGrief.testBreak(player, location)) return; - CustomBlock.remove(location); this.onInteractRipeCrop(location, blockID, player); return; @@ -140,7 +138,7 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler { ); } CustomBlock.remove(location); - CustomBlock.place(getNextStage(blockID), location); + CustomBlock.place(customInterface.getNextStage(blockID), location); } return; } @@ -178,87 +176,8 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler { } } - public void onInteractBlock(CustomBlockInteractEvent event) { - - // A broken API Event -// -// if (event.isCancelled()) return; -// if (event.getAction() != Action.RIGHT_CLICK_BLOCK) return; -// -// final Player player = event.getPlayer(); -// final String blockID = event.getNamespacedID(); -// //interact crop -// if (blockID.contains("_stage_")) { -// -// if (!blockID.equals(BasicItemConfig.deadCrop)) { -// //ripe crops -// if (!hasNextStage(blockID) && MainConfig.canRightClickHarvest) { -// Location seedLoc = event.getBlockClicked().getLocation(); -// CustomBlock.remove(seedLoc); -// this.onInteractRipeCrop(seedLoc, blockID, event.getPlayer()); -// } -// -// else { -// Location potLoc = event.getBlockClicked().getLocation().clone().subtract(0,1,0); -// super.tryMisc(player, event.getItem(), potLoc); -// } -// } -// } -// -// //interact pot (must have an item) -// else if (blockID.equals(BasicItemConfig.wetPot) || blockID.equals(BasicItemConfig.dryPot)) { -// -// Location seedLoc = event.getBlockClicked().getLocation().clone().add(0,1,0); -// if (!AntiGrief.testPlace(player, seedLoc)) return; -// -// ItemStack itemInHand = event.getItem(); -// Location potLoc = event.getBlockClicked().getLocation(); -// super.tryMisc(player, itemInHand, potLoc); -// -// if (event.getBlockFace() != BlockFace.UP) return; -// if (itemInHand == null || itemInHand.getType() == Material.AIR) return; -// CustomStack customStack = CustomStack.byItemStack(itemInHand); -// if (customStack == null) return; -// String namespacedID = customStack.getNamespacedID(); -// if (namespacedID.endsWith("_seeds")) { -// String cropName = customStack.getId().substring(0, customStack.getId().length() - 6); -// Crop crop = CropConfig.CROPS.get(cropName); -// if (crop == null) return; -// -// CustomWorld customWorld = cropManager.getCustomWorld(seedLoc.getWorld()); -// if (customWorld == null) return; -// -// if (FurnitureUtil.hasFurniture(seedLoc)) return; -// if (seedLoc.getBlock().getType() != Material.AIR) return; -// -// PlantingCondition plantingCondition = new PlantingCondition(seedLoc, player); -// -// if (crop.getRequirements() != null) { -// for (RequirementInterface requirement : crop.getRequirements()) { -// if (!requirement.isConditionMet(plantingCondition)) { -// return; -// } -// } -// } -// -// if (SoundConfig.plantSeed.isEnable()) { -// AdventureUtil.playerSound( -// player, -// SoundConfig.plantSeed.getSource(), -// SoundConfig.plantSeed.getKey(), -// 1,1 -// ); -// } -// -// if (player.getGameMode() != GameMode.CREATIVE) itemInHand.setAmount(itemInHand.getAmount() - 1); -// CustomBlock.place(namespacedID.substring(0, namespacedID.length() - 5) + "stage_1", seedLoc); -// customWorld.addCrop(seedLoc, cropName); -// } -// } - } - private void onInteractRipeCrop(Location location, String id, Player player) { - Crop crop = getCropFromID(id); + Crop crop = customInterface.getCropFromID(id); if (crop == null) return; if (super.onInteractRipeCrop(location, crop, player)) return; if (crop.getReturnStage() != null) CustomBlock.place(crop.getReturnStage(), location); @@ -295,7 +214,7 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler { } if (namespacedId.equals(BasicItemConfig.deadCrop)) return; - if (hasNextStage(namespacedId)) { + if (customInterface.hasNextStage(namespacedId)) { super.onBreakUnripeCrop(location); return; } @@ -327,7 +246,7 @@ public class ItemsAdderWireHandler extends ItemsAdderHandler { CustomBlock.remove(seedLocation); if (seedID.equals(BasicItemConfig.deadCrop)) return; //ripe or not - if (hasNextStage(seedID)) { + if (customInterface.hasNextStage(seedID)) { if (player.getGameMode() == GameMode.CREATIVE) return; customBlock.getLoot().forEach(loot -> location.getWorld().dropItemNaturally(seedLocation.getBlock().getLocation(), loot)); } diff --git a/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/listeners/ItemsAdderBlockListener.java b/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/listeners/ItemsAdderBlockListener.java index 48e4f89..79744c6 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/listeners/ItemsAdderBlockListener.java +++ b/src/main/java/net/momirealms/customcrops/integrations/customplugin/itemsadder/listeners/ItemsAdderBlockListener.java @@ -36,8 +36,4 @@ public class ItemsAdderBlockListener implements Listener { handler.onBreakBlock(event); } - @EventHandler - public void onInteractBlock(CustomBlockInteractEvent event) { - handler.onInteractBlock(event); - } } diff --git a/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenFrameCropImpl.java b/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenFrameCropImpl.java index bb60ba9..622ebe3 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenFrameCropImpl.java +++ b/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenFrameCropImpl.java @@ -52,76 +52,60 @@ public class OraxenFrameCropImpl implements CropModeInterface { Chunk chunk = location.getChunk(); - if (chunk.isEntitiesLoaded()) { + if (chunk.isEntitiesLoaded()) return false; - Location cropLoc = location.clone().add(0.5,0.03125,0.5); - ItemFrame itemFrame = FurnitureUtil.getItemFrame(cropLoc); - if (itemFrame == null) return true; - String id = customInterface.getItemID(itemFrame.getItem()); - if (id == null) return true; - if (id.equals(BasicItemConfig.deadCrop)) return true; + ItemFrame itemFrame = FurnitureUtil.getItemFrame(customInterface.getFrameCropLocation(location)); + if (itemFrame == null) return true; - String[] cropNameList = StringUtils.split(id,"_"); - String cropKey = cropNameList[0]; - Crop crop = CropConfig.CROPS.get(cropKey); - if (crop == null) return true; + String id = customInterface.getItemID(itemFrame.getItem()); + if (id == null || id.equals(BasicItemConfig.deadCrop)) return true; - if (MainConfig.needSkyLight && location.getBlock().getLightFromSky() < MainConfig.skyLightLevel) { - itemFrame.setItem(customInterface.getItemStack(BasicItemConfig.deadCrop), false); - itemFrame.getPersistentDataContainer().set(OraxenHook.FURNITURE, PersistentDataType.STRING, BasicItemConfig.deadCrop); - return true; - } + String[] cropNameList = StringUtils.split(id,"_"); + Crop crop = CropConfig.CROPS.get(cropNameList[0]); + if (crop == null) return true; - if (cropManager.isWrongSeason(location, crop.getSeasons())) { - itemFrame.setItem(customInterface.getItemStack(BasicItemConfig.deadCrop), false); - itemFrame.getPersistentDataContainer().set(OraxenHook.FURNITURE, PersistentDataType.STRING, BasicItemConfig.deadCrop); - return true; - } - - Location potLoc = location.clone().subtract(0,1,0); - String potID = customInterface.getBlockID(potLoc); - if (potID == null) return true; - - Fertilizer fertilizer = cropManager.getFertilizer(potLoc); - boolean certainGrow = potID.equals(BasicItemConfig.wetPot); - - int nextStage = Integer.parseInt(cropNameList[2]) + 1; - String temp = StringUtils.chop(id); - if (customInterface.doesExist(temp + nextStage)) { - if (MainConfig.enableCrow && cropManager.crowJudge(location, itemFrame)) return true; - if (fertilizer instanceof SpeedGrow speedGrow && Math.random() < speedGrow.getChance()) { - if (customInterface.doesExist(temp + (nextStage+1))) { - addStage(itemFrame, temp + (nextStage+1)); - } - } - else if (certainGrow || Math.random() < MainConfig.dryGrowChance) { - addStage(itemFrame, temp + nextStage); - } - } - else { - if (MainConfig.enableCrow && cropManager.crowJudge(location, itemFrame)) return true; - GiganticCrop giganticCrop = crop.getGiganticCrop(); - if (giganticCrop != null) { - double chance = giganticCrop.getChance(); - if (fertilizer instanceof Gigantic gigantic) { - chance += gigantic.getChance(); - } - if (Math.random() < chance) { - Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> { - customInterface.removeFurniture(itemFrame); - if (giganticCrop.isBlock()) { - customInterface.placeWire(location, giganticCrop.getBlockID()); - } - else { - customInterface.placeFurniture(location, giganticCrop.getBlockID()); - } - }); - } - } - return true; - } + if ((MainConfig.needSkyLight && location.getBlock().getLightFromSky() < MainConfig.skyLightLevel) || cropManager.isWrongSeason(location, crop.getSeasons())) { + itemFrame.setItem(customInterface.getItemStack(BasicItemConfig.deadCrop), false); + itemFrame.getPersistentDataContainer().set(OraxenHook.FURNITURE, PersistentDataType.STRING, BasicItemConfig.deadCrop); + return true; + } + + Location potLoc = location.clone().subtract(0,1,0); + String potID = customInterface.getBlockID(potLoc); + if (potID == null || (!potID.equals(BasicItemConfig.wetPot) && !potID.equals(BasicItemConfig.dryPot))) return true; + + Fertilizer fertilizer = cropManager.getFertilizer(potLoc); + boolean certainGrow = potID.equals(BasicItemConfig.wetPot); + + int nextStage = Integer.parseInt(cropNameList[2]) + 1; + String temp = StringUtils.chop(id); + + if (MainConfig.enableCrow && cropManager.crowJudge(location, itemFrame)) return true; + if (customInterface.doesExist(temp + nextStage)) { + if (fertilizer instanceof SpeedGrow speedGrow + && Math.random() < speedGrow.getChance() + && customInterface.doesExist(temp + (nextStage+1)) + ) + addStage(itemFrame, temp + (nextStage+1)); + else if (certainGrow || Math.random() < MainConfig.dryGrowChance) + addStage(itemFrame, temp + nextStage); + return false; + } + else { + GiganticCrop giganticCrop = crop.getGiganticCrop(); + if (giganticCrop != null) { + double chance = giganticCrop.getChance(); + if (fertilizer instanceof Gigantic gigantic) chance += gigantic.getChance(); + if (Math.random() < chance) { + Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> { + customInterface.removeFurniture(itemFrame); + if (giganticCrop.isBlock()) customInterface.placeWire(location, giganticCrop.getBlockID()); + else customInterface.placeFurniture(location, giganticCrop.getBlockID()); + }); + } + } + return true; } - return false; } private void addStage(ItemFrame itemFrame, String stage) { diff --git a/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenFrameHandler.java b/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenFrameHandler.java index d5a6f33..8250848 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenFrameHandler.java +++ b/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenFrameHandler.java @@ -79,7 +79,7 @@ public class OraxenFrameHandler extends OraxenHandler { if (furnitureID.contains("_stage_")) { itemFrame.remove(); if (furnitureID.equals(BasicItemConfig.deadCrop)) return; - if (hasNextStage(furnitureID)) { + if (customInterface.hasNextStage(furnitureID)) { FurnitureMechanic mechanic = (FurnitureMechanic) FurnitureFactory.instance.getMechanic(furnitureID); if (mechanic == null) return; Drop drop = mechanic.getDrop(); @@ -113,7 +113,7 @@ public class OraxenFrameHandler extends OraxenHandler { if (id.contains("_stage_")) { if (id.equals(BasicItemConfig.deadCrop)) return; - if (hasNextStage(id)) { + if (customInterface.hasNextStage(id)) { super.onBreakUnripeCrop(event.getBlock().getLocation()); return; } @@ -177,52 +177,51 @@ public class OraxenFrameHandler extends OraxenHandler { return; } - if (id.contains("_stage_")) { - if (!id.equals(BasicItemConfig.deadCrop)) { - ItemStack itemInHand = player.getInventory().getItemInMainHand(); - if (!hasNextStage(id)) { - if (MainConfig.canRightClickHarvest && !(MainConfig.emptyHand && itemInHand.getType() != Material.AIR)) { - if (!AntiGrief.testBreak(player, location)) return; - itemFrame.remove(); - this.onInteractRipeCrop(location, id, player); - return; - } - } - //has next stage - else if (MainConfig.enableBoneMeal && itemInHand.getType() == Material.BONE_MEAL) { - if (!AntiGrief.testPlace(player, location)) return; - if (player.getGameMode() != GameMode.CREATIVE) itemInHand.setAmount(itemInHand.getAmount() - 1); - if (Math.random() < MainConfig.boneMealChance) { - itemFrame.getWorld().spawnParticle(MainConfig.boneMealSuccess, location.clone().add(0,0.5, 0),3,0.2,0.2,0.2); - if (SoundConfig.boneMeal.isEnable()) { - AdventureUtil.playerSound( - player, - SoundConfig.boneMeal.getSource(), - SoundConfig.boneMeal.getKey(), - 1,1 - ); - } - String nextStage = getNextStage(id); - itemFrame.setItem(customInterface.getItemStack(nextStage)); - itemFrame.getPersistentDataContainer().set(OraxenHook.FURNITURE, PersistentDataType.STRING, nextStage); - } + if (!id.contains("_stage_")) return; + if (!id.equals(BasicItemConfig.deadCrop)) { + ItemStack itemInHand = player.getInventory().getItemInMainHand(); + if (!customInterface.hasNextStage(id)) { + if (MainConfig.canRightClickHarvest && !(MainConfig.emptyHand && itemInHand.getType() != Material.AIR)) { + if (!AntiGrief.testBreak(player, location)) return; + itemFrame.remove(); + this.onInteractRipeCrop(location, id, player); return; } } - - if (!AntiGrief.testPlace(player, location)) return; - Location potLoc = location.clone().subtract(0,1,0).getBlock().getLocation(); - super.tryMisc(player, player.getInventory().getItemInMainHand(), potLoc); + //has next stage + else if (MainConfig.enableBoneMeal && itemInHand.getType() == Material.BONE_MEAL) { + if (!AntiGrief.testPlace(player, location)) return; + if (player.getGameMode() != GameMode.CREATIVE) itemInHand.setAmount(itemInHand.getAmount() - 1); + if (Math.random() < MainConfig.boneMealChance) { + itemFrame.getWorld().spawnParticle(MainConfig.boneMealSuccess, location.clone().add(0,0.5, 0),3,0.2,0.2,0.2); + if (SoundConfig.boneMeal.isEnable()) { + AdventureUtil.playerSound( + player, + SoundConfig.boneMeal.getSource(), + SoundConfig.boneMeal.getKey(), + 1,1 + ); + } + String nextStage = customInterface.getNextStage(id); + itemFrame.setItem(customInterface.getItemStack(nextStage)); + itemFrame.getPersistentDataContainer().set(OraxenHook.FURNITURE, PersistentDataType.STRING, nextStage); + } + return; + } } + + if (!AntiGrief.testPlace(player, location)) return; + Location potLoc = location.clone().subtract(0,1,0).getBlock().getLocation(); + super.tryMisc(player, player.getInventory().getItemInMainHand(), potLoc); } private void onInteractRipeCrop(Location location, String id, Player player) { - Crop crop = getCropFromID(id); + Crop crop = customInterface.getCropFromID(id); if (crop == null) return; if (super.onInteractRipeCrop(location, crop, player)) return; - ItemFrame itemFrame = cropManager.getCustomInterface().placeFurniture(location, crop.getReturnStage()); - if (crop.canRotate() && itemFrame != null) { - itemFrame.setRotation(FurnitureUtil.getRandomRotation()); + if (crop.getReturnStage() != null) { + ItemFrame itemFrame = cropManager.getCustomInterface().placeFurniture(location, crop.getReturnStage()); + if (crop.canRotate() && itemFrame != null) itemFrame.setRotation(FurnitureUtil.getRandomRotation()); } } } \ No newline at end of file diff --git a/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenHandler.java b/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenHandler.java index b33dcca..18b266b 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenHandler.java +++ b/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenHandler.java @@ -23,9 +23,11 @@ import io.th0rgal.oraxen.api.OraxenItems; import io.th0rgal.oraxen.api.events.*; import io.th0rgal.oraxen.mechanics.provided.gameplay.furniture.FurnitureMechanic; import net.momirealms.customcrops.CustomCrops; -import net.momirealms.customcrops.api.crop.Crop; import net.momirealms.customcrops.api.event.WaterPotEvent; -import net.momirealms.customcrops.config.*; +import net.momirealms.customcrops.config.BasicItemConfig; +import net.momirealms.customcrops.config.MainConfig; +import net.momirealms.customcrops.config.SoundConfig; +import net.momirealms.customcrops.config.WaterCanConfig; import net.momirealms.customcrops.integrations.customplugin.HandlerP; import net.momirealms.customcrops.integrations.customplugin.oraxen.listeners.OraxenBlockListener; import net.momirealms.customcrops.integrations.customplugin.oraxen.listeners.OraxenFurnitureListener; @@ -33,7 +35,6 @@ import net.momirealms.customcrops.managers.CropManager; import net.momirealms.customcrops.managers.CustomWorld; import net.momirealms.customcrops.objects.WaterCan; import net.momirealms.customcrops.utils.AdventureUtil; -import org.apache.commons.lang.StringUtils; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; @@ -45,7 +46,6 @@ import org.bukkit.event.block.Action; import org.bukkit.event.player.PlayerInteractEvent; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; public abstract class OraxenHandler extends HandlerP { @@ -188,12 +188,6 @@ public abstract class OraxenHandler extends HandlerP { return true; } - @Nullable - @Override - public Crop getCropFromID(String id) { - return CropConfig.CROPS.get(StringUtils.split(id, "_")[0]); - } - public void onBreakNoteBlock(OraxenNoteBlockBreakEvent event) { } diff --git a/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenHook.java b/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenHook.java index 007f39b..eab0d2c 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenHook.java +++ b/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenHook.java @@ -27,8 +27,10 @@ import io.th0rgal.oraxen.mechanics.provided.gameplay.noteblock.NoteBlockMechanic import io.th0rgal.oraxen.mechanics.provided.gameplay.noteblock.NoteBlockMechanicFactory; import io.th0rgal.oraxen.mechanics.provided.gameplay.stringblock.StringBlockMechanic; import io.th0rgal.oraxen.mechanics.provided.gameplay.stringblock.StringBlockMechanicFactory; +import net.momirealms.customcrops.api.crop.Crop; +import net.momirealms.customcrops.config.CropConfig; import net.momirealms.customcrops.integrations.customplugin.CustomInterface; -import net.momirealms.customcrops.utils.FurnitureUtil; +import org.apache.commons.lang.StringUtils; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.NamespacedKey; @@ -106,4 +108,26 @@ public class OraxenHook implements CustomInterface { public boolean doesExist(String itemID) { return OraxenItems.getItemById(itemID) != null; } + + @Override + public boolean hasNextStage(String id) { + return doesExist(getNextStage(id)); + } + + @Override + public String getNextStage(String id) { + String[] crop = StringUtils.split(id,"_"); + int nextStage = Integer.parseInt(crop[2]) + 1; + return crop[0] + "_" + crop[1] + "_" + nextStage; + } + + @Override + public @Nullable Crop getCropFromID(String id) { + return CropConfig.CROPS.get(StringUtils.split(id, "_")[0]); + } + + @Override + public Location getFrameCropLocation(Location seedLoc) { + return seedLoc.clone().add(0.5,0.03125,0.5); + } } diff --git a/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenWireCropImpl.java b/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenWireCropImpl.java index bc3b844..a207f25 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenWireCropImpl.java +++ b/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenWireCropImpl.java @@ -46,65 +46,53 @@ public class OraxenWireCropImpl implements CropModeInterface { @Override public boolean growJudge(Location location) { String blockID = customInterface.getBlockID(location); - if (blockID == null) return true; - if (!blockID.contains("_stage_")) return true; + if (blockID == null || !blockID.contains("_stage_")) return true; + String[] cropNameList = StringUtils.split(blockID,"_"); - String cropKey = cropNameList[0]; - Crop crop = CropConfig.CROPS.get(cropKey); + Crop crop = CropConfig.CROPS.get(cropNameList[0]); if (crop == null) return true; - if (MainConfig.needSkyLight && location.getBlock().getLightFromSky() < MainConfig.skyLightLevel) { - Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> customInterface.placeWire(location, BasicItemConfig.deadCrop)); - return true; - } - - if (cropManager.isWrongSeason(location, crop.getSeasons())) { + if ((MainConfig.needSkyLight && location.getBlock().getLightFromSky() < MainConfig.skyLightLevel) || cropManager.isWrongSeason(location, crop.getSeasons())) { Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> customInterface.placeWire(location, BasicItemConfig.deadCrop)); return true; } Location potLoc = location.clone().subtract(0,1,0); String potID = customInterface.getBlockID(potLoc); - if (potID == null) return true; + if (potID == null || (!potID.equals(BasicItemConfig.wetPot) && !potID.equals(BasicItemConfig.dryPot))) return true; + + if (MainConfig.enableCrow && cropManager.crowJudge(location)) return true; Fertilizer fertilizer = cropManager.getFertilizer(potLoc); boolean certainGrow = potID.equals(BasicItemConfig.wetPot); int nextStage = Integer.parseInt(cropNameList[2]) + 1; + String temp = cropNameList[0] + "_" + cropNameList[1] + "_"; if (customInterface.doesExist(temp + nextStage)) { - if (MainConfig.enableCrow && cropManager.crowJudge(location)) return true; - if (fertilizer instanceof SpeedGrow speedGrow && Math.random() < speedGrow.getChance()) { - if (customInterface.doesExist(temp + (nextStage+1))) { - addStage(location, temp + (nextStage+1)); - } - } - else if (certainGrow || Math.random() < MainConfig.dryGrowChance) { + if (fertilizer instanceof SpeedGrow speedGrow + && Math.random() < speedGrow.getChance() + && customInterface.doesExist(temp + (nextStage+1)) + ) + addStage(location, temp + (nextStage+1)); + else if (certainGrow || Math.random() < MainConfig.dryGrowChance) addStage(location, temp + nextStage); - } + return false; } else { - if (MainConfig.enableCrow && cropManager.crowJudge(location)) return true; GiganticCrop giganticCrop = crop.getGiganticCrop(); if (giganticCrop != null) { double chance = giganticCrop.getChance(); - if (fertilizer instanceof Gigantic gigantic) { - chance += gigantic.getChance(); - } + if (fertilizer instanceof Gigantic gigantic) chance += gigantic.getChance(); if (Math.random() < chance) { Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> { customInterface.removeBlock(location); - if (giganticCrop.isBlock()) { - customInterface.placeWire(location, giganticCrop.getBlockID()); - } - else { - customInterface.placeFurniture(location, giganticCrop.getBlockID()); - } + if (giganticCrop.isBlock()) customInterface.placeWire(location, giganticCrop.getBlockID()); + else customInterface.placeFurniture(location, giganticCrop.getBlockID()); }); } } return true; } - return false; } private void addStage(Location seedLoc, String stage) { diff --git a/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenWireHandler.java b/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenWireHandler.java index b7c81fe..697cc8a 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenWireHandler.java +++ b/src/main/java/net/momirealms/customcrops/integrations/customplugin/oraxen/OraxenWireHandler.java @@ -47,11 +47,6 @@ public class OraxenWireHandler extends OraxenHandler{ super(cropManager); } - @Override - public void onBreakNoteBlock(OraxenNoteBlockBreakEvent event) { - // not necessary because string break event would be triggered too - } - @Override public void onBreakStringBlock(OraxenStringBlockBreakEvent event) { if (event.isCancelled()) return; @@ -86,7 +81,7 @@ public class OraxenWireHandler extends OraxenHandler{ } if (id.equals(BasicItemConfig.deadCrop)) return; - if (hasNextStage(id)) { + if (customInterface.hasNextStage(id)) { super.onBreakUnripeCrop(location); return; } @@ -183,7 +178,7 @@ public class OraxenWireHandler extends OraxenHandler{ //ripe crops if (!id.equals(BasicItemConfig.deadCrop)) { - if (!hasNextStage(id)) { + if (!customInterface.hasNextStage(id)) { if (MainConfig.canRightClickHarvest && !(MainConfig.emptyHand && itemInHand != null && itemInHand.getType() != Material.AIR)) { if (!AntiGrief.testBreak(player, seedLoc)) return; @@ -206,7 +201,7 @@ public class OraxenWireHandler extends OraxenHandler{ 1,1 ); } - StringBlockMechanicFactory.setBlockModel(block, getNextStage(id)); + StringBlockMechanicFactory.setBlockModel(block, customInterface.getNextStage(id)); } return; } @@ -221,9 +216,9 @@ public class OraxenWireHandler extends OraxenHandler{ } private void onInteractRipeCrop(Location location, String id, Player player) { - Crop crop = getCropFromID(id); + Crop crop = customInterface.getCropFromID(id); if (crop == null) return; if (super.onInteractRipeCrop(location, crop, player)) return; - StringBlockMechanicFactory.setBlockModel(location.getBlock(), crop.getReturnStage()); + if (crop.getReturnStage() != null) StringBlockMechanicFactory.setBlockModel(location.getBlock(), crop.getReturnStage()); } } \ No newline at end of file diff --git a/src/main/java/net/momirealms/customcrops/integrations/protection/WorldGuardHook.java b/src/main/java/net/momirealms/customcrops/integrations/protection/WorldGuardHook.java index e1abefa..e49e4d9 100644 --- a/src/main/java/net/momirealms/customcrops/integrations/protection/WorldGuardHook.java +++ b/src/main/java/net/momirealms/customcrops/integrations/protection/WorldGuardHook.java @@ -41,7 +41,7 @@ public class WorldGuardHook implements AntiGrief { WorldGuardPlatform platform = WorldGuard.getInstance().getPlatform(); if (hasRegion(world, BukkitAdapter.asBlockVector(location))){ RegionQuery query = platform.getRegionContainer().createQuery(); - return query.testState(BukkitAdapter.adapt(location), localPlayer, Flags.BUILD); + return query.testBuild(BukkitAdapter.adapt(location), localPlayer, Flags.BUILD); } else return true; } @@ -53,7 +53,7 @@ public class WorldGuardHook implements AntiGrief { WorldGuardPlatform platform = WorldGuard.getInstance().getPlatform(); if (hasRegion(world, BukkitAdapter.asBlockVector(location))){ RegionQuery query = platform.getRegionContainer().createQuery(); - return query.testState(BukkitAdapter.adapt(location), localPlayer, Flags.BLOCK_BREAK); + return query.testBuild(BukkitAdapter.adapt(location), localPlayer, Flags.BLOCK_BREAK); } else return true; }