From 2521ed8c9d77a4c0396172daad3b41986962f72e Mon Sep 17 00:00:00 2001 From: Nathan Wolf Date: Fri, 3 Aug 2018 10:20:21 -0700 Subject: [PATCH] Strip out WorldGuard support, rely on Magic for spawn-tags --- CHANGELOG.md | 1 + pom.xml | 24 +----- .../magicworlds/MagicWorldsController.java | 17 +---- .../bukkit/magicworlds/MagicWorldsPlugin.java | 1 - .../populator/MagicChestRunnable.java | 2 +- .../worldguard/WGCustomFlagsManager.java | 32 -------- .../magicworlds/worldguard/WorldGuardAPI.java | 74 ------------------- .../worldguard/WorldGuardFlags.java | 10 --- .../worldguard/WorldGuardFlagsManager.java | 35 --------- .../worldguard/WorldGuardManager.java | 59 --------------- src/main/resources/config.yml | 3 - 11 files changed, 4 insertions(+), 254 deletions(-) delete mode 100644 src/main/java/com/elmakers/mine/bukkit/magicworlds/worldguard/WGCustomFlagsManager.java delete mode 100644 src/main/java/com/elmakers/mine/bukkit/magicworlds/worldguard/WorldGuardAPI.java delete mode 100644 src/main/java/com/elmakers/mine/bukkit/magicworlds/worldguard/WorldGuardFlags.java delete mode 100644 src/main/java/com/elmakers/mine/bukkit/magicworlds/worldguard/WorldGuardFlagsManager.java delete mode 100644 src/main/java/com/elmakers/mine/bukkit/magicworlds/worldguard/WorldGuardManager.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 79860dd..46e53f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ - Now reacts to all spawn reasons by default. You can change this behavior in configs. - Adds quiet=true parameter to all spell casts. + - Requires Magic 7.6.6 or higher (to support WG7 and MC 1.13) # 1.5 diff --git a/pom.xml b/pom.xml index 14f910c..53bd9b5 100644 --- a/pom.xml +++ b/pom.xml @@ -70,33 +70,11 @@ com.elmakers.mine.bukkit.plugins Magic - 7.0-SNAPSHOT - provided - - - com.sk89q - worldedit - 5.5.6 - provided - - - com.sk89q - worldguard - 6.2.0 - provided - - - com.mewin - WGCustomFlags - 1.6.1 + 7.6.6-SNAPSHOT provided - - bukkit-repo - http://repo.bukkit.org/content/groups/public/ - elMakers http://maven.elmakers.com/repository/ diff --git a/src/main/java/com/elmakers/mine/bukkit/magicworlds/MagicWorldsController.java b/src/main/java/com/elmakers/mine/bukkit/magicworlds/MagicWorldsController.java index 5f153ba..c944eb8 100644 --- a/src/main/java/com/elmakers/mine/bukkit/magicworlds/MagicWorldsController.java +++ b/src/main/java/com/elmakers/mine/bukkit/magicworlds/MagicWorldsController.java @@ -5,7 +5,6 @@ import com.elmakers.mine.bukkit.magicworlds.listener.EntitySpawnListener; import com.elmakers.mine.bukkit.magicworlds.listener.PlayerListener; import com.elmakers.mine.bukkit.magicworlds.populator.builtin.MagicChestPopulator; -import com.elmakers.mine.bukkit.magicworlds.worldguard.WorldGuardManager; import com.elmakers.mine.bukkit.utility.ConfigurationUtils; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -21,7 +20,6 @@ import org.bukkit.plugin.PluginManager; import java.io.File; -import java.io.IOException; import java.util.HashMap; import java.util.Map; import java.util.Set; @@ -57,10 +55,6 @@ public void initialize() load(); } - public void initializeWorldGuardFlags() { - worldGuardManager.initializeFlags(plugin); - } - public void load() { File configFolder = plugin.getDataFolder(); @@ -91,14 +85,6 @@ public void load() pm.registerEvents(new PlayerListener(this), plugin); } - worldGuardManager.setEnabled(config.getBoolean("region_manager_enabled", true)); - plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() { - @Override - public void run() { - worldGuardManager.initialize(plugin); - } - }, 10); - ConfigurationSection worlds = config.getConfigurationSection("worlds"); if (worlds != null) { Set worldKeys = worlds.getKeys(false); @@ -197,7 +183,7 @@ public MagicWorld getWorld(String name) { } public boolean inTaggedRegion(Location location, Set tags) { - return worldGuardManager.inTaggedRegion(location, tags); + return magicAPI.getController().inTaggedRegion(location, tags); } /* @@ -208,7 +194,6 @@ public boolean inTaggedRegion(Location location, Set tags) { private boolean magicLoaded = false; private boolean loaded = false; - private WorldGuardManager worldGuardManager = new WorldGuardManager(); private final Map magicWorlds = new HashMap(); private final MagicChunkGenerator worldGenerator; private final Plugin plugin; diff --git a/src/main/java/com/elmakers/mine/bukkit/magicworlds/MagicWorldsPlugin.java b/src/main/java/com/elmakers/mine/bukkit/magicworlds/MagicWorldsPlugin.java index 85e8fa0..c577442 100644 --- a/src/main/java/com/elmakers/mine/bukkit/magicworlds/MagicWorldsPlugin.java +++ b/src/main/java/com/elmakers/mine/bukkit/magicworlds/MagicWorldsPlugin.java @@ -125,7 +125,6 @@ public void onLoad() if (controller == null) { controller = new MagicWorldsController(this); } - controller.initializeWorldGuardFlags(); } public boolean hasPermission(CommandSender sender, String pNode) diff --git a/src/main/java/com/elmakers/mine/bukkit/magicworlds/populator/MagicChestRunnable.java b/src/main/java/com/elmakers/mine/bukkit/magicworlds/populator/MagicChestRunnable.java index 5c847c3..fee9637 100644 --- a/src/main/java/com/elmakers/mine/bukkit/magicworlds/populator/MagicChestRunnable.java +++ b/src/main/java/com/elmakers/mine/bukkit/magicworlds/populator/MagicChestRunnable.java @@ -58,7 +58,7 @@ public void run() { logger.info("Loading/Generating chunk at " + chunk.getX() + ", " + chunk.getZ()); } } else { - if (!NMSUtils.isDone(chunk)) { + if (!NMSUtils.isReady(chunk)) { if (generate) { if (!chunk.load(true)) { logger.info("Failed to generate chunk at " + chunk.getX() + ", " + chunk.getZ()); diff --git a/src/main/java/com/elmakers/mine/bukkit/magicworlds/worldguard/WGCustomFlagsManager.java b/src/main/java/com/elmakers/mine/bukkit/magicworlds/worldguard/WGCustomFlagsManager.java deleted file mode 100644 index 182caf7..0000000 --- a/src/main/java/com/elmakers/mine/bukkit/magicworlds/worldguard/WGCustomFlagsManager.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.elmakers.mine.bukkit.magicworlds.worldguard; - -import com.mewin.WGCustomFlags.WGCustomFlagsPlugin; -import com.sk89q.worldguard.protection.ApplicableRegionSet; -import com.sk89q.worldguard.protection.association.RegionAssociable; -import com.sk89q.worldguard.protection.flags.RegionGroup; -import com.sk89q.worldguard.protection.flags.SetFlag; -import com.sk89q.worldguard.protection.flags.StringFlag; -import org.bukkit.plugin.Plugin; - -import java.util.Collections; -import java.util.Set; - -public class WGCustomFlagsManager implements WorldGuardFlags { - - private final WGCustomFlagsPlugin customFlags; - - public static SetFlag SPAWN_TAGS = new SetFlag("spawn-tags", RegionGroup.ALL, new StringFlag(null)); - - public WGCustomFlagsManager(Plugin wgCustomFlags) { - customFlags = (WGCustomFlagsPlugin)wgCustomFlags; - customFlags.addCustomFlag(SPAWN_TAGS); - } - - public boolean inTaggedRegion(RegionAssociable source, ApplicableRegionSet checkSet, Set tags) { - Set regionTags = checkSet.queryValue(source, SPAWN_TAGS); - if (regionTags == null) { - return false; - } - return regionTags.contains("*") || !Collections.disjoint(regionTags, tags); - } -} diff --git a/src/main/java/com/elmakers/mine/bukkit/magicworlds/worldguard/WorldGuardAPI.java b/src/main/java/com/elmakers/mine/bukkit/magicworlds/worldguard/WorldGuardAPI.java deleted file mode 100644 index f5f24e5..0000000 --- a/src/main/java/com/elmakers/mine/bukkit/magicworlds/worldguard/WorldGuardAPI.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.elmakers.mine.bukkit.magicworlds.worldguard; - -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import com.sk89q.worldguard.domains.Association; -import com.sk89q.worldguard.protection.ApplicableRegionSet; -import com.sk89q.worldguard.protection.association.Associables; -import com.sk89q.worldguard.protection.managers.RegionManager; -import org.bukkit.Location; -import org.bukkit.plugin.Plugin; - -import java.util.Set; -import java.util.logging.Level; - -public class WorldGuardAPI { - private final Plugin owningPlugin; - private WorldGuardPlugin worldGuard = null; - private WorldGuardFlags customFlags = null; - - public boolean isEnabled() { - return worldGuard != null; - } - - public WorldGuardAPI(Plugin plugin, Plugin owningPlugin) { - this.owningPlugin = owningPlugin; - if (plugin instanceof WorldGuardPlugin) { - worldGuard = (WorldGuardPlugin)plugin; - try { - owningPlugin.getLogger().info("Pre-check for WorldGuard custom flag registration"); - customFlags = new WorldGuardFlagsManager(owningPlugin, worldGuard); - } catch (NoSuchMethodError incompatible) { - // Ignored, will follow up in checkFlagSupport - } catch (Throwable ex) { - owningPlugin.getLogger().log(Level.WARNING, "Unexpected error setting up custom flags, please make sure you are on WorldGuard 6.2 or above", ex); - } - } - } - - public void checkFlagSupport() { - if (customFlags == null) { - try { - Plugin customFlagsPlugin = owningPlugin.getServer().getPluginManager().getPlugin("WGCustomFlags"); - if (customFlagsPlugin != null) { - customFlags = new WGCustomFlagsManager(customFlagsPlugin); - } - } catch (Throwable ex) { - owningPlugin.getLogger().log(Level.WARNING, "Error integration with WGCustomFlags", ex); - } - - if (customFlags != null) { - owningPlugin.getLogger().info("WGCustomFlags found, added custom flags"); - } else { - owningPlugin.getLogger().log(Level.WARNING, "Failed to set up custom flags, please make sure you are on WorldGuard 6.2 or above, or use the WGCustomFlags plugin"); - } - } - } - - public boolean inTaggedRegion(Location location, Set tags) { - if (location != null && worldGuard != null && customFlags != null) - { - RegionManager regionManager = worldGuard.getRegionManager(location.getWorld()); - if (regionManager == null) { - return false; - } - - ApplicableRegionSet checkSet = regionManager.getApplicableRegions(location); - if (checkSet == null) { - return false; - } - - return customFlags.inTaggedRegion(Associables.constant(Association.NON_MEMBER), checkSet, tags); - } - return false; - } -} diff --git a/src/main/java/com/elmakers/mine/bukkit/magicworlds/worldguard/WorldGuardFlags.java b/src/main/java/com/elmakers/mine/bukkit/magicworlds/worldguard/WorldGuardFlags.java deleted file mode 100644 index aa77348..0000000 --- a/src/main/java/com/elmakers/mine/bukkit/magicworlds/worldguard/WorldGuardFlags.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.elmakers.mine.bukkit.magicworlds.worldguard; - -import com.sk89q.worldguard.protection.ApplicableRegionSet; -import com.sk89q.worldguard.protection.association.RegionAssociable; - -import java.util.Set; - -public interface WorldGuardFlags { - boolean inTaggedRegion(RegionAssociable source, ApplicableRegionSet checkSet, Set tags); -} diff --git a/src/main/java/com/elmakers/mine/bukkit/magicworlds/worldguard/WorldGuardFlagsManager.java b/src/main/java/com/elmakers/mine/bukkit/magicworlds/worldguard/WorldGuardFlagsManager.java deleted file mode 100644 index d0c2cfc..0000000 --- a/src/main/java/com/elmakers/mine/bukkit/magicworlds/worldguard/WorldGuardFlagsManager.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.elmakers.mine.bukkit.magicworlds.worldguard; - -import com.sk89q.worldguard.bukkit.WorldGuardPlugin; -import com.sk89q.worldguard.protection.ApplicableRegionSet; -import com.sk89q.worldguard.protection.association.RegionAssociable; -import com.sk89q.worldguard.protection.flags.RegionGroup; -import com.sk89q.worldguard.protection.flags.SetFlag; -import com.sk89q.worldguard.protection.flags.StringFlag; -import com.sk89q.worldguard.protection.flags.registry.FlagRegistry; -import org.bukkit.plugin.Plugin; - -import java.util.Collections; -import java.util.Set; - -public class WorldGuardFlagsManager implements WorldGuardFlags { - - private final WorldGuardPlugin customFlags; - - public static SetFlag SPAWN_TAGS = new SetFlag("spawn-tags", RegionGroup.ALL, new StringFlag(null)); - - public WorldGuardFlagsManager(Plugin callingPlugin, Plugin wgCustomFlags) { - customFlags = (WorldGuardPlugin)wgCustomFlags; - FlagRegistry registry = customFlags.getFlagRegistry(); - registry.register(SPAWN_TAGS); - callingPlugin.getLogger().info("Registered custom WorldGuard flags: spawn-tags"); - } - - public boolean inTaggedRegion(RegionAssociable source, ApplicableRegionSet checkSet, Set tags) { - Set regionTags = checkSet.queryValue(source, SPAWN_TAGS); - if (regionTags == null) { - return false; - } - return regionTags.contains("*") || !Collections.disjoint(regionTags, tags); - } -} diff --git a/src/main/java/com/elmakers/mine/bukkit/magicworlds/worldguard/WorldGuardManager.java b/src/main/java/com/elmakers/mine/bukkit/magicworlds/worldguard/WorldGuardManager.java deleted file mode 100644 index de25c5d..0000000 --- a/src/main/java/com/elmakers/mine/bukkit/magicworlds/worldguard/WorldGuardManager.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.elmakers.mine.bukkit.magicworlds.worldguard; - -import org.apache.commons.lang.StringUtils; -import org.bukkit.Location; -import org.bukkit.plugin.Plugin; - -import java.util.Set; -import java.util.logging.Level; - -public class WorldGuardManager { - private boolean enabled = false; - private WorldGuardAPI worldGuard = null; - - public void setEnabled(boolean enabled) { - this.enabled = enabled; - } - - public boolean isEnabled() { - return enabled && worldGuard != null && worldGuard.isEnabled(); - } - - public void initialize(Plugin plugin) { - if (enabled) { - if (worldGuard == null) { - plugin.getLogger().info("WorldGuard not found, add WorldGuard 6 or higher for region-based spawning"); - } else { - plugin.getLogger().info("WorldGuard found, spawn-tags can be used for region-based spawning"); - worldGuard.checkFlagSupport(); - } - } else { - worldGuard = null; - plugin.getLogger().info("WorldGuard integration disabled."); - } - } - - public void initializeFlags(Plugin plugin) { - try { - Plugin wgPlugin = plugin.getServer().getPluginManager().getPlugin("WorldGuard"); - if (wgPlugin != null) { - String[] versionPieces = StringUtils.split(wgPlugin.getDescription().getVersion(), '.'); - int version = Integer.parseInt(versionPieces[0]); - if (version >= 6) { - worldGuard = new WorldGuardAPI(wgPlugin, plugin); - } else { - plugin.getLogger().warning("Only WorldGuard 6 and above are supported- please update! (WG version: " + wgPlugin.getDescription().getVersion() + ")"); - } - } - } catch (Throwable ex) { - plugin.getLogger().log(Level.WARNING, "Error setting up custom WorldGuard flags", ex); - } - } - - public boolean inTaggedRegion(Location location, Set tags) { - if (enabled && worldGuard != null) { - return worldGuard.inTaggedRegion(location, tags); - } - return false; - } -} diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 6f9e947..a652f09 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -7,9 +7,6 @@ entity_spawn_listener: true player_listener: true -# Enable or disable WorldGuard and custom flags integration -region_manager_enabled: true - # Configure spawn reasons to ignore ignore_reasons: - CUSTOM