From 241cfffa13236c259e3633c24ea9b56f9c1064a6 Mon Sep 17 00:00:00 2001 From: Xiao-MoMi <70987828+Xiao-MoMi@users.noreply.github.com> Date: Thu, 8 Dec 2022 11:45:40 +0800 Subject: [PATCH] 2.1.0 --- build.gradle | 6 +- .../momirealms/customcrops/CustomCrops.java | 3 - .../commands/subcmd/SetSeasonCommand.java | 2 +- .../customcrops/config/CropConfig.java | 204 +++++++++--------- .../customcrops/config/MainConfig.java | 3 + .../customcrops/managers/CropManager.java | 2 + .../managers/listener/ContainerListener.java | 2 +- .../customcrops/objects/Sprinkler.java | 8 - 8 files changed, 113 insertions(+), 117 deletions(-) diff --git a/build.gradle b/build.gradle index f4b70a4..99c4f88 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group = 'net.momirealms' -version = '2.1.0-r1' +version = '2.1.0-r3' repositories { mavenCentral() @@ -70,9 +70,9 @@ dependencies { compileOnly 'com.willfp:eco:6.38.3' compileOnly 'com.github.Zrips:Jobs:4.17.2' compileOnly fileTree(dir:'libs',includes:['*.jar']) - implementation("net.kyori:adventure-api:4.11.0") + implementation('net.kyori:adventure-api:4.12.0') implementation('net.kyori:adventure-platform-bukkit:4.1.2') - implementation("net.kyori:adventure-text-minimessage:4.11.0") + implementation('net.kyori:adventure-text-minimessage:4.12.0') implementation("de.tr7zw:item-nbt-api:2.10.0") implementation("org.bstats:bstats-bukkit:3.0.0") } diff --git a/src/main/java/net/momirealms/customcrops/CustomCrops.java b/src/main/java/net/momirealms/customcrops/CustomCrops.java index 4949cc0..d7dfafc 100644 --- a/src/main/java/net/momirealms/customcrops/CustomCrops.java +++ b/src/main/java/net/momirealms/customcrops/CustomCrops.java @@ -92,9 +92,6 @@ public final class CustomCrops extends JavaPlugin { ConfigUtil.reloadConfigs(); - if (MainConfig.cropMode) AdventureUtil.consoleMessage("[CustomCrops] Crop Mode: Tripwire"); - else AdventureUtil.consoleMessage("[CustomCrops] Crop Mode: ItemFrame"); - PluginCommand pluginCommand = new PluginCommand(); Objects.requireNonNull(Bukkit.getPluginCommand("customcrops")).setExecutor(pluginCommand); Objects.requireNonNull(Bukkit.getPluginCommand("customcrops")).setTabCompleter(pluginCommand); diff --git a/src/main/java/net/momirealms/customcrops/commands/subcmd/SetSeasonCommand.java b/src/main/java/net/momirealms/customcrops/commands/subcmd/SetSeasonCommand.java index 711ed83..f6c6a33 100644 --- a/src/main/java/net/momirealms/customcrops/commands/subcmd/SetSeasonCommand.java +++ b/src/main/java/net/momirealms/customcrops/commands/subcmd/SetSeasonCommand.java @@ -60,7 +60,7 @@ public class SetSeasonCommand extends AbstractSubCommand { ccSeason = CCSeason.valueOf(args.get(1).toUpperCase()); } catch (IllegalArgumentException e) { - AdventureUtil.sendMessage(sender, MessageConfig.prefix + MessageConfig.seasonNotExists); + AdventureUtil.sendMessage(sender, MessageConfig.prefix + MessageConfig.seasonNotExists.replace("{season}", args.get(1))); return true; } SeasonUtils.setSeason(world, ccSeason); diff --git a/src/main/java/net/momirealms/customcrops/config/CropConfig.java b/src/main/java/net/momirealms/customcrops/config/CropConfig.java index 09ea984..5adbee3 100644 --- a/src/main/java/net/momirealms/customcrops/config/CropConfig.java +++ b/src/main/java/net/momirealms/customcrops/config/CropConfig.java @@ -80,6 +80,7 @@ public class CropConfig { for (String key : config.getKeys(false)) { if (key.equals("namespace")) continue; + int max_stage; if (config.contains(key + ".max-stage")) { max_stage = config.getInt(key + ".max-stage"); @@ -91,115 +92,116 @@ public class CropConfig { } CCCrop crop = new CCCrop(key, max_stage); - for (String option : config.getConfigurationSection(key).getKeys(false)) { - if (option.equals("quality-loots")) { - String amount = config.getString(key + ".quality-loots.amount", "1~2"); - QualityLoot qualityLoot = new QualityLoot( - Integer.parseInt(amount.split("~")[0]), - Integer.parseInt(amount.split("~")[1]), - config.getString(key + ".quality-loots.quality.1"), - config.getString(key + ".quality-loots.quality.2"), - config.getString(key + ".quality-loots.quality.3") - ); - crop.setQualityLoot(qualityLoot); - } - if (option.equals("other-loots")) { - List otherLoots = new ArrayList<>(); - for (String loot : Objects.requireNonNull(config.getConfigurationSection(key + ".other-loots")).getKeys(false)) { - OtherLoot otherLoot = new OtherLoot( - config.getInt(key + ".other-loots." + loot + ".min_amount", 1), - config.getInt(key + ".other-loots." + loot + ".max_amount", 1), - config.getString(key + ".other-loots." + loot + ".item"), - config.getDouble(key + ".other-loots." + loot + ".chance", 1d) + for (String option : Objects.requireNonNull(config.getConfigurationSection(key)).getKeys(false)) { + switch (option) { + case "quality-loots" -> { + String amount = config.getString(key + ".quality-loots.amount", "1~2"); + QualityLoot qualityLoot = new QualityLoot( + Integer.parseInt(amount.split("~")[0]), + Integer.parseInt(amount.split("~")[1]), + config.getString(key + ".quality-loots.quality.1"), + config.getString(key + ".quality-loots.quality.2"), + config.getString(key + ".quality-loots.quality.3") ); - otherLoots.add(otherLoot); + crop.setQualityLoot(qualityLoot); } - crop.setOtherLoots(otherLoots.toArray(new OtherLoot[0])); - } - if (option.equals("harvest-actions")) { - List actions = new ArrayList<>(); - for (String action : Objects.requireNonNull(config.getConfigurationSection(key + ".harvest-actions")).getKeys(false)) { - switch (action) { - case "xp" -> actions.add(new ActionXP(config.getInt(key + ".harvest-actions." + action))); - case "skill-xp" -> actions.add(new ActionSkillXP(config.getDouble(key + ".harvest-actions." + action))); - case "commands" -> actions.add(new ActionCommand(config.getStringList(key + ".harvest-actions." + action).toArray(new String[0]))); - case "messages" -> actions.add(new ActionMessage(config.getStringList(key + ".harvest-actions." + action).toArray(new String[0]))); + case "harvest-actions" -> { + List actions = new ArrayList<>(); + for (String action : Objects.requireNonNull(config.getConfigurationSection(key + ".harvest-actions")).getKeys(false)) { + switch (action) { + case "xp" -> actions.add(new ActionXP(config.getInt(key + ".harvest-actions." + action))); + case "skill-xp" -> actions.add(new ActionSkillXP(config.getDouble(key + ".harvest-actions." + action))); + case "commands" -> actions.add(new ActionCommand(config.getStringList(key + ".harvest-actions." + action).toArray(new String[0]))); + case "messages" -> actions.add(new ActionMessage(config.getStringList(key + ".harvest-actions." + action).toArray(new String[0]))); + } } + crop.setActions(actions.toArray(new ActionInterface[0])); } - crop.setActions(actions.toArray(new ActionInterface[0])); - } - if (option.equals("season")) { - List seasonList = config.getStringList(key + ".season"); - CCSeason[] seasons = new CCSeason[seasonList.size()]; - for (int i = 0; i < seasonList.size(); i++) { - seasons[i] = CCSeason.valueOf(seasonList.get(i).toUpperCase()); - } - crop.setSeasons(seasons); - } - if (option.equals("gigantic-crop")) { - boolean isBlock = true; - String blockID = config.getString(key + ".gigantic-crop.block"); - if (blockID == null) { - blockID = config.getString(key + ".gigantic-crop.furniture"); - isBlock = false; - } - GiganticCrop giganticCrop = new GiganticCrop( - config.getDouble(key + ".gigantic-crop.chance"), - isBlock, - blockID - ); - crop.setGiganticCrop(giganticCrop); - } - if (option.equals("return")) { - crop.setReturnStage(config.getString(key + ".return")); - } - crop.setCanRotate(config.getBoolean(key + ".rotation", true)); - if (option.equals("requirements")) { - List requirementList = new ArrayList<>(); - for (String requirement : Objects.requireNonNull(config.getConfigurationSection(key + ".requirements")).getKeys(false)) { - String type = config.getString(key + ".requirements." + requirement + ".type"); - if (type == null) continue; - switch (type) { - case "time" -> requirementList.add(new RequirementTime( - config.getStringList(key + ".requirements." + requirement + ".value").toArray(new String[0]), - Objects.equals(config.getString(key + ".requirements." + requirement + ".mode"), "&&"), - config.getString(key + ".requirements." + requirement + ".message") - )); - case "weather" -> requirementList.add(new RequirementWeather( - config.getStringList(key + ".requirements." + requirement + ".value").toArray(new String[0]), - Objects.equals(config.getString(key + ".requirements." + requirement + ".mode"), "&&"), - config.getString(key + ".requirements." + requirement + ".message") - )); - case "yPos" -> requirementList.add(new RequirementYPos( - config.getStringList(key + ".requirements." + requirement + ".value").toArray(new String[0]), - Objects.equals(config.getString(key + ".requirements." + requirement + ".mode"), "&&"), - config.getString(key + ".requirements." + requirement + ".message") - )); - case "biome" -> requirementList.add(new RequirementBiome( - config.getStringList(key + ".requirements." + requirement + ".value").toArray(new String[0]), - Objects.equals(config.getString(key + ".requirements." + requirement + ".mode"), "&&"), - config.getString(key + ".requirements." + requirement + ".message") - )); - case "world" -> requirementList.add(new RequirementWorld( - config.getStringList(key + ".requirements." + requirement + ".value").toArray(new String[0]), - Objects.equals(config.getString(key + ".requirements." + requirement + ".mode"), "&&"), - config.getString(key + ".requirements." + requirement + ".message") - )); - case "permission" -> requirementList.add(new RequirementPermission( - config.getStringList(key + ".requirements." + requirement + ".value").toArray(new String[0]), - Objects.equals(config.getString(key + ".requirements." + requirement + ".mode"), "&&"), - config.getString(key + ".requirements." + requirement + ".message") - )); - case "papi-condition" -> requirementList.add(new CustomPapi( - Objects.requireNonNull(config.getConfigurationSection(key + ".requirements." + requirement + ".value")).getValues(false), - config.getString(key + ".requirements." + requirement + ".message") - )); + case "other-loots" -> { + List otherLoots = new ArrayList<>(); + for (String loot : Objects.requireNonNull(config.getConfigurationSection(key + ".other-loots")).getKeys(false)) { + OtherLoot otherLoot = new OtherLoot( + config.getInt(key + ".other-loots." + loot + ".min_amount", 1), + config.getInt(key + ".other-loots." + loot + ".max_amount", 1), + config.getString(key + ".other-loots." + loot + ".item"), + config.getDouble(key + ".other-loots." + loot + ".chance", 1d) + ); + otherLoots.add(otherLoot); } + crop.setOtherLoots(otherLoots.toArray(new OtherLoot[0])); + } + case "season" -> { + List seasonList = config.getStringList(key + ".season"); + CCSeason[] seasons = new CCSeason[seasonList.size()]; + for (int i = 0; i < seasonList.size(); i++) { + seasons[i] = CCSeason.valueOf(seasonList.get(i).toUpperCase()); + } + crop.setSeasons(seasons); + } + case "gigantic-crop" -> { + boolean isBlock = true; + String blockID = config.getString(key + ".gigantic-crop.block"); + if (blockID == null) { + blockID = config.getString(key + ".gigantic-crop.furniture"); + isBlock = false; + } + GiganticCrop giganticCrop = new GiganticCrop( + config.getDouble(key + ".gigantic-crop.chance"), + isBlock, + blockID + ); + crop.setGiganticCrop(giganticCrop); + } + case "return" -> { + crop.setReturnStage(config.getString(key + ".return")); + } + case "requirements" -> { + List requirementList = new ArrayList<>(); + for (String requirement : Objects.requireNonNull(config.getConfigurationSection(key + ".requirements")).getKeys(false)) { + String type = config.getString(key + ".requirements." + requirement + ".type"); + if (type == null) continue; + switch (type) { + case "time" -> requirementList.add(new RequirementTime( + config.getStringList(key + ".requirements." + requirement + ".value").toArray(new String[0]), + Objects.equals(config.getString(key + ".requirements." + requirement + ".mode"), "&&"), + config.getString(key + ".requirements." + requirement + ".message") + )); + case "weather" -> requirementList.add(new RequirementWeather( + config.getStringList(key + ".requirements." + requirement + ".value").toArray(new String[0]), + Objects.equals(config.getString(key + ".requirements." + requirement + ".mode"), "&&"), + config.getString(key + ".requirements." + requirement + ".message") + )); + case "yPos" -> requirementList.add(new RequirementYPos( + config.getStringList(key + ".requirements." + requirement + ".value").toArray(new String[0]), + Objects.equals(config.getString(key + ".requirements." + requirement + ".mode"), "&&"), + config.getString(key + ".requirements." + requirement + ".message") + )); + case "biome" -> requirementList.add(new RequirementBiome( + config.getStringList(key + ".requirements." + requirement + ".value").toArray(new String[0]), + Objects.equals(config.getString(key + ".requirements." + requirement + ".mode"), "&&"), + config.getString(key + ".requirements." + requirement + ".message") + )); + case "world" -> requirementList.add(new RequirementWorld( + config.getStringList(key + ".requirements." + requirement + ".value").toArray(new String[0]), + Objects.equals(config.getString(key + ".requirements." + requirement + ".mode"), "&&"), + config.getString(key + ".requirements." + requirement + ".message") + )); + case "permission" -> requirementList.add(new RequirementPermission( + config.getStringList(key + ".requirements." + requirement + ".value").toArray(new String[0]), + Objects.equals(config.getString(key + ".requirements." + requirement + ".mode"), "&&"), + config.getString(key + ".requirements." + requirement + ".message") + )); + case "papi-condition" -> requirementList.add(new CustomPapi( + Objects.requireNonNull(config.getConfigurationSection(key + ".requirements." + requirement + ".value")).getValues(false), + config.getString(key + ".requirements." + requirement + ".message") + )); + } + } + crop.setRequirements(requirementList.toArray(new RequirementInterface[0])); } - crop.setRequirements(requirementList.toArray(new RequirementInterface[0])); } } - + crop.setCanRotate(config.getBoolean(key + ".rotation", true)); CROPS.put(key, crop); } AdventureUtil.consoleMessage("[CustomCrops] Loaded " + CROPS.size() + " crops"); diff --git a/src/main/java/net/momirealms/customcrops/config/MainConfig.java b/src/main/java/net/momirealms/customcrops/config/MainConfig.java index c94e338..a8ab276 100644 --- a/src/main/java/net/momirealms/customcrops/config/MainConfig.java +++ b/src/main/java/net/momirealms/customcrops/config/MainConfig.java @@ -155,6 +155,9 @@ public class MainConfig { wireAmount = config.getInt("optimization.limitation.tripwire-amount", 64); frameAmount = config.getInt("optimization.limitation.itemframe-amount", 64); + if (MainConfig.cropMode) AdventureUtil.consoleMessage("[CustomCrops] Crop Mode: Tripwire"); + else AdventureUtil.consoleMessage("[CustomCrops] Crop Mode: ItemFrame"); + autoGrow = config.getBoolean("mechanics.auto-grow.enable", true); enableCompensation = config.getBoolean("mechanics.auto-grow.time-compensation", true); timeToGrow = config.getInt("mechanics.auto-grow.crops-grow-time", 20000); diff --git a/src/main/java/net/momirealms/customcrops/managers/CropManager.java b/src/main/java/net/momirealms/customcrops/managers/CropManager.java index 671d5a1..f67a89a 100644 --- a/src/main/java/net/momirealms/customcrops/managers/CropManager.java +++ b/src/main/java/net/momirealms/customcrops/managers/CropManager.java @@ -504,6 +504,8 @@ public class CropManager extends Function { Crop crop = CropConfig.CROPS.get(growingCrop.getType()); if (crop == null) return true; + if (!location.getChunk().isEntitiesLoaded()) return false; + Location potLoc = location.clone().subtract(0,1,0); Fertilizer fertilizer = getFertilizer(potLoc); diff --git a/src/main/java/net/momirealms/customcrops/managers/listener/ContainerListener.java b/src/main/java/net/momirealms/customcrops/managers/listener/ContainerListener.java index 9b0cf70..1b197c8 100644 --- a/src/main/java/net/momirealms/customcrops/managers/listener/ContainerListener.java +++ b/src/main/java/net/momirealms/customcrops/managers/listener/ContainerListener.java @@ -23,7 +23,7 @@ import java.util.List; public class ContainerListener extends PacketAdapter { - private CropManager cropManager; + private final CropManager cropManager; public ContainerListener(CropManager cropManager) { super(CustomCrops.plugin, ListenerPriority.HIGHEST, PacketType.Play.Server.WINDOW_ITEMS); diff --git a/src/main/java/net/momirealms/customcrops/objects/Sprinkler.java b/src/main/java/net/momirealms/customcrops/objects/Sprinkler.java index 72d3f63..ffec5f2 100644 --- a/src/main/java/net/momirealms/customcrops/objects/Sprinkler.java +++ b/src/main/java/net/momirealms/customcrops/objects/Sprinkler.java @@ -53,10 +53,6 @@ public class Sprinkler { return key; } - /** - * Only needed in config - * @return twoD - */ @Nullable public String getTwoD() { return twoD; @@ -66,10 +62,6 @@ public class Sprinkler { this.twoD = twoD; } - /** - * Only needed in config - * @return threeD - */ @Nullable public String getThreeD() { return threeD;