diff --git a/api/src/main/java/net/momirealms/customcrops/api/mechanic/misc/MatchRule.java b/api/src/main/java/net/momirealms/customcrops/api/mechanic/misc/MatchRule.java new file mode 100644 index 0000000..8258d72 --- /dev/null +++ b/api/src/main/java/net/momirealms/customcrops/api/mechanic/misc/MatchRule.java @@ -0,0 +1,8 @@ +package net.momirealms.customcrops.api.mechanic.misc; + +public enum MatchRule { + + BLACKLIST, + WHITELIST, + REGEX +} diff --git a/build.gradle.kts b/build.gradle.kts index bfd1354..68e2d73 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ plugins { allprojects { project.group = "net.momirealms" - project.version = "3.4.3.0" + project.version = "3.4.3.1" apply() apply(plugin = "java") diff --git a/plugin/build.gradle.kts b/plugin/build.gradle.kts index 433e9cb..6d954cc 100644 --- a/plugin/build.gradle.kts +++ b/plugin/build.gradle.kts @@ -51,8 +51,9 @@ dependencies { implementation(project(":legacy-api")) implementation("net.kyori:adventure-api:4.15.0") implementation("net.kyori:adventure-platform-bukkit:4.3.2") - implementation("com.github.Xiao-MoMi:AntiGriefLib:0.8") + implementation("com.github.Xiao-MoMi:AntiGriefLib:0.9") implementation("com.github.Xiao-MoMi:BiomeAPI:0.3") + compileOnly("net.kyori:adventure-text-minimessage:4.15.0") compileOnly("net.kyori:adventure-text-serializer-legacy:4.15.0") compileOnly("de.tr7zw:item-nbt-api:2.12.2") diff --git a/plugin/libs/AntiGriefLib-0.8.jar b/plugin/libs/AntiGriefLib-0.8.jar new file mode 100644 index 0000000..e655645 Binary files /dev/null and b/plugin/libs/AntiGriefLib-0.8.jar differ diff --git a/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/CWorld.java b/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/CWorld.java index 0741514..f2f2805 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/CWorld.java +++ b/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/CWorld.java @@ -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; -// } } } diff --git a/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/WorldManagerImpl.java b/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/WorldManagerImpl.java index 08819cc..24e215b 100644 --- a/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/WorldManagerImpl.java +++ b/plugin/src/main/java/net/momirealms/customcrops/mechanic/world/WorldManagerImpl.java @@ -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 loadedWorlds; private final HashMap worldSettingMap; private WorldSetting defaultWorldSetting; - private boolean whiteListOrBlackList; + private MatchRule matchRule; private HashSet 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; } } diff --git a/plugin/src/main/resources/config.yml b/plugin/src/main/resources/config.yml index 5af91b8..758262c 100644 --- a/plugin/src/main/resources/config.yml +++ b/plugin/src/main/resources/config.yml @@ -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