Refactoring and clean up

This commit is contained in:
isokissa3 2018-04-12 20:57:52 +03:00
parent ee6dafd4f2
commit 395a808a34
45 changed files with 1220 additions and 1234 deletions

View file

@ -3,7 +3,6 @@
<modelVersion>4.0.0</modelVersion>
<groupId>net.goldtreeservers</groupId>
<artifactId>worldguardextraflags</artifactId>
<version>2.14.3</version>
<name>WorldGuardExtraFlags</name>
<build>
<finalName>WorldGuardExtraFlagsPlugin</finalName>
@ -74,4 +73,5 @@
<scope>provided</scope>
</dependency>
</dependencies>
<version>3.0.0</version>
</project>

View file

@ -1,37 +1,18 @@
package net.goldtreeservers.worldguardextraflags;
import java.awt.Color;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityToggleGlideEvent;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import com.earth2me.essentials.Essentials;
import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldedit.bukkit.WorldEditPlugin;
import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
import com.sk89q.worldguard.protection.flags.StateFlag.State;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import lombok.Getter;
import net.goldtreeservers.worldguardextraflags.flags.handlers.BlockedEffectsFlag;
import net.goldtreeservers.worldguardextraflags.flags.handlers.CommandOnEntryFlag;
import net.goldtreeservers.worldguardextraflags.flags.handlers.CommandOnExitFlag;
import net.goldtreeservers.worldguardextraflags.flags.handlers.ConsoleCommandOnEntryFlag;
import net.goldtreeservers.worldguardextraflags.flags.handlers.ConsoleCommandOnExitFlag;
import net.goldtreeservers.worldguardextraflags.flags.handlers.FlyFlag;
import net.goldtreeservers.worldguardextraflags.flags.handlers.GiveEffectsFlag;
import net.goldtreeservers.worldguardextraflags.flags.handlers.GlideFlag;
import net.goldtreeservers.worldguardextraflags.flags.handlers.GodmodeFlag;
import net.goldtreeservers.worldguardextraflags.flags.handlers.PlaySoundsFlag;
import net.goldtreeservers.worldguardextraflags.flags.handlers.TeleportOnEntryFlag;
import net.goldtreeservers.worldguardextraflags.flags.handlers.TeleportOnExitFlag;
import net.goldtreeservers.worldguardextraflags.flags.handlers.WalkSpeedFlag;
import net.elseland.xikage.MythicMobs.MythicMobs;
import net.goldtreeservers.worldguardextraflags.fawe.FAWEUtils;
import net.goldtreeservers.worldguardextraflags.flags.Flags;
import net.goldtreeservers.worldguardextraflags.listeners.BlockListener;
import net.goldtreeservers.worldguardextraflags.listeners.EntityListener;
import net.goldtreeservers.worldguardextraflags.listeners.EntityListenerOnePointNine;
@ -39,107 +20,105 @@ import net.goldtreeservers.worldguardextraflags.listeners.EssentialsListener;
import net.goldtreeservers.worldguardextraflags.listeners.PlayerListener;
import net.goldtreeservers.worldguardextraflags.listeners.WorldEditListener;
import net.goldtreeservers.worldguardextraflags.listeners.WorldListener;
import net.goldtreeservers.worldguardextraflags.utils.FlagUtils;
import net.goldtreeservers.worldguardextraflags.utils.PluginUtils;
import net.goldtreeservers.worldguardextraflags.utils.WorldUtils;
import net.goldtreeservers.worldguardextraflags.wg.handlers.BlockedEffectsFlagHandler;
import net.goldtreeservers.worldguardextraflags.wg.handlers.CommandOnEntryFlagHandler;
import net.goldtreeservers.worldguardextraflags.wg.handlers.CommandOnExitFlagHandler;
import net.goldtreeservers.worldguardextraflags.wg.handlers.ConsoleCommandOnEntryFlagHandler;
import net.goldtreeservers.worldguardextraflags.wg.handlers.ConsoleCommandOnExitFlagHandler;
import net.goldtreeservers.worldguardextraflags.wg.handlers.FlyFlagHandler;
import net.goldtreeservers.worldguardextraflags.wg.handlers.GiveEffectsFlagHandler;
import net.goldtreeservers.worldguardextraflags.wg.handlers.GlideFlagHandler;
import net.goldtreeservers.worldguardextraflags.wg.handlers.GodmodeFlagHandler;
import net.goldtreeservers.worldguardextraflags.wg.handlers.PlaySoundsFlagHandler;
import net.goldtreeservers.worldguardextraflags.wg.handlers.TeleportOnEntryFlagHandler;
import net.goldtreeservers.worldguardextraflags.wg.handlers.TeleportOnExitFlagHandler;
import net.goldtreeservers.worldguardextraflags.wg.handlers.WalkSpeedFlagHandler;
public class WorldGuardExtraFlagsPlugin extends JavaPlugin
{
@Getter private static WorldGuardExtraFlagsPlugin plugin;
@Getter private static WorldGuardPlugin worldGuardPlugin;
@Getter private static WorldEditPlugin worldEditPlugin;
@Getter private static Essentials essentialsPlugin;
@Getter private static boolean supportsMobEffectColors;
@Getter private static boolean supportFrostwalker;
@Getter private static boolean supportsStopSound;
@Getter private static boolean mythicMobsEnabled;
@Getter private static boolean fastAsyncWorldEditEnabled;
@Getter private static MythicMobs mythicMobsPlugin;
@Getter private static boolean fastAsyncWorldEditPluginEnabled;
public WorldGuardExtraFlagsPlugin()
{
WorldGuardExtraFlagsPlugin.plugin = this;
try
{
if (Material.FROSTED_ICE != null) //LOL, Just making it look nice xD
{
WorldGuardExtraFlagsPlugin.supportFrostwalker = true;
}
}
catch (Throwable ignored)
{
}
try
{
WorldGuardExtraFlagsPlugin.supportsMobEffectColors = PotionEffect.class.getDeclaredMethod("getColor", Color.class) != null;
}
catch (Throwable ignored)
{
}
try
{
WorldGuardExtraFlagsPlugin.supportsStopSound = Player.class.getDeclaredMethod("stopSound", Color.class) != null;
}
catch (Throwable ignored)
{
}
}
@Override
public void onLoad()
{
WorldGuardExtraFlagsPlugin.worldEditPlugin = (WorldEditPlugin) this.getServer().getPluginManager().getPlugin("WorldEdit");
WorldGuardExtraFlagsPlugin.worldEditPlugin = (WorldEditPlugin)this.getServer().getPluginManager().getPlugin("WorldEdit");
WorldGuardExtraFlagsPlugin.worldGuardPlugin = (WorldGuardPlugin) this.getServer().getPluginManager().getPlugin("WorldGuard");
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(FlagUtils.TELEPORT_ON_ENTRY);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(FlagUtils.TELEPORT_ON_EXIT);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(FlagUtils.COMMAND_ON_ENTRY);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(FlagUtils.COMMAND_ON_EXIT);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(FlagUtils.CONSOLE_COMMAND_ON_ENTRY);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(FlagUtils.CONSOLE_COMMAND_ON_EXIT);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(FlagUtils.WALK_SPEED);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(FlagUtils.KEEP_INVENTORY);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(FlagUtils.KEEP_EXP);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(FlagUtils.CHAT_PREFIX);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(FlagUtils.CHAT_SUFFIX);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(FlagUtils.BLOCKED_EFFECTS);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(FlagUtils.GODMODE);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(FlagUtils.RESPAWN_LOCATION);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(FlagUtils.WORLDEDIT);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(FlagUtils.GIVE_EFFECTS);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(FlagUtils.FLY);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(FlagUtils.PLAY_SOUNDS);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(FlagUtils.MYTHICMOB_EGGS);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(FlagUtils.FROSTWALKER);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(FlagUtils.NETHER_PORTALS);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(FlagUtils.ALLOW_BLOCK_PLACE);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(FlagUtils.DENY_BLOCK_PLACE);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(FlagUtils.ALLOW_BLOCK_BREAK);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(FlagUtils.DENY_BLOCK_BREAK);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(FlagUtils.GLIDE);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(FlagUtils.CHUNK_UNLOAD);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(FlagUtils.ITEM_DURABILITY);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(FlagUtils.JOIN_LOCATION);
WorldGuardExtraFlagsPlugin.worldGuardPlugin = (WorldGuardPlugin)this.getServer().getPluginManager().getPlugin("WorldGuard");
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(Flags.TELEPORT_ON_ENTRY);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(Flags.TELEPORT_ON_EXIT);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(Flags.COMMAND_ON_ENTRY);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(Flags.COMMAND_ON_EXIT);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(Flags.CONSOLE_COMMAND_ON_ENTRY);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(Flags.CONSOLE_COMMAND_ON_EXIT);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(Flags.WALK_SPEED);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(Flags.KEEP_INVENTORY);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(Flags.KEEP_EXP);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(Flags.CHAT_PREFIX);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(Flags.CHAT_SUFFIX);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(Flags.BLOCKED_EFFECTS);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(Flags.GODMODE);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(Flags.RESPAWN_LOCATION);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(Flags.WORLDEDIT);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(Flags.GIVE_EFFECTS);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(Flags.FLY);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(Flags.PLAY_SOUNDS);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(Flags.MYTHICMOB_EGGS);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(Flags.FROSTWALKER);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(Flags.NETHER_PORTALS);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(Flags.ALLOW_BLOCK_PLACE);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(Flags.DENY_BLOCK_PLACE);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(Flags.ALLOW_BLOCK_BREAK);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(Flags.DENY_BLOCK_BREAK);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(Flags.GLIDE);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(Flags.CHUNK_UNLOAD);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(Flags.ITEM_DURABILITY);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(Flags.JOIN_LOCATION);
//Soft dependencies, due to some compatibility issues or add flags related to a plugin
Plugin essentialsPlugin = this.getServer().getPluginManager().getPlugin("Essentials");
if (essentialsPlugin != null)
{
WorldGuardExtraFlagsPlugin.essentialsPlugin = (Essentials)essentialsPlugin;
}
Plugin mythicMobsPlugin = this.getServer().getPluginManager().getPlugin("MythicMobs");
if (mythicMobsPlugin != null)
{
WorldGuardExtraFlagsPlugin.mythicMobsPlugin = (MythicMobs)mythicMobsPlugin;
}
WorldGuardExtraFlagsPlugin.fastAsyncWorldEditPluginEnabled = this.getServer().getPluginManager().isPluginEnabled("FastAsyncWorldEdit");
}
@Override
public void onEnable()
{
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getSessionManager().registerHandler(TeleportOnEntryFlag.FACTORY, null);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getSessionManager().registerHandler(TeleportOnExitFlag.FACTORY, null);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getSessionManager().registerHandler(CommandOnEntryFlag.FACTORY, null);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getSessionManager().registerHandler(CommandOnExitFlag.FACTORY, null);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getSessionManager().registerHandler(ConsoleCommandOnEntryFlag.FACTORY, null);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getSessionManager().registerHandler(ConsoleCommandOnExitFlag.FACTORY, null);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getSessionManager().registerHandler(WalkSpeedFlag.FACTORY, null);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getSessionManager().registerHandler(BlockedEffectsFlag.FACTORY, null);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getSessionManager().registerHandler(GodmodeFlag.FACTORY, null);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getSessionManager().registerHandler(GiveEffectsFlag.FACTORY, null);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getSessionManager().registerHandler(FlyFlag.FACTORY, null);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getSessionManager().registerHandler(PlaySoundsFlag.FACTORY, null);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getSessionManager().registerHandler(GlideFlag.FACTORY, null);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getSessionManager().registerHandler(TeleportOnEntryFlagHandler.FACTORY, null);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getSessionManager().registerHandler(TeleportOnExitFlagHandler.FACTORY, null);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getSessionManager().registerHandler(CommandOnEntryFlagHandler.FACTORY, null);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getSessionManager().registerHandler(CommandOnExitFlagHandler.FACTORY, null);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getSessionManager().registerHandler(ConsoleCommandOnEntryFlagHandler.FACTORY, null);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getSessionManager().registerHandler(ConsoleCommandOnExitFlagHandler.FACTORY, null);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getSessionManager().registerHandler(WalkSpeedFlagHandler.FACTORY, null);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getSessionManager().registerHandler(BlockedEffectsFlagHandler.FACTORY, null);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getSessionManager().registerHandler(GodmodeFlagHandler.FACTORY, null);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getSessionManager().registerHandler(GiveEffectsFlagHandler.FACTORY, null);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getSessionManager().registerHandler(FlyFlagHandler.FACTORY, null);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getSessionManager().registerHandler(PlaySoundsFlagHandler.FACTORY, null);
WorldGuardExtraFlagsPlugin.worldGuardPlugin.getSessionManager().registerHandler(GlideFlagHandler.FACTORY, null);
this.getServer().getPluginManager().registerEvents(new PlayerListener(), this);
this.getServer().getPluginManager().registerEvents(new BlockListener(), this);
@ -157,19 +136,10 @@ public class WorldGuardExtraFlagsPlugin extends JavaPlugin
{
}
Plugin essentialsPlugin = this.getServer().getPluginManager().getPlugin("Essentials");
if (essentialsPlugin != null)
{
WorldGuardExtraFlagsPlugin.essentialsPlugin = (Essentials)essentialsPlugin;
}
WorldGuardExtraFlagsPlugin.mythicMobsEnabled = this.getServer().getPluginManager().isPluginEnabled("MythicMobs");
WorldGuardExtraFlagsPlugin.fastAsyncWorldEditEnabled = this.getServer().getPluginManager().isPluginEnabled("FastAsyncWorldEdit");
if (WorldGuardExtraFlagsPlugin.fastAsyncWorldEditEnabled)
if (WorldGuardExtraFlagsPlugin.fastAsyncWorldEditPluginEnabled)
{
PluginUtils.registerFAWE();
FAWEUtils.registerFAWE();
}
else
{
@ -183,7 +153,7 @@ public class WorldGuardExtraFlagsPlugin extends JavaPlugin
for(World world : this.getServer().getWorlds())
{
WorldGuardExtraFlagsPlugin.doUnloadChunkFlagWorldCheck(world);
WorldUtils.doUnloadChunkFlagCheck(world);
}
}
@ -192,25 +162,8 @@ public class WorldGuardExtraFlagsPlugin extends JavaPlugin
return WorldGuardExtraFlagsPlugin.essentialsPlugin != null;
}
public static void doUnloadChunkFlagWorldCheck(World world)
public static boolean isMythicMobsPluginEnabled()
{
for (ProtectedRegion region : WorldGuardExtraFlagsPlugin.worldGuardPlugin.getRegionManager(world).getRegions().values())
{
if (region.getFlag(FlagUtils.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");
Location min = BukkitUtil.toLocation(world, region.getMinimumPoint());
Location max = BukkitUtil.toLocation(world, region.getMaximumPoint());
for(int x = min.getChunk().getX(); x <= max.getChunk().getX(); x++)
{
for(int z = min.getChunk().getZ(); z <= max.getChunk().getZ(); z++)
{
world.getChunkAt(x, z).load(true);
}
}
}
}
return WorldGuardExtraFlagsPlugin.essentialsPlugin != null;
}
}

View file

@ -0,0 +1,11 @@
package net.goldtreeservers.worldguardextraflags.fawe;
import com.boydti.fawe.FaweAPI;
public class FAWEUtils
{
public static void registerFAWE()
{
FaweAPI.addMaskManager(new FaweWorldEditFlagMaskManager());
}
}

View file

@ -1,4 +1,4 @@
package net.goldtreeservers.worldguardextraflags.utils;
package net.goldtreeservers.worldguardextraflags.fawe;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@ -14,15 +14,16 @@ import com.sk89q.worldguard.protection.managers.RegionManager;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
import net.goldtreeservers.worldguardextraflags.flags.Flags;
public class FaweWorldEditFlag extends FaweMaskManager<Player>
public class FaweWorldEditFlagMaskManager extends FaweMaskManager<Player>
{
public FaweWorldEditFlag()
public FaweWorldEditFlagMaskManager()
{
super("WorldGuardExtraFlags");
}
public ProtectedRegion getRegion(final Player player, final Location loc)
public ProtectedRegion getRegion(Player player, Location loc)
{
final com.sk89q.worldguard.LocalPlayer localplayer = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().wrapPlayer(player);
RegionManager manager = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getRegionManager(player.getWorld());
@ -45,7 +46,7 @@ public class FaweWorldEditFlag extends FaweMaskManager<Player>
public boolean isDenied(LocalPlayer localplayer, ProtectedRegion region)
{
return region.getFlag(FlagUtils.WORLDEDIT) == State.DENY;
return region.getFlag(Flags.WORLDEDIT) == State.DENY;
}
@Override
@ -54,6 +55,7 @@ public class FaweWorldEditFlag extends FaweMaskManager<Player>
final Player player = fawePlayer.parent;
final Location location = player.getLocation();
final ProtectedRegion myregion = this.getRegion(player, location);
if (myregion != null)
{
final BlockVector pos1;

View file

@ -1,4 +1,4 @@
package net.goldtreeservers.worldguardextraflags.utils;
package net.goldtreeservers.worldguardextraflags.flags;
import org.bukkit.Material;
import org.bukkit.potion.PotionEffect;
@ -12,41 +12,62 @@ 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.flags.data.SoundData;
import net.goldtreeservers.worldguardextraflags.flags.helpers.CustomSetFlag;
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;
public final class FlagUtils
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 CustomSetFlag<String> COMMAND_ON_ENTRY = new CustomSetFlag<String>("command-on-entry", new CommandStringFlag(null));
public final static CustomSetFlag<String> COMMAND_ON_EXIT = new CustomSetFlag<String>("command-on-exit", new CommandStringFlag(null));
public final static CustomSetFlag<String> CONSOLE_COMMAND_ON_ENTRY = new CustomSetFlag<String>("console-command-on-entry", new CommandStringFlag(null));
public final static CustomSetFlag<String> CONSOLE_COMMAND_ON_EXIT = new CustomSetFlag<String>("console-command-on-exit", new CommandStringFlag(null));
public final static DoubleFlag WALK_SPEED = new DoubleFlag("walk-speed");
public final static BooleanFlag KEEP_INVENTORY = new BooleanFlag("keep-inventory");
public final static BooleanFlag KEEP_EXP = new BooleanFlag("keep-exp");
public final static StringFlag CHAT_PREFIX = new StringFlag("chat-prefix");
public final static StringFlag CHAT_SUFFIX = new StringFlag("chat-suffix");
public final static SetFlag<PotionEffectType> BLOCKED_EFFECTS = new SetFlag<PotionEffectType>("blocked-effects", new PotionEffectTypeFlag(null));
public final static SetFlag<PotionEffectType> BLOCKED_EFFECTS = new SetFlag<PotionEffectType>("blocked-effects", new PotionEffectTypeFlag(null)); //LOOK AT MORE
public final static StateFlag GODMODE = new StateFlag("godmode", false);
public final static LocationFlag RESPAWN_LOCATION = new LocationFlag("respawn-location");
public final static StateFlag WORLDEDIT = new StateFlag("worldedit", true);
public final static SetFlag<PotionEffect> GIVE_EFFECTS = new SetFlag<PotionEffect>("give-effects", new PotionEffectFlag(null));
public final static StateFlag FLY = new StateFlag("fly", false);
public final static SetFlag<SoundData> PLAY_SOUNDS = new SetFlag<SoundData>("play-sounds", new SoundDataFlag(null));
public final static StateFlag MYTHICMOB_EGGS = new StateFlag("mythicmobs-eggs", true);
public final static StateFlag FROSTWALKER = new StateFlag("frostwalker", true);
public final static StateFlag NETHER_PORTALS = new StateFlag("nether-portals", true);
public final static SetFlag<Material> ALLOW_BLOCK_PLACE = new SetFlag<Material>("allow-block-place", new MaterialFlag(null));
public final static SetFlag<Material> DENY_BLOCK_PLACE = new SetFlag<Material>("deny-block-place", new MaterialFlag(null));
public final static SetFlag<Material> ALLOW_BLOCK_BREAK = new SetFlag<Material>("allow-block-break", new MaterialFlag(null));
public final static SetFlag<Material> DENY_BLOCK_BREAK = new SetFlag<Material>("deny-block-break", new MaterialFlag(null));
public final static StateFlag GLIDE = new StateFlag("glide", false);
public final static StateFlag GLIDE = new StateFlag("glide", false); //UNSUPPORTED
public final static StateFlag CHUNK_UNLOAD = new StateFlag("chunk-unload", true);
public final static StateFlag ITEM_DURABILITY = new StateFlag("item-durability", true);
public final static LocationFlag JOIN_LOCATION = new LocationFlag("join-location");
}

View file

@ -1,15 +1,16 @@
package net.goldtreeservers.worldguardextraflags.helpers;
package net.goldtreeservers.worldguardextraflags.flags.data;
import java.util.concurrent.TimeUnit;
import org.bukkit.Color;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import net.goldtreeservers.worldguardextraflags.utils.TimeUtils;
@RequiredArgsConstructor
public class PotionEffectDetails
{
@Getter private final double endTime;
@Getter private final long endTime;
@Getter private final int amplifier;
@Getter private final boolean ambient;
@Getter private final boolean particles;
@ -17,7 +18,7 @@ public class PotionEffectDetails
public double getTimeLeft()
{
return this.endTime - TimeUtils.getUnixtimestamp();
return (this.endTime - System.nanoTime()) / TimeUnit.MICROSECONDS.toNanos(50L);
}
public int getTimeLeftInTicks()

View file

@ -1,4 +1,4 @@
package net.goldtreeservers.worldguardextraflags.utils;
package net.goldtreeservers.worldguardextraflags.flags.data;
public class SoundData
{

View file

@ -1,78 +0,0 @@
package net.goldtreeservers.worldguardextraflags.flags.handlers;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.session.MoveType;
import com.sk89q.worldguard.session.Session;
import com.sk89q.worldguard.session.handler.Handler;
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
import net.goldtreeservers.worldguardextraflags.utils.FlagUtils;
import net.goldtreeservers.worldguardextraflags.utils.WorldGuardUtils;
public class CommandOnEntryFlag extends Handler
{
public static final Factory FACTORY = new Factory();
public static class Factory extends Handler.Factory<CommandOnEntryFlag>
{
@Override
public CommandOnEntryFlag create(Session session)
{
return new CommandOnEntryFlag(session);
}
}
private Collection<Set<String>> lastCommands;
protected CommandOnEntryFlag(Session session)
{
super(session);
this.lastCommands = new ArrayList<>();
}
@Override
public boolean onCrossBoundary(Player player, Location from, Location to, ApplicableRegionSet toSet, Set<ProtectedRegion> entered, Set<ProtectedRegion> exited, MoveType moveType)
{
if (!WorldGuardUtils.hasBypass(player))
{
Collection<Set<String>> commands = toSet.queryAllValues(WorldGuardUtils.wrapPlayer(player), FlagUtils.COMMAND_ON_ENTRY);
for(Set<String> commands_ : commands)
{
if (!this.lastCommands.contains(commands_) && commands_.size() > 0)
{
for(String command : commands_)
{
WorldGuardExtraFlagsPlugin.getPlugin().getServer().dispatchCommand(player, command.substring(1).replace("%username%", player.getName())); //TODO: Make this better
}
break;
}
}
this.lastCommands = new ArrayList<Set<String>>(commands);
if (!this.lastCommands.isEmpty())
{
for (ProtectedRegion region : toSet)
{
Set<String> commands_ = region.getFlag(FlagUtils.COMMAND_ON_ENTRY);
if (commands_ != null)
{
this.lastCommands.add(commands_);
}
}
}
}
return true;
}
}

View file

@ -1,82 +0,0 @@
package net.goldtreeservers.worldguardextraflags.flags.handlers;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.session.MoveType;
import com.sk89q.worldguard.session.Session;
import com.sk89q.worldguard.session.handler.Handler;
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
import net.goldtreeservers.worldguardextraflags.utils.FlagUtils;
import net.goldtreeservers.worldguardextraflags.utils.WorldGuardUtils;
public class CommandOnExitFlag extends Handler
{
public static final Factory FACTORY = new Factory();
public static class Factory extends Handler.Factory<CommandOnExitFlag>
{
@Override
public CommandOnExitFlag create(Session session)
{
return new CommandOnExitFlag(session);
}
}
private Collection<Set<String>> lastCommands;
protected CommandOnExitFlag(Session session)
{
super(session);
this.lastCommands = new ArrayList<>();
}
@Override
public void initialize(Player player, Location current, ApplicableRegionSet set)
{
this.lastCommands = set.queryAllValues(WorldGuardUtils.wrapPlayer(player), FlagUtils.COMMAND_ON_EXIT);
}
@Override
public boolean onCrossBoundary(Player player, Location from, Location to, ApplicableRegionSet toSet, Set<ProtectedRegion> entered, Set<ProtectedRegion> exited, MoveType moveType)
{
if (!WorldGuardUtils.hasBypass(player))
{
Collection<Set<String>> commands = new ArrayList<Set<String>>(toSet.queryAllValues(WorldGuardUtils.wrapPlayer(player), FlagUtils.COMMAND_ON_EXIT));
if (!commands.isEmpty())
{
for (ProtectedRegion region : toSet)
{
Set<String> commands_ = region.getFlag(FlagUtils.COMMAND_ON_EXIT);
if (commands_ != null)
{
commands.add(commands_);
}
}
}
for(Set<String> commands_ : this.lastCommands)
{
if (!commands.contains(commands_) && commands_.size() > 0)
{
for(String command : commands_)
{
WorldGuardExtraFlagsPlugin.getPlugin().getServer().dispatchCommand(player, command.substring(1).replace("%username%", player.getName())); //TODO: Make this better
}
}
}
this.lastCommands = commands;
}
return true;
}
}

View file

@ -1,78 +0,0 @@
package net.goldtreeservers.worldguardextraflags.flags.handlers;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.session.MoveType;
import com.sk89q.worldguard.session.Session;
import com.sk89q.worldguard.session.handler.Handler;
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
import net.goldtreeservers.worldguardextraflags.utils.FlagUtils;
import net.goldtreeservers.worldguardextraflags.utils.WorldGuardUtils;
public class ConsoleCommandOnEntryFlag extends Handler
{
public static final Factory FACTORY = new Factory();
public static class Factory extends Handler.Factory<ConsoleCommandOnEntryFlag>
{
@Override
public ConsoleCommandOnEntryFlag create(Session session)
{
return new ConsoleCommandOnEntryFlag(session);
}
}
private Collection<Set<String>> lastCommands;
protected ConsoleCommandOnEntryFlag(Session session)
{
super(session);
this.lastCommands = new ArrayList<>();
}
@Override
public boolean onCrossBoundary(Player player, Location from, Location to, ApplicableRegionSet toSet, Set<ProtectedRegion> entered, Set<ProtectedRegion> exited, MoveType moveType)
{
if (!WorldGuardUtils.hasBypass(player))
{
Collection<Set<String>> commands = toSet.queryAllValues(WorldGuardUtils.wrapPlayer(player), FlagUtils.CONSOLE_COMMAND_ON_ENTRY);
for(Set<String> commands_ : commands)
{
if (!this.lastCommands.contains(commands_))
{
for(String command : commands_)
{
WorldGuardExtraFlagsPlugin.getPlugin().getServer().dispatchCommand(WorldGuardExtraFlagsPlugin.getPlugin().getServer().getConsoleSender(), command.substring(1).replace("%username%", player.getName())); //TODO: Make this better
}
break;
}
}
this.lastCommands = new ArrayList<Set<String>>(commands);
if (!this.lastCommands.isEmpty())
{
for (ProtectedRegion region : toSet)
{
Set<String> commands_ = region.getFlag(FlagUtils.CONSOLE_COMMAND_ON_ENTRY);
if (commands_ != null)
{
this.lastCommands.add(commands_);
}
}
}
}
return true;
}
}

View file

@ -1,84 +0,0 @@
package net.goldtreeservers.worldguardextraflags.flags.handlers;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.session.MoveType;
import com.sk89q.worldguard.session.Session;
import com.sk89q.worldguard.session.handler.Handler;
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
import net.goldtreeservers.worldguardextraflags.utils.FlagUtils;
import net.goldtreeservers.worldguardextraflags.utils.WorldGuardUtils;
public class ConsoleCommandOnExitFlag extends Handler
{
public static final Factory FACTORY = new Factory();
public static class Factory extends Handler.Factory<ConsoleCommandOnExitFlag>
{
@Override
public ConsoleCommandOnExitFlag create(Session session)
{
return new ConsoleCommandOnExitFlag(session);
}
}
private Collection<Set<String>> lastCommands;
protected ConsoleCommandOnExitFlag(Session session)
{
super(session);
this.lastCommands = new ArrayList<>();
}
@Override
public void initialize(Player player, Location current, ApplicableRegionSet set)
{
this.lastCommands = set.queryAllValues(WorldGuardUtils.wrapPlayer(player), FlagUtils.CONSOLE_COMMAND_ON_EXIT);
}
@Override
public boolean onCrossBoundary(Player player, Location from, Location to, ApplicableRegionSet toSet, Set<ProtectedRegion> entered, Set<ProtectedRegion> exited, MoveType moveType)
{
if (!WorldGuardUtils.hasBypass(player))
{
Collection<Set<String>> commands = new ArrayList<Set<String>>(toSet.queryAllValues(WorldGuardUtils.wrapPlayer(player), FlagUtils.CONSOLE_COMMAND_ON_EXIT));
if (!commands.isEmpty())
{
for (ProtectedRegion region : toSet)
{
Set<String> commands_ = region.getFlag(FlagUtils.CONSOLE_COMMAND_ON_EXIT);
if (commands_ != null)
{
commands.add(commands_);
}
}
}
for(Set<String> commands_ : this.lastCommands)
{
if (!commands.contains(commands_))
{
for(String command : commands_)
{
WorldGuardExtraFlagsPlugin.getPlugin().getServer().dispatchCommand(WorldGuardExtraFlagsPlugin.getPlugin().getServer().getConsoleSender(), command.substring(1).replace("%username%", player.getName())); //TODO: Make this better
}
break;
}
}
this.lastCommands = commands;
}
return true;
}
}

View file

@ -1,97 +0,0 @@
package net.goldtreeservers.worldguardextraflags.flags.handlers;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.StateFlag.State;
import com.sk89q.worldguard.session.MoveType;
import com.sk89q.worldguard.session.Session;
import com.sk89q.worldguard.session.handler.FlagValueChangeHandler;
import com.sk89q.worldguard.session.handler.Handler;
import lombok.Getter;
import net.goldtreeservers.worldguardextraflags.utils.FlagUtils;
import net.goldtreeservers.worldguardextraflags.utils.WorldGuardUtils;
public class FlyFlag extends FlagValueChangeHandler<State>
{
public static final Factory FACTORY = new Factory();
public static class Factory extends Handler.Factory<FlyFlag>
{
@Override
public FlyFlag create(Session session)
{
return new FlyFlag(session);
}
}
@Getter private Boolean currentValue;
private Boolean originalFly;
protected FlyFlag(Session session)
{
super(session, FlagUtils.FLY);
}
private void updateFly(Player player, State newValue, World world)
{
if (!WorldGuardUtils.hasBypass(player) && newValue != null)
{
boolean value = (newValue == State.ALLOW ? true : false);
if (player.getAllowFlight() != value)
{
if (this.originalFly == null)
{
this.originalFly = player.getAllowFlight();
}
player.setAllowFlight(value);
}
}
else
{
if (this.originalFly != null)
{
player.setAllowFlight(this.originalFly);
this.originalFly = null;
}
}
}
@Override
protected void onInitialValue(Player player, ApplicableRegionSet set, State value)
{
this.updateFly(player, value, player.getWorld());
}
@Override
protected boolean onSetValue(Player player, Location from, Location to, ApplicableRegionSet toSet, State currentValue, State lastValue, MoveType moveType)
{
this.updateFly(player, currentValue, to.getWorld());
return true;
}
@Override
protected boolean onAbsentValue(Player player, Location from, Location to, ApplicableRegionSet toSet, State lastValue, MoveType moveType)
{
this.updateFly(player, null, player.getWorld());
return true;
}
@Override
public boolean testMoveTo(Player player, Location from, Location to, ApplicableRegionSet toSet, MoveType moveType)
{
if (this.currentValue != null && player.getAllowFlight() != this.currentValue)
{
player.setAllowFlight(this.currentValue);
}
return true;
}
}

View file

@ -1,96 +0,0 @@
package net.goldtreeservers.worldguardextraflags.flags.handlers;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.StateFlag.State;
import com.sk89q.worldguard.session.MoveType;
import com.sk89q.worldguard.session.Session;
import com.sk89q.worldguard.session.handler.FlagValueChangeHandler;
import com.sk89q.worldguard.session.handler.Handler;
import net.goldtreeservers.worldguardextraflags.utils.FlagUtils;
import net.goldtreeservers.worldguardextraflags.utils.WorldGuardUtils;
public class GlideFlag extends FlagValueChangeHandler<State>
{
public static final Factory FACTORY = new Factory();
public static class Factory extends Handler.Factory<GlideFlag>
{
@Override
public GlideFlag create(Session session)
{
return new GlideFlag(session);
}
}
private Boolean originalGlide;
private Boolean currentValue;
protected GlideFlag(Session session)
{
super(session, FlagUtils.GLIDE);
}
private void updateGlide(Player player, State newValue, World world)
{
if (!WorldGuardUtils.hasBypass(player) && newValue != null)
{
boolean value = (newValue == State.ALLOW ? true : false);
if (player.isGliding() != value)
{
if (this.originalGlide == null)
{
this.originalGlide = player.isGliding();
}
player.setGliding(value);
}
}
else
{
if (this.originalGlide != null)
{
player.setGliding(this.originalGlide);
this.originalGlide = null;
}
}
}
@Override
protected void onInitialValue(Player player, ApplicableRegionSet set, State value)
{
this.updateGlide(player, value, player.getWorld());
}
@Override
protected boolean onSetValue(Player player, Location from, Location to, ApplicableRegionSet toSet, State currentValue, State lastValue, MoveType moveType)
{
this.updateGlide(player, currentValue, to.getWorld());
return true;
}
@Override
protected boolean onAbsentValue(Player player, Location from, Location to, ApplicableRegionSet toSet, State lastValue, MoveType moveType)
{
this.updateGlide(player, null, player.getWorld());
return true;
}
@Override
public boolean testMoveTo(Player player, Location from, Location to, ApplicableRegionSet toSet, MoveType moveType)
{
if (this.currentValue != null && player.isGliding() != this.currentValue)
{
player.setGliding(this.currentValue);
}
return true;
}
}

View file

@ -1,84 +0,0 @@
package net.goldtreeservers.worldguardextraflags.flags.handlers;
import javax.annotation.Nullable;
import org.bukkit.entity.Player;
import com.earth2me.essentials.User;
import com.sk89q.worldguard.protection.flags.StateFlag.State;
import com.sk89q.worldguard.session.Session;
import com.sk89q.worldguard.session.handler.Handler;
import lombok.Getter;
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
import net.goldtreeservers.worldguardextraflags.utils.FlagUtils;
import net.goldtreeservers.worldguardextraflags.utils.WorldGuardUtils;
public class GodmodeFlag extends Handler
{
public static final Factory FACTORY = new Factory();
public static class Factory extends Handler.Factory<GodmodeFlag>
{
@Override
public GodmodeFlag create(Session session)
{
return new GodmodeFlag(session);
}
}
@Getter private Boolean isGodmodeEnabled;
private Boolean originalEssentialsGodmode;
protected GodmodeFlag(Session session)
{
super(session);
}
@Nullable
@Override
public State getInvincibility(Player player)
{
if (!WorldGuardUtils.hasBypass(player))
{
State state = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getRegionContainer().createQuery().getApplicableRegions(player.getLocation()).queryValue(WorldGuardUtils.wrapPlayer(player), FlagUtils.GODMODE);
if (state != null)
{
this.isGodmodeEnabled = (state == State.ALLOW ? true : false);
}
else
{
this.isGodmodeEnabled = null;
}
if (WorldGuardExtraFlagsPlugin.isEssentialsEnable())
{
User user = WorldGuardExtraFlagsPlugin.getEssentialsPlugin().getUser(player);
if (this.isGodmodeEnabled != null)
{
if (this.isGodmodeEnabled != user.isGodModeEnabled())
{
this.originalEssentialsGodmode = user.isGodModeEnabled();
user.setGodModeEnabled(this.isGodmodeEnabled);
}
}
else
{
if (this.originalEssentialsGodmode != null)
{
user.setGodModeEnabled(this.isGodmodeEnabled);
this.originalEssentialsGodmode = null;
}
}
}
return state;
}
else
{
return null;
}
}
}

View file

@ -1,89 +0,0 @@
package net.goldtreeservers.worldguardextraflags.flags.handlers;
import org.bukkit.Location;
import org.bukkit.World;
import org.bukkit.entity.Player;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.session.MoveType;
import com.sk89q.worldguard.session.Session;
import com.sk89q.worldguard.session.handler.FlagValueChangeHandler;
import com.sk89q.worldguard.session.handler.Handler;
import net.goldtreeservers.worldguardextraflags.utils.FlagUtils;
public class WalkSpeedFlag extends FlagValueChangeHandler<Double>
{
public static final Factory FACTORY = new Factory();
public static class Factory extends Handler.Factory<WalkSpeedFlag>
{
@Override
public WalkSpeedFlag create(Session session)
{
return new WalkSpeedFlag(session);
}
}
private Float originalWalkSpeed;
protected WalkSpeedFlag(Session session)
{
super(session, FlagUtils.WALK_SPEED);
}
private void updateWalkSpeed(Player player, Double newValue, World world)
{
if (!this.getSession().getManager().hasBypass(player, world) && newValue != null)
{
if (newValue > 1.0)
{
newValue = 1.0;
}
else if (newValue < -1.0)
{
newValue = -1.0;
}
if (player.getWalkSpeed() != newValue.floatValue())
{
if (this.originalWalkSpeed == null)
{
this.originalWalkSpeed = player.getWalkSpeed();
}
player.setWalkSpeed(newValue.floatValue());
}
}
else
{
if (this.originalWalkSpeed != null)
{
player.setWalkSpeed(this.originalWalkSpeed);
this.originalWalkSpeed = null;
}
}
}
@Override
protected void onInitialValue(Player player, ApplicableRegionSet set, Double value)
{
this.updateWalkSpeed(player, value, player.getWorld());
}
@Override
protected boolean onSetValue(Player player, Location from, Location to, ApplicableRegionSet toSet, Double currentValue, Double lastValue, MoveType moveType)
{
this.updateWalkSpeed(player, currentValue, to.getWorld());
return true;
}
@Override
protected boolean onAbsentValue(Player player, Location from, Location to, ApplicableRegionSet toSet, Double lastValue, MoveType moveType)
{
this.updateWalkSpeed(player, null, player.getWorld());
return true;
}
}

View file

@ -1,48 +0,0 @@
package net.goldtreeservers.worldguardextraflags.flags.handlers;
import org.bukkit.entity.Player;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldedit.extension.platform.Actor;
import com.sk89q.worldedit.extent.AbstractDelegateExtent;
import com.sk89q.worldedit.extent.Extent;
import com.sk89q.worldguard.protection.flags.StateFlag.State;
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
import net.goldtreeservers.worldguardextraflags.utils.FlagUtils;
import net.goldtreeservers.worldguardextraflags.utils.WorldGuardUtils;
public class WorldEditFlag extends AbstractDelegateExtent
{
private final Actor actor;
public WorldEditFlag(Extent extent, Actor actor)
{
super(extent);
this.actor = actor;
}
@Override
public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException
{
Player player = WorldGuardExtraFlagsPlugin.getPlugin().getServer().getPlayer(this.actor.getUniqueId());
if (WorldGuardUtils.hasBypass(player))
{
return super.setBlock(location, block);
}
else
{
if (WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getRegionContainer().createQuery().getApplicableRegions(BukkitUtil.toLocation(player.getWorld(), location)).queryValue(WorldGuardUtils.wrapPlayer(player), FlagUtils.WORLDEDIT) != State.DENY)
{
return super.setBlock(location, block);
}
else
{
return false;
}
}
}
}

View file

@ -4,7 +4,7 @@ import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.FlagContext;
import com.sk89q.worldguard.protection.flags.InvalidFlagFormat;
import net.goldtreeservers.worldguardextraflags.utils.SoundData;
import net.goldtreeservers.worldguardextraflags.flags.data.SoundData;
public class SoundDataFlag extends Flag<SoundData>
{

View file

@ -5,6 +5,7 @@ import java.util.Set;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Result;
import org.bukkit.event.EventHandler;
@ -18,36 +19,43 @@ import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.StateFlag.State;
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
import net.goldtreeservers.worldguardextraflags.utils.FlagUtils;
import net.goldtreeservers.worldguardextraflags.utils.WorldGuardUtils;
import net.goldtreeservers.worldguardextraflags.flags.Flags;
import net.goldtreeservers.worldguardextraflags.utils.SupportedFeatures;
import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils;
public class BlockListener implements Listener
{
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@EventHandler(ignoreCancelled = true)
public void onEntityBlockFormEvent(EntityBlockFormEvent event)
{
if (WorldGuardExtraFlagsPlugin.isSupportFrostwalker())
if (SupportedFeatures.isFrostwalkerSupported())
{
BlockState newState = event.getNewState();
if (newState.getType() == Material.FROSTED_ICE)
{
if (event.getEntity() instanceof Player)
ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getRegionContainer().createQuery().getApplicableRegions(newState.getLocation());
Entity entity = event.getEntity();
if (entity instanceof Player)
{
Player player = (Player)event.getEntity();
if (!WorldGuardUtils.hasBypass(player))
Player player = (Player)entity;
if (WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.FROSTWALKER) == State.DENY)
{
ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getRegionContainer().createQuery().getApplicableRegions(newState.getLocation());
if (regions.queryValue(WorldGuardUtils.wrapPlayer(player), FlagUtils.FROSTWALKER) == State.DENY)
{
event.setCancelled(true);
}
event.setCancelled(true);
}
}
else
{
if (regions.queryValue(null, Flags.FROSTWALKER) == State.DENY)
{
event.setCancelled(true);
}
}
}
}
}
//TODO: Figure out something better for this
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false)
public void onBlockPlaceEvent(PlaceBlockEvent event)
{
@ -58,36 +66,34 @@ public class BlockListener implements Listener
{
Player player = (Player)cause;
if (!WorldGuardUtils.hasBypass(player))
for(Block block : event.getBlocks())
{
for(Block block : event.getBlocks())
ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getRegionContainer().createQuery().getApplicableRegions(block.getLocation());
Set<Material> state = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.ALLOW_BLOCK_PLACE);
if (state != null && state.contains(block.getType()))
{
ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getRegionContainer().createQuery().getApplicableRegions(block.getLocation());
Set<Material> state = regions.queryValue(WorldGuardUtils.wrapPlayer(player), FlagUtils.ALLOW_BLOCK_PLACE);
if (state != null && state.contains(block.getType()))
event.setResult(Result.ALLOW);
}
else
{
Set<Material> state2 = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.DENY_BLOCK_PLACE);
if (state2 != null && state2.contains(block.getType()))
{
event.setResult(Result.ALLOW);
event.setResult(Result.DENY);
return;
}
else
{
Set<Material> state2 = regions.queryValue(WorldGuardUtils.wrapPlayer(player), FlagUtils.DENY_BLOCK_PLACE);
if (state2 != null && state2.contains(block.getType()))
{
event.setResult(Result.DENY);
return;
}
else
{
event.setResult(originalResult);
return;
}
event.setResult(originalResult);
return;
}
}
}
}
}
}
}
//TODO: Figure out something better for this
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false)
public void onBlockBreakEvent(BreakBlockEvent event)
{
@ -98,30 +104,27 @@ public class BlockListener implements Listener
{
Player player = (Player)cause;
if (!WorldGuardUtils.hasBypass(player))
for(Block block : event.getBlocks())
{
for(Block block : event.getBlocks())
{
ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getRegionContainer().createQuery().getApplicableRegions(block.getLocation());
ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getRegionContainer().createQuery().getApplicableRegions(block.getLocation());
Set<Material> state = regions.queryValue(WorldGuardUtils.wrapPlayer(player), FlagUtils.ALLOW_BLOCK_BREAK);
if (state != null && state.contains(block.getType()))
Set<Material> state = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.ALLOW_BLOCK_BREAK);
if (state != null && state.contains(block.getType()))
{
event.setResult(Result.ALLOW);
}
else
{
Set<Material> state2 = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.DENY_BLOCK_BREAK);
if (state2 != null && state2.contains(block.getType()))
{
event.setResult(Result.ALLOW);
event.setResult(Result.DENY);
return;
}
else
{
Set<Material> state2 = regions.queryValue(WorldGuardUtils.wrapPlayer(player), FlagUtils.DENY_BLOCK_BREAK);
if (state2 != null && state2.contains(block.getType()))
{
event.setResult(Result.DENY);
return;
}
else
{
event.setResult(originalResult);
return;
}
event.setResult(originalResult);
return;
}
}
}

View file

@ -2,7 +2,6 @@ package net.goldtreeservers.worldguardextraflags.listeners;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.world.PortalCreateEvent;
@ -10,11 +9,11 @@ import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.StateFlag.State;
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
import net.goldtreeservers.worldguardextraflags.utils.FlagUtils;
import net.goldtreeservers.worldguardextraflags.flags.Flags;
public class EntityListener implements Listener
{
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@EventHandler(ignoreCancelled = true)
public void onPortalCreateEvent(PortalCreateEvent event)
{
for(Block block : event.getBlocks())
@ -22,7 +21,7 @@ public class EntityListener implements Listener
//Unable to get the player who created it....
ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getRegionContainer().createQuery().getApplicableRegions(block.getLocation());
if (regions.queryValue(null, FlagUtils.NETHER_PORTALS) == State.DENY)
if (regions.queryValue(null, Flags.NETHER_PORTALS) == State.DENY)
{
event.setCancelled(true);
break;

View file

@ -1,5 +1,6 @@
package net.goldtreeservers.worldguardextraflags.listeners;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
@ -10,27 +11,26 @@ import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.StateFlag.State;
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
import net.goldtreeservers.worldguardextraflags.utils.FlagUtils;
import net.goldtreeservers.worldguardextraflags.utils.WorldGuardUtils;
import net.goldtreeservers.worldguardextraflags.flags.Flags;
import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils;
public class EntityListenerOnePointNine implements Listener
{
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onEntityToggleGlideEvent(EntityToggleGlideEvent event)
{
if (event.getEntity() instanceof Player)
Entity entity = event.getEntity();
if (entity instanceof Player)
{
Player player = (Player)event.getEntity();
if (!WorldGuardUtils.hasBypass(player))
{
ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getRegionContainer().createQuery().getApplicableRegions(player.getLocation());
Player player = (Player)entity;
ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getRegionContainer().createQuery().getApplicableRegions(player.getLocation());
State state = regions.queryValue(WorldGuardUtils.wrapPlayer(player), FlagUtils.GLIDE);
if (state != null)
{
event.setCancelled(true);
player.setGliding(state == State.ALLOW);
}
State state = regions.queryValue(WorldGuardUtils.wrapPlayer(player), Flags.GLIDE);
if (state != null)
{
event.setCancelled(true);
player.setGliding(state == State.ALLOW);
}
}
}

View file

@ -1,22 +1,34 @@
package net.goldtreeservers.worldguardextraflags.listeners;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.StateFlag.State;
import net.ess3.api.IUser;
import net.ess3.api.events.GodStatusChangeEvent;
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
import net.goldtreeservers.worldguardextraflags.flags.handlers.GodmodeFlag;
import net.goldtreeservers.worldguardextraflags.utils.WorldGuardUtils;
import net.goldtreeservers.worldguardextraflags.flags.Flags;
import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils;
import net.goldtreeservers.worldguardextraflags.wg.handlers.GodmodeFlagHandler;
public class EssentialsListener implements Listener
{
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onGodStatusChangeEvent(GodStatusChangeEvent event)
{
if (!WorldGuardUtils.hasBypass(event.getController().getBase()))
IUser user = event.getController();
Player player = user.getBase();
ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getRegionContainer().createQuery().getApplicableRegions(player.getLocation());
State state = WorldGuardUtils.queryState(player, player.getWorld(), regions.getRegions(), Flags.GODMODE);
if (state != null)
{
if (WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().get(event.getController().getBase()).getHandler(GodmodeFlag.class).getIsGodmodeEnabled() != null)
if (WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().get(player).getHandler(GodmodeFlagHandler.class).getIsGodmodeEnabled() != null)
{
event.setCancelled(true);
}

View file

@ -1,27 +1,19 @@
package net.goldtreeservers.worldguardextraflags.listeners;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.Event.Result;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.AsyncPlayerChatEvent;
import org.bukkit.event.player.PlayerChangedWorldEvent;
import org.bukkit.event.player.PlayerGameModeChangeEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerItemConsumeEvent;
import org.bukkit.event.player.PlayerItemDamageEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import org.bukkit.event.player.PlayerTeleportEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.Potion;
@ -33,13 +25,11 @@ import com.sk89q.worldedit.bukkit.BukkitUtil;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.StateFlag.State;
import net.elseland.xikage.MythicMobs.Mobs.EggManager;
import net.elseland.xikage.MythicMobs.Mobs.MythicMob;
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
import net.goldtreeservers.worldguardextraflags.flags.handlers.FlyFlag;
import net.goldtreeservers.worldguardextraflags.flags.handlers.GiveEffectsFlag;
import net.goldtreeservers.worldguardextraflags.utils.FlagUtils;
import net.goldtreeservers.worldguardextraflags.utils.WorldGuardUtils;
import net.goldtreeservers.worldguardextraflags.flags.Flags;
import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils;
import net.goldtreeservers.worldguardextraflags.wg.handlers.FlyFlagHandler;
import net.goldtreeservers.worldguardextraflags.wg.handlers.GiveEffectsFlagHandler;
@SuppressWarnings("deprecation")
public class PlayerListener implements Listener
@ -47,41 +37,42 @@ public class PlayerListener implements Listener
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerTeleportEvent(PlayerTeleportEvent event)
{
event.getPlayer().removeMetadata("WGEFP-TPOEF", WorldGuardExtraFlagsPlugin.getPlugin());
Player player = event.getPlayer();
player.removeMetadata(WorldGuardUtils.PREVENT_TELEPORT_LOOP_META, WorldGuardExtraFlagsPlugin.getPlugin());
}
@EventHandler(priority = EventPriority.HIGHEST)
@EventHandler
public void onPlayerDeathEvent(PlayerDeathEvent event)
{
Player player = event.getEntity();
ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getRegionContainer().createQuery().getApplicableRegions(player.getLocation());
Boolean keepInventory = regions.queryValue(WorldGuardUtils.wrapPlayer(player), FlagUtils.KEEP_INVENTORY); //Not sure should we add bypass for this
if (keepInventory != null && keepInventory)
Boolean keepInventory = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.KEEP_INVENTORY);
if (Boolean.TRUE.equals(keepInventory))
{
event.setKeepInventory(true);
event.getDrops().clear();
}
Boolean keepExp = regions.queryValue(WorldGuardUtils.wrapPlayer(player), FlagUtils.KEEP_EXP); //Not sure should we add bypass for this
if (keepExp != null && keepExp)
Boolean keepExp = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.KEEP_EXP);
if (Boolean.TRUE.equals(keepExp))
{
event.setKeepLevel(true);
event.setDroppedExp(0);
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@EventHandler(ignoreCancelled = true)
public void onAsyncPlayerChatEvent(AsyncPlayerChatEvent event)
{
Player player = event.getPlayer();
ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getRegionContainer().createQuery().getApplicableRegions(player.getLocation());
String prefix = regions.queryValue(WorldGuardUtils.wrapPlayer(player), FlagUtils.CHAT_PREFIX); //Not sure should we add bypass for this
String suffix = regions.queryValue(WorldGuardUtils.wrapPlayer(player), FlagUtils.CHAT_SUFFIX); //Not sure should we add bypass for this
String prefix = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.CHAT_PREFIX);
String suffix = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.CHAT_SUFFIX);
if (prefix != null)
{
event.setFormat(prefix + event.getFormat());
@ -93,39 +84,36 @@ public class PlayerListener implements Listener
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@EventHandler(ignoreCancelled = true)
public void onPlayerRespawnEvent(PlayerRespawnEvent event)
{
Player player = event.getPlayer();
ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getRegionContainer().createQuery().getApplicableRegions(player.getLocation());
Location respawnLocation = regions.queryValue(WorldGuardUtils.wrapPlayer(player), FlagUtils.RESPAWN_LOCATION); //Not sure should we add bypass for this
Location respawnLocation = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.RESPAWN_LOCATION);
if (respawnLocation != null)
{
event.setRespawnLocation(BukkitUtil.toLocation(respawnLocation));
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerItemConsumeEvent(PlayerItemConsumeEvent event)
{
Player player = event.getPlayer();
if (!WorldGuardUtils.hasBypass(player))
ItemMeta itemMeta = event.getItem().getItemMeta();
if (itemMeta instanceof PotionMeta)
{
ItemMeta itemMeta = event.getItem().getItemMeta();
if (itemMeta instanceof PotionMeta)
WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().get(player).getHandler(GiveEffectsFlagHandler.class).drinkPotion(player, Potion.fromItemStack(event.getItem()).getEffects());
}
else
{
Material material = event.getItem().getType();
if (material == Material.MILK_BUCKET)
{
WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().get(player).getHandler(GiveEffectsFlag.class).drinkPotion(player, Potion.fromItemStack(event.getItem()).getEffects());
}
else
{
Material material = event.getItem().getType();
if (material == Material.MILK_BUCKET)
{
WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().get(player).getHandler(GiveEffectsFlag.class).drinkMilk(player);
}
WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().get(player).getHandler(GiveEffectsFlagHandler.class).drinkMilk(player);
}
}
}
@ -135,31 +123,29 @@ public class PlayerListener implements Listener
{
Player player = event.getPlayer();
if (!WorldGuardUtils.hasBypass(player))
Boolean value = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().get(player).getHandler(FlyFlagHandler.class).getCurrentValue();
if (value != null)
{
new BukkitRunnable()
{
@Override
public void run()
{
try
Boolean value = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().get(player).getHandler(FlyFlagHandler.class).getCurrentValue();
if (value != null)
{
event.getPlayer().setAllowFlight(WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().get(player).getHandler(FlyFlag.class).getCurrentValue());
}
catch(Exception ignored)
{
player.setAllowFlight(value);
}
}
}.runTask(WorldGuardExtraFlagsPlugin.getPlugin());
}
}
//Last time I checked, the plugin don't check for cancelled events
@EventHandler(priority = EventPriority.LOWEST)
//Re-enable if needed and the plugin checks for cancelled events
/*@EventHandler(priority = EventPriority.LOWEST)
public void onPlayerInteractEvent(PlayerInteractEvent event)
{
if (WorldGuardExtraFlagsPlugin.isMythicMobsEnabled())
if (WorldGuardExtraFlagsPlugin.isMythicMobsPluginEnabled())
{
Player player = event.getPlayer();
@ -182,7 +168,7 @@ public class PlayerListener implements Listener
if (mm != null)
{
ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getRegionContainer().createQuery().getApplicableRegions(action == Action.RIGHT_CLICK_BLOCK ? event.getClickedBlock().getLocation() : player.getLocation());
if (regions.queryValue(WorldGuardUtils.wrapPlayer(player), FlagUtils.MYTHICMOB_EGGS) == State.DENY)
if (regions.queryValue(WorldGuardUtils.wrapPlayer(player), Flags.MYTHICMOB_EGGS) == State.DENY)
{
event.setCancelled(true);
event.setUseItemInHand(Result.DENY);
@ -195,7 +181,7 @@ public class PlayerListener implements Listener
}
}
}
}
}*/
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onPlayerChangedWorldEvent(PlayerChangedWorldEvent event)
@ -204,49 +190,17 @@ public class PlayerListener implements Listener
if (WorldGuardExtraFlagsPlugin.isEssentialsEnable()) //Essentials how dare u do this to me!?!
{
if (!WorldGuardUtils.hasBypass(player))
if (player.getGameMode() != GameMode.CREATIVE && !WorldGuardExtraFlagsPlugin.getEssentialsPlugin().getUser(player).isAuthorized("essentials.fly"))
{
if (player.getGameMode() != GameMode.CREATIVE && !WorldGuardExtraFlagsPlugin.getEssentialsPlugin().getUser(player).isAuthorized("essentials.fly"))
//Essentials now turns off flight, fuck him
Boolean value = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().get(player).getHandler(FlyFlagHandler.class).getCurrentValue();
if (value != null)
{
//Essentials now turns off flight, fuck him
try
{
player.setAllowFlight(WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().get(player).getHandler(FlyFlag.class).getCurrentValue());
}
catch(Exception ignored)
{
}
player.setAllowFlight(value);
}
}
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerJoinEvent(PlayerJoinEvent event)
{
Player player = event.getPlayer();
if (!WorldGuardUtils.hasBypass(player))
{
new BukkitRunnable()
{
@Override
public void run()
{
try
{
event.getPlayer().setAllowFlight(WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().get(player).getHandler(FlyFlag.class).getCurrentValue());
}
catch(Exception ignored)
{
}
}
}.runTaskLater(WorldGuardExtraFlagsPlugin.getPlugin(), 2);
}
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onPlayerItemDamageEvent(PlayerItemDamageEvent event)
@ -254,7 +208,7 @@ public class PlayerListener implements Listener
Player player = event.getPlayer();
ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getRegionContainer().createQuery().getApplicableRegions(player.getLocation());
if (regions.queryState(WorldGuardUtils.wrapPlayer(player), FlagUtils.ITEM_DURABILITY) == State.DENY) //Not sure should we add bypass for this
if (WorldGuardUtils.queryState(player, player.getWorld(), regions.getRegions(), Flags.ITEM_DURABILITY) == State.DENY)
{
event.setCancelled(true);
}
@ -267,10 +221,22 @@ public class PlayerListener implements Listener
ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getRegionContainer().createQuery().getApplicableRegions(player.getLocation());
Location location = regions.queryValue(WorldGuardUtils.wrapPlayer(player), FlagUtils.JOIN_LOCATION); //Not sure should we add bypass for this
Location location = WorldGuardUtils.queryValue(player, player.getWorld(), regions.getRegions(), Flags.JOIN_LOCATION);
if (location != null)
{
event.setSpawnLocation(BukkitUtil.toLocation(location));
}
}
@EventHandler(priority = EventPriority.MONITOR)
public void onPlayerSpawnLocationEventMonitor(PlayerSpawnLocationEvent event)
{
Player player = event.getPlayer();
Boolean value = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().get(player).getHandler(FlyFlagHandler.class).getCurrentValue();
if (value != null)
{
player.setAllowFlight(value);
}
}
}

View file

@ -1,19 +1,23 @@
package net.goldtreeservers.worldguardextraflags.listeners;
import com.sk89q.worldedit.bukkit.BukkitWorld;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.event.extent.EditSessionEvent;
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.flags.handlers.WorldEditFlag;
import net.goldtreeservers.worldguardextraflags.we.WorldEditFlagHandler;
public class WorldEditListener
{
@Subscribe(priority = EventHandler.Priority.VERY_EARLY)
public void onEditSessionEvent(EditSessionEvent event)
{
if (event.getActor() != null) //Not a player?
Actor actor = event.getActor();
if (actor != null && actor.isPlayer())
{
event.setExtent(new WorldEditFlag(event.getExtent(), event.getActor()));
event.setExtent(new WorldEditFlagHandler((BukkitWorld)event.getWorld(), event.getExtent(), (Player)actor));
}
}
}

View file

@ -1,5 +1,7 @@
package net.goldtreeservers.worldguardextraflags.listeners;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
@ -12,22 +14,25 @@ import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
import net.goldtreeservers.worldguardextraflags.utils.FlagUtils;
import net.goldtreeservers.worldguardextraflags.flags.Flags;
import net.goldtreeservers.worldguardextraflags.utils.WorldUtils;
public class WorldListener implements Listener
{
@EventHandler(priority = EventPriority.MONITOR)
public void onWorldLoadEvent(WorldLoadEvent event)
{
WorldGuardExtraFlagsPlugin.doUnloadChunkFlagWorldCheck(event.getWorld());
WorldUtils.doUnloadChunkFlagCheck(event.getWorld());
}
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
@EventHandler(ignoreCancelled = true)
public void onChunkUnloadEvent(ChunkUnloadEvent event)
{
for (ProtectedRegion region : WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getRegionManager(event.getWorld()).getApplicableRegions(new ProtectedCuboidRegion("UnloadChunkFlagTester", new BlockVector(event.getChunk().getX() * 16, 0, event.getChunk().getZ() * 16), new BlockVector(event.getChunk().getX() * 16 + 15, 256, event.getChunk().getZ() * 16 + 15))))
World world = event.getWorld();
Chunk chunk = event.getChunk();
for (ProtectedRegion region : WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getRegionManager(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(FlagUtils.CHUNK_UNLOAD) == State.DENY)
if (region.getFlag(Flags.CHUNK_UNLOAD) == State.DENY)
{
event.setCancelled(true);
break;

View file

@ -1,11 +0,0 @@
package net.goldtreeservers.worldguardextraflags.utils;
import com.boydti.fawe.FaweAPI;
public class PluginUtils
{
public static void registerFAWE()
{
FaweAPI.addMaskManager(new FaweWorldEditFlag());
}
}

View file

@ -0,0 +1,46 @@
package net.goldtreeservers.worldguardextraflags.utils;
import java.awt.Color;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.potion.PotionEffect;
import lombok.Getter;
/**
* Helper class to decide what features are supported by the server
*/
public class SupportedFeatures
{
@Getter private static boolean frostwalkerSupported;
@Getter private static boolean mobEffectColorsSupported;
@Getter private static boolean stopSoundSupported;
static
{
try
{
SupportedFeatures.frostwalkerSupported = Material.FROSTED_ICE != null;
}
catch (Throwable ignored)
{
}
try
{
SupportedFeatures.mobEffectColorsSupported = PotionEffect.class.getDeclaredMethod("getColor", Color.class) != null;
}
catch (Throwable ignored)
{
}
try
{
SupportedFeatures.stopSoundSupported = Player.class.getDeclaredMethod("stopSound", Color.class) != null;
}
catch (Throwable ignored)
{
}
}
}

View file

@ -1,9 +0,0 @@
package net.goldtreeservers.worldguardextraflags.utils;
public class TimeUtils
{
public static double getUnixtimestamp()
{
return System.currentTimeMillis() / 1000;
}
}

View file

@ -1,22 +0,0 @@
package net.goldtreeservers.worldguardextraflags.utils;
import org.bukkit.entity.Player;
import com.sk89q.worldguard.LocalPlayer;
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
public class WorldGuardUtils
{
public static LocalPlayer wrapPlayer(Player player)
{
return WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().wrapPlayer(player);
}
public static boolean hasBypass(Player player)
{
return WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getSessionManager().hasBypass(player, player.getWorld());
//TODO: Add flag & region specified permissions
}
}

View file

@ -0,0 +1,36 @@
package net.goldtreeservers.worldguardextraflags.utils;
import org.bukkit.Location;
import org.bukkit.World;
import com.sk89q.worldedit.bukkit.BukkitUtil;
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.getWorldGuardPlugin().getRegionManager(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");
Location min = BukkitUtil.toLocation(world, region.getMinimumPoint());
Location max = BukkitUtil.toLocation(world, region.getMaximumPoint());
for(int x = min.getChunk().getX(); x <= max.getChunk().getX(); x++)
{
for(int z = min.getChunk().getZ(); z <= max.getChunk().getZ(); z++)
{
world.getChunkAt(x, z).load(true);
}
}
}
}
}
}

View file

@ -0,0 +1,45 @@
package net.goldtreeservers.worldguardextraflags.we;
import com.sk89q.worldedit.Vector;
import com.sk89q.worldedit.WorldEditException;
import com.sk89q.worldedit.blocks.BaseBlock;
import com.sk89q.worldedit.bukkit.BukkitUtil;
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.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 AbstractDelegateExtent
{
private final BukkitWorld world;
private final Player player;
public WorldEditFlagHandler(BukkitWorld world, Extent extent, Player player)
{
super(extent);
this.world = world;
this.player = player;
}
//TODO: Prebuild list
@Override
public boolean setBlock(Vector location, BaseBlock block) throws WorldEditException
{
ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getRegionContainer().createQuery().getApplicableRegions(BukkitUtil.toLocation(this.world.getWorld(), location));
State state = WorldGuardUtils.queryState(WorldGuardExtraFlagsPlugin.getPlugin().getServer().getPlayer(this.player.getUniqueId()), this.world.getWorld(), regions.getRegions(), Flags.WORLDEDIT);
if (state != State.DENY)
{
return super.setBlock(location, block);
}
return false;
}
}

View file

@ -0,0 +1,73 @@
package net.goldtreeservers.worldguardextraflags.wg;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Set;
import org.bukkit.World;
import org.bukkit.entity.Player;
import com.sk89q.worldguard.LocalPlayer;
import com.sk89q.worldguard.protection.FlagValueCalculator;
import com.sk89q.worldguard.protection.flags.Flag;
import com.sk89q.worldguard.protection.flags.StateFlag;
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;
public class WorldGuardUtils
{
public static final String PREVENT_TELEPORT_LOOP_META = "WGEFP: TLP";
public static LocalPlayer wrapPlayer(Player player)
{
return WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().wrapPlayer(player);
}
public static boolean hasBypass(Player player, World world, ProtectedRegion region, Flag<?> flag)
{
//Permission system that supports wildcars is really helpful here :)
if (player.hasPermission("worldguard.region.bypass." + world.getName() + "." + region.getId() + "." + flag.getName()))
{
return true;
}
return false;
}
public static State queryState(Player player, World world, Set<ProtectedRegion> regions, StateFlag flag)
{
return WorldGuardUtils.createFlagValueCalculator(player, world, regions, flag).queryState(WorldGuardUtils.wrapPlayer(player), flag);
}
public static <T> T queryValue(Player player, World world, Set<ProtectedRegion> regions, Flag<T> flag)
{
return WorldGuardUtils.createFlagValueCalculator(player, world, regions, flag).queryValue(WorldGuardUtils.wrapPlayer(player), flag);
}
public static <T> Collection<T> queryAllValues(Player player, World world, Set<ProtectedRegion> regions, Flag<T> flag)
{
return WorldGuardUtils.createFlagValueCalculator(player, world, regions, flag).queryAllValues(WorldGuardUtils.wrapPlayer(player), flag);
}
public static <T> FlagValueCalculator createFlagValueCalculator(Player player, World world, Set<ProtectedRegion> regions, Flag<T> flag)
{
List<ProtectedRegion> checkForRegions = new ArrayList<>();
for(ProtectedRegion region : regions)
{
if (!WorldGuardUtils.hasBypass(player, world, region, flag))
{
checkForRegions.add(region);
}
}
NormativeOrders.sort(checkForRegions);
ProtectedRegion global = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getRegionManager(world).getRegion(ProtectedRegion.GLOBAL_REGION);
return new FlagValueCalculator(checkForRegions, global);
}
}

View file

@ -1,9 +1,10 @@
package net.goldtreeservers.worldguardextraflags.flags.handlers;
package net.goldtreeservers.worldguardextraflags.wg.handlers;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@ -16,27 +17,26 @@ import com.sk89q.worldguard.session.MoveType;
import com.sk89q.worldguard.session.Session;
import com.sk89q.worldguard.session.handler.Handler;
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
import net.goldtreeservers.worldguardextraflags.helpers.PotionEffectDetails;
import net.goldtreeservers.worldguardextraflags.utils.FlagUtils;
import net.goldtreeservers.worldguardextraflags.utils.TimeUtils;
import net.goldtreeservers.worldguardextraflags.utils.WorldGuardUtils;
import net.goldtreeservers.worldguardextraflags.flags.Flags;
import net.goldtreeservers.worldguardextraflags.flags.data.PotionEffectDetails;
import net.goldtreeservers.worldguardextraflags.utils.SupportedFeatures;
import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils;
public class BlockedEffectsFlag extends Handler
public class BlockedEffectsFlagHandler extends Handler
{
public static final Factory FACTORY = new Factory();
public static class Factory extends Handler.Factory<BlockedEffectsFlag>
public static class Factory extends Handler.Factory<BlockedEffectsFlagHandler>
{
@Override
public BlockedEffectsFlag create(Session session)
public BlockedEffectsFlagHandler create(Session session)
{
return new BlockedEffectsFlag(session);
return new BlockedEffectsFlagHandler(session);
}
}
private HashMap<PotionEffectType, PotionEffectDetails> removedEffects;
protected BlockedEffectsFlag(Session session)
protected BlockedEffectsFlagHandler(Session session)
{
super(session);
@ -46,19 +46,13 @@ public class BlockedEffectsFlag extends Handler
@Override
public void initialize(Player player, Location current, ApplicableRegionSet set)
{
if (!WorldGuardUtils.hasBypass(player))
{
this.check(player, set);
}
this.check(player, set);
}
@Override
public boolean onCrossBoundary(Player player, Location from, Location to, ApplicableRegionSet toSet, Set<ProtectedRegion> entered, Set<ProtectedRegion> exited, MoveType moveType)
{
if (!WorldGuardUtils.hasBypass(player))
{
this.check(player, toSet);
}
this.check(player, toSet);
return true;
}
@ -66,15 +60,12 @@ public class BlockedEffectsFlag extends Handler
@Override
public void tick(Player player, ApplicableRegionSet set)
{
if (!WorldGuardUtils.hasBypass(player))
{
this.check(player, set);
}
this.check(player, set);
}
private void check(Player player, ApplicableRegionSet set)
{
Set<PotionEffectType> potionEffects = set.queryValue(WorldGuardUtils.wrapPlayer(player), FlagUtils.BLOCKED_EFFECTS);
Set<PotionEffectType> potionEffects = WorldGuardUtils.queryValue(player, player.getWorld(), set.getRegions(), Flags.BLOCKED_EFFECTS);
if (potionEffects != null && potionEffects.size() > 0)
{
for (PotionEffectType effectType : potionEffects)
@ -91,14 +82,7 @@ public class BlockedEffectsFlag extends Handler
if (effect != null)
{
if (WorldGuardExtraFlagsPlugin.isSupportsMobEffectColors())
{
this.removedEffects.put(effect.getType(), new PotionEffectDetails(TimeUtils.getUnixtimestamp() + effect.getDuration() / 20, effect.getAmplifier(), effect.isAmbient(), effect.hasParticles(), effect.getColor()));
}
else
{
this.removedEffects.put(effect.getType(), new PotionEffectDetails(TimeUtils.getUnixtimestamp() + effect.getDuration() / 20, effect.getAmplifier(), effect.isAmbient(), effect.hasParticles(), null));
}
this.removedEffects.put(effect.getType(), new PotionEffectDetails(System.nanoTime() + (long)(effect.getDuration() / 20D * TimeUnit.SECONDS.toNanos(1L)), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles(), SupportedFeatures.isMobEffectColorsSupported() ? effect.getColor() : null));
player.removePotionEffect(effectType);
}
@ -118,7 +102,7 @@ public class BlockedEffectsFlag extends Handler
int timeLeft = removedEffect.getTimeLeftInTicks();
if (timeLeft > 0)
{
if (WorldGuardExtraFlagsPlugin.isSupportsMobEffectColors())
if (SupportedFeatures.isMobEffectColorsSupported())
{
player.addPotionEffect(new PotionEffect(potionEffect.getKey(), timeLeft, removedEffect.getAmplifier(), removedEffect.isAmbient(), removedEffect.isParticles(), removedEffect.getColor()), true);
}

View file

@ -0,0 +1,75 @@
package net.goldtreeservers.worldguardextraflags.wg.handlers;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.session.MoveType;
import com.sk89q.worldguard.session.Session;
import com.sk89q.worldguard.session.handler.Handler;
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
import net.goldtreeservers.worldguardextraflags.flags.Flags;
import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils;
public class CommandOnEntryFlagHandler extends Handler
{
public static final Factory FACTORY = new Factory();
public static class Factory extends Handler.Factory<CommandOnEntryFlagHandler>
{
@Override
public CommandOnEntryFlagHandler create(Session session)
{
return new CommandOnEntryFlagHandler(session);
}
}
private Collection<Set<String>> lastCommands;
protected CommandOnEntryFlagHandler(Session session)
{
super(session);
this.lastCommands = new ArrayList<>();
}
@Override
public boolean onCrossBoundary(Player player, Location from, Location to, ApplicableRegionSet toSet, Set<ProtectedRegion> entered, Set<ProtectedRegion> exited, MoveType moveType)
{
Collection<Set<String>> commands = WorldGuardUtils.queryAllValues(player, to.getWorld(), toSet.getRegions(), Flags.COMMAND_ON_ENTRY);
for(Set<String> commands_ : commands)
{
if (!this.lastCommands.contains(commands_) && commands_.size() > 0)
{
for(String command : commands_)
{
WorldGuardExtraFlagsPlugin.getPlugin().getServer().dispatchCommand(player, command.substring(1).replace("%username%", player.getName())); //TODO: Make this better
}
break;
}
}
this.lastCommands = new ArrayList<Set<String>>(commands);
if (!this.lastCommands.isEmpty())
{
for (ProtectedRegion region : toSet)
{
Set<String> commands_ = region.getFlag(Flags.COMMAND_ON_ENTRY);
if (commands_ != null)
{
this.lastCommands.add(commands_);
}
}
}
return true;
}
}

View file

@ -0,0 +1,79 @@
package net.goldtreeservers.worldguardextraflags.wg.handlers;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.session.MoveType;
import com.sk89q.worldguard.session.Session;
import com.sk89q.worldguard.session.handler.Handler;
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
import net.goldtreeservers.worldguardextraflags.flags.Flags;
import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils;
public class CommandOnExitFlagHandler extends Handler
{
public static final Factory FACTORY = new Factory();
public static class Factory extends Handler.Factory<CommandOnExitFlagHandler>
{
@Override
public CommandOnExitFlagHandler create(Session session)
{
return new CommandOnExitFlagHandler(session);
}
}
private Collection<Set<String>> lastCommands;
protected CommandOnExitFlagHandler(Session session)
{
super(session);
this.lastCommands = new ArrayList<>();
}
@Override
public void initialize(Player player, Location current, ApplicableRegionSet set)
{
this.lastCommands = WorldGuardUtils.queryAllValues(player, current.getWorld(), set.getRegions(), Flags.COMMAND_ON_EXIT);
}
@Override
public boolean onCrossBoundary(Player player, Location from, Location to, ApplicableRegionSet toSet, Set<ProtectedRegion> entered, Set<ProtectedRegion> exited, MoveType moveType)
{
Collection<Set<String>> commands = new ArrayList<Set<String>>(WorldGuardUtils.queryAllValues(player, to.getWorld(), toSet.getRegions(), Flags.COMMAND_ON_EXIT));
if (!commands.isEmpty())
{
for (ProtectedRegion region : toSet)
{
Set<String> commands_ = region.getFlag(Flags.COMMAND_ON_EXIT);
if (commands_ != null)
{
commands.add(commands_);
}
}
}
for(Set<String> commands_ : this.lastCommands)
{
if (!commands.contains(commands_) && commands_.size() > 0)
{
for(String command : commands_)
{
WorldGuardExtraFlagsPlugin.getPlugin().getServer().dispatchCommand(player, command.substring(1).replace("%username%", player.getName())); //TODO: Make this better
}
}
}
this.lastCommands = commands;
return true;
}
}

View file

@ -0,0 +1,75 @@
package net.goldtreeservers.worldguardextraflags.wg.handlers;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.session.MoveType;
import com.sk89q.worldguard.session.Session;
import com.sk89q.worldguard.session.handler.Handler;
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
import net.goldtreeservers.worldguardextraflags.flags.Flags;
import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils;
public class ConsoleCommandOnEntryFlagHandler extends Handler
{
public static final Factory FACTORY = new Factory();
public static class Factory extends Handler.Factory<ConsoleCommandOnEntryFlagHandler>
{
@Override
public ConsoleCommandOnEntryFlagHandler create(Session session)
{
return new ConsoleCommandOnEntryFlagHandler(session);
}
}
private Collection<Set<String>> lastCommands;
protected ConsoleCommandOnEntryFlagHandler(Session session)
{
super(session);
this.lastCommands = new ArrayList<>();
}
@Override
public boolean onCrossBoundary(Player player, Location from, Location to, ApplicableRegionSet toSet, Set<ProtectedRegion> entered, Set<ProtectedRegion> exited, MoveType moveType)
{
Collection<Set<String>> commands = WorldGuardUtils.queryAllValues(player, to.getWorld(), toSet.getRegions(), Flags.CONSOLE_COMMAND_ON_ENTRY);
for(Set<String> commands_ : commands)
{
if (!this.lastCommands.contains(commands_))
{
for(String command : commands_)
{
WorldGuardExtraFlagsPlugin.getPlugin().getServer().dispatchCommand(WorldGuardExtraFlagsPlugin.getPlugin().getServer().getConsoleSender(), command.substring(1).replace("%username%", player.getName())); //TODO: Make this better
}
break;
}
}
this.lastCommands = new ArrayList<Set<String>>(commands);
if (!this.lastCommands.isEmpty())
{
for (ProtectedRegion region : toSet)
{
Set<String> commands_ = region.getFlag(Flags.CONSOLE_COMMAND_ON_ENTRY);
if (commands_ != null)
{
this.lastCommands.add(commands_);
}
}
}
return true;
}
}

View file

@ -0,0 +1,81 @@
package net.goldtreeservers.worldguardextraflags.wg.handlers;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.session.MoveType;
import com.sk89q.worldguard.session.Session;
import com.sk89q.worldguard.session.handler.Handler;
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
import net.goldtreeservers.worldguardextraflags.flags.Flags;
import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils;
public class ConsoleCommandOnExitFlagHandler extends Handler
{
public static final Factory FACTORY = new Factory();
public static class Factory extends Handler.Factory<ConsoleCommandOnExitFlagHandler>
{
@Override
public ConsoleCommandOnExitFlagHandler create(Session session)
{
return new ConsoleCommandOnExitFlagHandler(session);
}
}
private Collection<Set<String>> lastCommands;
protected ConsoleCommandOnExitFlagHandler(Session session)
{
super(session);
this.lastCommands = new ArrayList<>();
}
@Override
public void initialize(Player player, Location current, ApplicableRegionSet set)
{
this.lastCommands = WorldGuardUtils.queryAllValues(player, current.getWorld(), set.getRegions(), Flags.CONSOLE_COMMAND_ON_EXIT);
}
@Override
public boolean onCrossBoundary(Player player, Location from, Location to, ApplicableRegionSet toSet, Set<ProtectedRegion> entered, Set<ProtectedRegion> exited, MoveType moveType)
{
Collection<Set<String>> commands = new ArrayList<Set<String>>(WorldGuardUtils.queryAllValues(player, to.getWorld(), toSet.getRegions(), Flags.CONSOLE_COMMAND_ON_EXIT));
if (!commands.isEmpty())
{
for (ProtectedRegion region : toSet)
{
Set<String> commands_ = region.getFlag(Flags.CONSOLE_COMMAND_ON_EXIT);
if (commands_ != null)
{
commands.add(commands_);
}
}
}
for(Set<String> commands_ : this.lastCommands)
{
if (!commands.contains(commands_))
{
for(String command : commands_)
{
WorldGuardExtraFlagsPlugin.getPlugin().getServer().dispatchCommand(WorldGuardExtraFlagsPlugin.getPlugin().getServer().getConsoleSender(), command.substring(1).replace("%username%", player.getName())); //TODO: Make this better
}
break;
}
}
this.lastCommands = commands;
return true;
}
}

View file

@ -0,0 +1,81 @@
package net.goldtreeservers.worldguardextraflags.wg.handlers;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.StateFlag.State;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.session.MoveType;
import com.sk89q.worldguard.session.Session;
import com.sk89q.worldguard.session.handler.Handler;
import lombok.Getter;
import net.goldtreeservers.worldguardextraflags.flags.Flags;
import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils;
public class FlyFlagHandler extends Handler
{
public static final Factory FACTORY = new Factory();
public static class Factory extends Handler.Factory<FlyFlagHandler>
{
@Override
public FlyFlagHandler create(Session session)
{
return new FlyFlagHandler(session);
}
}
@Getter private Boolean currentValue;
private Boolean originalFly;
protected FlyFlagHandler(Session session)
{
super(session);
}
@Override
public void initialize(Player player, Location current, ApplicableRegionSet set)
{
State state = WorldGuardUtils.queryState(player, current.getWorld(), set.getRegions(), Flags.FLY);
this.handleValue(player, state);
}
@Override
public boolean onCrossBoundary(Player player, Location from, Location to, ApplicableRegionSet toSet, Set<ProtectedRegion> entered, Set<ProtectedRegion> exited, MoveType moveType)
{
State state = WorldGuardUtils.queryState(player, to.getWorld(), toSet.getRegions(), Flags.FLY);
this.handleValue(player, state);
return true;
}
private void handleValue(Player player, State state)
{
if (state != null)
{
boolean value = (state == State.ALLOW ? true : false);
if (player.getAllowFlight() != value)
{
if (this.originalFly == null)
{
this.originalFly = player.getAllowFlight();
}
player.setAllowFlight(value);
}
}
else
{
if (this.originalFly != null)
{
player.setAllowFlight(this.originalFly);
this.originalFly = null;
}
}
}
}

View file

@ -1,11 +1,13 @@
package net.goldtreeservers.worldguardextraflags.flags.handlers;
package net.goldtreeservers.worldguardextraflags.wg.handlers;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.bukkit.Location;
import org.bukkit.entity.Player;
@ -19,27 +21,27 @@ import com.sk89q.worldguard.session.Session;
import com.sk89q.worldguard.session.handler.Handler;
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
import net.goldtreeservers.worldguardextraflags.helpers.PotionEffectDetails;
import net.goldtreeservers.worldguardextraflags.utils.FlagUtils;
import net.goldtreeservers.worldguardextraflags.utils.TimeUtils;
import net.goldtreeservers.worldguardextraflags.utils.WorldGuardUtils;
import net.goldtreeservers.worldguardextraflags.flags.Flags;
import net.goldtreeservers.worldguardextraflags.flags.data.PotionEffectDetails;
import net.goldtreeservers.worldguardextraflags.utils.SupportedFeatures;
import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils;
public class GiveEffectsFlag extends Handler
public class GiveEffectsFlagHandler extends Handler
{
public static final Factory FACTORY = new Factory();
public static class Factory extends Handler.Factory<GiveEffectsFlag>
public static class Factory extends Handler.Factory<GiveEffectsFlagHandler>
{
@Override
public GiveEffectsFlag create(Session session)
public GiveEffectsFlagHandler create(Session session)
{
return new GiveEffectsFlag(session);
return new GiveEffectsFlagHandler(session);
}
}
private HashMap<PotionEffectType, PotionEffectDetails> removedEffects;
private HashSet<PotionEffectType> givenEffects;
private Map<PotionEffectType, PotionEffectDetails> removedEffects;
private Set<PotionEffectType> givenEffects;
protected GiveEffectsFlag(Session session)
protected GiveEffectsFlagHandler(Session session)
{
super(session);
@ -50,19 +52,13 @@ public class GiveEffectsFlag extends Handler
@Override
public void initialize(Player player, Location current, ApplicableRegionSet set)
{
if (!WorldGuardUtils.hasBypass(player))
{
this.check(player, set);
}
this.check(player, set);
}
@Override
public boolean onCrossBoundary(Player player, Location from, Location to, ApplicableRegionSet toSet, Set<ProtectedRegion> entered, Set<ProtectedRegion> exited, MoveType moveType)
{
if (!WorldGuardUtils.hasBypass(player))
{
this.check(player, toSet);
}
this.check(player, toSet);
return true;
}
@ -70,15 +66,12 @@ public class GiveEffectsFlag extends Handler
@Override
public void tick(Player player, ApplicableRegionSet set)
{
if (!WorldGuardUtils.hasBypass(player))
{
this.check(player, set);
}
this.check(player, set);
}
private void check(Player player, ApplicableRegionSet set)
{
Set<PotionEffect> potionEffects = set.queryValue(WorldGuardUtils.wrapPlayer(player), FlagUtils.GIVE_EFFECTS);
Set<PotionEffect> potionEffects = WorldGuardUtils.queryValue(player, player.getWorld(), set.getRegions(), Flags.GIVE_EFFECTS);
if (potionEffects != null && potionEffects.size() > 0)
{
for (PotionEffect effect : potionEffects)
@ -95,14 +88,7 @@ public class GiveEffectsFlag extends Handler
if (this.givenEffects.add(effect.getType()) && effect_ != null)
{
if (WorldGuardExtraFlagsPlugin.isSupportsMobEffectColors())
{
this.removedEffects.put(effect_.getType(), new PotionEffectDetails(TimeUtils.getUnixtimestamp() + effect_.getDuration() / 20, effect_.getAmplifier(), effect_.isAmbient(), effect_.hasParticles(), effect_.getColor()));
}
else
{
this.removedEffects.put(effect_.getType(), new PotionEffectDetails(TimeUtils.getUnixtimestamp() + effect_.getDuration() / 20, effect_.getAmplifier(), effect_.isAmbient(), effect_.hasParticles(), null));
}
this.removedEffects.put(effect_.getType(), new PotionEffectDetails(System.nanoTime() + (long)(effect.getDuration() / 20D * TimeUnit.SECONDS.toNanos(1L)), effect_.getAmplifier(), effect_.isAmbient(), effect_.hasParticles(), SupportedFeatures.isMobEffectColorsSupported() ? effect_.getColor() : null));
player.removePotionEffect(effect_.getType());
}
@ -152,7 +138,7 @@ public class GiveEffectsFlag extends Handler
if (timeLeft > 0)
{
if (WorldGuardExtraFlagsPlugin.isSupportsMobEffectColors())
if (SupportedFeatures.isMobEffectColorsSupported())
{
player.addPotionEffect(new PotionEffect(effect.getKey(), timeLeft, removedEffect.getAmplifier(), removedEffect.isAmbient(), removedEffect.isParticles(), removedEffect.getColor()), true);
}
@ -179,14 +165,7 @@ public class GiveEffectsFlag extends Handler
{
for(PotionEffect effect : effects)
{
if (WorldGuardExtraFlagsPlugin.isSupportsMobEffectColors())
{
this.removedEffects.put(effect.getType(), new PotionEffectDetails(TimeUtils.getUnixtimestamp() + effect.getDuration() / 20, effect.getAmplifier(), effect.isAmbient(), effect.hasParticles(), effect.getColor()));
}
else
{
this.removedEffects.put(effect.getType(), new PotionEffectDetails(TimeUtils.getUnixtimestamp() + effect.getDuration() / 20, effect.getAmplifier(), effect.isAmbient(), effect.hasParticles(), null));
}
this.removedEffects.put(effect.getType(), new PotionEffectDetails(System.nanoTime() + (long)(effect.getDuration() / 20D * TimeUnit.SECONDS.toNanos(1L)), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles(), SupportedFeatures.isMobEffectColorsSupported() ? effect.getColor() : null));
}
this.check(player, WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getRegionContainer().createQuery().getApplicableRegions(player.getLocation()));

View file

@ -0,0 +1,79 @@
package net.goldtreeservers.worldguardextraflags.wg.handlers;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.StateFlag.State;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.session.MoveType;
import com.sk89q.worldguard.session.Session;
import com.sk89q.worldguard.session.handler.Handler;
import net.goldtreeservers.worldguardextraflags.flags.Flags;
import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils;
public class GlideFlagHandler extends Handler
{
public static final Factory FACTORY = new Factory();
public static class Factory extends Handler.Factory<GlideFlagHandler>
{
@Override
public GlideFlagHandler create(Session session)
{
return new GlideFlagHandler(session);
}
}
private Boolean originalGlide;
protected GlideFlagHandler(Session session)
{
super(session);
}
@Override
public void initialize(Player player, Location current, ApplicableRegionSet set)
{
State state = WorldGuardUtils.queryState(player, current.getWorld(), set.getRegions(), Flags.GLIDE);
this.handleValue(player, state);
}
@Override
public boolean onCrossBoundary(Player player, Location from, Location to, ApplicableRegionSet toSet, Set<ProtectedRegion> entered, Set<ProtectedRegion> exited, MoveType moveType)
{
State state = WorldGuardUtils.queryState(player, to.getWorld(), toSet.getRegions(), Flags.GLIDE);
this.handleValue(player, state);
return true;
}
private void handleValue(Player player, State state)
{
if (state != null)
{
boolean value = (state == State.ALLOW ? true : false);
if (player.isGliding() != value)
{
if (this.originalGlide == null)
{
this.originalGlide = player.isGliding();
}
player.setGliding(value);
}
}
else
{
if (this.originalGlide != null)
{
player.setGliding(this.originalGlide);
this.originalGlide = null;
}
}
}
}

View file

@ -0,0 +1,83 @@
package net.goldtreeservers.worldguardextraflags.wg.handlers;
import javax.annotation.Nullable;
import org.bukkit.entity.Player;
import com.earth2me.essentials.User;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.flags.StateFlag.State;
import com.sk89q.worldguard.session.Session;
import com.sk89q.worldguard.session.handler.Handler;
import lombok.Getter;
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
import net.goldtreeservers.worldguardextraflags.flags.Flags;
import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils;
public class GodmodeFlagHandler extends Handler
{
public static final Factory FACTORY = new Factory();
public static class Factory extends Handler.Factory<GodmodeFlagHandler>
{
@Override
public GodmodeFlagHandler create(Session session)
{
return new GodmodeFlagHandler(session);
}
}
@Getter private Boolean isGodmodeEnabled;
private Boolean originalEssentialsGodmode;
protected GodmodeFlagHandler(Session session)
{
super(session);
}
@Nullable
@Override
public State getInvincibility(Player player)
{
ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuardPlugin().getRegionContainer().createQuery().getApplicableRegions(player.getLocation());
State state = WorldGuardUtils.queryState(player, player.getWorld(), regions.getRegions(), Flags.GODMODE);
if (state != null)
{
this.isGodmodeEnabled = (state == State.ALLOW ? true : false);
}
else
{
this.isGodmodeEnabled = null;
}
if (WorldGuardExtraFlagsPlugin.isEssentialsEnable())
{
User user = WorldGuardExtraFlagsPlugin.getEssentialsPlugin().getUser(player);
if (this.isGodmodeEnabled != null)
{
if (this.isGodmodeEnabled != user.isGodModeEnabled())
{
if (this.originalEssentialsGodmode == null)
{
this.originalEssentialsGodmode = user.isGodModeEnabled();
}
user.setGodModeEnabled(this.isGodmodeEnabled);
}
}
else
{
if (this.originalEssentialsGodmode != null)
{
user.setGodModeEnabled(this.isGodmodeEnabled);
this.originalEssentialsGodmode = null;
}
}
}
return state;
}
}

View file

@ -1,7 +1,8 @@
package net.goldtreeservers.worldguardextraflags.flags.handlers;
package net.goldtreeservers.worldguardextraflags.wg.handlers;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
@ -16,25 +17,26 @@ import com.sk89q.worldguard.session.Session;
import com.sk89q.worldguard.session.handler.Handler;
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
import net.goldtreeservers.worldguardextraflags.utils.FlagUtils;
import net.goldtreeservers.worldguardextraflags.utils.SoundData;
import net.goldtreeservers.worldguardextraflags.utils.WorldGuardUtils;
import net.goldtreeservers.worldguardextraflags.flags.Flags;
import net.goldtreeservers.worldguardextraflags.flags.data.SoundData;
import net.goldtreeservers.worldguardextraflags.utils.SupportedFeatures;
import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils;
public class PlaySoundsFlag extends Handler
public class PlaySoundsFlagHandler extends Handler
{
public static final Factory FACTORY = new Factory();
public static class Factory extends Handler.Factory<PlaySoundsFlag>
public static class Factory extends Handler.Factory<PlaySoundsFlagHandler>
{
@Override
public PlaySoundsFlag create(Session session)
public PlaySoundsFlagHandler create(Session session)
{
return new PlaySoundsFlag(session);
return new PlaySoundsFlagHandler(session);
}
}
private HashMap<String, BukkitRunnable> runnables;
private Map<String, BukkitRunnable> runnables;
protected PlaySoundsFlag(Session session)
protected PlaySoundsFlagHandler(Session session)
{
super(session);
@ -44,34 +46,25 @@ public class PlaySoundsFlag extends Handler
@Override
public void initialize(Player player, Location current, ApplicableRegionSet set)
{
if (!WorldGuardUtils.hasBypass(player))
{
this.check(player, set);
}
this.check(player, set);
}
@Override
public boolean onCrossBoundary(Player player, Location from, Location to, ApplicableRegionSet toSet, Set<ProtectedRegion> entered, Set<ProtectedRegion> exited, MoveType moveType)
{
if (!WorldGuardUtils.hasBypass(player))
{
this.check(player, toSet);
}
this.check(player, toSet);
return true;
}
public void tick(Player player, ApplicableRegionSet set)
{
if (!WorldGuardUtils.hasBypass(player))
{
this.check(player, set);
}
this.check(player, set);
}
private void check(Player player, ApplicableRegionSet set)
{
Set<SoundData> soundData = set.queryValue(WorldGuardUtils.wrapPlayer(player), FlagUtils.PLAY_SOUNDS);
Set<SoundData> soundData = WorldGuardUtils.queryValue(player, player.getWorld(), set.getRegions(), Flags.PLAY_SOUNDS);
if (soundData != null && soundData.size() > 0)
{
for(SoundData sound : soundData)
@ -91,7 +84,7 @@ public class PlaySoundsFlag extends Handler
{
super.cancel();
if (WorldGuardExtraFlagsPlugin.isSupportsStopSound())
if (SupportedFeatures.isStopSoundSupported())
{
player.stopSound(sound.getSound());
}

View file

@ -1,4 +1,4 @@
package net.goldtreeservers.worldguardextraflags.flags.handlers;
package net.goldtreeservers.worldguardextraflags.wg.handlers;
import java.util.Set;
@ -14,22 +14,22 @@ import com.sk89q.worldguard.session.Session;
import com.sk89q.worldguard.session.handler.Handler;
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
import net.goldtreeservers.worldguardextraflags.utils.FlagUtils;
import net.goldtreeservers.worldguardextraflags.utils.WorldGuardUtils;
import net.goldtreeservers.worldguardextraflags.flags.Flags;
import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils;
public class TeleportOnEntryFlag extends Handler
public class TeleportOnEntryFlagHandler extends Handler
{
public static final Factory FACTORY = new Factory();
public static class Factory extends Handler.Factory<TeleportOnEntryFlag>
public static class Factory extends Handler.Factory<TeleportOnEntryFlagHandler>
{
@Override
public TeleportOnEntryFlag create(Session session)
public TeleportOnEntryFlagHandler create(Session session)
{
return new TeleportOnEntryFlag(session);
return new TeleportOnEntryFlagHandler(session);
}
}
protected TeleportOnEntryFlag(Session session)
protected TeleportOnEntryFlagHandler(Session session)
{
super(session);
}
@ -38,16 +38,15 @@ public class TeleportOnEntryFlag extends Handler
@Override
public boolean onCrossBoundary(Player player, Location from, Location to, ApplicableRegionSet toSet, Set<ProtectedRegion> entered, Set<ProtectedRegion> exited, MoveType moveType)
{
if (!WorldGuardUtils.hasBypass(player))
if (!player.hasMetadata(WorldGuardUtils.PREVENT_TELEPORT_LOOP_META))
{
if (!player.hasMetadata("WGEFP-TPOEF"))
com.sk89q.worldedit.Location location = WorldGuardUtils.queryValue(player, to.getWorld(), entered, Flags.TELEPORT_ON_ENTRY);
if (location != null)
{
com.sk89q.worldedit.Location location = toSet.queryValue(WorldGuardUtils.wrapPlayer(player), FlagUtils.TELEPORT_ON_ENTRY);
if (location != null)
{
player.setMetadata("WGEFP-TPOEF", new FixedMetadataValue(WorldGuardExtraFlagsPlugin.getPlugin(), null));
player.teleport(BukkitUtil.toLocation(location));
}
player.setMetadata(WorldGuardUtils.PREVENT_TELEPORT_LOOP_META, new FixedMetadataValue(WorldGuardExtraFlagsPlugin.getPlugin(), true));
player.teleport(BukkitUtil.toLocation(location));
return false;
}
}

View file

@ -1,4 +1,4 @@
package net.goldtreeservers.worldguardextraflags.flags.handlers;
package net.goldtreeservers.worldguardextraflags.wg.handlers;
import java.util.Set;
@ -14,22 +14,22 @@ import com.sk89q.worldguard.session.Session;
import com.sk89q.worldguard.session.handler.Handler;
import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin;
import net.goldtreeservers.worldguardextraflags.utils.FlagUtils;
import net.goldtreeservers.worldguardextraflags.utils.WorldGuardUtils;
import net.goldtreeservers.worldguardextraflags.flags.Flags;
import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils;
public class TeleportOnExitFlag extends Handler
public class TeleportOnExitFlagHandler extends Handler
{
public static final Factory FACTORY = new Factory();
public static class Factory extends Handler.Factory<TeleportOnExitFlag>
public static class Factory extends Handler.Factory<TeleportOnExitFlagHandler>
{
@Override
public TeleportOnExitFlag create(Session session)
public TeleportOnExitFlagHandler create(Session session)
{
return new TeleportOnExitFlag(session);
return new TeleportOnExitFlagHandler(session);
}
}
protected TeleportOnExitFlag(Session session)
protected TeleportOnExitFlagHandler(Session session)
{
super(session);
}
@ -38,21 +38,15 @@ public class TeleportOnExitFlag extends Handler
@Override
public boolean onCrossBoundary(Player player, Location from, Location to, ApplicableRegionSet toSet, Set<ProtectedRegion> entered, Set<ProtectedRegion> exited, MoveType moveType)
{
if (!WorldGuardUtils.hasBypass(player))
if (!player.hasMetadata(WorldGuardUtils.PREVENT_TELEPORT_LOOP_META))
{
if (!player.hasMetadata("WGEFP-TPOEF"))
com.sk89q.worldedit.Location location = WorldGuardUtils.queryValue(player, to.getWorld(), exited, Flags.TELEPORT_ON_EXIT);
if (location != null)
{
for (ProtectedRegion exitd : exited)
{
com.sk89q.worldedit.Location location = exitd.getFlag(FlagUtils.TELEPORT_ON_EXIT);
if (location != null)
{
player.setMetadata("WGEFP-TPOEF", new FixedMetadataValue(WorldGuardExtraFlagsPlugin.getPlugin(), null));
player.teleport(BukkitUtil.toLocation(location));
break;
}
}
player.setMetadata(WorldGuardUtils.PREVENT_TELEPORT_LOOP_META, new FixedMetadataValue(WorldGuardExtraFlagsPlugin.getPlugin(), true));
player.teleport(BukkitUtil.toLocation(location));
return false;
}
}

View file

@ -0,0 +1,85 @@
package net.goldtreeservers.worldguardextraflags.wg.handlers;
import java.util.Set;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import com.sk89q.worldguard.protection.ApplicableRegionSet;
import com.sk89q.worldguard.protection.regions.ProtectedRegion;
import com.sk89q.worldguard.session.MoveType;
import com.sk89q.worldguard.session.Session;
import com.sk89q.worldguard.session.handler.Handler;
import net.goldtreeservers.worldguardextraflags.flags.Flags;
import net.goldtreeservers.worldguardextraflags.wg.WorldGuardUtils;
public class WalkSpeedFlagHandler extends Handler
{
public static final Factory FACTORY = new Factory();
public static class Factory extends Handler.Factory<WalkSpeedFlagHandler>
{
@Override
public WalkSpeedFlagHandler create(Session session)
{
return new WalkSpeedFlagHandler(session);
}
}
private Float originalWalkSpeed;
protected WalkSpeedFlagHandler(Session session)
{
super(session);
}
@Override
public void initialize(Player player, Location current, ApplicableRegionSet set)
{
Double speed = WorldGuardUtils.queryValue(player, current.getWorld(), set.getRegions(), Flags.WALK_SPEED);
this.handleValue(player, speed);
}
@Override
public boolean onCrossBoundary(Player player, Location from, Location to, ApplicableRegionSet toSet, Set<ProtectedRegion> entered, Set<ProtectedRegion> exited, MoveType moveType)
{
Double speed = WorldGuardUtils.queryValue(player, to.getWorld(), toSet.getRegions(), Flags.WALK_SPEED);
this.handleValue(player, speed);
return true;
}
private void handleValue(Player player, Double speed)
{
if (speed != null)
{
if (speed > 1.0)
{
speed = 1.0;
}
else if (speed < -1.0)
{
speed = -1.0;
}
if (player.getWalkSpeed() != speed.floatValue())
{
if (this.originalWalkSpeed == null)
{
this.originalWalkSpeed = player.getWalkSpeed();
}
player.setWalkSpeed(speed.floatValue());
}
}
else
{
if (this.originalWalkSpeed != null)
{
player.setWalkSpeed(this.originalWalkSpeed);
this.originalWalkSpeed = null;
}
}
}
}

View file

@ -1,6 +1,6 @@
name: WorldGuardExtraFlags
version: 2.14.3
description: Adds more flags to worldguard to help manage your server easily!
version: 3.0.0
description: Adds more flags to WorldGuard to help manage your server easily!
author: isokissa3
website: https://goldtreevers.net
depend: [ WorldGuard ]