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:
@@ -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;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user