mirror of
https://github.com/Xiao-MoMi/Custom-Crops.git
synced 2025-12-26 18:39:17 +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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -21,4 +21,5 @@ messages:
|
||||
world-not-exist: '<white>世界 {world} 不存在.'
|
||||
season-not-exist: '<white>{season} 不是一个有效的季节.'
|
||||
force-sprinkler-work: '<white>已强制世界 {world} 的洒水器进行工作.'
|
||||
force-consume: '<white>已强制世界 {world} 的肥料、水分消耗.'
|
||||
force-consume: '<white>已强制世界 {world} 的肥料、水分消耗.'
|
||||
force-grow: '<white>已强制世界 {world} 的农作物生长.'
|
||||
@@ -21,4 +21,5 @@ messages:
|
||||
world-not-exist: '<white>World {world} does not exist.'
|
||||
season-not-exist: '<white>Season {season} does not exist.'
|
||||
force-sprinkler-work: "<white>Forced {world}'s sprinklers to start working."
|
||||
force-consume: "<white>Forced {world}'s pots to reduce water amount and the remaining use of fertilizers."
|
||||
force-consume: "<white>Forced {world}'s pots to reduce water amount and the remaining use of fertilizers."
|
||||
force-grow: "<white>Forced {world}'s crops to grow one point."
|
||||
@@ -21,4 +21,5 @@ messages:
|
||||
world-not-exist: '<white>El mundo {world} no existe.'
|
||||
season-not-exist: '<white>Temporada {season} no existe.'
|
||||
force-sprinkler-work: "<white>Se forzo {world}'s sprinklers para trabajar"
|
||||
force-consume: "<white>Se forzo {world}'s pot para reducir la cantidad de consumo del agua y fertilizantes"
|
||||
force-consume: "<white>Se forzo {world}'s pot para reducir la cantidad de consumo del agua y fertilizantes"
|
||||
force-grow: "<white>Forced {world}'s crops to grow one point."
|
||||
@@ -21,4 +21,5 @@ messages:
|
||||
world-not-exist: '<white>{world} adında bir dünya bulunamadı.'
|
||||
season-not-exist: '<white>{season} adında bir mevsim bulunamadı.'
|
||||
force-sprinkler-work: "<white>{world}'nin sulama sistemlerinin çalışmasını zorladı"
|
||||
force-consume: "<white>{world}'nin tenceresindeki su miktarını azaltmayı ve kalan gübre kullanımını zorladı"
|
||||
force-consume: "<white>{world}'nin tenceresindeki su miktarını azaltmayı ve kalan gübre kullanımını zorladı"
|
||||
force-grow: "<white>Forced {world}'s crops to grow one point."
|
||||
Reference in New Issue
Block a user