9
0
mirror of https://github.com/Xiao-MoMi/Custom-Crops.git synced 2025-12-26 02:19:28 +00:00

regex world match

This commit is contained in:
XiaoMoMi
2024-03-22 00:57:07 +08:00
parent 146c893ab9
commit 738445dfd9
7 changed files with 24 additions and 15 deletions

View File

@@ -480,15 +480,7 @@ public class CWorld implements CustomCropsWorld {
loadChunk(chunk);
return chunk;
} else {
// is an unloaded chunk, but has been generated
// if (bukkitWorld.isChunkGenerated(chunkPos.x(), chunkPos.z())) {
// Chunk bukkitChunk = bukkitWorld.getChunkAt(chunkPos.x(), chunkPos.z());
// worldManager.handleChunkLoad(bukkitChunk);
// chunk = loadedChunks.get(chunkPos);
// return Objects.requireNonNullElseGet(chunk, () -> new CChunk(this, chunkPos));
// } else {
return null;
// }
}
}

View File

@@ -20,6 +20,7 @@ package net.momirealms.customcrops.mechanic.world;
import net.momirealms.customcrops.api.CustomCropsPlugin;
import net.momirealms.customcrops.api.manager.WorldManager;
import net.momirealms.customcrops.api.mechanic.item.*;
import net.momirealms.customcrops.api.mechanic.misc.MatchRule;
import net.momirealms.customcrops.api.mechanic.world.AbstractWorldAdaptor;
import net.momirealms.customcrops.api.mechanic.world.ChunkPos;
import net.momirealms.customcrops.api.mechanic.world.CustomCropsBlock;
@@ -50,7 +51,7 @@ public class WorldManagerImpl implements WorldManager, Listener {
private final ConcurrentHashMap<String, CWorld> loadedWorlds;
private final HashMap<String, WorldSetting> worldSettingMap;
private WorldSetting defaultWorldSetting;
private boolean whiteListOrBlackList;
private MatchRule matchRule;
private HashSet<String> worldList;
private AbstractWorldAdaptor worldAdaptor;
private String absoluteWorldFolder;
@@ -118,7 +119,7 @@ public class WorldManagerImpl implements WorldManager, Listener {
}
this.absoluteWorldFolder = section.getString("absolute-world-folder-path","");
this.whiteListOrBlackList = section.getString("mode", "blacklist").equalsIgnoreCase("whitelist");
this.matchRule = MatchRule.valueOf(section.getString("mode", "blacklist").toUpperCase(Locale.ENGLISH));
this.worldList = new HashSet<>(section.getStringList("list"));
// limitation
@@ -196,10 +197,17 @@ public class WorldManagerImpl implements WorldManager, Listener {
@Override
public boolean isMechanicEnabled(@NotNull World world) {
if (whiteListOrBlackList) {
if (matchRule == MatchRule.WHITELIST) {
return worldList.contains(world.getName());
} else {
} else if (matchRule == MatchRule.BLACKLIST) {
return !worldList.contains(world.getName());
} else {
for (String regex : worldList) {
if (world.getName().matches(regex)) {
return true;
}
}
return false;
}
}

View File

@@ -19,7 +19,7 @@ worlds:
# Especially for realm systems
absolute-world-folder-path: ''
# A list of worlds that would decide where the plugin mechanisms take effect
# Mode: whitelist/blacklist
# Mode: whitelist/blacklist/regex
mode: blacklist
list:
- blacklist_world