Updated to WG 7 Vectors, closes #57 and #58

This commit is contained in:
isokissa3 2018-11-17 19:42:03 +02:00
parent 07d03b2229
commit 4ddde4438a
29 changed files with 333 additions and 214 deletions

View file

@ -3,7 +3,7 @@
<parent> <parent>
<groupId>net.goldtreeservers</groupId> <groupId>net.goldtreeservers</groupId>
<artifactId>worldguardextraflags</artifactId> <artifactId>worldguardextraflags</artifactId>
<version>4.1.0</version> <version>4.1.1</version>
</parent> </parent>
<groupId>net.goldtreeservers.worldguardextraflags</groupId> <groupId>net.goldtreeservers.worldguardextraflags</groupId>
@ -26,11 +26,6 @@
<id>empcraft</id> <id>empcraft</id>
<url>http://ci.athion.net/job/FastAsyncWorldEdit/ws/mvn/</url> <url>http://ci.athion.net/job/FastAsyncWorldEdit/ws/mvn/</url>
</repository> </repository>
<!-- FOR NOW -->
<repository>
<id>elMakers</id>
<url>http://maven.elmakers.com/repository/</url>
</repository>
</repositories> </repositories>
@ -62,14 +57,14 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.sk89q.worldedit</groupId> <groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit</artifactId> <artifactId>worldedit-bukkit</artifactId>
<version>7.0-SNAPSHOT</version> <version>7.0.0-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.sk89q.worldguard</groupId> <groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-legacy</artifactId> <artifactId>worldguard-legacy</artifactId>
<version>7.0-SNAPSHOT</version> <version>7.0.0-SNAPSHOT</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>

View file

@ -19,7 +19,6 @@ import net.goldtreeservers.worldguardextraflags.listeners.EntityListenerOnePoint
import net.goldtreeservers.worldguardextraflags.listeners.PlayerListener; import net.goldtreeservers.worldguardextraflags.listeners.PlayerListener;
import net.goldtreeservers.worldguardextraflags.listeners.WorldEditListener; import net.goldtreeservers.worldguardextraflags.listeners.WorldEditListener;
import net.goldtreeservers.worldguardextraflags.listeners.WorldListener; import net.goldtreeservers.worldguardextraflags.listeners.WorldListener;
import net.goldtreeservers.worldguardextraflags.utils.WorldUtils;
import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils; import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils;
import net.goldtreeservers.worldguardextraflags.wg.handlers.BlockedEffectsFlagHandler; import net.goldtreeservers.worldguardextraflags.wg.handlers.BlockedEffectsFlagHandler;
import net.goldtreeservers.worldguardextraflags.wg.handlers.CommandOnEntryFlagHandler; 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.handlers.WalkSpeedFlagHandler;
import net.goldtreeservers.worldguardextraflags.wg.wrappers.AbstractSessionManagerWrapper; import net.goldtreeservers.worldguardextraflags.wg.wrappers.AbstractSessionManagerWrapper;
import net.goldtreeservers.worldguardextraflags.wg.wrappers.WorldGuardCommunicator; 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 public class WorldGuardExtraFlagsPlugin extends JavaPlugin
{ {
@ -60,12 +61,14 @@ public class WorldGuardExtraFlagsPlugin extends JavaPlugin
this.worldEditPlugin = (WorldEditPlugin)this.getServer().getPluginManager().getPlugin("WorldEdit"); this.worldEditPlugin = (WorldEditPlugin)this.getServer().getPluginManager().getPlugin("WorldEdit");
this.worldGuardPlugin = (WorldGuardPlugin)this.getServer().getPluginManager().getPlugin("WorldGuard"); this.worldGuardPlugin = (WorldGuardPlugin)this.getServer().getPluginManager().getPlugin("WorldGuard");
this.worldGuardCommunicator = WorldGuardUtils.createWorldGuardCommunicator(); this.worldGuardCommunicator = WorldGuardExtraFlagsPlugin.createWorldGuardCommunicator();
if (this.worldGuardCommunicator == null) if (this.worldGuardCommunicator == null)
{ {
throw new RuntimeException("Unsupported WorldGuard version: " + this.worldGuardPlugin.getDescription().getVersion()); throw new RuntimeException("Unsupported WorldGuard version: " + this.worldGuardPlugin.getDescription().getVersion());
} }
WorldGuardUtils.setCommunicator(this.worldGuardCommunicator);
try try
{ {
this.worldGuardCommunicator.onLoad(); this.worldGuardCommunicator.onLoad();
@ -195,7 +198,7 @@ public class WorldGuardExtraFlagsPlugin extends JavaPlugin
} }
else else
{ {
this.worldEditPlugin.getWorldEdit().getEventBus().register(new WorldEditListener()); this.worldEditPlugin.getWorldEdit().getEventBus().register(new WorldEditListener(this));
} }
if (this.essentialsHelper != null) if (this.essentialsHelper != null)
@ -205,7 +208,36 @@ public class WorldGuardExtraFlagsPlugin extends JavaPlugin
for(World world : this.getServer().getWorlds()) 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;
}
} }

View file

@ -6,17 +6,21 @@ import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.util.eventbus.EventHandler; import com.sk89q.worldedit.util.eventbus.EventHandler;
import com.sk89q.worldedit.util.eventbus.Subscribe; 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 public class WorldEditListener
{ {
private final WorldGuardExtraFlagsPlugin plugin;
@Subscribe(priority = EventHandler.Priority.VERY_EARLY) @Subscribe(priority = EventHandler.Priority.VERY_EARLY)
public void onEditSessionEvent(EditSessionEvent event) public void onEditSessionEvent(EditSessionEvent event)
{ {
Actor actor = event.getActor(); Actor actor = event.getActor();
if (actor != null && actor.isPlayer()) 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));
} }
} }
} }

View file

@ -8,16 +8,9 @@ import org.bukkit.event.Listener;
import org.bukkit.event.world.ChunkUnloadEvent; import org.bukkit.event.world.ChunkUnloadEvent;
import org.bukkit.event.world.WorldLoadEvent; 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.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin; import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
import net.goldtreeservers.worldguardextraflags.flags.Flags;
import net.goldtreeservers.worldguardextraflags.utils.WorldUtils;
@RequiredArgsConstructor @RequiredArgsConstructor
public class WorldListener implements Listener public class WorldListener implements Listener
@ -27,7 +20,9 @@ public class WorldListener implements Listener
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void onWorldLoadEvent(WorldLoadEvent event) public void onWorldLoadEvent(WorldLoadEvent event)
{ {
WorldUtils.doUnloadChunkFlagCheck(event.getWorld()); World world = event.getWorld();
this.plugin.getWorldGuardCommunicator().doUnloadChunkFlagCheck(world);
} }
@EventHandler(ignoreCancelled = true) @EventHandler(ignoreCancelled = true)
@ -35,14 +30,10 @@ public class WorldListener implements Listener
{ {
World world = event.getWorld(); World world = event.getWorld();
Chunk chunk = event.getChunk(); 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);
{
event.setCancelled(true);
break;
}
} }
} }
} }

View file

@ -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);
}
}
}
}
}
}

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -3,7 +3,7 @@
<parent> <parent>
<groupId>net.goldtreeservers</groupId> <groupId>net.goldtreeservers</groupId>
<artifactId>worldguardextraflags</artifactId> <artifactId>worldguardextraflags</artifactId>
<version>4.1.0</version> <version>4.1.1</version>
</parent> </parent>
<groupId>net.goldtreeservers.worldguardextraflags</groupId> <groupId>net.goldtreeservers.worldguardextraflags</groupId>

View file

@ -1,5 +1,5 @@
name: WorldGuardExtraFlags name: WorldGuardExtraFlags
version: 4.1.0 version: 4.1.1
description: Adds more flags to WorldGuard to help manage your server easily! description: Adds more flags to WorldGuard to help manage your server easily!
author: isokissa3 author: isokissa3
website: https://goldtreevers.net website: https://goldtreevers.net

View file

@ -3,7 +3,7 @@
<parent> <parent>
<groupId>net.goldtreeservers</groupId> <groupId>net.goldtreeservers</groupId>
<artifactId>worldguardextraflags</artifactId> <artifactId>worldguardextraflags</artifactId>
<version>4.1.0</version> <version>4.1.1</version>
</parent> </parent>
<groupId>net.goldtreeservers.worldguardextraflags</groupId> <groupId>net.goldtreeservers.worldguardextraflags</groupId>
@ -18,11 +18,6 @@
<id>sk89q-repo</id> <id>sk89q-repo</id>
<url>https://maven.sk89q.com/repo/</url> <url>https://maven.sk89q.com/repo/</url>
</repository> </repository>
<!-- FOR NOW -->
<repository>
<id>elMakers</id>
<url>http://maven.elmakers.com/repository/</url>
</repository>
</repositories> </repositories>
<dependencies> <dependencies>
@ -34,14 +29,26 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.sk89q.worldedit</groupId> <groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit</artifactId> <artifactId>worldedit-core</artifactId>
<version>7.0-SNAPSHOT</version> <version>7.0.0-20181117.020138-26</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId>
<version>7.0.0-20181117.020138-26</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-core</artifactId>
<version>7.0.0-20181117.063337-9</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.sk89q.worldguard</groupId> <groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-legacy</artifactId> <artifactId>worldguard-legacy</artifactId>
<version>7.0-SNAPSHOT</version> <version>7.0.0-20181117.063337-9</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View file

@ -12,23 +12,23 @@ import com.sk89q.worldguard.protection.flags.SetFlag;
import com.sk89q.worldguard.protection.flags.StateFlag; import com.sk89q.worldguard.protection.flags.StateFlag;
import com.sk89q.worldguard.protection.flags.StringFlag; import com.sk89q.worldguard.protection.flags.StringFlag;
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
import net.goldtreeservers.worldguardextraflags.flags.data.SoundData; import net.goldtreeservers.worldguardextraflags.flags.data.SoundData;
import net.goldtreeservers.worldguardextraflags.flags.helpers.MaterialFlag; import net.goldtreeservers.worldguardextraflags.flags.helpers.MaterialFlag;
import net.goldtreeservers.worldguardextraflags.flags.helpers.PotionEffectFlag; import net.goldtreeservers.worldguardextraflags.flags.helpers.PotionEffectFlag;
import net.goldtreeservers.worldguardextraflags.flags.helpers.PotionEffectTypeFlag; import net.goldtreeservers.worldguardextraflags.flags.helpers.PotionEffectTypeFlag;
import net.goldtreeservers.worldguardextraflags.flags.helpers.SoundDataFlag; import net.goldtreeservers.worldguardextraflags.flags.helpers.SoundDataFlag;
import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils;
public final class Flags public final class Flags
{ {
public final static LocationFlag TELEPORT_ON_ENTRY = new LocationFlag("teleport-on-entry"); 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 LocationFlag TELEPORT_ON_EXIT = new LocationFlag("teleport-on-exit");
public final static SetFlag<String> COMMAND_ON_ENTRY = WorldGuardExtraFlagsPlugin.getPlugin().getWorldGuardCommunicator().getCustomSetFlag("command-on-entry", new CommandStringFlag(null)); public final static SetFlag<String> COMMAND_ON_ENTRY = WorldGuardUtils.getCommunicator().getCustomSetFlag("command-on-entry", new CommandStringFlag(null));
public final static SetFlag<String> COMMAND_ON_EXIT = WorldGuardExtraFlagsPlugin.getPlugin().getWorldGuardCommunicator().getCustomSetFlag("command-on-exit", new CommandStringFlag(null)); public final static SetFlag<String> COMMAND_ON_EXIT = WorldGuardUtils.getCommunicator().getCustomSetFlag("command-on-exit", new CommandStringFlag(null));
public final static SetFlag<String> CONSOLE_COMMAND_ON_ENTRY = WorldGuardExtraFlagsPlugin.getPlugin().getWorldGuardCommunicator().getCustomSetFlag("console-command-on-entry", new CommandStringFlag(null)); public final static SetFlag<String> CONSOLE_COMMAND_ON_ENTRY = WorldGuardUtils.getCommunicator().getCustomSetFlag("console-command-on-entry", new CommandStringFlag(null));
public final static SetFlag<String> CONSOLE_COMMAND_ON_EXIT = WorldGuardExtraFlagsPlugin.getPlugin().getWorldGuardCommunicator().getCustomSetFlag("console-command-on-exit", new CommandStringFlag(null)); public final static SetFlag<String> CONSOLE_COMMAND_ON_EXIT = WorldGuardUtils.getCommunicator().getCustomSetFlag("console-command-on-exit", new CommandStringFlag(null));
public final static DoubleFlag WALK_SPEED = new DoubleFlag("walk-speed"); public final static DoubleFlag WALK_SPEED = new DoubleFlag("walk-speed");

View file

@ -16,18 +16,19 @@ import com.sk89q.worldguard.protection.flags.StateFlag.State;
import com.sk89q.worldguard.protection.regions.ProtectedRegion; import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.protection.util.NormativeOrders; 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.WorldGuardCommunicator;
import net.goldtreeservers.worldguardextraflags.wg.wrappers.v6.WorldGuardSixCommunicator;
import net.goldtreeservers.worldguardextraflags.wg.wrappers.v7.WorldGuardSevenCommunicator;
public class WorldGuardUtils public class WorldGuardUtils
{ {
public static final String PREVENT_TELEPORT_LOOP_META = "WGEFP: TLP"; public static final String PREVENT_TELEPORT_LOOP_META = "WGEFP: TLP";
@Getter @Setter private static WorldGuardCommunicator communicator;
private static LocalPlayer wrapPlayer(Player player) 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) public static boolean hasBypass(Player player, World world, ProtectedRegion region, Flag<?> flag)
@ -75,7 +76,7 @@ public class WorldGuardUtils
NormativeOrders.sort(checkForRegions); 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 (global != null) //Global region can be null
{ {
if (WorldGuardUtils.hasBypass(player, world, global, flag)) //Lets do like this for now to reduce dublicated code 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); 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;
}
} }

View file

@ -4,8 +4,6 @@ import java.util.Map;
import org.bukkit.Location; 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.ApplicableRegionSet;
import com.sk89q.worldguard.protection.managers.RegionManager; import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion; import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
@ -23,17 +21,9 @@ public abstract class AbstractRegionManagerWrapper
return this.regionManager.getRegion(id); return this.regionManager.getRegion(id);
} }
public ApplicableRegionSet getApplicableRegions(Vector location) public abstract ApplicableRegionSet getApplicableRegions(Location location);
{
return this.regionManager.getApplicableRegions(location);
}
public ApplicableRegionSet getApplicableRegions(Location location) public ApplicableRegionSet getApplicableRegions(ProtectedCuboidRegion protectedCuboidRegion)
{
return this.getApplicableRegions(BukkitAdapter.asVector(location));
}
public ApplicableRegionSet getApplicableRegions(ProtectedCuboidRegion protectedCuboidRegion)
{ {
return this.regionManager.getApplicableRegions(protectedCuboidRegion); return this.regionManager.getApplicableRegions(protectedCuboidRegion);
} }

View file

@ -2,6 +2,9 @@ package net.goldtreeservers.worldguardextraflags.wg.wrappers;
import org.bukkit.entity.Player; 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.LocalPlayer;
import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.SetFlag; import com.sk89q.worldguard.protection.flags.SetFlag;
@ -20,4 +23,9 @@ public interface WorldGuardCommunicator
public LocalPlayer wrapPlayer(Player player); public LocalPlayer wrapPlayer(Player player);
public <T> SetFlag<T> getCustomSetFlag(String name, Flag<T> flag); public <T> SetFlag<T> getCustomSetFlag(String name, Flag<T> 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);
} }

View file

@ -3,7 +3,7 @@
<parent> <parent>
<groupId>net.goldtreeservers</groupId> <groupId>net.goldtreeservers</groupId>
<artifactId>worldguardextraflags</artifactId> <artifactId>worldguardextraflags</artifactId>
<version>4.1.0</version> <version>4.1.1</version>
</parent> </parent>
<groupId>net.goldtreeservers.worldguardextraflags</groupId> <groupId>net.goldtreeservers.worldguardextraflags</groupId>
@ -39,6 +39,12 @@
<version>1.2</version> <version>1.2</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId>
<version>6.1.3-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency> <dependency>
<groupId>com.sk89q.worldguard</groupId> <groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-legacy</artifactId> <artifactId>worldguard-legacy</artifactId>

View file

@ -1,5 +1,9 @@
package net.goldtreeservers.worldguardextraflags.wg.wrappers.v6; 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 com.sk89q.worldguard.protection.managers.RegionManager;
import net.goldtreeservers.worldguardextraflags.wg.wrappers.AbstractRegionManagerWrapper; import net.goldtreeservers.worldguardextraflags.wg.wrappers.AbstractRegionManagerWrapper;
@ -10,4 +14,10 @@ public class RegionManagerWrapper extends AbstractRegionManagerWrapper
{ {
super(regionManager); super(regionManager);
} }
@Override
public ApplicableRegionSet getApplicableRegions(Location location)
{
return this.regionManager.getApplicableRegions(BukkitUtil.toVector(location));
}
} }

View file

@ -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;
}
}

View file

@ -1,13 +1,22 @@
package net.goldtreeservers.worldguardextraflags.wg.wrappers.v6; package net.goldtreeservers.worldguardextraflags.wg.wrappers.v6;
import org.bukkit.Chunk;
import org.bukkit.entity.Player; 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.LocalPlayer;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.SetFlag; 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.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.AbstractRegionContainerWrapper;
import net.goldtreeservers.worldguardextraflags.wg.wrappers.AbstractSessionManagerWrapper; import net.goldtreeservers.worldguardextraflags.wg.wrappers.AbstractSessionManagerWrapper;
import net.goldtreeservers.worldguardextraflags.wg.wrappers.WorldGuardCommunicator; import net.goldtreeservers.worldguardextraflags.wg.wrappers.WorldGuardCommunicator;
@ -58,4 +67,47 @@ public class WorldGuardSixCommunicator implements WorldGuardCommunicator
{ {
return new CustomSetFlag<T>(name, flag); return new CustomSetFlag<T>(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;
}
} }

View file

@ -3,7 +3,7 @@
<parent> <parent>
<groupId>net.goldtreeservers</groupId> <groupId>net.goldtreeservers</groupId>
<artifactId>worldguardextraflags</artifactId> <artifactId>worldguardextraflags</artifactId>
<version>4.1.0</version> <version>4.1.1</version>
</parent> </parent>
<groupId>net.goldtreeservers.worldguardextraflags</groupId> <groupId>net.goldtreeservers.worldguardextraflags</groupId>
@ -18,11 +18,6 @@
<id>sk89q-repo</id> <id>sk89q-repo</id>
<url>https://maven.sk89q.com/repo/</url> <url>https://maven.sk89q.com/repo/</url>
</repository> </repository>
<!-- FOR NOW -->
<repository>
<id>elMakers</id>
<url>http://maven.elmakers.com/repository/</url>
</repository>
</repositories> </repositories>
<dependencies> <dependencies>
@ -40,14 +35,26 @@
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.sk89q.worldedit</groupId> <groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit</artifactId> <artifactId>worldedit-core</artifactId>
<version>7.0-SNAPSHOT</version> <version>7.0.0-20181117.020138-26</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldedit</groupId>
<artifactId>worldedit-bukkit</artifactId>
<version>7.0.0-20181117.020138-26</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-core</artifactId>
<version>7.0.0-20181117.063337-9</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>com.sk89q.worldguard</groupId> <groupId>com.sk89q.worldguard</groupId>
<artifactId>worldguard-legacy</artifactId> <artifactId>worldguard-legacy</artifactId>
<version>7.0-SNAPSHOT</version> <version>7.0.0-20181117.063337-9</version>
<scope>provided</scope> <scope>provided</scope>
</dependency> </dependency>
</dependencies> </dependencies>

View file

@ -1,5 +1,9 @@
package net.goldtreeservers.worldguardextraflags.wg.wrappers.v7; 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 com.sk89q.worldguard.protection.managers.RegionManager;
import net.goldtreeservers.worldguardextraflags.wg.wrappers.AbstractRegionManagerWrapper; import net.goldtreeservers.worldguardextraflags.wg.wrappers.AbstractRegionManagerWrapper;
@ -10,4 +14,10 @@ public class RegionManagerWrapper extends AbstractRegionManagerWrapper
{ {
super(regionManager); super(regionManager);
} }
@Override
public ApplicableRegionSet getApplicableRegions(Location location)
{
return this.regionManager.getApplicableRegions(BukkitAdapter.asBlockVector(location));
}
} }

View file

@ -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;
}
}

View file

@ -1,14 +1,23 @@
package net.goldtreeservers.worldguardextraflags.wg.wrappers.v7; package net.goldtreeservers.worldguardextraflags.wg.wrappers.v7;
import org.bukkit.Chunk;
import org.bukkit.entity.Player; 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.LocalPlayer;
import com.sk89q.worldguard.WorldGuard; import com.sk89q.worldguard.WorldGuard;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin; import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.flags.Flag; import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.SetFlag; 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.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.AbstractRegionContainerWrapper;
import net.goldtreeservers.worldguardextraflags.wg.wrappers.AbstractSessionManagerWrapper; import net.goldtreeservers.worldguardextraflags.wg.wrappers.AbstractSessionManagerWrapper;
import net.goldtreeservers.worldguardextraflags.wg.wrappers.WorldGuardCommunicator; import net.goldtreeservers.worldguardextraflags.wg.wrappers.WorldGuardCommunicator;
@ -59,4 +68,47 @@ public class WorldGuardSevenCommunicator implements WorldGuardCommunicator
{ {
return new CustomSetFlag<T>(name, flag); return new CustomSetFlag<T>(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;
}
} }

View file

@ -4,7 +4,7 @@
<groupId>net.goldtreeservers</groupId> <groupId>net.goldtreeservers</groupId>
<artifactId>worldguardextraflags</artifactId> <artifactId>worldguardextraflags</artifactId>
<name>WorldGuardExtraFlags</name> <name>WorldGuardExtraFlags</name>
<version>4.1.0</version> <version>4.1.1</version>
<packaging>pom</packaging> <packaging>pom</packaging>