From 6895ddccdd3c7a839f5da03895d559b72a524f8e Mon Sep 17 00:00:00 2001 From: Xiao-MoMi <70987828+Xiao-MoMi@users.noreply.github.com> Date: Sun, 14 May 2023 16:12:33 +0800 Subject: [PATCH] 3.1.3 --- .../customcrops/api/CustomCropsAPI.java | 29 ++++++ .../api/object/basic/ConfigManager.java | 8 +- .../api/object/basic/MessageManager.java | 3 +- .../api/object/sprinkler/SprinklerConfig.java | 15 ++- .../object/sprinkler/SprinklerManager.java | 2 + .../object/wateringcan/WateringCanConfig.java | 8 +- .../customcrops/api/object/world/CCChunk.java | 42 +++----- .../customcrops/api/object/world/CCWorld.java | 99 +++++++++++++------ .../command/subcmd/ForceCommand.java | 2 + .../subcmd/force/ConsumeTaskCommand.java | 8 +- .../command/subcmd/force/CropGrowCommand.java | 70 +++++++++++++ .../subcmd/force/SprinklerWorkCommand.java | 8 +- src/main/resources/config.yml | 27 ++--- .../resources/contents/sprinklers/default.yml | 7 +- .../resources/messages/messages_chinese.yml | 3 +- .../resources/messages/messages_english.yml | 3 +- .../resources/messages/messages_spanish.yml | 3 +- .../resources/messages/messages_turkish.yml | 3 +- 18 files changed, 243 insertions(+), 97 deletions(-) create mode 100644 src/main/java/net/momirealms/customcrops/command/subcmd/force/CropGrowCommand.java diff --git a/src/main/java/net/momirealms/customcrops/api/CustomCropsAPI.java b/src/main/java/net/momirealms/customcrops/api/CustomCropsAPI.java index 32023fa..3e6d586 100644 --- a/src/main/java/net/momirealms/customcrops/api/CustomCropsAPI.java +++ b/src/main/java/net/momirealms/customcrops/api/CustomCropsAPI.java @@ -23,8 +23,10 @@ import net.momirealms.customcrops.api.object.pot.Pot; import net.momirealms.customcrops.api.object.season.CCSeason; import net.momirealms.customcrops.api.object.season.SeasonData; import net.momirealms.customcrops.api.object.sprinkler.Sprinkler; +import net.momirealms.customcrops.api.object.world.CCWorld; import net.momirealms.customcrops.api.object.world.SimpleLocation; import org.bukkit.Location; +import org.bukkit.World; import org.jetbrains.annotations.Nullable; public class CustomCropsAPI { @@ -92,4 +94,31 @@ public class CustomCropsAPI { } return null; } + + public void grow(World world, int seconds) { + CustomCrops.getInstance().getScheduler().runTaskAsync(() -> { + CCWorld ccworld = CustomCrops.getInstance().getWorldDataManager().getWorld(world.getName()); + if (ccworld != null) { + ccworld.scheduleConsumeTask(seconds); + } + }); + } + + public void sprinklerWork(World world, int seconds) { + CustomCrops.getInstance().getScheduler().runTaskAsync(() -> { + CCWorld ccworld = CustomCrops.getInstance().getWorldDataManager().getWorld(world.getName()); + if (ccworld != null) { + ccworld.scheduleSprinklerWork(seconds); + } + }); + } + + public void consume(World world, int seconds) { + CustomCrops.getInstance().getScheduler().runTaskAsync(() -> { + CCWorld ccworld = CustomCrops.getInstance().getWorldDataManager().getWorld(world.getName()); + if (ccworld != null) { + ccworld.scheduleConsumeTask(seconds); + } + }); + } } diff --git a/src/main/java/net/momirealms/customcrops/api/object/basic/ConfigManager.java b/src/main/java/net/momirealms/customcrops/api/object/basic/ConfigManager.java index 336d8e6..2e24c6d 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/basic/ConfigManager.java +++ b/src/main/java/net/momirealms/customcrops/api/object/basic/ConfigManager.java @@ -60,7 +60,6 @@ public class ConfigManager extends Function { public static boolean enableLimitation; public static int maxCropPerChunk; public static int cacheSaveInterval; - public static boolean setUpMode; public static int intervalConsume; public static int intervalWork; public static boolean disableMoistureMechanic; @@ -93,7 +92,6 @@ public class ConfigManager extends Function { enableBStats = config.getBoolean("metrics"); lang = config.getString("lang"); debug = config.getBoolean("debug"); - setUpMode = config.getBoolean("set-up-mode", true); loadWorlds(Objects.requireNonNull(config.getConfigurationSection("worlds"))); loadOptimization(Objects.requireNonNull(config.getConfigurationSection("optimization"))); loadScheduleSystem(Objects.requireNonNull(config.getConfigurationSection("schedule-system"))); @@ -122,14 +120,14 @@ public class ConfigManager extends Function { } private void loadScheduleSystem(ConfigurationSection section) { - enableScheduleSystem = section.getBoolean("others.enable", true); + enableScheduleSystem = section.getBoolean("enable", true); pointGainInterval = section.getInt("point-gain-interval", 600); corePoolSize = section.getInt("thread-pool-settings.corePoolSize", 2); maxPoolSize = section.getInt("thread-pool-settings.maximumPoolSize", 4); keepAliveTime = section.getInt("thread-pool-settings.keepAliveTime", 10); cacheSaveInterval = section.getInt("cache-save-interval", 12000); - intervalConsume = section.getInt("others.consume-water-fertilizer-every-x-point", 2); - intervalWork = section.getInt("others.sprinkler-work-every-x-point", 2); + intervalConsume = section.getInt("consume-water-fertilizer-every-x-point", 2); + intervalWork = section.getInt("sprinkler-work-every-x-point", 2); } private void loadMechanic(ConfigurationSection section) { diff --git a/src/main/java/net/momirealms/customcrops/api/object/basic/MessageManager.java b/src/main/java/net/momirealms/customcrops/api/object/basic/MessageManager.java index 3dcef23..171cca0 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/basic/MessageManager.java +++ b/src/main/java/net/momirealms/customcrops/api/object/basic/MessageManager.java @@ -26,7 +26,6 @@ import java.io.File; public class MessageManager extends Function { - private CustomCrops plugin; public static String prefix; @@ -51,6 +50,7 @@ public class MessageManager extends Function { public static String seasonNotExist; public static String forceWork; public static String forceConsume; + public static String forceGrow; public MessageManager(CustomCrops plugin) { this.plugin =plugin; @@ -85,5 +85,6 @@ public class MessageManager extends Function { seasonNotExist = config.getString("messages.season-not-exist", "Season {season} does not exist."); forceWork = config.getString("messages.force-sprinkler-work", "Forced {world}'s sprinklers to work."); forceConsume = config.getString("messages.force-consume", "Forced {world}'s pots to reduce water amount and the remaining use of fertilizers."); + forceGrow = config.getString("messages.force-grow", "Forced {world}'s crops to grow one point."); } } diff --git a/src/main/java/net/momirealms/customcrops/api/object/sprinkler/SprinklerConfig.java b/src/main/java/net/momirealms/customcrops/api/object/sprinkler/SprinklerConfig.java index d3e8b09..8e0dff9 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/sprinkler/SprinklerConfig.java +++ b/src/main/java/net/momirealms/customcrops/api/object/sprinkler/SprinklerConfig.java @@ -33,15 +33,19 @@ public class SprinklerConfig { private final ItemMode itemMode; private final String threeD; private final String twoD; + private final String[] potWhitelist; private final PassiveFillMethod[] passiveFillMethods; private final WaterAmountHologram waterAmountHologram; private final SprinklerAnimation sprinklerAnimation; + private final int water; - public SprinklerConfig(String key, int storage, int range, @Nullable Sound sound, @NotNull ItemMode itemMode, @NotNull String threeD, @Nullable String twoD, + public SprinklerConfig(String key, int storage, int range, int water, @Nullable String[] potWhitelist, @Nullable Sound sound, @NotNull ItemMode itemMode, @NotNull String threeD, @Nullable String twoD, @NotNull PassiveFillMethod[] passiveFillMethods, @Nullable WaterAmountHologram waterAmountHologram, SprinklerAnimation sprinklerAnimation) { this.key = key; this.storage = storage; this.range = range; + this.water = water; + this.potWhitelist = potWhitelist; this.sound = sound; this.itemMode = itemMode; this.threeD = threeD; @@ -97,4 +101,13 @@ public class SprinklerConfig { public SprinklerAnimation getSprinklerAnimation() { return sprinklerAnimation; } + + @Nullable + public String[] getPotWhitelist() { + return potWhitelist; + } + + public int getWaterFillAbility() { + return water; + } } diff --git a/src/main/java/net/momirealms/customcrops/api/object/sprinkler/SprinklerManager.java b/src/main/java/net/momirealms/customcrops/api/object/sprinkler/SprinklerManager.java index 7840a9a..d218fc3 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/sprinkler/SprinklerManager.java +++ b/src/main/java/net/momirealms/customcrops/api/object/sprinkler/SprinklerManager.java @@ -99,6 +99,8 @@ public class SprinklerManager extends Function implements Listener { key, sprinklerSec.getInt("storage", 3), sprinklerSec.getInt("range", 1), + sprinklerSec.getInt("water",1), + sprinklerSec.contains("pot-whitelist") ? sprinklerSec.getStringList("pot-whitelist").toArray(new String[0]) : null, sound, itemMode, threeD, diff --git a/src/main/java/net/momirealms/customcrops/api/object/wateringcan/WateringCanConfig.java b/src/main/java/net/momirealms/customcrops/api/object/wateringcan/WateringCanConfig.java index 9feb4c6..7806f0f 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/wateringcan/WateringCanConfig.java +++ b/src/main/java/net/momirealms/customcrops/api/object/wateringcan/WateringCanConfig.java @@ -32,7 +32,7 @@ public class WateringCanConfig { private final int width; private final int length; private final int storage; - private final String[] pot_whitelist; + private final String[] potWhitelist; private final String[] sprinkler_whitelist; private final boolean hasDynamicLore; private final boolean hasActionBar; @@ -49,7 +49,7 @@ public class WateringCanConfig { public WateringCanConfig(int width, int length, int storage, boolean hasDynamicLore, boolean hasActionBar, @Nullable List loreTemplate, @Nullable String actionBarMsg, @Nullable String bar_left, @Nullable String bar_full, @Nullable String bar_empty, @Nullable String bar_right, - String[] pot_whitelist, String[] sprinkler_whitelist, @Nullable Sound sound, @Nullable Particle particle, @NotNull PositiveFillMethod[] positiveFillMethods) { + String[] potWhitelist, String[] sprinkler_whitelist, @Nullable Sound sound, @Nullable Particle particle, @NotNull PositiveFillMethod[] positiveFillMethods) { this.width = width; this.length = length; this.storage = storage; @@ -61,7 +61,7 @@ public class WateringCanConfig { this.bar_full = bar_full; this.bar_empty = bar_empty; this.bar_right = bar_right; - this.pot_whitelist = pot_whitelist; + this.potWhitelist = potWhitelist; this.sprinkler_whitelist = sprinkler_whitelist; this.sound = sound; this.particle = particle; @@ -114,7 +114,7 @@ public class WateringCanConfig { } public String[] getPotWhitelist() { - return pot_whitelist; + return potWhitelist; } public String[] getSprinklerWhitelist() { diff --git a/src/main/java/net/momirealms/customcrops/api/object/world/CCChunk.java b/src/main/java/net/momirealms/customcrops/api/object/world/CCChunk.java index b9d4d5d..dd2965f 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/world/CCChunk.java +++ b/src/main/java/net/momirealms/customcrops/api/object/world/CCChunk.java @@ -134,69 +134,53 @@ public class CCChunk implements Serializable { Pot pot = potMap.get(simpleLocation); if (pot != null) { if (pot.addWater(amount)) { - CustomCrops.getInstance().getScheduler().callSyncMethod(() -> { - changePotModel(simpleLocation, pot); - return null; - }); + CustomCrops.getInstance().getScheduler().runTask(() -> changePotModel(simpleLocation, pot)); } return; } if (pot_id == null) { Location bukkitLoc = simpleLocation.getBukkitLocation(); if (bukkitLoc == null) return; - String id = CustomCrops.getInstance().getPlatformInterface().getCustomBlockID(bukkitLoc); - if (id != null) { - pot_id = CustomCrops.getInstance().getPotManager().getPotKeyByBlockID(id); - } else { - return; - } + String id = CustomCrops.getInstance().getPlatformInterface().getBlockID(bukkitLoc.getBlock()); + pot_id = CustomCrops.getInstance().getPotManager().getPotKeyByBlockID(id); + if (pot_id == null) return; } - Pot newPot = new Pot(pot_id, null, amount); potMap.put(simpleLocation, newPot); - CustomCrops.getInstance().getScheduler().callSyncMethod(() -> { - changePotModel(simpleLocation, newPot); - return null; - }); + CustomCrops.getInstance().getScheduler().runTask(() -> changePotModel(simpleLocation, newPot)); } public void addFertilizerToPot(SimpleLocation simpleLocation, Fertilizer fertilizer, @NotNull String pot_id) { Pot pot = potMap.get(simpleLocation); if (pot != null) { pot.setFertilizer(fertilizer); - CustomCrops.getInstance().getScheduler().callSyncMethod(() -> { - changePotModel(simpleLocation, pot); - return null; - }); + CustomCrops.getInstance().getScheduler().runTask(() -> changePotModel(simpleLocation, pot)); } else { Pot newPot = new Pot(pot_id, fertilizer, 0); potMap.put(simpleLocation, newPot); - CustomCrops.getInstance().getScheduler().callSyncMethod(() -> { - changePotModel(simpleLocation, newPot); - return null; - }); + CustomCrops.getInstance().getScheduler().runTask(() -> changePotModel(simpleLocation, newPot)); } } - public void scheduleGrowTask(CCWorld ccWorld) { + public void scheduleGrowTask(CCWorld ccWorld, int force) { Random randomGenerator = ThreadLocalRandom.current(); - int delay = ConfigManager.pointGainInterval * 1000; + int delay = force == -1 ? ConfigManager.pointGainInterval * 1000 : force * 1000; for (SimpleLocation simpleLocation : growingCropMap.keySet()) { ccWorld.pushCropTask(simpleLocation, randomGenerator.nextInt(delay)); } } - public void scheduleSprinklerTask(CCWorld ccWorld, int startDelay) { + public void scheduleSprinklerTask(CCWorld ccWorld, int force) { Random randomGenerator = ThreadLocalRandom.current(); - int delay = (Math.min(30, ConfigManager.pointGainInterval) + startDelay) * 1000; + int delay = force == -1 ? ConfigManager.pointGainInterval * 1000 : force * 1000; for (SimpleLocation simpleLocation : sprinklerMap.keySet()) { ccWorld.pushSprinklerTask(simpleLocation, randomGenerator.nextInt(delay)); } } - public void scheduleConsumeTask(CCWorld ccWorld, int startDelay) { + public void scheduleConsumeTask(CCWorld ccWorld, int force) { Random randomGenerator = ThreadLocalRandom.current(); - int delay = (Math.min(30, ConfigManager.pointGainInterval) + startDelay) * 1000; + int delay = force == -1 ? ConfigManager.pointGainInterval * 1000 : force * 1000; for (SimpleLocation simpleLocation : potMap.keySet()) { ccWorld.pushConsumeTask(simpleLocation, randomGenerator.nextInt(delay)); } diff --git a/src/main/java/net/momirealms/customcrops/api/object/world/CCWorld.java b/src/main/java/net/momirealms/customcrops/api/object/world/CCWorld.java index eef89d8..a270bf9 100644 --- a/src/main/java/net/momirealms/customcrops/api/object/world/CCWorld.java +++ b/src/main/java/net/momirealms/customcrops/api/object/world/CCWorld.java @@ -18,6 +18,7 @@ package net.momirealms.customcrops.api.object.world; import net.momirealms.customcrops.CustomCrops; +import net.momirealms.customcrops.api.customplugin.PlatformInterface; import net.momirealms.customcrops.api.object.Function; import net.momirealms.customcrops.api.object.ItemMode; import net.momirealms.customcrops.api.object.action.Action; @@ -34,6 +35,7 @@ import net.momirealms.customcrops.api.object.fertilizer.SoilRetain; import net.momirealms.customcrops.api.object.fertilizer.SpeedGrow; import net.momirealms.customcrops.api.object.pot.Pot; import net.momirealms.customcrops.api.object.pot.PotConfig; +import net.momirealms.customcrops.api.object.pot.PotManager; import net.momirealms.customcrops.api.object.season.CCSeason; import net.momirealms.customcrops.api.object.season.SeasonData; import net.momirealms.customcrops.api.object.sprinkler.Sprinkler; @@ -88,7 +90,6 @@ public class CCWorld extends Function { } @Override - @SuppressWarnings("ResultOfMethodCallIgnored") public void init() { loadDateData(); if (!ConfigManager.onlyInLoadedChunks) { @@ -104,6 +105,7 @@ public class CCWorld extends Function { CustomCrops.getInstance().getSeasonManager().unloadSeasonData(worldName); } + @SuppressWarnings("ResultOfMethodCallIgnored") public void loadAllChunkData() { chunks_folder = ConfigUtils.getChunkFolder(worldName); if (!chunks_folder.exists()) chunks_folder.mkdirs(); @@ -251,28 +253,28 @@ public class CCWorld extends Function { } public void onReachPoint() { - if (ConfigManager.debug) Log.info("== Grow point =="); - plantToday.clear(); - int size = schedule.getQueue().size(); - if (size != 0) { - schedule.getQueue().clear(); - if (ConfigManager.debug) Log.info("== Clear queue =="); - } - for (CCChunk chunk : chunkMap.values()) { - chunk.scheduleGrowTask(this); - } if (ConfigManager.enableScheduleSystem) { + if (ConfigManager.debug) Log.info("== Grow point =="); + plantToday.clear(); + int size = schedule.getQueue().size(); + if (size != 0) { + schedule.getQueue().clear(); + if (ConfigManager.debug) Log.info("== Clear queue =="); + } + for (CCChunk chunk : chunkMap.values()) { + chunk.scheduleGrowTask(this, -1); + } workCounter--; consumeCounter--; if (consumeCounter <= 0) { consumeCounter = ConfigManager.intervalConsume; if (ConfigManager.debug) Log.info("== Consume time =="); - scheduleConsumeTask(0); + scheduleConsumeTask(-1); } if (workCounter <= 0) { workCounter = ConfigManager.intervalWork; if (ConfigManager.debug) Log.info("== Work time =="); - scheduleSprinklerWork(Math.min(30, ConfigManager.pointGainInterval)); + scheduleSprinklerWork(-1); } } } @@ -349,21 +351,17 @@ public class CCWorld extends Function { pot.setWater(pot.getWater() + 1); } if (pot.reduceWater() | pot.reduceFertilizer()) { - PotConfig potConfig = pot.getConfig(); Fertilizer fertilizer = pot.getFertilizer(); boolean wet = pot.isWet(); - if (!wet && fertilizer == null) { removePotData(simpleLocation); } - Location location = simpleLocation.getBukkitLocation(); if (location == null) { return; } - - CustomCrops.getInstance().getScheduler().callSyncMethod(() -> { + CustomCrops.getInstance().getScheduler().runTask(() -> { if (CustomCrops.getInstance().getPlatformInterface().removeAnyBlock(location)) { String replacer = wet ? potConfig.getWetPot(fertilizer) : potConfig.getDryPot(fertilizer); if (ConfigUtils.isVanillaItem(replacer)) { @@ -379,7 +377,6 @@ public class CCWorld extends Function { } else { CustomCrops.getInstance().getWorldDataManager().removePotData(SimpleLocation.getByBukkitLocation(location)); } - return null; }); } } @@ -423,10 +420,44 @@ public class CCWorld extends Function { if (water == 0) { removeSprinklerData(simpleLocation); } + int range = sprinklerConfig.getRange(); - for (int i = -range; i <= range; i++) { - for (int j = -range; j <= range; j++) { - addWaterToPot(simpleLocation.add(i, -1, j), 1, null); + PlatformInterface platformInterface = CustomCrops.getInstance().getPlatformInterface(); + PotManager potManager = CustomCrops.getInstance().getPotManager(); + String[] whiteList = sprinklerConfig.getPotWhitelist(); + int amount = sprinklerConfig.getWaterFillAbility(); + if (whiteList == null) { + for (int i = -range; i <= range; i++) { + for (int j = -range; j <= range; j++) { + SimpleLocation potLoc = simpleLocation.add(i, -1, j); + Location bLoc = potLoc.getBukkitLocation(); + if (bLoc != null) { + String blockID = platformInterface.getBlockID(potLoc.getBukkitLocation().getBlock()); + String current_id = potManager.getPotKeyByBlockID(blockID); + if (current_id != null) { + addWaterToPot(potLoc, amount, current_id); + } + } + } + } + } else { + for (int i = -range; i <= range; i++) { + outer: + for (int j = -range; j <= range; j++) { + SimpleLocation potLoc = simpleLocation.add(i, -1, j); + Location bLoc = potLoc.getBukkitLocation(); + if (bLoc != null) { + String blockID = platformInterface.getBlockID(bLoc.getBlock()); + String current_id = potManager.getPotKeyByBlockID(blockID); + if (current_id == null) continue; + for (String pot : whiteList) { + if (pot.equals(current_id)) { + addWaterToPot(potLoc, amount, current_id); + continue outer; + } + } + } + } } } } @@ -533,24 +564,22 @@ public class CCWorld extends Function { return chunk.isEntitiesLoaded(); }); loadEntities.whenComplete((result, throwable) -> - CustomCrops.getInstance().getScheduler().callSyncMethod(() -> { + CustomCrops.getInstance().getScheduler().runTask(() -> { if (CustomCrops.getInstance().getPlatformInterface().removeCustomItem(location, itemMode)) { CustomCrops.getInstance().getPlatformInterface().placeCustomItem(location, finalNextModel, itemMode); } else { removeCropData(simpleLocation); } - return null; })); } else { asyncGetChunk.whenComplete((result, throwable) -> - CustomCrops.getInstance().getScheduler().callSyncMethod(() -> { + CustomCrops.getInstance().getScheduler().runTask(() -> { if (CustomCrops.getInstance().getPlatformInterface().removeCustomItem(location, itemMode)) { CustomCrops.getInstance().getPlatformInterface().placeCustomItem(location, finalNextModel, itemMode); } else { removeCropData(simpleLocation); } - return null; })); } } @@ -672,7 +701,7 @@ public class CCWorld extends Function { return chunk.getSprinklerData(simpleLocation); } - public void addWaterToPot(SimpleLocation simpleLocation, int amount, @Nullable String pot_id) { + public void addWaterToPot(SimpleLocation simpleLocation, int amount, @NotNull String pot_id) { CCChunk chunk = chunkMap.get(simpleLocation.getChunkCoordinate()); if (chunk != null) { chunk.addWaterToPot(simpleLocation, amount, pot_id); @@ -714,18 +743,26 @@ public class CCWorld extends Function { return newChunk; } - public void scheduleSprinklerWork(int delay) { + public void scheduleSprinklerWork(int force) { schedule.execute(() -> { for (CCChunk chunk : chunkMap.values()) { - chunk.scheduleSprinklerTask(this, delay); + chunk.scheduleSprinklerTask(this, force); } }); } - public void scheduleConsumeTask(int delay) { + public void scheduleConsumeTask(int force) { schedule.execute(() -> { for (CCChunk chunk : chunkMap.values()) { - chunk.scheduleConsumeTask(this, delay); + chunk.scheduleConsumeTask(this, force); + } + }); + } + + public void scheduleCropGrowTask(int force) { + schedule.execute(() -> { + for (CCChunk chunk : chunkMap.values()) { + chunk.scheduleGrowTask(this, force); } }); } diff --git a/src/main/java/net/momirealms/customcrops/command/subcmd/ForceCommand.java b/src/main/java/net/momirealms/customcrops/command/subcmd/ForceCommand.java index f4abc6f..cc57e63 100644 --- a/src/main/java/net/momirealms/customcrops/command/subcmd/ForceCommand.java +++ b/src/main/java/net/momirealms/customcrops/command/subcmd/ForceCommand.java @@ -19,6 +19,7 @@ package net.momirealms.customcrops.command.subcmd; import net.momirealms.customcrops.command.AbstractSubCommand; import net.momirealms.customcrops.command.subcmd.force.ConsumeTaskCommand; +import net.momirealms.customcrops.command.subcmd.force.CropGrowCommand; import net.momirealms.customcrops.command.subcmd.force.SprinklerWorkCommand; public class ForceCommand extends AbstractSubCommand { @@ -29,5 +30,6 @@ public class ForceCommand extends AbstractSubCommand { super("force"); regSubCommand(SprinklerWorkCommand.INSTANCE); regSubCommand(ConsumeTaskCommand.INSTANCE); + regSubCommand(CropGrowCommand.INSTANCE); } } diff --git a/src/main/java/net/momirealms/customcrops/command/subcmd/force/ConsumeTaskCommand.java b/src/main/java/net/momirealms/customcrops/command/subcmd/force/ConsumeTaskCommand.java index d948626..2acbf7e 100644 --- a/src/main/java/net/momirealms/customcrops/command/subcmd/force/ConsumeTaskCommand.java +++ b/src/main/java/net/momirealms/customcrops/command/subcmd/force/ConsumeTaskCommand.java @@ -40,17 +40,18 @@ public class ConsumeTaskCommand extends AbstractSubCommand { @Override public boolean onCommand(CommandSender sender, List args) { - if (lackArgs(sender, 1, args.size())) return true; + if (lackArgs(sender, 2, args.size())) return true; World world = Bukkit.getWorld(args.get(0)); if (world == null) { AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.worldNotExist.replace("{world}", args.get(0))); return true; } + int seconds = Integer.parseInt(args.get(1)); AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.forceConsume.replace("{world}", args.get(0))); CustomCrops.getInstance().getScheduler().runTaskAsync(() -> { CCWorld ccworld = CustomCrops.getInstance().getWorldDataManager().getWorld(args.get(0)); if (ccworld != null) { - ccworld.scheduleConsumeTask(0); + ccworld.scheduleConsumeTask(seconds); } }); return true; @@ -61,6 +62,9 @@ public class ConsumeTaskCommand extends AbstractSubCommand { if (args.size() == 1) { return super.filterStartingWith(Bukkit.getWorlds().stream().filter(world -> CustomCrops.getInstance().getWorldDataManager().isWorldAllowed(world)).map(WorldInfo::getName).collect(Collectors.toList()), args.get(0)); } + if (args.size() == 2) { + return List.of(""); + } return null; } } diff --git a/src/main/java/net/momirealms/customcrops/command/subcmd/force/CropGrowCommand.java b/src/main/java/net/momirealms/customcrops/command/subcmd/force/CropGrowCommand.java new file mode 100644 index 0000000..dc87507 --- /dev/null +++ b/src/main/java/net/momirealms/customcrops/command/subcmd/force/CropGrowCommand.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) <2022> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.momirealms.customcrops.command.subcmd.force; + +import net.momirealms.customcrops.CustomCrops; +import net.momirealms.customcrops.api.object.basic.MessageManager; +import net.momirealms.customcrops.api.object.world.CCWorld; +import net.momirealms.customcrops.api.util.AdventureUtils; +import net.momirealms.customcrops.command.AbstractSubCommand; +import org.bukkit.Bukkit; +import org.bukkit.World; +import org.bukkit.command.CommandSender; +import org.bukkit.generator.WorldInfo; + +import java.util.List; +import java.util.stream.Collectors; + +public class CropGrowCommand extends AbstractSubCommand { + + public static final CropGrowCommand INSTANCE = new CropGrowCommand(); + + public CropGrowCommand() { + super("cropgrow"); + } + + @Override + public boolean onCommand(CommandSender sender, List args) { + if (lackArgs(sender, 2, args.size())) return true; + World world = Bukkit.getWorld(args.get(0)); + if (world == null) { + AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.worldNotExist.replace("{world}", args.get(0))); + return true; + } + int seconds = Integer.parseInt(args.get(1)); + AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.forceGrow.replace("{world}", args.get(0))); + CustomCrops.getInstance().getScheduler().runTaskAsync(() -> { + CCWorld ccworld = CustomCrops.getInstance().getWorldDataManager().getWorld(args.get(0)); + if (ccworld != null) { + ccworld.scheduleCropGrowTask(seconds); + } + }); + return true; + } + + @Override + public List onTabComplete(CommandSender sender, List args) { + if (args.size() == 1) { + return super.filterStartingWith(Bukkit.getWorlds().stream().filter(world -> CustomCrops.getInstance().getWorldDataManager().isWorldAllowed(world)).map(WorldInfo::getName).collect(Collectors.toList()), args.get(0)); + } + if (args.size() == 2) { + return List.of(""); + } + return null; + } +} diff --git a/src/main/java/net/momirealms/customcrops/command/subcmd/force/SprinklerWorkCommand.java b/src/main/java/net/momirealms/customcrops/command/subcmd/force/SprinklerWorkCommand.java index 813fc46..83bcc24 100644 --- a/src/main/java/net/momirealms/customcrops/command/subcmd/force/SprinklerWorkCommand.java +++ b/src/main/java/net/momirealms/customcrops/command/subcmd/force/SprinklerWorkCommand.java @@ -40,17 +40,18 @@ public class SprinklerWorkCommand extends AbstractSubCommand { @Override public boolean onCommand(CommandSender sender, List args) { - if (lackArgs(sender, 1, args.size())) return true; + if (lackArgs(sender, 2, args.size())) return true; World world = Bukkit.getWorld(args.get(0)); if (world == null) { AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.worldNotExist.replace("{world}", args.get(0))); return true; } + int seconds = Integer.parseInt(args.get(1)); AdventureUtils.sendMessage(sender, MessageManager.prefix + MessageManager.forceWork.replace("{world}", args.get(0))); CustomCrops.getInstance().getScheduler().runTaskAsync(() -> { CCWorld ccworld = CustomCrops.getInstance().getWorldDataManager().getWorld(args.get(0)); if (ccworld != null) { - ccworld.scheduleSprinklerWork(0); + ccworld.scheduleSprinklerWork(seconds); } }); return true; @@ -61,6 +62,9 @@ public class SprinklerWorkCommand extends AbstractSubCommand { if (args.size() == 1) { return super.filterStartingWith(Bukkit.getWorlds().stream().filter(world -> CustomCrops.getInstance().getWorldDataManager().isWorldAllowed(world)).map(WorldInfo::getName).collect(Collectors.toList()), args.get(0)); } + if (args.size() == 2) { + return List.of(""); + } return null; } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index c522459..36c08c3 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -1,5 +1,5 @@ # Don't change -config-version: '30' +config-version: '31' # BStats metrics: true # Language: english / spanish / chinese / turkish @@ -20,23 +20,18 @@ worlds: - world schedule-system: - - default-schedule: true + # if disabled, you can do that manually with command /customcrops force [consume/sprinklerwork/cropgrow] or API + # 如果禁用,你可以使用指令/customcrops force [consume/sprinklerwork/cropgrow]手动操作或使用API + enable: true # The average interval for a crop to gain one point (measured in seconds) # 平均每个农作物获得一生长点的时间间隔(秒) point-gain-interval: 600 - - others: - # if disabled, you can do that manually with command /customcrops force [consume/sprinklerwork] - # 如果禁用,你可以使用指令/customcrops force [consume/sprinklerwork]手动操作 - enable: true - # Water amount and fertilizer would reduce every two points are gained - # As the default point-gain-interval is 600s, so here it would be 1200s(20min = a minecraft day) - # 默认每两个生长点进行一次水分、肥料消耗/洒水器工作 - consume-water-fertilizer-every-x-point: 2 - # Sprinkler would work every two points are gained - sprinkler-work-every-x-point: 2 - + # Water amount and fertilizer would reduce every two points are gained + # As the default point-gain-interval is 600s, so here it would be 1200s(20min = a minecraft day) + # 默认每两个生长点进行一次水分、肥料消耗/洒水器工作 + consume-water-fertilizer-every-x-point: 2 + # Sprinkler would work every two points are gained + sprinkler-work-every-x-point: 2 # Save cache to file interval (seconds) # set "-1" to disable # 保存缓存的时间间隔 (秒) @@ -71,11 +66,9 @@ mechanics: # Does the system only work in loaded chunks (Requires you to stop the server before changing this setting) # 插件是否只在加载中的区块工作 (需要关闭服务器再设置此项) only-work-in-loaded-chunks: false - # 17/2/1 = 85%/10%/5% # 2/2/1 = 40%/40%/20% default-quality-ratio: 17/2/1 - # Season mechanic # 季节机制 season: diff --git a/src/main/resources/contents/sprinklers/default.yml b/src/main/resources/contents/sprinklers/default.yml index 06edf88..c458cdc 100644 --- a/src/main/resources/contents/sprinklers/default.yml +++ b/src/main/resources/contents/sprinklers/default.yml @@ -7,6 +7,9 @@ sprinkler_1: # max water storage # 最大储水量 storage: 4 + # The water amount add to the pot + # 单次洒水加到种植盆的水量 + water: 1 # 2/3D物品 3D-item: customcrops:sprinkler_1 # Optional, remove this section if you don't need 2d items @@ -78,6 +81,7 @@ sprinkler_2: # (1+2x2)²=25 range: 2 storage: 5 + water: 1 3D-item: customcrops:sprinkler_2 2D-item: customcrops:sprinkler_2_item type: ITEM_FRAME @@ -123,7 +127,8 @@ sprinkler_2: sprinkler_3: range: 2 - storage: 7 + storage: 3 + water: 2 3D-item: customcrops:sprinkler_3 2D-item: customcrops:sprinkler_3_item type: ITEM_FRAME diff --git a/src/main/resources/messages/messages_chinese.yml b/src/main/resources/messages/messages_chinese.yml index ce657d9..f6f2350 100644 --- a/src/main/resources/messages/messages_chinese.yml +++ b/src/main/resources/messages/messages_chinese.yml @@ -21,4 +21,5 @@ messages: world-not-exist: '世界 {world} 不存在.' season-not-exist: '{season} 不是一个有效的季节.' force-sprinkler-work: '已强制世界 {world} 的洒水器进行工作.' - force-consume: '已强制世界 {world} 的肥料、水分消耗.' \ No newline at end of file + force-consume: '已强制世界 {world} 的肥料、水分消耗.' + force-grow: '已强制世界 {world} 的农作物生长.' \ No newline at end of file diff --git a/src/main/resources/messages/messages_english.yml b/src/main/resources/messages/messages_english.yml index 34fde1f..7a5e6ab 100644 --- a/src/main/resources/messages/messages_english.yml +++ b/src/main/resources/messages/messages_english.yml @@ -21,4 +21,5 @@ messages: world-not-exist: 'World {world} does not exist.' season-not-exist: 'Season {season} does not exist.' force-sprinkler-work: "Forced {world}'s sprinklers to start working." - force-consume: "Forced {world}'s pots to reduce water amount and the remaining use of fertilizers." \ No newline at end of file + force-consume: "Forced {world}'s pots to reduce water amount and the remaining use of fertilizers." + force-grow: "Forced {world}'s crops to grow one point." \ No newline at end of file diff --git a/src/main/resources/messages/messages_spanish.yml b/src/main/resources/messages/messages_spanish.yml index c8a56cf..c719cd4 100644 --- a/src/main/resources/messages/messages_spanish.yml +++ b/src/main/resources/messages/messages_spanish.yml @@ -21,4 +21,5 @@ messages: world-not-exist: 'El mundo {world} no existe.' season-not-exist: 'Temporada {season} no existe.' force-sprinkler-work: "Se forzo {world}'s sprinklers para trabajar" - force-consume: "Se forzo {world}'s pot para reducir la cantidad de consumo del agua y fertilizantes" \ No newline at end of file + force-consume: "Se forzo {world}'s pot para reducir la cantidad de consumo del agua y fertilizantes" + force-grow: "Forced {world}'s crops to grow one point." \ No newline at end of file diff --git a/src/main/resources/messages/messages_turkish.yml b/src/main/resources/messages/messages_turkish.yml index 812f17a..6919fe9 100644 --- a/src/main/resources/messages/messages_turkish.yml +++ b/src/main/resources/messages/messages_turkish.yml @@ -21,4 +21,5 @@ messages: world-not-exist: '{world} adında bir dünya bulunamadı.' season-not-exist: '{season} adında bir mevsim bulunamadı.' force-sprinkler-work: "{world}'nin sulama sistemlerinin çalışmasını zorladı" - force-consume: "{world}'nin tenceresindeki su miktarını azaltmayı ve kalan gübre kullanımını zorladı" \ No newline at end of file + force-consume: "{world}'nin tenceresindeki su miktarını azaltmayı ve kalan gübre kullanımını zorladı" + force-grow: "Forced {world}'s crops to grow one point." \ No newline at end of file