From 4ddde4438abe2239b85f12974340ec3ddafdc489 Mon Sep 17 00:00:00 2001 From: isokissa3 Date: Sat, 17 Nov 2018 19:42:03 +0200 Subject: [PATCH] Updated to WG 7 Vectors, closes #57 and #58 --- Common/pom.xml | 13 ++--- .../WorldGuardExtraFlagsPlugin.java | 40 ++++++++++++-- .../listeners/WorldEditListener.java | 8 ++- .../listeners/WorldListener.java | 21 +++----- .../utils/WorldUtils.java | 35 ------------- .../we/AbstractWorldEditFlagHandler.java | 40 -------------- .../we/WorldEditFlagHandler.java | 36 ------------- Spigot/pom.xml | 2 +- Spigot/src/main/resources/plugin.yml | 2 +- WG/pom.xml | 25 +++++---- .../worldguardextraflags/flags/Flags.java | 10 ++-- .../flags/data/PotionEffectDetails.java | 0 .../flags/data/SoundData.java | 0 .../flags/helpers/MaterialFlag.java | 0 .../flags/helpers/PotionEffectFlag.java | 0 .../flags/helpers/PotionEffectTypeFlag.java | 0 .../flags/helpers/SoundDataFlag.java | 0 .../wg/WorldGuardUtils.java | 40 +++----------- .../AbstractRegionManagerWrapper.java | 14 +---- .../wg/wrappers/WorldGuardCommunicator.java | 8 +++ WG6/pom.xml | 8 ++- .../wg/wrappers/v6/RegionManagerWrapper.java | 10 ++++ .../wg/wrappers/v6/WorldEditFlagHandler.java | 48 +++++++++++++++++ .../v6/WorldGuardSixCommunicator.java | 52 +++++++++++++++++++ WG7/pom.xml | 25 +++++---- .../wg/wrappers/v7/RegionManagerWrapper.java | 10 ++++ .../wg/wrappers/v7/WorldEditFlagHandler.java | 46 ++++++++++++++++ .../v7/WorldGuardSevenCommunicator.java | 52 +++++++++++++++++++ pom.xml | 2 +- 29 files changed, 333 insertions(+), 214 deletions(-) delete mode 100644 Common/src/main/java/net/goldtreeservers/worldguardextraflags/utils/WorldUtils.java delete mode 100644 Common/src/main/java/net/goldtreeservers/worldguardextraflags/we/AbstractWorldEditFlagHandler.java delete mode 100644 Common/src/main/java/net/goldtreeservers/worldguardextraflags/we/WorldEditFlagHandler.java rename {Common => WG}/src/main/java/net/goldtreeservers/worldguardextraflags/flags/Flags.java (85%) rename {Common => WG}/src/main/java/net/goldtreeservers/worldguardextraflags/flags/data/PotionEffectDetails.java (100%) rename {Common => WG}/src/main/java/net/goldtreeservers/worldguardextraflags/flags/data/SoundData.java (100%) rename {Common => WG}/src/main/java/net/goldtreeservers/worldguardextraflags/flags/helpers/MaterialFlag.java (100%) rename {Common => WG}/src/main/java/net/goldtreeservers/worldguardextraflags/flags/helpers/PotionEffectFlag.java (100%) rename {Common => WG}/src/main/java/net/goldtreeservers/worldguardextraflags/flags/helpers/PotionEffectTypeFlag.java (100%) rename {Common => WG}/src/main/java/net/goldtreeservers/worldguardextraflags/flags/helpers/SoundDataFlag.java (100%) rename {Common => WG}/src/main/java/net/goldtreeservers/worldguardextraflags/wg/WorldGuardUtils.java (73%) create mode 100644 WG6/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/v6/WorldEditFlagHandler.java create mode 100644 WG7/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/v7/WorldEditFlagHandler.java diff --git a/Common/pom.xml b/Common/pom.xml index 766dada..ddbc7b8 100644 --- a/Common/pom.xml +++ b/Common/pom.xml @@ -3,7 +3,7 @@ net.goldtreeservers worldguardextraflags - 4.1.0 + 4.1.1 net.goldtreeservers.worldguardextraflags @@ -26,11 +26,6 @@ empcraft http://ci.athion.net/job/FastAsyncWorldEdit/ws/mvn/ - - - elMakers - http://maven.elmakers.com/repository/ - @@ -62,14 +57,14 @@ com.sk89q.worldedit - worldedit - 7.0-SNAPSHOT + worldedit-bukkit + 7.0.0-SNAPSHOT provided com.sk89q.worldguard worldguard-legacy - 7.0-SNAPSHOT + 7.0.0-SNAPSHOT provided diff --git a/Common/src/main/java/net/goldtreeservers/worldguardextraflags/WorldGuardExtraFlagsPlugin.java b/Common/src/main/java/net/goldtreeservers/worldguardextraflags/WorldGuardExtraFlagsPlugin.java index 9ba1a8d..521cee0 100644 --- a/Common/src/main/java/net/goldtreeservers/worldguardextraflags/WorldGuardExtraFlagsPlugin.java +++ b/Common/src/main/java/net/goldtreeservers/worldguardextraflags/WorldGuardExtraFlagsPlugin.java @@ -19,7 +19,6 @@ import net.goldtreeservers.worldguardextraflags.listeners.EntityListenerOnePoint import net.goldtreeservers.worldguardextraflags.listeners.PlayerListener; import net.goldtreeservers.worldguardextraflags.listeners.WorldEditListener; import net.goldtreeservers.worldguardextraflags.listeners.WorldListener; -import net.goldtreeservers.worldguardextraflags.utils.WorldUtils; import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils; import net.goldtreeservers.worldguardextraflags.wg.handlers.BlockedEffectsFlagHandler; import net.goldtreeservers.worldguardextraflags.wg.handlers.CommandOnEntryFlagHandler; @@ -36,6 +35,8 @@ import net.goldtreeservers.worldguardextraflags.wg.handlers.TeleportOnExitFlagHa import net.goldtreeservers.worldguardextraflags.wg.handlers.WalkSpeedFlagHandler; import net.goldtreeservers.worldguardextraflags.wg.wrappers.AbstractSessionManagerWrapper; import net.goldtreeservers.worldguardextraflags.wg.wrappers.WorldGuardCommunicator; +import net.goldtreeservers.worldguardextraflags.wg.wrappers.v6.WorldGuardSixCommunicator; +import net.goldtreeservers.worldguardextraflags.wg.wrappers.v7.WorldGuardSevenCommunicator; public class WorldGuardExtraFlagsPlugin extends JavaPlugin { @@ -60,12 +61,14 @@ public class WorldGuardExtraFlagsPlugin extends JavaPlugin this.worldEditPlugin = (WorldEditPlugin)this.getServer().getPluginManager().getPlugin("WorldEdit"); this.worldGuardPlugin = (WorldGuardPlugin)this.getServer().getPluginManager().getPlugin("WorldGuard"); - this.worldGuardCommunicator = WorldGuardUtils.createWorldGuardCommunicator(); + this.worldGuardCommunicator = WorldGuardExtraFlagsPlugin.createWorldGuardCommunicator(); if (this.worldGuardCommunicator == null) { throw new RuntimeException("Unsupported WorldGuard version: " + this.worldGuardPlugin.getDescription().getVersion()); } + WorldGuardUtils.setCommunicator(this.worldGuardCommunicator); + try { this.worldGuardCommunicator.onLoad(); @@ -195,7 +198,7 @@ public class WorldGuardExtraFlagsPlugin extends JavaPlugin } else { - this.worldEditPlugin.getWorldEdit().getEventBus().register(new WorldEditListener()); + this.worldEditPlugin.getWorldEdit().getEventBus().register(new WorldEditListener(this)); } if (this.essentialsHelper != null) @@ -205,7 +208,36 @@ public class WorldGuardExtraFlagsPlugin extends JavaPlugin for(World world : this.getServer().getWorlds()) { - WorldUtils.doUnloadChunkFlagCheck(world); + this.getWorldGuardCommunicator().doUnloadChunkFlagCheck(world); } } + + public static WorldGuardCommunicator createWorldGuardCommunicator() + { + try + { + Class.forName("com.sk89q.worldguard.WorldGuard"); //Only exists in WG 7 + + return new WorldGuardSevenCommunicator(); + } + catch (Throwable ignored) + { + + } + + try + { + Class clazz = Class.forName("com.sk89q.worldguard.bukkit.WorldGuardPlugin"); + if (clazz.getMethod("getFlagRegistry") != null) + { + return new WorldGuardSixCommunicator(); + } + } + catch (Throwable ignored) + { + ignored.printStackTrace(); + } + + return null; + } } diff --git a/Common/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/WorldEditListener.java b/Common/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/WorldEditListener.java index 8ae4c91..e6001b5 100644 --- a/Common/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/WorldEditListener.java +++ b/Common/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/WorldEditListener.java @@ -6,17 +6,21 @@ import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.util.eventbus.EventHandler; import com.sk89q.worldedit.util.eventbus.Subscribe; -import net.goldtreeservers.worldguardextraflags.we.WorldEditFlagHandler; +import lombok.RequiredArgsConstructor; +import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin; +@RequiredArgsConstructor public class WorldEditListener { + private final WorldGuardExtraFlagsPlugin plugin; + @Subscribe(priority = EventHandler.Priority.VERY_EARLY) public void onEditSessionEvent(EditSessionEvent event) { Actor actor = event.getActor(); if (actor != null && actor.isPlayer()) { - event.setExtent(new WorldEditFlagHandler(event.getWorld(), event.getExtent(), (Player)actor)); + event.setExtent(this.plugin.getWorldGuardCommunicator().getWorldEditFlag(event.getWorld(), event.getExtent(), (Player)actor)); } } } diff --git a/Common/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/WorldListener.java b/Common/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/WorldListener.java index dc73cff..a4a1bc5 100644 --- a/Common/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/WorldListener.java +++ b/Common/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/WorldListener.java @@ -8,16 +8,9 @@ import org.bukkit.event.Listener; import org.bukkit.event.world.ChunkUnloadEvent; import org.bukkit.event.world.WorldLoadEvent; -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldguard.protection.flags.StateFlag.State; -import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; -import com.sk89q.worldguard.protection.regions.ProtectedRegion; - import lombok.Getter; import lombok.RequiredArgsConstructor; import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin; -import net.goldtreeservers.worldguardextraflags.flags.Flags; -import net.goldtreeservers.worldguardextraflags.utils.WorldUtils; @RequiredArgsConstructor public class WorldListener implements Listener @@ -27,7 +20,9 @@ public class WorldListener implements Listener @EventHandler(priority = EventPriority.MONITOR) public void onWorldLoadEvent(WorldLoadEvent event) { - WorldUtils.doUnloadChunkFlagCheck(event.getWorld()); + World world = event.getWorld(); + + this.plugin.getWorldGuardCommunicator().doUnloadChunkFlagCheck(world); } @EventHandler(ignoreCancelled = true) @@ -35,14 +30,10 @@ public class WorldListener implements Listener { World world = event.getWorld(); Chunk chunk = event.getChunk(); - - for (ProtectedRegion region : this.plugin.getWorldGuardCommunicator().getRegionContainer().get(world).getApplicableRegions(new ProtectedCuboidRegion("UnloadChunkFlagTester", new BlockVector(chunk.getX() * 16, 0, chunk.getZ() * 16), new BlockVector(chunk.getX() * 16 + 15, 256, chunk.getZ() * 16 + 15)))) + + if (!this.plugin.getWorldGuardCommunicator().doUnloadChunkFlagCheck(world, chunk)) { - if (region.getFlag(Flags.CHUNK_UNLOAD) == State.DENY) - { - event.setCancelled(true); - break; - } + event.setCancelled(true); } } } \ No newline at end of file diff --git a/Common/src/main/java/net/goldtreeservers/worldguardextraflags/utils/WorldUtils.java b/Common/src/main/java/net/goldtreeservers/worldguardextraflags/utils/WorldUtils.java deleted file mode 100644 index 839473a..0000000 --- a/Common/src/main/java/net/goldtreeservers/worldguardextraflags/utils/WorldUtils.java +++ /dev/null @@ -1,35 +0,0 @@ -package net.goldtreeservers.worldguardextraflags.utils; - -import org.bukkit.World; - -import com.sk89q.worldedit.BlockVector; -import com.sk89q.worldguard.protection.flags.StateFlag.State; -import com.sk89q.worldguard.protection.regions.ProtectedRegion; - -import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin; -import net.goldtreeservers.worldguardextraflags.flags.Flags; - -public class WorldUtils -{ - public static void doUnloadChunkFlagCheck(World world) - { - for (ProtectedRegion region : WorldGuardExtraFlagsPlugin.getPlugin().getWorldGuardCommunicator().getRegionContainer().get(world).getRegions().values()) - { - if (region.getFlag(Flags.CHUNK_UNLOAD) == State.DENY) - { - WorldGuardExtraFlagsPlugin.getPlugin().getLogger().info("Loading chunks for region " + region.getId() + " located in " + world.getName() + " due to chunk-unload flag being deny"); - - BlockVector min = region.getMinimumPoint(); - BlockVector max = region.getMaximumPoint(); - - for(int x = min.getBlockX() << 16; x <= max.getBlockX() << 16; x++) - { - for(int z = max.getBlockZ() << 16; z <= max.getBlockZ() << 16; z++) - { - world.getChunkAt(x, z).load(true); - } - } - } - } - } -} diff --git a/Common/src/main/java/net/goldtreeservers/worldguardextraflags/we/AbstractWorldEditFlagHandler.java b/Common/src/main/java/net/goldtreeservers/worldguardextraflags/we/AbstractWorldEditFlagHandler.java deleted file mode 100644 index 70a1ba0..0000000 --- a/Common/src/main/java/net/goldtreeservers/worldguardextraflags/we/AbstractWorldEditFlagHandler.java +++ /dev/null @@ -1,40 +0,0 @@ -package net.goldtreeservers.worldguardextraflags.we; - -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.entity.Player; -import com.sk89q.worldedit.extent.AbstractDelegateExtent; -import com.sk89q.worldedit.extent.Extent; -import com.sk89q.worldedit.world.World; -import com.sk89q.worldedit.world.block.BlockState; -import com.sk89q.worldedit.world.block.BlockStateHolder; - -import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin; - -public abstract class AbstractWorldEditFlagHandler extends AbstractDelegateExtent -{ - protected final org.bukkit.World world; - protected final org.bukkit.entity.Player player; - - protected AbstractWorldEditFlagHandler(World world, Extent extent, Player player) - { - super(extent); - - this.world = WorldGuardExtraFlagsPlugin.getPlugin().getServer().getWorld(world.getName()); - this.player = WorldGuardExtraFlagsPlugin.getPlugin().getServer().getPlayer(player.getUniqueId()); - } - - public abstract boolean setBlock(Vector location, BlockState block) throws WorldEditException; - - //TODO: Prebuild list - @Override - public boolean setBlock(Vector location, @SuppressWarnings("rawtypes") BlockStateHolder block) throws WorldEditException - { - if (this.setBlock(location, block.toImmutableState())) - { - return super.setBlock(location, block); - } - - return false; - } -} diff --git a/Common/src/main/java/net/goldtreeservers/worldguardextraflags/we/WorldEditFlagHandler.java b/Common/src/main/java/net/goldtreeservers/worldguardextraflags/we/WorldEditFlagHandler.java deleted file mode 100644 index a7cf7b6..0000000 --- a/Common/src/main/java/net/goldtreeservers/worldguardextraflags/we/WorldEditFlagHandler.java +++ /dev/null @@ -1,36 +0,0 @@ -package net.goldtreeservers.worldguardextraflags.we; - -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.WorldEditException; -import com.sk89q.worldedit.entity.Player; -import com.sk89q.worldedit.extent.Extent; -import com.sk89q.worldedit.world.World; -import com.sk89q.worldedit.world.block.BlockState; -import com.sk89q.worldguard.protection.ApplicableRegionSet; -import com.sk89q.worldguard.protection.flags.StateFlag.State; - -import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin; -import net.goldtreeservers.worldguardextraflags.flags.Flags; -import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils; - -public class WorldEditFlagHandler extends AbstractWorldEditFlagHandler -{ - public WorldEditFlagHandler(World world, Extent extent, Player player) - { - super(world, extent, player); - } - - @Override - public boolean setBlock(Vector location, BlockState block) throws WorldEditException - { - ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getPlugin().getWorldGuardCommunicator().getRegionContainer().get(this.world).getApplicableRegions(location); - - State state = WorldGuardUtils.queryState(this.player, this.world, regions.getRegions(), Flags.WORLDEDIT); - if (state != State.DENY) - { - return true; - } - - return false; - } -} diff --git a/Spigot/pom.xml b/Spigot/pom.xml index 1d14522..62d54de 100644 --- a/Spigot/pom.xml +++ b/Spigot/pom.xml @@ -3,7 +3,7 @@ net.goldtreeservers worldguardextraflags - 4.1.0 + 4.1.1 net.goldtreeservers.worldguardextraflags diff --git a/Spigot/src/main/resources/plugin.yml b/Spigot/src/main/resources/plugin.yml index f261ce8..ac05f59 100644 --- a/Spigot/src/main/resources/plugin.yml +++ b/Spigot/src/main/resources/plugin.yml @@ -1,5 +1,5 @@ name: WorldGuardExtraFlags -version: 4.1.0 +version: 4.1.1 description: Adds more flags to WorldGuard to help manage your server easily! author: isokissa3 website: https://goldtreevers.net diff --git a/WG/pom.xml b/WG/pom.xml index 165a1fa..48c51d2 100644 --- a/WG/pom.xml +++ b/WG/pom.xml @@ -3,7 +3,7 @@ net.goldtreeservers worldguardextraflags - 4.1.0 + 4.1.1 net.goldtreeservers.worldguardextraflags @@ -18,11 +18,6 @@ sk89q-repo https://maven.sk89q.com/repo/ - - - elMakers - http://maven.elmakers.com/repository/ - @@ -34,14 +29,26 @@ com.sk89q.worldedit - worldedit - 7.0-SNAPSHOT + worldedit-core + 7.0.0-20181117.020138-26 + provided + + + com.sk89q.worldedit + worldedit-bukkit + 7.0.0-20181117.020138-26 + provided + + + com.sk89q.worldguard + worldguard-core + 7.0.0-20181117.063337-9 provided com.sk89q.worldguard worldguard-legacy - 7.0-SNAPSHOT + 7.0.0-20181117.063337-9 provided diff --git a/Common/src/main/java/net/goldtreeservers/worldguardextraflags/flags/Flags.java b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/flags/Flags.java similarity index 85% rename from Common/src/main/java/net/goldtreeservers/worldguardextraflags/flags/Flags.java rename to WG/src/main/java/net/goldtreeservers/worldguardextraflags/flags/Flags.java index 4c29d86..14599af 100644 --- a/Common/src/main/java/net/goldtreeservers/worldguardextraflags/flags/Flags.java +++ b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/flags/Flags.java @@ -12,23 +12,23 @@ import com.sk89q.worldguard.protection.flags.SetFlag; import com.sk89q.worldguard.protection.flags.StateFlag; import com.sk89q.worldguard.protection.flags.StringFlag; -import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin; import net.goldtreeservers.worldguardextraflags.flags.data.SoundData; import net.goldtreeservers.worldguardextraflags.flags.helpers.MaterialFlag; import net.goldtreeservers.worldguardextraflags.flags.helpers.PotionEffectFlag; import net.goldtreeservers.worldguardextraflags.flags.helpers.PotionEffectTypeFlag; import net.goldtreeservers.worldguardextraflags.flags.helpers.SoundDataFlag; +import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils; public final class Flags { public final static LocationFlag TELEPORT_ON_ENTRY = new LocationFlag("teleport-on-entry"); public final static LocationFlag TELEPORT_ON_EXIT = new LocationFlag("teleport-on-exit"); - public final static SetFlag COMMAND_ON_ENTRY = WorldGuardExtraFlagsPlugin.getPlugin().getWorldGuardCommunicator().getCustomSetFlag("command-on-entry", new CommandStringFlag(null)); - public final static SetFlag COMMAND_ON_EXIT = WorldGuardExtraFlagsPlugin.getPlugin().getWorldGuardCommunicator().getCustomSetFlag("command-on-exit", new CommandStringFlag(null)); + public final static SetFlag COMMAND_ON_ENTRY = WorldGuardUtils.getCommunicator().getCustomSetFlag("command-on-entry", new CommandStringFlag(null)); + public final static SetFlag COMMAND_ON_EXIT = WorldGuardUtils.getCommunicator().getCustomSetFlag("command-on-exit", new CommandStringFlag(null)); - public final static SetFlag CONSOLE_COMMAND_ON_ENTRY = WorldGuardExtraFlagsPlugin.getPlugin().getWorldGuardCommunicator().getCustomSetFlag("console-command-on-entry", new CommandStringFlag(null)); - public final static SetFlag CONSOLE_COMMAND_ON_EXIT = WorldGuardExtraFlagsPlugin.getPlugin().getWorldGuardCommunicator().getCustomSetFlag("console-command-on-exit", new CommandStringFlag(null)); + public final static SetFlag CONSOLE_COMMAND_ON_ENTRY = WorldGuardUtils.getCommunicator().getCustomSetFlag("console-command-on-entry", new CommandStringFlag(null)); + public final static SetFlag CONSOLE_COMMAND_ON_EXIT = WorldGuardUtils.getCommunicator().getCustomSetFlag("console-command-on-exit", new CommandStringFlag(null)); public final static DoubleFlag WALK_SPEED = new DoubleFlag("walk-speed"); diff --git a/Common/src/main/java/net/goldtreeservers/worldguardextraflags/flags/data/PotionEffectDetails.java b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/flags/data/PotionEffectDetails.java similarity index 100% rename from Common/src/main/java/net/goldtreeservers/worldguardextraflags/flags/data/PotionEffectDetails.java rename to WG/src/main/java/net/goldtreeservers/worldguardextraflags/flags/data/PotionEffectDetails.java diff --git a/Common/src/main/java/net/goldtreeservers/worldguardextraflags/flags/data/SoundData.java b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/flags/data/SoundData.java similarity index 100% rename from Common/src/main/java/net/goldtreeservers/worldguardextraflags/flags/data/SoundData.java rename to WG/src/main/java/net/goldtreeservers/worldguardextraflags/flags/data/SoundData.java diff --git a/Common/src/main/java/net/goldtreeservers/worldguardextraflags/flags/helpers/MaterialFlag.java b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/flags/helpers/MaterialFlag.java similarity index 100% rename from Common/src/main/java/net/goldtreeservers/worldguardextraflags/flags/helpers/MaterialFlag.java rename to WG/src/main/java/net/goldtreeservers/worldguardextraflags/flags/helpers/MaterialFlag.java diff --git a/Common/src/main/java/net/goldtreeservers/worldguardextraflags/flags/helpers/PotionEffectFlag.java b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/flags/helpers/PotionEffectFlag.java similarity index 100% rename from Common/src/main/java/net/goldtreeservers/worldguardextraflags/flags/helpers/PotionEffectFlag.java rename to WG/src/main/java/net/goldtreeservers/worldguardextraflags/flags/helpers/PotionEffectFlag.java diff --git a/Common/src/main/java/net/goldtreeservers/worldguardextraflags/flags/helpers/PotionEffectTypeFlag.java b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/flags/helpers/PotionEffectTypeFlag.java similarity index 100% rename from Common/src/main/java/net/goldtreeservers/worldguardextraflags/flags/helpers/PotionEffectTypeFlag.java rename to WG/src/main/java/net/goldtreeservers/worldguardextraflags/flags/helpers/PotionEffectTypeFlag.java diff --git a/Common/src/main/java/net/goldtreeservers/worldguardextraflags/flags/helpers/SoundDataFlag.java b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/flags/helpers/SoundDataFlag.java similarity index 100% rename from Common/src/main/java/net/goldtreeservers/worldguardextraflags/flags/helpers/SoundDataFlag.java rename to WG/src/main/java/net/goldtreeservers/worldguardextraflags/flags/helpers/SoundDataFlag.java diff --git a/Common/src/main/java/net/goldtreeservers/worldguardextraflags/wg/WorldGuardUtils.java b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/wg/WorldGuardUtils.java similarity index 73% rename from Common/src/main/java/net/goldtreeservers/worldguardextraflags/wg/WorldGuardUtils.java rename to WG/src/main/java/net/goldtreeservers/worldguardextraflags/wg/WorldGuardUtils.java index 24ebc47..6fc471e 100644 --- a/Common/src/main/java/net/goldtreeservers/worldguardextraflags/wg/WorldGuardUtils.java +++ b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/wg/WorldGuardUtils.java @@ -16,18 +16,19 @@ import com.sk89q.worldguard.protection.flags.StateFlag.State; import com.sk89q.worldguard.protection.regions.ProtectedRegion; import com.sk89q.worldguard.protection.util.NormativeOrders; -import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin; +import lombok.Getter; +import lombok.Setter; import net.goldtreeservers.worldguardextraflags.wg.wrappers.WorldGuardCommunicator; -import net.goldtreeservers.worldguardextraflags.wg.wrappers.v6.WorldGuardSixCommunicator; -import net.goldtreeservers.worldguardextraflags.wg.wrappers.v7.WorldGuardSevenCommunicator; public class WorldGuardUtils { public static final String PREVENT_TELEPORT_LOOP_META = "WGEFP: TLP"; + @Getter @Setter private static WorldGuardCommunicator communicator; + private static LocalPlayer wrapPlayer(Player player) { - return WorldGuardExtraFlagsPlugin.getPlugin().getWorldGuardCommunicator().wrapPlayer(player); + return WorldGuardUtils.getCommunicator().wrapPlayer(player); } public static boolean hasBypass(Player player, World world, ProtectedRegion region, Flag flag) @@ -75,7 +76,7 @@ public class WorldGuardUtils NormativeOrders.sort(checkForRegions); - ProtectedRegion global = WorldGuardExtraFlagsPlugin.getPlugin().getWorldGuardCommunicator().getRegionContainer().get(world).getRegion(ProtectedRegion.GLOBAL_REGION); + ProtectedRegion global = WorldGuardUtils.getCommunicator().getRegionContainer().get(world).getRegion(ProtectedRegion.GLOBAL_REGION); if (global != null) //Global region can be null { if (WorldGuardUtils.hasBypass(player, world, global, flag)) //Lets do like this for now to reduce dublicated code @@ -86,33 +87,4 @@ public class WorldGuardUtils return new FlagValueCalculator(checkForRegions, global); } - - public static WorldGuardCommunicator createWorldGuardCommunicator() - { - try - { - Class.forName("com.sk89q.worldguard.WorldGuard"); //Only exists in WG 7 - - return new WorldGuardSevenCommunicator(); - } - catch (Throwable ignored) - { - - } - - try - { - Class clazz = Class.forName("com.sk89q.worldguard.bukkit.WorldGuardPlugin"); - if (clazz.getMethod("getFlagRegistry") != null) - { - return new WorldGuardSixCommunicator(); - } - } - catch (Throwable ignored) - { - ignored.printStackTrace(); - } - - return null; - } } diff --git a/WG/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/AbstractRegionManagerWrapper.java b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/AbstractRegionManagerWrapper.java index 609e041..1811a39 100644 --- a/WG/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/AbstractRegionManagerWrapper.java +++ b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/AbstractRegionManagerWrapper.java @@ -4,8 +4,6 @@ import java.util.Map; import org.bukkit.Location; -import com.sk89q.worldedit.Vector; -import com.sk89q.worldedit.bukkit.BukkitAdapter; import com.sk89q.worldguard.protection.ApplicableRegionSet; import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; @@ -23,17 +21,9 @@ public abstract class AbstractRegionManagerWrapper return this.regionManager.getRegion(id); } - public ApplicableRegionSet getApplicableRegions(Vector location) - { - return this.regionManager.getApplicableRegions(location); - } + public abstract ApplicableRegionSet getApplicableRegions(Location location); - public ApplicableRegionSet getApplicableRegions(Location location) - { - return this.getApplicableRegions(BukkitAdapter.asVector(location)); - } - - public ApplicableRegionSet getApplicableRegions(ProtectedCuboidRegion protectedCuboidRegion) + public ApplicableRegionSet getApplicableRegions(ProtectedCuboidRegion protectedCuboidRegion) { return this.regionManager.getApplicableRegions(protectedCuboidRegion); } diff --git a/WG/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/WorldGuardCommunicator.java b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/WorldGuardCommunicator.java index cc6993b..7c3cd55 100644 --- a/WG/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/WorldGuardCommunicator.java +++ b/WG/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/WorldGuardCommunicator.java @@ -2,6 +2,9 @@ package net.goldtreeservers.worldguardextraflags.wg.wrappers; import org.bukkit.entity.Player; +import com.sk89q.worldedit.extent.AbstractDelegateExtent; +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.world.World; import com.sk89q.worldguard.LocalPlayer; import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.flags.SetFlag; @@ -20,4 +23,9 @@ public interface WorldGuardCommunicator public LocalPlayer wrapPlayer(Player player); public SetFlag getCustomSetFlag(String name, Flag flag); + + public AbstractDelegateExtent getWorldEditFlag(World world, Extent extent, com.sk89q.worldedit.entity.Player player); + + public void doUnloadChunkFlagCheck(org.bukkit.World world); + public boolean doUnloadChunkFlagCheck(org.bukkit.World world, org.bukkit.Chunk chunk); } diff --git a/WG6/pom.xml b/WG6/pom.xml index dc45e2d..4ab0d55 100644 --- a/WG6/pom.xml +++ b/WG6/pom.xml @@ -3,7 +3,7 @@ net.goldtreeservers worldguardextraflags - 4.1.0 + 4.1.1 net.goldtreeservers.worldguardextraflags @@ -39,6 +39,12 @@ 1.2 provided + + com.sk89q.worldedit + worldedit-bukkit + 6.1.3-SNAPSHOT + provided + com.sk89q.worldguard worldguard-legacy diff --git a/WG6/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/v6/RegionManagerWrapper.java b/WG6/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/v6/RegionManagerWrapper.java index e751bbc..6cdb2bd 100644 --- a/WG6/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/v6/RegionManagerWrapper.java +++ b/WG6/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/v6/RegionManagerWrapper.java @@ -1,5 +1,9 @@ package net.goldtreeservers.worldguardextraflags.wg.wrappers.v6; +import org.bukkit.Location; + +import com.sk89q.worldguard.bukkit.BukkitUtil; +import com.sk89q.worldguard.protection.ApplicableRegionSet; import com.sk89q.worldguard.protection.managers.RegionManager; import net.goldtreeservers.worldguardextraflags.wg.wrappers.AbstractRegionManagerWrapper; @@ -10,4 +14,10 @@ public class RegionManagerWrapper extends AbstractRegionManagerWrapper { super(regionManager); } + + @Override + public ApplicableRegionSet getApplicableRegions(Location location) + { + return this.regionManager.getApplicableRegions(BukkitUtil.toVector(location)); + } } diff --git a/WG6/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/v6/WorldEditFlagHandler.java b/WG6/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/v6/WorldEditFlagHandler.java new file mode 100644 index 0000000..0d1ec85 --- /dev/null +++ b/WG6/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/v6/WorldEditFlagHandler.java @@ -0,0 +1,48 @@ +package net.goldtreeservers.worldguardextraflags.wg.wrappers.v6; + +import org.bukkit.Bukkit; + +import com.sk89q.worldedit.Vector; +import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.blocks.BaseBlock; +import com.sk89q.worldedit.bukkit.BukkitWorld; +import com.sk89q.worldedit.entity.Player; +import com.sk89q.worldedit.extent.AbstractDelegateExtent; +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.world.World; +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.sk89q.worldguard.protection.ApplicableRegionSet; +import com.sk89q.worldguard.protection.flags.StateFlag.State; + +import net.goldtreeservers.worldguardextraflags.flags.Flags; +import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils; + +public class WorldEditFlagHandler extends AbstractDelegateExtent +{ + protected final World world; + protected final org.bukkit.entity.Player player; + + protected WorldEditFlagHandler(World world, Extent extent, Player player) + { + super(extent); + + this.world = world; + this.player = Bukkit.getPlayer(player.getUniqueId()); + } + + @Override + public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException + { + org.bukkit.World world = ((BukkitWorld)this.world).getWorld(); + + ApplicableRegionSet regions = WorldGuardPlugin.inst().getRegionContainer().get(world).getApplicableRegions(location); + + State state = WorldGuardUtils.queryState(this.player, world, regions.getRegions(), Flags.WORLDEDIT); + if (state != State.DENY) + { + return super.setBlock(location, block); + } + + return false; + } +} diff --git a/WG6/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/v6/WorldGuardSixCommunicator.java b/WG6/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/v6/WorldGuardSixCommunicator.java index 7ca399c..15f36a7 100644 --- a/WG6/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/v6/WorldGuardSixCommunicator.java +++ b/WG6/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/v6/WorldGuardSixCommunicator.java @@ -1,13 +1,22 @@ package net.goldtreeservers.worldguardextraflags.wg.wrappers.v6; +import org.bukkit.Chunk; import org.bukkit.entity.Player; +import com.sk89q.worldedit.BlockVector; +import com.sk89q.worldedit.extent.AbstractDelegateExtent; +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.world.World; import com.sk89q.worldguard.LocalPlayer; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.flags.SetFlag; +import com.sk89q.worldguard.protection.flags.StateFlag.State; import com.sk89q.worldguard.protection.flags.registry.FlagRegistry; +import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; +import com.sk89q.worldguard.protection.regions.ProtectedRegion; +import net.goldtreeservers.worldguardextraflags.flags.Flags; import net.goldtreeservers.worldguardextraflags.wg.wrappers.AbstractRegionContainerWrapper; import net.goldtreeservers.worldguardextraflags.wg.wrappers.AbstractSessionManagerWrapper; import net.goldtreeservers.worldguardextraflags.wg.wrappers.WorldGuardCommunicator; @@ -58,4 +67,47 @@ public class WorldGuardSixCommunicator implements WorldGuardCommunicator { return new CustomSetFlag(name, flag); } + + @Override + public AbstractDelegateExtent getWorldEditFlag(World world, Extent extent, com.sk89q.worldedit.entity.Player player) + { + return new WorldEditFlagHandler(world, extent, player); + } + + @Override + public void doUnloadChunkFlagCheck(org.bukkit.World world) + { + for (ProtectedRegion region : this.getRegionContainer().get(world).getRegions().values()) + { + if (region.getFlag(Flags.CHUNK_UNLOAD) == State.DENY) + { + System.out.println("Loading chunks for region " + region.getId() + " located in " + world.getName() + " due to chunk-unload flag being deny"); + + BlockVector min = region.getMinimumPoint(); + BlockVector max = region.getMaximumPoint(); + + for(int x = min.getBlockX() << 16; x <= max.getBlockX() << 16; x++) + { + for(int z = max.getBlockZ() << 16; z <= max.getBlockZ() << 16; z++) + { + world.getChunkAt(x, z).load(true); + } + } + } + } + } + + @Override + public boolean doUnloadChunkFlagCheck(org.bukkit.World world, Chunk chunk) + { + for (ProtectedRegion region : this.getRegionContainer().get(world).getApplicableRegions(new ProtectedCuboidRegion("UnloadChunkFlagTester", new BlockVector(chunk.getX() * 16, 0, chunk.getZ() * 16), new BlockVector(chunk.getX() * 16 + 15, 256, chunk.getZ() * 16 + 15)))) + { + if (region.getFlag(Flags.CHUNK_UNLOAD) == State.DENY) + { + return false; + } + } + + return true; + } } diff --git a/WG7/pom.xml b/WG7/pom.xml index c53d124..76cf3d7 100644 --- a/WG7/pom.xml +++ b/WG7/pom.xml @@ -3,7 +3,7 @@ net.goldtreeservers worldguardextraflags - 4.1.0 + 4.1.1 net.goldtreeservers.worldguardextraflags @@ -18,11 +18,6 @@ sk89q-repo https://maven.sk89q.com/repo/ - - - elMakers - http://maven.elmakers.com/repository/ - @@ -40,14 +35,26 @@ com.sk89q.worldedit - worldedit - 7.0-SNAPSHOT + worldedit-core + 7.0.0-20181117.020138-26 + provided + + + com.sk89q.worldedit + worldedit-bukkit + 7.0.0-20181117.020138-26 + provided + + + com.sk89q.worldguard + worldguard-core + 7.0.0-20181117.063337-9 provided com.sk89q.worldguard worldguard-legacy - 7.0-SNAPSHOT + 7.0.0-20181117.063337-9 provided diff --git a/WG7/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/v7/RegionManagerWrapper.java b/WG7/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/v7/RegionManagerWrapper.java index 6f14810..9f0c869 100644 --- a/WG7/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/v7/RegionManagerWrapper.java +++ b/WG7/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/v7/RegionManagerWrapper.java @@ -1,5 +1,9 @@ package net.goldtreeservers.worldguardextraflags.wg.wrappers.v7; +import org.bukkit.Location; + +import com.sk89q.worldedit.bukkit.BukkitAdapter; +import com.sk89q.worldguard.protection.ApplicableRegionSet; import com.sk89q.worldguard.protection.managers.RegionManager; import net.goldtreeservers.worldguardextraflags.wg.wrappers.AbstractRegionManagerWrapper; @@ -10,4 +14,10 @@ public class RegionManagerWrapper extends AbstractRegionManagerWrapper { super(regionManager); } + + @Override + public ApplicableRegionSet getApplicableRegions(Location location) + { + return this.regionManager.getApplicableRegions(BukkitAdapter.asBlockVector(location)); + } } diff --git a/WG7/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/v7/WorldEditFlagHandler.java b/WG7/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/v7/WorldEditFlagHandler.java new file mode 100644 index 0000000..90e9318 --- /dev/null +++ b/WG7/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/v7/WorldEditFlagHandler.java @@ -0,0 +1,46 @@ +package net.goldtreeservers.worldguardextraflags.wg.wrappers.v7; + +import org.bukkit.Bukkit; + +import com.sk89q.worldedit.WorldEditException; +import com.sk89q.worldedit.bukkit.BukkitWorld; +import com.sk89q.worldedit.entity.Player; +import com.sk89q.worldedit.extent.AbstractDelegateExtent; +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.world.World; +import com.sk89q.worldedit.world.block.BlockStateHolder; +import com.sk89q.worldguard.WorldGuard; +import com.sk89q.worldguard.protection.ApplicableRegionSet; +import com.sk89q.worldguard.protection.flags.StateFlag.State; + +import net.goldtreeservers.worldguardextraflags.flags.Flags; +import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils; + +public class WorldEditFlagHandler extends AbstractDelegateExtent +{ + protected final World world; + protected final org.bukkit.entity.Player player; + + public WorldEditFlagHandler(World world, Extent extent, Player player) + { + super(extent); + + this.world = world; + this.player = Bukkit.getPlayer(player.getUniqueId()); + } + + @Override + public boolean setBlock(BlockVector3 location, BlockStateHolder block) throws WorldEditException + { + ApplicableRegionSet regions = WorldGuard.getInstance().getPlatform().getRegionContainer().get(this.world).getApplicableRegions(location); + + State state = WorldGuardUtils.queryState(this.player, ((BukkitWorld)this.world).getWorld(), regions.getRegions(), Flags.WORLDEDIT); + if (state != State.DENY) + { + return super.setBlock(location, block); + } + + return false; + } +} diff --git a/WG7/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/v7/WorldGuardSevenCommunicator.java b/WG7/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/v7/WorldGuardSevenCommunicator.java index 43f3490..4e441e6 100644 --- a/WG7/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/v7/WorldGuardSevenCommunicator.java +++ b/WG7/src/main/java/net/goldtreeservers/worldguardextraflags/wg/wrappers/v7/WorldGuardSevenCommunicator.java @@ -1,14 +1,23 @@ package net.goldtreeservers.worldguardextraflags.wg.wrappers.v7; +import org.bukkit.Chunk; import org.bukkit.entity.Player; +import com.sk89q.worldedit.extent.AbstractDelegateExtent; +import com.sk89q.worldedit.extent.Extent; +import com.sk89q.worldedit.math.BlockVector3; +import com.sk89q.worldedit.world.World; import com.sk89q.worldguard.LocalPlayer; import com.sk89q.worldguard.WorldGuard; import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.flags.SetFlag; +import com.sk89q.worldguard.protection.flags.StateFlag.State; import com.sk89q.worldguard.protection.flags.registry.FlagRegistry; +import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; +import com.sk89q.worldguard.protection.regions.ProtectedRegion; +import net.goldtreeservers.worldguardextraflags.flags.Flags; import net.goldtreeservers.worldguardextraflags.wg.wrappers.AbstractRegionContainerWrapper; import net.goldtreeservers.worldguardextraflags.wg.wrappers.AbstractSessionManagerWrapper; import net.goldtreeservers.worldguardextraflags.wg.wrappers.WorldGuardCommunicator; @@ -59,4 +68,47 @@ public class WorldGuardSevenCommunicator implements WorldGuardCommunicator { return new CustomSetFlag(name, flag); } + + @Override + public AbstractDelegateExtent getWorldEditFlag(World world, Extent extent, com.sk89q.worldedit.entity.Player player) + { + return new WorldEditFlagHandler(world, extent, player); + } + + @Override + public void doUnloadChunkFlagCheck(org.bukkit.World world) + { + for (ProtectedRegion region : this.getRegionContainer().get(world).getRegions().values()) + { + if (region.getFlag(Flags.CHUNK_UNLOAD) == State.DENY) + { + System.out.println("Loading chunks for region " + region.getId() + " located in " + world.getName() + " due to chunk-unload flag being deny"); + + BlockVector3 min = region.getMinimumPoint(); + BlockVector3 max = region.getMaximumPoint(); + + for(int x = min.getBlockX() << 16; x <= max.getBlockX() << 16; x++) + { + for(int z = max.getBlockZ() << 16; z <= max.getBlockZ() << 16; z++) + { + world.getChunkAt(x, z).load(true); + } + } + } + } + } + + @Override + public boolean doUnloadChunkFlagCheck(org.bukkit.World world, Chunk chunk) + { + for (ProtectedRegion region : this.getRegionContainer().get(world).getApplicableRegions(new ProtectedCuboidRegion("UnloadChunkFlagTester", BlockVector3.at(chunk.getX() * 16, 0, chunk.getZ() * 16), BlockVector3.at(chunk.getX() * 16 + 15, 256, chunk.getZ() * 16 + 15)))) + { + if (region.getFlag(Flags.CHUNK_UNLOAD) == State.DENY) + { + return false; + } + } + + return true; + } } diff --git a/pom.xml b/pom.xml index 9abbd49..95ad396 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ net.goldtreeservers worldguardextraflags WorldGuardExtraFlags - 4.1.0 + 4.1.1 pom