9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-20 07:29:27 +00:00
This commit is contained in:
XiaoMoMi
2024-10-24 01:29:50 +08:00
parent 1e36768382
commit a320a2153c
8 changed files with 32 additions and 24 deletions

View File

@@ -194,9 +194,10 @@ public interface CustomCropsWorld<W> {
/** /**
* Saves the world data to a file. * Saves the world data to a file.
* *
* @param async async or not * @param async async or not
* @param disabling is the server disabled
*/ */
void save(boolean async); void save(boolean async, boolean disabling);
/** /**
* Sets whether the ticking task is ongoing. * Sets whether the ticking task is ongoing.

View File

@@ -186,11 +186,15 @@ public class CustomCropsWorldImpl<W> implements CustomCropsWorld<W> {
} }
@Override @Override
public void save(boolean async) { public void save(boolean async, boolean disabling) {
if (async) { if (async && !disabling) {
this.scheduler.async().execute(this::save); this.scheduler.async().execute(this::save);
} else { } else {
BukkitCustomCropsPlugin.getInstance().getScheduler().sync().run(this::save, null); if (disabling) {
save();
} else {
BukkitCustomCropsPlugin.getInstance().getScheduler().sync().run(this::save, null);
}
} }
} }

View File

@@ -66,10 +66,11 @@ public interface WorldManager extends Reloadable {
/** /**
* Unloads the CustomCrops world associated with the specified Bukkit world. * Unloads the CustomCrops world associated with the specified Bukkit world.
* *
* @param world The Bukkit world to unload. * @param world The Bukkit world to unload.
* @param disabling
* @return True if the world was successfully unloaded, false otherwise. * @return True if the world was successfully unloaded, false otherwise.
*/ */
boolean unloadWorld(World world); boolean unloadWorld(World world, boolean disabling);
/** /**
* Retrieves a CustomCrops world based on the specified Bukkit world, if loaded. * Retrieves a CustomCrops world based on the specified Bukkit world, if loaded.

View File

@@ -129,7 +129,7 @@ public abstract class AbstractRequirementManager<T> implements RequirementManage
if (inner != null) { if (inner != null) {
requirements.add(parseRequirement(inner, runActions)); requirements.add(parseRequirement(inner, runActions));
} else { } else {
plugin.getPluginLogger().warn("Section " + typeOrName + " is misconfigured"); plugin.getPluginLogger().warn("Section " + section.getRouteAsString() + "." + typeOrName + " is misconfigured");
} }
} }
} }

View File

@@ -1,6 +1,6 @@
# Project settings # Project settings
# Rule: [major update].[feature update].[bug fix] # Rule: [major update].[feature update].[bug fix]
project_version=3.6.16 project_version=3.6.17
config_version=41 config_version=41
project_group=net.momirealms project_group=net.momirealms
@@ -40,9 +40,9 @@ guava_version=33.3.1-jre
vault_version=1.7 vault_version=1.7
# Proxy settings # Proxy settings
#systemProp.socks.proxyHost=127.0.0.1 systemProp.socks.proxyHost=127.0.0.1
#systemProp.socks.proxyPort=7890 systemProp.socks.proxyPort=7890
#systemProp.http.proxyHost=127.0.0.1 systemProp.http.proxyHost=127.0.0.1
#systemProp.http.proxyPort=7890 systemProp.http.proxyPort=7890
#systemProp.https.proxyHost=127.0.0.1 systemProp.https.proxyHost=127.0.0.1
#systemProp.https.proxyPort=7890 systemProp.https.proxyPort=7890

View File

@@ -120,7 +120,7 @@ public class ConfigType {
.vanillaPots(ListUtils.toList(section.get("vanilla-blocks"))) .vanillaPots(ListUtils.toList(section.get("vanilla-blocks")))
.ignoreRandomTick(section.getBoolean("ignore-random-tick", false)) .ignoreRandomTick(section.getBoolean("ignore-random-tick", false))
.ignoreScheduledTick(section.getBoolean("ignore-scheduled-tick", false)) .ignoreScheduledTick(section.getBoolean("ignore-scheduled-tick", false))
.storage(section.getInt("storage", 5)) .storage(section.getInt("storage", section.getInt("max-water-storage", 5)))
.isRainDropAccepted(section.getBoolean("absorb-rainwater", false)) .isRainDropAccepted(section.getBoolean("absorb-rainwater", false))
.isNearbyWaterAccepted(section.getBoolean("absorb-nearby-water", false)) .isNearbyWaterAccepted(section.getBoolean("absorb-nearby-water", false))
.maxFertilizers(section.getInt("max-fertilizers", 1)) .maxFertilizers(section.getInt("max-fertilizers", 1))

View File

@@ -80,6 +80,7 @@ public class PlayerRequirementManager extends AbstractRequirementManager<Player>
} }
int amount = section.getInt("amount", 0); int amount = section.getInt("amount", 0);
List<String> items = ListUtils.toList(section.get("item")); List<String> items = ListUtils.toList(section.get("item"));
boolean any = items.contains("any") || items.contains("*");
return context -> { return context -> {
Player player = context.holder(); Player player = context.holder();
if (player == null) return true; if (player == null) return true;
@@ -96,7 +97,7 @@ public class PlayerRequirementManager extends AbstractRequirementManager<Player>
} }
String id = plugin.getItemManager().id(itemStack); String id = plugin.getItemManager().id(itemStack);
if (!regex) { if (!regex) {
if (items.contains(id) && itemStack.getAmount() >= amount) return true; if ((any || items.contains(id)) && itemStack.getAmount() >= amount) return true;
} else { } else {
for (String itemRegex : items) { for (String itemRegex : items) {
if (id.matches(itemRegex) && itemStack.getAmount() >= amount) { if (id.matches(itemRegex) && itemStack.getAmount() >= amount) {
@@ -130,6 +131,7 @@ public class PlayerRequirementManager extends AbstractRequirementManager<Player>
} }
int amount = section.getInt("amount", 0); int amount = section.getInt("amount", 0);
List<String> items = ListUtils.toList(section.get("material")); List<String> items = ListUtils.toList(section.get("material"));
boolean any = items.contains("any") || items.contains("*");
return context -> { return context -> {
Player player = context.holder(); Player player = context.holder();
if (player == null) return true; if (player == null) return true;
@@ -146,7 +148,7 @@ public class PlayerRequirementManager extends AbstractRequirementManager<Player>
} }
String id = itemStack.getType().name(); String id = itemStack.getType().name();
if (!regex) { if (!regex) {
if (items.contains(id) && itemStack.getAmount() >= amount) return true; if ((any || items.contains(id)) && itemStack.getAmount() >= amount) return true;
} else { } else {
for (String itemRegex : items) { for (String itemRegex : items) {
if (id.matches(itemRegex) && itemStack.getAmount() >= amount) { if (id.matches(itemRegex) && itemStack.getAmount() >= amount) {

View File

@@ -129,7 +129,7 @@ public class BukkitWorldManager implements WorldManager, Listener {
if (isMechanicEnabled(world)) { if (isMechanicEnabled(world)) {
loadWorld(world); loadWorld(world);
} else { } else {
unloadWorld(world); unloadWorld(world, false);
} }
} }
} }
@@ -180,7 +180,7 @@ public class BukkitWorldManager implements WorldManager, Listener {
public void disable() { public void disable() {
this.unload(); this.unload();
for (World world : Bukkit.getWorlds()) { for (World world : Bukkit.getWorlds()) {
unloadWorld(world); unloadWorld(world, true);
} }
} }
@@ -217,13 +217,13 @@ public class BukkitWorldManager implements WorldManager, Listener {
} }
@Override @Override
public boolean unloadWorld(World world) { public boolean unloadWorld(World world, boolean disabling) {
CustomCropsWorld<?> removedWorld = worlds.remove(world.getName()); CustomCropsWorld<?> removedWorld = worlds.remove(world.getName());
if (removedWorld == null) { if (removedWorld == null) {
return false; return false;
} }
removedWorld.setTicking(false); removedWorld.setTicking(false);
removedWorld.save(false); removedWorld.save(false, disabling);
removedWorld.scheduler().shutdownScheduler(); removedWorld.scheduler().shutdownScheduler();
removedWorld.scheduler().shutdownExecutor(); removedWorld.scheduler().shutdownExecutor();
return true; return true;
@@ -232,7 +232,7 @@ public class BukkitWorldManager implements WorldManager, Listener {
@EventHandler @EventHandler
public void onWorldSave(WorldSaveEvent event) { public void onWorldSave(WorldSaveEvent event) {
final World world = event.getWorld(); final World world = event.getWorld();
getWorld(world).ifPresent(world1 -> world1.save(true)); getWorld(world).ifPresent(world1 -> world1.save(true, false));
} }
@EventHandler (priority = EventPriority.HIGH) @EventHandler (priority = EventPriority.HIGH)
@@ -246,7 +246,7 @@ public class BukkitWorldManager implements WorldManager, Listener {
public void onWorldUnload(WorldUnloadEvent event) { public void onWorldUnload(WorldUnloadEvent event) {
World world = event.getWorld(); World world = event.getWorld();
if (!isMechanicEnabled(world)) return; if (!isMechanicEnabled(world)) return;
unloadWorld(world); unloadWorld(world, false);
} }
@EventHandler @EventHandler