From 649f7d28a8f7f22a7c2fe3c7ee96af4f94b91917 Mon Sep 17 00:00:00 2001 From: Xiao-MoMi <70987828+Xiao-MoMi@users.noreply.github.com> Date: Tue, 5 Jul 2022 23:56:07 +0800 Subject: [PATCH] 1.5.1 --- .../momirealms/customcrops/ConfigReader.java | 1 - .../customcrops/commands/Executor.java | 5 +- .../customcrops/datamanager/CropManager.java | 20 +- .../datamanager/SprinklerManager.java | 10 + .../customcrops/listener/RightClick.java | 339 +++++++++--------- src/main/resources/config.yml | 2 + src/main/resources/plugin.yml | 2 +- 7 files changed, 197 insertions(+), 182 deletions(-) diff --git a/src/main/java/net/momirealms/customcrops/ConfigReader.java b/src/main/java/net/momirealms/customcrops/ConfigReader.java index 3c8b2b8..bef1247 100644 --- a/src/main/java/net/momirealms/customcrops/ConfigReader.java +++ b/src/main/java/net/momirealms/customcrops/ConfigReader.java @@ -348,7 +348,6 @@ public class ConfigReader { forceSave = config.getString("messages.force-save"); beforePlant = config.getString("messages.before-plant"); - hasCropInfo = config.getBoolean("hologram.grow-info.enable"); if (hasCropInfo){ cropTime = config.getInt("hologram.grow-info.duration"); diff --git a/src/main/java/net/momirealms/customcrops/commands/Executor.java b/src/main/java/net/momirealms/customcrops/commands/Executor.java index c661940..1a1cc57 100644 --- a/src/main/java/net/momirealms/customcrops/commands/Executor.java +++ b/src/main/java/net/momirealms/customcrops/commands/Executor.java @@ -120,8 +120,9 @@ public class Executor implements CommandExecutor { } return true; } - case "test" -> { - plugin.getCropManager().testData(); + case "cleandata" -> { + plugin.getCropManager().cleanData(); + plugin.getSprinklerManager().cleanData(); } case "setseason" -> { if (args.length < 3) { diff --git a/src/main/java/net/momirealms/customcrops/datamanager/CropManager.java b/src/main/java/net/momirealms/customcrops/datamanager/CropManager.java index 5ca8d4d..75d0438 100644 --- a/src/main/java/net/momirealms/customcrops/datamanager/CropManager.java +++ b/src/main/java/net/momirealms/customcrops/datamanager/CropManager.java @@ -50,15 +50,6 @@ public class CropManager { this.data = YamlConfiguration.loadConfiguration(file); } - public void testData(){ - for (int i = -200; i <= 200; i++){ - for (int j = -200; j <= 200; j++){ - Location location = new Location(Bukkit.getWorld("world"), i, 91,j); - Cache.put(location, "tomato"); - } - } - } - //保存数据 public void saveData() { File file = new File(CustomCrops.instance.getDataFolder(), "data" + File.separator + "crop.yml"); @@ -80,6 +71,17 @@ public class CropManager { Cache.clear(); } + //隐藏指令,清除无用数据 + public void cleanData(){ + data.getKeys(false).forEach(world -> { + data.getConfigurationSection(world).getKeys(false).forEach(chunk ->{ + if (data.getConfigurationSection(world + "." + chunk).getKeys(false).size() == 0){ + data.set(world + "." + chunk, null); + } + }); + }); + } + //农作物生长 public void cropGrow(String worldName){ Long time1 = System.currentTimeMillis(); diff --git a/src/main/java/net/momirealms/customcrops/datamanager/SprinklerManager.java b/src/main/java/net/momirealms/customcrops/datamanager/SprinklerManager.java index b515b78..1db8d12 100644 --- a/src/main/java/net/momirealms/customcrops/datamanager/SprinklerManager.java +++ b/src/main/java/net/momirealms/customcrops/datamanager/SprinklerManager.java @@ -51,6 +51,16 @@ public class SprinklerManager { } } + public void cleanData(){ + data.getKeys(false).forEach(world -> { + data.getConfigurationSection(world).getKeys(false).forEach(chunk ->{ + if (data.getConfigurationSection(world + "." + chunk).getKeys(false).size() == 0){ + data.set(world + "." + chunk, null); + } + }); + }); + } + public void updateData(){ Cache.forEach((location, sprinklerData) -> { String world = location.getWorld().getName(); diff --git a/src/main/java/net/momirealms/customcrops/listener/RightClick.java b/src/main/java/net/momirealms/customcrops/listener/RightClick.java index d9e504f..813e6d6 100644 --- a/src/main/java/net/momirealms/customcrops/listener/RightClick.java +++ b/src/main/java/net/momirealms/customcrops/listener/RightClick.java @@ -54,7 +54,8 @@ public class RightClick implements Listener { Action action = event.getAction(); if (action == Action.RIGHT_CLICK_AIR || action == Action.RIGHT_CLICK_BLOCK){ ItemStack itemStack = event.getItem(); - if (itemStack == null && action == Action.RIGHT_CLICK_BLOCK){ + if (itemStack == null){ + if (action != Action.RIGHT_CLICK_BLOCK) return; Block block = event.getClickedBlock(); Location location = block.getLocation(); CustomBlock customBlock = CustomBlock.byAlreadyPlaced(block); @@ -108,88 +109,121 @@ public class RightClick implements Listener { } } } - return; - } - NBTItem nbtItem = new NBTItem(itemStack); - NBTCompound nbtCompound = nbtItem.getCompound("itemsadder"); - if (nbtCompound != null){ - String id = nbtCompound.getString("id"); - if (id.endsWith("_seeds") && action == Action.RIGHT_CLICK_BLOCK && event.getBlockFace() == BlockFace.UP){ - String cropName = StringUtils.remove(id, "_seeds"); - Optional crop = Optional.ofNullable(ConfigReader.CROPS.get(cropName)); - if (crop.isPresent()){ - Block block = event.getClickedBlock(); - CustomBlock customBlock = CustomBlock.byAlreadyPlaced(block); - if (customBlock == null) return; - String namespacedID = customBlock.getNamespacedID(); - if (namespacedID.equals(ConfigReader.Basic.pot) || namespacedID.equals(ConfigReader.Basic.watered_pot)){ - Location location = block.getLocation().add(0,1,0); //已+1 - for (Integration integration : ConfigReader.Config.integration){ - if(!integration.canPlace(location, player)) return; - } - CropInstance cropInstance = crop.get(); - PlantingCondition plantingCondition = new PlantingCondition(player, location); - for (Requirement requirement : cropInstance.getRequirements()){ - if (!requirement.canPlant(plantingCondition)) return; - } - Label_out: - if (ConfigReader.Season.enable && cropInstance.getSeasons() != null){ - for (String season : cropInstance.getSeasons()) { - if (season.equals(SeasonManager.SEASON.get(location.getWorld().getName()))){ - break Label_out; - } + }else { + NBTItem nbtItem = new NBTItem(itemStack); + NBTCompound nbtCompound = nbtItem.getCompound("itemsadder"); + if (nbtCompound != null){ + String id = nbtCompound.getString("id"); + if (id.endsWith("_seeds") && action == Action.RIGHT_CLICK_BLOCK && event.getBlockFace() == BlockFace.UP){ + String cropName = StringUtils.remove(id, "_seeds"); + Optional crop = Optional.ofNullable(ConfigReader.CROPS.get(cropName)); + if (crop.isPresent()){ + Block block = event.getClickedBlock(); + CustomBlock customBlock = CustomBlock.byAlreadyPlaced(block); + if (customBlock == null) return; + String namespacedID = customBlock.getNamespacedID(); + if (namespacedID.equals(ConfigReader.Basic.pot) || namespacedID.equals(ConfigReader.Basic.watered_pot)){ + Location location = block.getLocation().add(0,1,0); //已+1 + for (Integration integration : ConfigReader.Config.integration){ + if(!integration.canPlace(location, player)) return; } - if(ConfigReader.Season.greenhouse){ - for(int i = 1; i <= ConfigReader.Season.range; i++){ - CustomBlock cb = CustomBlock.byAlreadyPlaced(location.clone().add(0,i,0).getBlock()); - if (cb != null){ - if(cb.getNamespacedID().equalsIgnoreCase(ConfigReader.Basic.glass)){ - break Label_out; + CropInstance cropInstance = crop.get(); + PlantingCondition plantingCondition = new PlantingCondition(player, location); + for (Requirement requirement : cropInstance.getRequirements()){ + if (!requirement.canPlant(plantingCondition)) return; + } + Label_out: + if (ConfigReader.Season.enable && cropInstance.getSeasons() != null){ + for (String season : cropInstance.getSeasons()) { + if (season.equals(SeasonManager.SEASON.get(location.getWorld().getName()))){ + break Label_out; + } + } + if(ConfigReader.Season.greenhouse){ + for(int i = 1; i <= ConfigReader.Season.range; i++){ + CustomBlock cb = CustomBlock.byAlreadyPlaced(location.clone().add(0,i,0).getBlock()); + if (cb != null){ + if(cb.getNamespacedID().equalsIgnoreCase(ConfigReader.Basic.glass)){ + break Label_out; + } } } } + AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.badSeason); + return; } - AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.badSeason); + if(location.getBlock().getType() != Material.AIR){ + return; + } + if(CropsPerChunk.isLimited(location)){ + AdventureManager.playerMessage(player,ConfigReader.Message.prefix + ConfigReader.Message.crop_limit.replace("{max}", String.valueOf(ConfigReader.Config.cropLimit))); + return; + } + itemStack.setAmount(itemStack.getAmount() - 1); + CropManager.Cache.put(location, cropName); + CustomBlock.place((nbtCompound.getString("namespace") + ":" + cropName + "_stage_1"), location); return; } - if(location.getBlock().getType() != Material.AIR){ - return; - } - if(CropsPerChunk.isLimited(location)){ - AdventureManager.playerMessage(player,ConfigReader.Message.prefix + ConfigReader.Message.crop_limit.replace("{max}", String.valueOf(ConfigReader.Config.cropLimit))); - return; - } - itemStack.setAmount(itemStack.getAmount() - 1); - CropManager.Cache.put(location, cropName); - CustomBlock.place((nbtCompound.getString("namespace") + ":" + cropName + "_stage_1"), location); - return; + }else { + AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.not_configed); } - }else { - AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.not_configed); + return; } - return; - } - Optional can = Optional.ofNullable(ConfigReader.CANS.get(id)); - if (can.isPresent()){ - WateringCan wateringCan = can.get(); - int water = nbtItem.getInteger("WaterAmount"); - List lineOfSight = player.getLineOfSight(null, 5); - for (Block block : lineOfSight) { - if (block.getType() == Material.WATER) { - if (wateringCan.getMax() > water){ - nbtItem.setInteger("WaterAmount", water + 1); - player.getWorld().playSound(player.getLocation(), Sound.ITEM_BUCKET_FILL,1,1); + Optional can = Optional.ofNullable(ConfigReader.CANS.get(id)); + if (can.isPresent()){ + WateringCan wateringCan = can.get(); + int water = nbtItem.getInteger("WaterAmount"); + List lineOfSight = player.getLineOfSight(null, 5); + for (Block block : lineOfSight) { + if (block.getType() == Material.WATER) { + if (wateringCan.getMax() > water){ + nbtItem.setInteger("WaterAmount", water + 1); + player.getWorld().playSound(player.getLocation(), Sound.ITEM_BUCKET_FILL,1,1); + itemStack.setItemMeta(nbtItem.getItem().getItemMeta()); + if (ConfigReader.Message.hasWaterInfo){ + String string = ConfigReader.Message.waterLeft + ConfigReader.Message.waterFull.repeat(water + 1) + + ConfigReader.Message.waterEmpty.repeat(wateringCan.getMax() - water - 1) + ConfigReader.Message.waterRight; + AdventureManager.playerActionbar(player, string.replace("{max_water}", String.valueOf(wateringCan.getMax())).replace("{water}", String.valueOf(water + 1))); + } + } + return; + } + } + if(water != 0 && action == Action.RIGHT_CLICK_BLOCK && event.getBlockFace() == BlockFace.UP){ + Block block = event.getClickedBlock(); + CustomBlock customBlock = CustomBlock.byAlreadyPlaced(block); + if (customBlock == null) return; + for (Integration integration : ConfigReader.Config.integration){ + if(!integration.canPlace(block.getLocation(), player)) return; + } + String namespacedID = customBlock.getNamespacedID(); + if (namespacedID.equals(ConfigReader.Basic.pot) || namespacedID.equals(ConfigReader.Basic.watered_pot)){ + nbtItem.setInteger("WaterAmount", water - 1); itemStack.setItemMeta(nbtItem.getItem().getItemMeta()); + player.getWorld().playSound(player.getLocation(), Sound.BLOCK_WATER_AMBIENT,1,1); + waterPot(wateringCan.getWidth(), wateringCan.getLength(), block.getLocation(), player.getLocation().getYaw()); if (ConfigReader.Message.hasWaterInfo){ - String string = ConfigReader.Message.waterLeft + ConfigReader.Message.waterFull.repeat(water + 1) + - ConfigReader.Message.waterEmpty.repeat(wateringCan.getMax() - water - 1) + ConfigReader.Message.waterRight; - AdventureManager.playerActionbar(player, string.replace("{max_water}", String.valueOf(wateringCan.getMax())).replace("{water}", String.valueOf(water + 1))); + String string = ConfigReader.Message.waterLeft + ConfigReader.Message.waterFull.repeat(water - 1) + + ConfigReader.Message.waterEmpty.repeat(wateringCan.getMax() - water + 1) + ConfigReader.Message.waterRight; + AdventureManager.playerActionbar(player, string.replace("{max_water}", String.valueOf(wateringCan.getMax())).replace("{water}", String.valueOf(water -1))); + } + }else if (namespacedID.contains("_stage_")){ + nbtItem.setInteger("WaterAmount", water - 1); + itemStack.setItemMeta(nbtItem.getItem().getItemMeta()); + player.getWorld().playSound(player.getLocation(), Sound.BLOCK_WATER_AMBIENT,1,1); + waterPot(wateringCan.getWidth(), wateringCan.getLength(), block.getLocation().subtract(0,1,0), player.getLocation().getYaw()); + if (ConfigReader.Message.hasWaterInfo){ + String string = ConfigReader.Message.waterLeft + ConfigReader.Message.waterFull.repeat(water - 1) + + ConfigReader.Message.waterEmpty.repeat(wateringCan.getMax() - water + 1) + ConfigReader.Message.waterRight; + AdventureManager.playerActionbar(player, string.replace("{max_water}", String.valueOf(wateringCan.getMax())).replace("{water}", String.valueOf(water -1))); } } - return; } + return; } - if(water != 0 && action == Action.RIGHT_CLICK_BLOCK && event.getBlockFace() == BlockFace.UP){ + Optional fertilize = Optional.ofNullable(ConfigReader.FERTILIZERS.get(id)); + if (fertilize.isPresent() && action == Action.RIGHT_CLICK_BLOCK){ + Fertilizer fertilizerConfig = fertilize.get(); Block block = event.getClickedBlock(); CustomBlock customBlock = CustomBlock.byAlreadyPlaced(block); if (customBlock == null) return; @@ -198,114 +232,81 @@ public class RightClick implements Listener { } String namespacedID = customBlock.getNamespacedID(); if (namespacedID.equals(ConfigReader.Basic.pot) || namespacedID.equals(ConfigReader.Basic.watered_pot)){ - nbtItem.setInteger("WaterAmount", water - 1); - itemStack.setItemMeta(nbtItem.getItem().getItemMeta()); - player.getWorld().playSound(player.getLocation(), Sound.BLOCK_WATER_AMBIENT,1,1); - waterPot(wateringCan.getWidth(), wateringCan.getLength(), block.getLocation(), player.getLocation().getYaw()); - if (ConfigReader.Message.hasWaterInfo){ - String string = ConfigReader.Message.waterLeft + ConfigReader.Message.waterFull.repeat(water - 1) + - ConfigReader.Message.waterEmpty.repeat(wateringCan.getMax() - water + 1) + ConfigReader.Message.waterRight; - AdventureManager.playerActionbar(player, string.replace("{max_water}", String.valueOf(wateringCan.getMax())).replace("{water}", String.valueOf(water -1))); - } - }else if (namespacedID.contains("_stage_")){ - nbtItem.setInteger("WaterAmount", water - 1); - itemStack.setItemMeta(nbtItem.getItem().getItemMeta()); - player.getWorld().playSound(player.getLocation(), Sound.BLOCK_WATER_AMBIENT,1,1); - waterPot(wateringCan.getWidth(), wateringCan.getLength(), block.getLocation().subtract(0,1,0), player.getLocation().getYaw()); - if (ConfigReader.Message.hasWaterInfo){ - String string = ConfigReader.Message.waterLeft + ConfigReader.Message.waterFull.repeat(water - 1) + - ConfigReader.Message.waterEmpty.repeat(wateringCan.getMax() - water + 1) + ConfigReader.Message.waterRight; - AdventureManager.playerActionbar(player, string.replace("{max_water}", String.valueOf(wateringCan.getMax())).replace("{water}", String.valueOf(water -1))); - } - } - } - return; - } - Optional fertilize = Optional.ofNullable(ConfigReader.FERTILIZERS.get(id)); - if (fertilize.isPresent() && action == Action.RIGHT_CLICK_BLOCK){ - Fertilizer fertilizerConfig = fertilize.get(); - Block block = event.getClickedBlock(); - CustomBlock customBlock = CustomBlock.byAlreadyPlaced(block); - if (customBlock == null) return; - for (Integration integration : ConfigReader.Config.integration){ - if(!integration.canPlace(block.getLocation(), player)) return; - } - String namespacedID = customBlock.getNamespacedID(); - if (namespacedID.equals(ConfigReader.Basic.pot) || namespacedID.equals(ConfigReader.Basic.watered_pot)){ - CustomBlock customBlockUp = CustomBlock.byAlreadyPlaced(block.getLocation().clone().add(0,1,0).getBlock()); - if (customBlockUp != null){ - if (fertilizerConfig.isBefore() && customBlockUp.getNamespacedID().contains("_stage_")){ - AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.beforePlant); - return; + CustomBlock customBlockUp = CustomBlock.byAlreadyPlaced(block.getLocation().clone().add(0,1,0).getBlock()); + if (customBlockUp != null){ + if (fertilizerConfig.isBefore() && customBlockUp.getNamespacedID().contains("_stage_")){ + AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.beforePlant); + return; + }else { + itemStack.setAmount(itemStack.getAmount() - 1); + player.getWorld().playSound(player.getLocation(), Sound.ITEM_HOE_TILL,1,1); + addFertilizer(fertilizerConfig, block); + } }else { itemStack.setAmount(itemStack.getAmount() - 1); player.getWorld().playSound(player.getLocation(), Sound.ITEM_HOE_TILL,1,1); addFertilizer(fertilizerConfig, block); } - }else { - itemStack.setAmount(itemStack.getAmount() - 1); - player.getWorld().playSound(player.getLocation(), Sound.ITEM_HOE_TILL,1,1); - addFertilizer(fertilizerConfig, block); - } - }else if (namespacedID.contains("_stage_")){ - if (!fertilizerConfig.isBefore()){ - itemStack.setAmount(itemStack.getAmount() - 1); - addFertilizer(fertilizerConfig, block); - player.getWorld().playSound(player.getLocation(), Sound.ITEM_HOE_TILL,1,1); - }else { - AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.beforePlant); - return; - } - } - return; - } - Optional sprinkler = Optional.ofNullable(ConfigReader.SPRINKLERS.get(id)); - if (sprinkler.isPresent() && action == Action.RIGHT_CLICK_BLOCK && event.getBlockFace() == BlockFace.UP){ - Location location = event.getClickedBlock().getLocation(); - for (Integration integration : ConfigReader.Config.integration){ - if (!integration.canPlace(location, player)) return; - } - if(IAFurniture.getFromLocation(location.clone().add(0.5, 1.5, 0.5), location.getWorld())){ - return; - } - if(SprinklersPerChunk.isLimited(location)){ - AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.sprinkler_limit.replace("{max}", String.valueOf(ConfigReader.Config.sprinklerLimit))); - return; - } - Sprinkler sprinklerData = new Sprinkler(sprinkler.get().getRange(), 0); - itemStack.setAmount(itemStack.getAmount() - 1); - SprinklerManager.Cache.put(location.add(0,1,0), sprinklerData); - IAFurniture.placeFurniture(sprinkler.get().getNamespacedID_2(),location); - return; - } - if (ConfigReader.Message.hasCropInfo && id.equals(ConfigReader.Basic.soilDetector) && action == Action.RIGHT_CLICK_BLOCK){ - Block block = event.getClickedBlock(); - CustomBlock customBlock = CustomBlock.byAlreadyPlaced(block); - if (customBlock == null) return; - for (Integration integration : ConfigReader.Config.integration){ - if(!integration.canPlace(block.getLocation(), player)) return; - } - String namespacedID = customBlock.getNamespacedID(); - if (namespacedID.contains("_stage_")){ - Location location = block.getLocation().subtract(0,1,0); - Fertilizer fertilizer = PotManager.Cache.get(location); - if (fertilizer != null){ - Fertilizer config = ConfigReader.FERTILIZERS.get(fertilizer.getKey()); - String name = config.getName(); - int max_times = config.getTimes(); - if(HoloUtil.cache.get(player) == null) { - HoloUtil.showHolo(ConfigReader.Message.cropText.replace("{fertilizer}", name).replace("{times}", String.valueOf(fertilizer.getTimes())).replace("{max_times}", String.valueOf(max_times)), player, location.add(0.5, ConfigReader.Message.cropOffset, 0.5), ConfigReader.Message.cropTime); + }else if (namespacedID.contains("_stage_")){ + if (!fertilizerConfig.isBefore()){ + itemStack.setAmount(itemStack.getAmount() - 1); + addFertilizer(fertilizerConfig, block); + player.getWorld().playSound(player.getLocation(), Sound.ITEM_HOE_TILL,1,1); + }else { + AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.beforePlant); + return; } } - }else if(namespacedID.equals(ConfigReader.Basic.pot) || namespacedID.equals(ConfigReader.Basic.watered_pot)){ - Location location = block.getLocation(); - Fertilizer fertilizer = PotManager.Cache.get(block.getLocation()); - if (fertilizer != null){ - Fertilizer config = ConfigReader.FERTILIZERS.get(fertilizer.getKey()); - String name = config.getName(); - int max_times = config.getTimes(); - if(HoloUtil.cache.get(player) == null){ - HoloUtil.showHolo(ConfigReader.Message.cropText.replace("{fertilizer}", name).replace("{times}", String.valueOf(fertilizer.getTimes())).replace("{max_times}", String.valueOf(max_times)), player, location.add(0.5,ConfigReader.Message.cropOffset,0.5), ConfigReader.Message.cropTime); + return; + } + Optional sprinkler = Optional.ofNullable(ConfigReader.SPRINKLERS.get(id)); + if (sprinkler.isPresent() && action == Action.RIGHT_CLICK_BLOCK && event.getBlockFace() == BlockFace.UP){ + Location location = event.getClickedBlock().getLocation(); + for (Integration integration : ConfigReader.Config.integration){ + if (!integration.canPlace(location, player)) return; + } + if(IAFurniture.getFromLocation(location.clone().add(0.5, 1.5, 0.5), location.getWorld())){ + return; + } + if(SprinklersPerChunk.isLimited(location)){ + AdventureManager.playerMessage(player, ConfigReader.Message.prefix + ConfigReader.Message.sprinkler_limit.replace("{max}", String.valueOf(ConfigReader.Config.sprinklerLimit))); + return; + } + Sprinkler sprinklerData = new Sprinkler(sprinkler.get().getRange(), 0); + itemStack.setAmount(itemStack.getAmount() - 1); + SprinklerManager.Cache.put(location.add(0,1,0), sprinklerData); + IAFurniture.placeFurniture(sprinkler.get().getNamespacedID_2(),location); + return; + } + if (ConfigReader.Message.hasCropInfo && id.equals(ConfigReader.Basic.soilDetector) && action == Action.RIGHT_CLICK_BLOCK){ + Block block = event.getClickedBlock(); + CustomBlock customBlock = CustomBlock.byAlreadyPlaced(block); + if (customBlock == null) return; + for (Integration integration : ConfigReader.Config.integration){ + if(!integration.canPlace(block.getLocation(), player)) return; + } + String namespacedID = customBlock.getNamespacedID(); + if (namespacedID.contains("_stage_")){ + Location location = block.getLocation().subtract(0,1,0); + Fertilizer fertilizer = PotManager.Cache.get(location); + if (fertilizer != null){ + Fertilizer config = ConfigReader.FERTILIZERS.get(fertilizer.getKey()); + String name = config.getName(); + int max_times = config.getTimes(); + if(HoloUtil.cache.get(player) == null) { + HoloUtil.showHolo(ConfigReader.Message.cropText.replace("{fertilizer}", name).replace("{times}", String.valueOf(fertilizer.getTimes())).replace("{max_times}", String.valueOf(max_times)), player, location.add(0.5, ConfigReader.Message.cropOffset, 0.5), ConfigReader.Message.cropTime); + } + } + }else if(namespacedID.equals(ConfigReader.Basic.pot) || namespacedID.equals(ConfigReader.Basic.watered_pot)){ + Location location = block.getLocation(); + Fertilizer fertilizer = PotManager.Cache.get(block.getLocation()); + if (fertilizer != null){ + Fertilizer config = ConfigReader.FERTILIZERS.get(fertilizer.getKey()); + String name = config.getName(); + int max_times = config.getTimes(); + if(HoloUtil.cache.get(player) == null){ + HoloUtil.showHolo(ConfigReader.Message.cropText.replace("{fertilizer}", name).replace("{times}", String.valueOf(fertilizer.getTimes())).replace("{max_times}", String.valueOf(max_times)), player, location.add(0.5,ConfigReader.Message.cropOffset,0.5), ConfigReader.Message.cropTime); + } } } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 67ee930..86489cb 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -15,12 +15,14 @@ config: #生长时间点(tick) #洒水器将会在农作物全部完成生长后开始工作 + #1000代表上午7点,农作物陆续开始生长 grow-time: - 1000 #生长的时间(秒) #农作物将在90秒内随机完成生长以避免在短时间内大量方块替换造成卡顿 #但也不建议设置过长时间,否则内存无法及时释放,区块会被持续加载 + #配合上方的默认时间点,意思为每天上午7点后,农作物将在90秒内完成生长过程 time-to-grow: 90 #产物品质 diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index fc9e07f..2f5d392 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: CustomCrops -version: '1.5.0-SNAPSHOT' +version: '1.5.1' main: net.momirealms.customcrops.CustomCrops api-version: 1.16 depend: