mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-28 19:39:20 +00:00
3.1.3
This commit is contained in:
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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", "<white>Season {season} does not exist.");
|
||||
forceWork = config.getString("messages.force-sprinkler-work", "<white>Forced {world}'s sprinklers to work.");
|
||||
forceConsume = config.getString("messages.force-consume", "<white>Forced {world}'s pots to reduce water amount and the remaining use of fertilizers.");
|
||||
forceGrow = config.getString("messages.force-grow", "<white>Forced {world}'s crops to grow one point.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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<String> 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() {
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,17 +40,18 @@ public class ConsumeTaskCommand extends AbstractSubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, List<String> 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("<Seconds>");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Copyright (C) <2022> <XiaoMoMi>
|
||||
*
|
||||
* 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 <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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<String> 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<String> onTabComplete(CommandSender sender, List<String> 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("<Seconds>");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -40,17 +40,18 @@ public class SprinklerWorkCommand extends AbstractSubCommand {
|
||||
|
||||
@Override
|
||||
public boolean onCommand(CommandSender sender, List<String> 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("<Seconds>");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user