diff --git a/src/main/java/net/momirealms/customcrops/datamanager/CropManager.java b/src/main/java/net/momirealms/customcrops/datamanager/CropManager.java index bedd804..54f718c 100644 --- a/src/main/java/net/momirealms/customcrops/datamanager/CropManager.java +++ b/src/main/java/net/momirealms/customcrops/datamanager/CropManager.java @@ -146,10 +146,13 @@ public class CropManager { } Location potLocation = seedLocation.clone().subtract(0,1,0); CustomBlock pot = CustomBlock.byAlreadyPlaced(potLocation.getBlock()); - if (pot == null) return; String potNamespacedID = pot.getNamespacedID(); String[] cropNameList = StringUtils.split(id,"_"); CropInstance cropInstance = ConfigReader.CROPS.get(cropNameList[0]); + if (pot == null || cropInstance == null){ + data.set(stringBuilder.toString(), null); + return; + } int random = new Random().nextInt(ConfigReader.Config.timeToGrow); if (potNamespacedID.equals(ConfigReader.Basic.watered_pot)){ //如果启用季节限制且农作物有季节需求 @@ -207,7 +210,7 @@ public class CropManager { } }, random); }else { - if (cropInstance.getReturnStage() == null && !ConfigReader.Season.enable) data.set(stringBuilder.toString(), null); + if (!ConfigReader.Season.enable) data.set(stringBuilder.toString(), null); bukkitScheduler.runTaskLater(CustomCrops.instance, () -> { CustomBlock.remove(potLocation); CustomBlock.place(ConfigReader.Basic.pot, potLocation); @@ -222,6 +225,8 @@ public class CropManager { CustomBlock.place(ConfigReader.Basic.dead, seedLocation); }, random); } + }else { + data.set(stringBuilder.toString(), null); } }); } @@ -277,10 +282,13 @@ public class CropManager { } Location potLocation = seedLocation.clone().subtract(0,1,0); CustomBlock pot = CustomBlock.byAlreadyPlaced(potLocation.getBlock()); - if (pot == null) return; String potNamespacedID = pot.getNamespacedID(); String[] cropNameList = StringUtils.split(id,"_"); CropInstance cropInstance = ConfigReader.CROPS.get(cropNameList[0]); + if (pot == null || cropInstance == null){ + data.set(stringBuilder.toString(), null); + return; + } int random = new Random().nextInt(ConfigReader.Config.timeToGrow); if (potNamespacedID.equals(ConfigReader.Basic.watered_pot)){ if (ConfigReader.Season.enable && cropInstance.getSeasons() != null){ @@ -337,7 +345,7 @@ public class CropManager { } }, random); }else { - if (cropInstance.getReturnStage() == null && !ConfigReader.Season.enable) data.set(stringBuilder.toString(), null); + if (!ConfigReader.Season.enable) data.set(stringBuilder.toString(), null); bukkitScheduler.runTaskLater(CustomCrops.instance, () -> { CustomBlock.remove(potLocation); CustomBlock.place(ConfigReader.Basic.pot, potLocation); @@ -352,6 +360,8 @@ public class CropManager { CustomBlock.place(ConfigReader.Basic.dead, seedLocation); }, random); } + }else { + data.set(stringBuilder.toString(), null); } }); } diff --git a/src/main/java/net/momirealms/customcrops/listener/RightClick.java b/src/main/java/net/momirealms/customcrops/listener/RightClick.java index a2a45ec..e79f9e3 100644 --- a/src/main/java/net/momirealms/customcrops/listener/RightClick.java +++ b/src/main/java/net/momirealms/customcrops/listener/RightClick.java @@ -369,8 +369,8 @@ public class RightClick implements Listener { String[] cropNameList = StringUtils.split(customBlock.getId(), "_"); int nextStage = Integer.parseInt(cropNameList[2]) + 1; if (CustomBlock.getInstance(StringUtils.chop(namespacedID) + nextStage) == null) { + CropInstance cropInstance = ConfigReader.CROPS.get(cropNameList[0]); if (ConfigReader.Config.quality){ - CropInstance cropInstance = ConfigReader.CROPS.get(cropNameList[0]); ThreadLocalRandom current = ThreadLocalRandom.current(); int random = current.nextInt(cropInstance.getMin(), cropInstance.getMax() + 1); World world = location.getWorld(); @@ -417,10 +417,10 @@ public class RightClick implements Listener { customBlock.getLoot().forEach(loot-> location.getWorld().dropItem(location.clone().add(0.5,0.2,0.5), loot)); } CustomBlock.remove(location); - CropInstance crop = ConfigReader.CROPS.get(cropNameList[0]); AdventureManager.playerSound(player, ConfigReader.Sounds.harvestSource, ConfigReader.Sounds.harvestKey); - if(crop.getReturnStage() != null){ - CustomBlock.place(crop.getReturnStage(), location); + if(cropInstance.getReturnStage() != null){ + CustomBlock.place(cropInstance.getReturnStage(), location); + CropManager.Cache.put(location, cropNameList[0]); } } } diff --git a/src/main/resources/crops.yml b/src/main/resources/crops.yml index 67abffa..4ca5116 100644 --- a/src/main/resources/crops.yml +++ b/src/main/resources/crops.yml @@ -58,8 +58,9 @@ crops: 1: customcrops:cabbage 2: customcrops:cabbage_silver_star 3: customcrops:cabbage_golden_star - gigantic: customcrops:gigantic_cabbage - gigantic-chance: 0.01 + gigantic: + block: customcrops:gigantic_cabbage + chance: 0.01 season: - spring