diff --git a/build.gradle b/build.gradle index c350f24..07d1361 100644 --- a/build.gradle +++ b/build.gradle @@ -4,7 +4,7 @@ plugins { } group = 'net.momirealms' -version = '2.0-PRE-2' +version = '2.0-r1-hotfix' repositories { mavenCentral() 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 6e9668b..35fc4e8 100644 --- a/src/main/java/net/momirealms/customcrops/commands/subcmd/SetSeasonCommand.java +++ b/src/main/java/net/momirealms/customcrops/commands/subcmd/SetSeasonCommand.java @@ -21,6 +21,7 @@ import net.momirealms.customcrops.api.utils.SeasonUtils; import net.momirealms.customcrops.commands.AbstractSubCommand; import net.momirealms.customcrops.commands.SubCommand; import net.momirealms.customcrops.config.MessageConfig; +import net.momirealms.customcrops.config.SeasonConfig; import net.momirealms.customcrops.integrations.season.CCSeason; import net.momirealms.customcrops.utils.AdventureUtil; import org.bukkit.Bukkit; @@ -40,6 +41,10 @@ public class SetSeasonCommand extends AbstractSubCommand { @Override public boolean onCommand(CommandSender sender, List args) { + if (!SeasonConfig.enable) { + AdventureUtil.sendMessage(sender, MessageConfig.prefix + MessageConfig.seasonDisabled); + return true; + } if (args.size() < 2) { AdventureUtil.sendMessage(sender, MessageConfig.prefix + MessageConfig.lackArgs); return true; @@ -66,6 +71,7 @@ public class SetSeasonCommand extends AbstractSubCommand { @Override public List onTabComplete(CommandSender sender, List args) { + if (!SeasonConfig.enable) return null; if (args.size() == 1) { return getWorlds(args); } diff --git a/src/main/java/net/momirealms/customcrops/config/ConfigUtil.java b/src/main/java/net/momirealms/customcrops/config/ConfigUtil.java index d0ceec1..7b84bef 100644 --- a/src/main/java/net/momirealms/customcrops/config/ConfigUtil.java +++ b/src/main/java/net/momirealms/customcrops/config/ConfigUtil.java @@ -74,5 +74,9 @@ public class ConfigUtil { CustomCrops.plugin.getPlaceholderManager().unload(); CustomCrops.plugin.getPlaceholderManager().load(); } + if (CustomCrops.plugin.getCropManager() != null) { + CustomCrops.plugin.getCropManager().loadMode(); + CustomCrops.plugin.getCropManager().loadSeason(); + } } } diff --git a/src/main/java/net/momirealms/customcrops/config/CropConfig.java b/src/main/java/net/momirealms/customcrops/config/CropConfig.java index 0aa5717..c341489 100644 --- a/src/main/java/net/momirealms/customcrops/config/CropConfig.java +++ b/src/main/java/net/momirealms/customcrops/config/CropConfig.java @@ -141,7 +141,7 @@ public class CropConfig { config.getString(key + ".requirements." + requirement + ".message") )); case "papi-condition" -> requirementList.add(new CustomPapi( - Objects.requireNonNull(config.getConfigurationSection(key + ".requirements." + requirement + ".papi-condition")).getValues(false), + Objects.requireNonNull(config.getConfigurationSection(key + ".requirements." + requirement + ".value")).getValues(false), config.getString(key + ".requirements." + requirement + ".message") )); } diff --git a/src/main/java/net/momirealms/customcrops/config/MainConfig.java b/src/main/java/net/momirealms/customcrops/config/MainConfig.java index c2f44d8..f5a0cfd 100644 --- a/src/main/java/net/momirealms/customcrops/config/MainConfig.java +++ b/src/main/java/net/momirealms/customcrops/config/MainConfig.java @@ -88,6 +88,8 @@ public class MainConfig { public static boolean syncSeason; public static World syncWorld; public static boolean autoBackUp; + public static boolean needSkyLight; + public static int skyLightLevel; public static void load() { ConfigUtil.update("config.yml"); @@ -146,6 +148,9 @@ public class MainConfig { enableCrow = config.getBoolean("mechanics.crow.enable", false); crowChance = config.getDouble("mechanics.crow.chance", 0.001); + skyLightLevel = config.getInt("mechanics.dead-if-no-sky-light.level", 10); + needSkyLight = config.getBoolean("mechanics.dead-if-no-sky-light.enable", true); + String[] split = StringUtils.split(config.getString("mechanics.default-quality-ratio", "17/2/1"), "/"); double[] weight = new double[3]; assert split != null; 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 5c07644..f758b1b 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 @@ -148,7 +148,7 @@ public abstract class OraxenHandler extends HandlerP { if (waterEvent.isCancelled()) { return true; } - nbtItem.setInteger("WaterAmount", water - 1); + nbtItem.setInteger("WaterAmount", --water); if (SoundConfig.waterPot.isEnable()) { AdventureUtil.playerSound( diff --git a/src/main/java/net/momirealms/customcrops/managers/CropManager.java b/src/main/java/net/momirealms/customcrops/managers/CropManager.java index 39a1daa..f781807 100644 --- a/src/main/java/net/momirealms/customcrops/managers/CropManager.java +++ b/src/main/java/net/momirealms/customcrops/managers/CropManager.java @@ -85,21 +85,41 @@ public class CropManager extends Function { public void load() { super.load(); this.customWorlds = new ConcurrentHashMap<>(); - this.itemSpawnListener = new ItemSpawnListener(this); this.worldListener = new WorldListener(this); this.armorStandUtil = new ArmorStandUtil(this); + loadMode(); + loadSeason(); + + //load Worlds + for (World world : Bukkit.getWorlds()) { + onWorldLoad(world); + } + //new Time Check task + this.timerTask = new TimerTask(this); + this.timerTask.runTaskTimerAsynchronously(CustomCrops.plugin, 1,100); + } + + public void loadMode() { + + if (this.handler != null) { + handler.unload(); + handler = null; + } + //Custom Plugin if (MainConfig.customPlugin.equals("itemsadder")) { customInterface = new ItemsAdderHook(); if (MainConfig.cropMode) { this.handler = new ItemsAdderWireHandler(this); this.cropMode = new ItemsAdderWireCropImpl(this); + this.handler.load(); } else { this.handler = new ItemsAdderFrameHandler(this); this.cropMode = new ItemsAdderFrameCropImpl(this); + this.handler.load(); } } else if (MainConfig.customPlugin.equals("oraxen")){ @@ -107,29 +127,25 @@ public class CropManager extends Function { if (MainConfig.cropMode) { this.handler = new OraxenWireHandler(this); this.cropMode = new OraxenWireCropImpl(this); + this.handler.load(); } else { this.handler = new OraxenFrameHandler(this); this.cropMode = new OraxenFrameCropImpl(this); + this.handler.load(); } } + } - //new Time Check task - this.timerTask = new TimerTask(this); - this.timerTask.runTaskTimerAsynchronously(CustomCrops.plugin, 1,100); - - handler.load(); - + public void loadSeason() { if (SeasonConfig.enable) { if (MainConfig.realisticSeasonHook) seasonInterface = new RealisticSeasonsHook(); else seasonInterface = new InternalSeason(); + seasonInterface.load(); } - - seasonInterface.load(); - - //load Worlds - for (World world : Bukkit.getWorlds()) { - onWorldLoad(world); + else if (this.seasonInterface != null) { + this.seasonInterface.unload(); + this.seasonInterface = null; } } diff --git a/src/main/java/net/momirealms/customcrops/managers/CustomWorld.java b/src/main/java/net/momirealms/customcrops/managers/CustomWorld.java index 64a1cc2..7a23467 100644 --- a/src/main/java/net/momirealms/customcrops/managers/CustomWorld.java +++ b/src/main/java/net/momirealms/customcrops/managers/CustomWorld.java @@ -157,9 +157,7 @@ public class CustomWorld { } scarecrowCache.put(en.getKey(), simpleLocations); } - } - SeasonUtils.setSeason(world, CCSeason.UNKNOWN); } catch (FileNotFoundException e) { //bypass @@ -183,7 +181,6 @@ public class CustomWorld { } catch (IOException e) { e.printStackTrace(); } - SeasonUtils.unloadSeason(world); } private void loadSeason() { diff --git a/src/main/java/net/momirealms/customcrops/managers/ItemsAdderFrameCropImpl.java b/src/main/java/net/momirealms/customcrops/managers/ItemsAdderFrameCropImpl.java index 693c1ef..17b70a0 100644 --- a/src/main/java/net/momirealms/customcrops/managers/ItemsAdderFrameCropImpl.java +++ b/src/main/java/net/momirealms/customcrops/managers/ItemsAdderFrameCropImpl.java @@ -62,6 +62,12 @@ public class ItemsAdderFrameCropImpl implements CropModeInterface { String cropKey = StringUtils.split(cropNameList[0], ":")[1]; 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; diff --git a/src/main/java/net/momirealms/customcrops/managers/ItemsAdderWireCropImpl.java b/src/main/java/net/momirealms/customcrops/managers/ItemsAdderWireCropImpl.java index b75578f..3b0c2e9 100644 --- a/src/main/java/net/momirealms/customcrops/managers/ItemsAdderWireCropImpl.java +++ b/src/main/java/net/momirealms/customcrops/managers/ItemsAdderWireCropImpl.java @@ -50,6 +50,15 @@ public class ItemsAdderWireCropImpl implements CropModeInterface{ String cropKey = StringUtils.split(cropNameList[0], ":")[1]; Crop crop = CropConfig.CROPS.get(cropKey); if (crop == null) return true; + + if (MainConfig.needSkyLight && location.getBlock().getLightFromSky() < MainConfig.skyLightLevel) { + Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> { + customInterface.removeBlock(location); + customInterface.placeWire(location, BasicItemConfig.deadCrop); + }); + return true; + } + if (cropManager.isWrongSeason(location, crop.getSeasons())) { Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> { customInterface.removeBlock(location); diff --git a/src/main/java/net/momirealms/customcrops/managers/OraxenFrameCropImpl.java b/src/main/java/net/momirealms/customcrops/managers/OraxenFrameCropImpl.java index fa0e7b1..f678410 100644 --- a/src/main/java/net/momirealms/customcrops/managers/OraxenFrameCropImpl.java +++ b/src/main/java/net/momirealms/customcrops/managers/OraxenFrameCropImpl.java @@ -64,6 +64,13 @@ public class OraxenFrameCropImpl implements CropModeInterface { String cropKey = cropNameList[0]; 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); + itemFrame.getPersistentDataContainer().set(OraxenHook.FURNITURE, PersistentDataType.STRING, BasicItemConfig.deadCrop); + return true; + } + if (cropManager.isWrongSeason(location, crop.getSeasons())) { itemFrame.setItem(customInterface.getItemStack(BasicItemConfig.deadCrop), false); itemFrame.getPersistentDataContainer().set(OraxenHook.FURNITURE, PersistentDataType.STRING, BasicItemConfig.deadCrop); diff --git a/src/main/java/net/momirealms/customcrops/managers/OraxenWireCropImpl.java b/src/main/java/net/momirealms/customcrops/managers/OraxenWireCropImpl.java index 1529066..117e51f 100644 --- a/src/main/java/net/momirealms/customcrops/managers/OraxenWireCropImpl.java +++ b/src/main/java/net/momirealms/customcrops/managers/OraxenWireCropImpl.java @@ -50,9 +50,16 @@ public class OraxenWireCropImpl implements CropModeInterface{ String cropKey = cropNameList[0]; Crop crop = CropConfig.CROPS.get(cropKey); 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())) { Bukkit.getScheduler().runTask(CustomCrops.plugin, () -> { - customInterface.removeBlock(location); customInterface.placeWire(location, BasicItemConfig.deadCrop); }); return true; diff --git a/src/main/java/net/momirealms/customcrops/objects/requirements/CustomPapi.java b/src/main/java/net/momirealms/customcrops/objects/requirements/CustomPapi.java index afb56cc..192571b 100644 --- a/src/main/java/net/momirealms/customcrops/objects/requirements/CustomPapi.java +++ b/src/main/java/net/momirealms/customcrops/objects/requirements/CustomPapi.java @@ -75,7 +75,7 @@ public class CustomPapi implements RequirementInterface { @Override public boolean isConditionMet(PlantingCondition plantingCondition) { if (!papiRequirement.isMet(plantingCondition.getPapiMap())) { - AdventureUtil.playerMessage(plantingCondition.getPlayer(), msg); + if (msg != null) AdventureUtil.playerMessage(plantingCondition.getPlayer(), msg); return false; } return true; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index d213513..45ca6bb 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -2,7 +2,7 @@ config-version: '10' # lang: english / spanish / chinese -lang: chinese +lang: english integration: # AntiGrief @@ -33,6 +33,7 @@ worlds: optimization: # Recommend enabling this to prevent large quantities of crops/itemframes lagging the server + # When you are using both item_frame mode and ItemsAdder, you should set "max-furniture-vehicles-per-chunk" in ItemsAdder's config.yml to a higher value limitation: enable: true # max amount per chunk @@ -47,7 +48,6 @@ optimization: auto-back-up: true mechanics: - # Requires a restart tp change mode # Mode: tripwire/item_frame crops-mode: tripwire @@ -102,6 +102,7 @@ mechanics: world: world auto-season-change: + # If enabled, setseason command would only work for only one day enable: true #duration of each season duration: 28 @@ -114,8 +115,15 @@ mechanics: crow: enable: true chance: 0.005 + + # 17/2/1 means 85%/10%/5% + # 2/2/1 means 40%/40%/20% default-quality-ratio: 17/2/1 + # A crop would go to dead stage if the sky-light level is lower than a value. + dead-if-no-sky-light: + enable: true + level: 10 sounds: diff --git a/src/main/resources/crops_itemsadder.yml b/src/main/resources/crops_itemsadder.yml index 4aedc23..ac6660e 100644 --- a/src/main/resources/crops_itemsadder.yml +++ b/src/main/resources/crops_itemsadder.yml @@ -27,9 +27,9 @@ tomato: chance: 0.01 harvest-actions: + # https://docs.adventure.kyori.net/minimessage/format.html messages: - - 'Hello, {player}! Click here to read the CustomCrops wiki' - - 'This plugin uses MiniMessage Format, check it here [Click Me]' + - 'Hello, {player}! Click here to read the CustomCrops wiki' commands: - 'say {player} harvested a tomato! lol' xp: 10