commit 09eae2ac3c0caf5f21e88d5ce57b1304b99966b3 Author: isokissa3 Date: Mon Dec 12 21:33:07 2016 +0200 Intial commit diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..9b0caac --- /dev/null +++ b/pom.xml @@ -0,0 +1,88 @@ + + 4.0.0 + net.goldtreeservers + worldguardextraflags + 2.11.0 + WorldGuardExtraFlags + + + WorldGuardExtraFlagsPlugin + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + 1.8 + 1.8 + + + + + + + + spigot-repo + https://hub.spigotmc.org/nexus/content/repositories/snapshots/ + + + sk89q-repo + https://maven.sk89q.com/repo/ + + + ess-repo + http://repo.ess3.net/content/groups/essentials + + + + + + + org.spigotmc + spigot + 1.10.2 + provided + + + + org.spigotmc + spigot-api + 1.10.2-R0.1-SNAPSHOT + provided + + + + org.bukkit + bukkit + 1.10.2-R0.1-SNAPSHOT + provided + + + + com.sk89q.worldguard + worldguard-legacy + LATEST + provided + + + com.connorlinfoot + TitleAPI + 1.7.4 + + + net.elseland.xikage + MythicMobs + 2.4.5 + + + com.boydti + fawe-api + 3.5.1 + + + net.ess3 + Essentials + 2.13-SNAPSHOT + + + \ No newline at end of file diff --git a/src/main/java/net/goldtreeservers/worldguardextraflags/WorldGuardExtraFlagsPlugin.java b/src/main/java/net/goldtreeservers/worldguardextraflags/WorldGuardExtraFlagsPlugin.java new file mode 100644 index 0000000..57f752d --- /dev/null +++ b/src/main/java/net/goldtreeservers/worldguardextraflags/WorldGuardExtraFlagsPlugin.java @@ -0,0 +1,213 @@ +package net.goldtreeservers.worldguardextraflags; + +import org.bukkit.plugin.Plugin; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import com.earth2me.essentials.Essentials; +import com.sk89q.worldedit.bukkit.WorldEditPlugin; +import com.sk89q.worldguard.bukkit.WorldGuardPlugin; +import com.sk89q.worldguard.protection.flags.BooleanFlag; +import com.sk89q.worldguard.protection.flags.CommandStringFlag; +import com.sk89q.worldguard.protection.flags.DoubleFlag; +import com.sk89q.worldguard.protection.flags.LocationFlag; +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.BlockedEffectsFlag; +import net.goldtreeservers.worldguardextraflags.flags.CaseForcedStringFlag; +import net.goldtreeservers.worldguardextraflags.flags.CommandOnEntryFlag; +import net.goldtreeservers.worldguardextraflags.flags.CommandOnExitFlag; +import net.goldtreeservers.worldguardextraflags.flags.ConsoleCommandOnEntryFlag; +import net.goldtreeservers.worldguardextraflags.flags.ConsoleCommandOnExitFlag; +import net.goldtreeservers.worldguardextraflags.flags.CustomSetFlag; +import net.goldtreeservers.worldguardextraflags.flags.FlyFlag; +import net.goldtreeservers.worldguardextraflags.flags.GiveEffectsFlag; +import net.goldtreeservers.worldguardextraflags.flags.GlideFlag; +import net.goldtreeservers.worldguardextraflags.flags.GodmodeFlag; +import net.goldtreeservers.worldguardextraflags.flags.PlaySoundsFlag; +import net.goldtreeservers.worldguardextraflags.flags.PotionEffectFlag; +import net.goldtreeservers.worldguardextraflags.flags.PotionEffectTypeFlag; +import net.goldtreeservers.worldguardextraflags.flags.SoundDataFlag; +import net.goldtreeservers.worldguardextraflags.flags.TeleportOnEntryFlag; +import net.goldtreeservers.worldguardextraflags.flags.TeleportOnExitFlag; +import net.goldtreeservers.worldguardextraflags.flags.WalkSpeedFlag; +import net.goldtreeservers.worldguardextraflags.listeners.BlockListener; +import net.goldtreeservers.worldguardextraflags.listeners.EntityListener; +import net.goldtreeservers.worldguardextraflags.listeners.EssentialsListener; +import net.goldtreeservers.worldguardextraflags.listeners.PlayerListener; +import net.goldtreeservers.worldguardextraflags.listeners.WorldEditListener; +import net.goldtreeservers.worldguardextraflags.utils.PluginUtils; +import net.goldtreeservers.worldguardextraflags.utils.SoundData; + +public class WorldGuardExtraFlagsPlugin extends JavaPlugin +{ + private static WorldGuardExtraFlagsPlugin plugin; + private static WorldGuardPlugin worldGuardPlugin; + private static WorldEditPlugin worldEditPlugin; + private static Essentials essentialsPlugin; + private static boolean mythicMobsEnabled; + private static boolean supportFrostwalker; + private static boolean fastAsyncWorldEditEnabled; + private static boolean essentialsEnabled; + + public final static LocationFlag teleportOnEntry = new LocationFlag("teleport-on-entry"); + public final static LocationFlag teleportOnExit = new LocationFlag("teleport-on-exit"); + public final static CustomSetFlag commandOnEntry = new CustomSetFlag("command-on-entry", new CommandStringFlag(null)); + public final static CustomSetFlag commandOnExit = new CustomSetFlag("command-on-exit", new CommandStringFlag(null)); + public final static CustomSetFlag consoleCommandOnEntry = new CustomSetFlag("console-command-on-entry", new CommandStringFlag(null)); + public final static CustomSetFlag consoleCommandOnExit = new CustomSetFlag("console-command-on-exit", new CommandStringFlag(null)); + public final static DoubleFlag walkSpeed = new DoubleFlag("walk-speed"); + public final static BooleanFlag keepInventory = new BooleanFlag("keep-inventory"); + public final static BooleanFlag keepExp = new BooleanFlag("keep-exp"); + public final static StringFlag chatPrefix = new StringFlag("chat-prefix"); + public final static StringFlag chatSuffix = new StringFlag("chat-suffix"); + public final static SetFlag blockedEffects = new SetFlag("blocked-effects", new PotionEffectTypeFlag(null)); + public final static StateFlag godmode = new StateFlag("godmode", false); + public final static LocationFlag respawnLocation = new LocationFlag("respawn-location"); + public final static StateFlag worldEdit = new StateFlag("worldedit", true); + public final static SetFlag giveEffects = new SetFlag("give-effects", new PotionEffectFlag(null)); + public final static StateFlag fly = new StateFlag("fly", false); + public final static SetFlag playSounds = new SetFlag("play-sounds", new SoundDataFlag(null)); + public final static StateFlag mythicMobsEggs = new StateFlag("mythicmobs-eggs", true); + public final static StateFlag frostwalker = new StateFlag("frostwalker", true); + public final static StateFlag netherPortals = new StateFlag("nether-portals", true); + public final static SetFlag allowBlockPlace = new SetFlag("allow-block-place", new CaseForcedStringFlag(null, true)); + public final static SetFlag denyBlockPlace = new SetFlag("deny-block-place", new CaseForcedStringFlag(null, true)); + public final static SetFlag allowBlockBreak = new SetFlag("allow-block-break", new CaseForcedStringFlag(null, true)); + public final static SetFlag denyBlockBreak = new SetFlag("deny-block-break", new CaseForcedStringFlag(null, true)); + public final static StateFlag glide = new StateFlag("glide", false); + + public WorldGuardExtraFlagsPlugin() + { + WorldGuardExtraFlagsPlugin.plugin = this; + + String a = getServer().getClass().getPackage().getName(); + String version = a.substring(a.lastIndexOf('.') + 1); + if (version.equalsIgnoreCase("v1_10_R1") || version.equalsIgnoreCase("v1_9_R1")) + { + WorldGuardExtraFlagsPlugin.supportFrostwalker = true; + } + } + + @Override + public void onLoad() + { + WorldGuardExtraFlagsPlugin.worldEditPlugin = (WorldEditPlugin) this.getServer().getPluginManager().getPlugin("WorldEdit"); + + WorldGuardExtraFlagsPlugin.worldGuardPlugin = (WorldGuardPlugin) this.getServer().getPluginManager().getPlugin("WorldGuard"); + WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(WorldGuardExtraFlagsPlugin.teleportOnEntry); + WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(WorldGuardExtraFlagsPlugin.teleportOnExit); + WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(WorldGuardExtraFlagsPlugin.commandOnEntry); + WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(WorldGuardExtraFlagsPlugin.commandOnExit); + WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(WorldGuardExtraFlagsPlugin.consoleCommandOnEntry); + WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(WorldGuardExtraFlagsPlugin.consoleCommandOnExit); + WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(WorldGuardExtraFlagsPlugin.walkSpeed); + WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(WorldGuardExtraFlagsPlugin.keepInventory); + WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(WorldGuardExtraFlagsPlugin.keepExp); + WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(WorldGuardExtraFlagsPlugin.chatPrefix); + WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(WorldGuardExtraFlagsPlugin.chatSuffix); + WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(WorldGuardExtraFlagsPlugin.blockedEffects); + WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(WorldGuardExtraFlagsPlugin.godmode); + WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(WorldGuardExtraFlagsPlugin.respawnLocation); + WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(WorldGuardExtraFlagsPlugin.worldEdit); + WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(WorldGuardExtraFlagsPlugin.giveEffects); + WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(WorldGuardExtraFlagsPlugin.fly); + WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(WorldGuardExtraFlagsPlugin.playSounds); + WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(WorldGuardExtraFlagsPlugin.mythicMobsEggs); + WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(WorldGuardExtraFlagsPlugin.frostwalker); + WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(WorldGuardExtraFlagsPlugin.netherPortals); + WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(WorldGuardExtraFlagsPlugin.allowBlockPlace); + WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(WorldGuardExtraFlagsPlugin.denyBlockPlace); + WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(WorldGuardExtraFlagsPlugin.allowBlockBreak); + WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(WorldGuardExtraFlagsPlugin.denyBlockBreak); + WorldGuardExtraFlagsPlugin.worldGuardPlugin.getFlagRegistry().register(WorldGuardExtraFlagsPlugin.glide); + } + + @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); + + this.getServer().getPluginManager().registerEvents(new PlayerListener(), this); + this.getServer().getPluginManager().registerEvents(new BlockListener(), this); + this.getServer().getPluginManager().registerEvents(new EntityListener(), this); + + 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"); + WorldGuardExtraFlagsPlugin.essentialsEnabled = this.getServer().getPluginManager().isPluginEnabled("Essentials"); + + if (WorldGuardExtraFlagsPlugin.fastAsyncWorldEditEnabled) + { + PluginUtils.registerFAWE(); + } + else + { + WorldGuardExtraFlagsPlugin.worldEditPlugin.getWorldEdit().getEventBus().register(new WorldEditListener()); + } + + if (WorldGuardExtraFlagsPlugin.essentialsEnabled) + { + this.getServer().getPluginManager().registerEvents(new EssentialsListener(), this); + } + } + + public static WorldGuardExtraFlagsPlugin getPlugin() + { + return WorldGuardExtraFlagsPlugin.plugin; + } + + public static WorldGuardPlugin getWorldGuard() + { + return WorldGuardExtraFlagsPlugin.worldGuardPlugin; + } + + public static WorldEditPlugin getWorldEditPlugin() + { + return WorldGuardExtraFlagsPlugin.worldEditPlugin; + } + + public static boolean isMythicMobsEnabled() + { + return WorldGuardExtraFlagsPlugin.mythicMobsEnabled; + } + + public static boolean isSupportingFrostwalker() + { + return WorldGuardExtraFlagsPlugin.supportFrostwalker; + } + + public static boolean isFastAsyncWorldEditEnabled() + { + return WorldGuardExtraFlagsPlugin.fastAsyncWorldEditEnabled; + } + + public static boolean isEssentialsEnabled() + { + return WorldGuardExtraFlagsPlugin.essentialsEnabled; + } + + public static Essentials getEssentialsPlugin() + { + return WorldGuardExtraFlagsPlugin.essentialsPlugin; + } +} diff --git a/src/main/java/net/goldtreeservers/worldguardextraflags/flags/BlockedEffectsFlag.java b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/BlockedEffectsFlag.java new file mode 100644 index 0000000..f829ed6 --- /dev/null +++ b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/BlockedEffectsFlag.java @@ -0,0 +1,51 @@ +package net.goldtreeservers.worldguardextraflags.flags; + +import java.util.Set; + +import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffectType; + +import com.sk89q.worldguard.protection.ApplicableRegionSet; +import com.sk89q.worldguard.session.Session; +import com.sk89q.worldguard.session.handler.Handler; + +import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin; + +public class BlockedEffectsFlag extends Handler +{ + public static final Factory FACTORY = new Factory(); + public static class Factory extends Handler.Factory + { + @Override + public BlockedEffectsFlag create(Session session) + { + return new BlockedEffectsFlag(session); + } + } + + protected BlockedEffectsFlag(Session session) + { + super(session); + } + + @Override + public void tick(Player player, ApplicableRegionSet set) + { + if (!this.getSession().getManager().hasBypass(player, player.getWorld())) + { + for(Set potionEffects : set.queryAllValues(WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(player), WorldGuardExtraFlagsPlugin.blockedEffects)) + { + if (potionEffects != null) + { + for(PotionEffectType potionEffect : potionEffects) + { + if (potionEffect != null) + { + player.removePotionEffect(potionEffect); + } + } + } + } + } + } +} diff --git a/src/main/java/net/goldtreeservers/worldguardextraflags/flags/CaseForcedStringFlag.java b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/CaseForcedStringFlag.java new file mode 100644 index 0000000..502d48e --- /dev/null +++ b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/CaseForcedStringFlag.java @@ -0,0 +1,23 @@ +package net.goldtreeservers.worldguardextraflags.flags; + +import com.sk89q.worldguard.protection.flags.FlagContext; +import com.sk89q.worldguard.protection.flags.InvalidFlagFormat; +import com.sk89q.worldguard.protection.flags.StringFlag; + +public class CaseForcedStringFlag extends StringFlag +{ + private final boolean upperCase; + + public CaseForcedStringFlag(String name, boolean upperCase) + { + super(name); + + this.upperCase = upperCase; + } + + @Override + public String parseInput(FlagContext context) throws InvalidFlagFormat + { + return this.upperCase ? super.parseInput(context).toUpperCase() : super.parseInput(context).toLowerCase(); + } +} diff --git a/src/main/java/net/goldtreeservers/worldguardextraflags/flags/CommandOnEntryFlag.java b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/CommandOnEntryFlag.java new file mode 100644 index 0000000..b5549f7 --- /dev/null +++ b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/CommandOnEntryFlag.java @@ -0,0 +1,59 @@ +package net.goldtreeservers.worldguardextraflags.flags; + +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; + +public class CommandOnEntryFlag extends Handler +{ + public static final Factory FACTORY = new Factory(); + public static class Factory extends Handler.Factory + { + @Override + public CommandOnEntryFlag create(Session session) + { + return new CommandOnEntryFlag(session); + } + } + + protected CommandOnEntryFlag(Session session) + { + super(session); + } + + @Override + public boolean onCrossBoundary(Player player, Location from, Location to, ApplicableRegionSet toSet, Set entered, Set exited, MoveType moveType) + { + for(ProtectedRegion region : entered) + { + Set commands = region.getFlag(WorldGuardExtraFlagsPlugin.commandOnEntry); + if (commands != null) + { + for(String command : commands) + { + boolean isOp = player.isOp(); + + try + { + player.setOp(true); + WorldGuardExtraFlagsPlugin.getPlugin().getServer().dispatchCommand(player, command.substring(1).replace("%username%", player.getName())); + } + finally + { + player.setOp(isOp); + } + } + } + } + return true; + } +} diff --git a/src/main/java/net/goldtreeservers/worldguardextraflags/flags/CommandOnExitFlag.java b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/CommandOnExitFlag.java new file mode 100644 index 0000000..10b0e6c --- /dev/null +++ b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/CommandOnExitFlag.java @@ -0,0 +1,60 @@ +package net.goldtreeservers.worldguardextraflags.flags; + +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; + +public class CommandOnExitFlag extends Handler +{ + public static final Factory FACTORY = new Factory(); + public static class Factory extends Handler.Factory + { + @Override + public CommandOnExitFlag create(Session session) + { + return new CommandOnExitFlag(session); + } + } + + protected CommandOnExitFlag(Session session) + { + super(session); + } + + @Override + public boolean onCrossBoundary(Player player, Location from, Location to, ApplicableRegionSet toSet, Set entered, Set exited, MoveType moveType) + { + for(ProtectedRegion region : exited) + { + Set commands = region.getFlag(WorldGuardExtraFlagsPlugin.commandOnExit); + if (commands != null) + { + for(String command : commands) + { + boolean isOp = player.isOp(); + + try + { + player.setOp(true); + WorldGuardExtraFlagsPlugin.getPlugin().getServer().dispatchCommand(player, command.substring(1).replace("%username%", player.getName())); + } + finally + { + player.setOp(isOp); + } + } + } + } + + return true; + } +} diff --git a/src/main/java/net/goldtreeservers/worldguardextraflags/flags/ConsoleCommandOnEntryFlag.java b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/ConsoleCommandOnEntryFlag.java new file mode 100644 index 0000000..3903c35 --- /dev/null +++ b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/ConsoleCommandOnEntryFlag.java @@ -0,0 +1,49 @@ +package net.goldtreeservers.worldguardextraflags.flags; + +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; + +public class ConsoleCommandOnEntryFlag extends Handler +{ + public static final Factory FACTORY = new Factory(); + public static class Factory extends Handler.Factory + { + @Override + public ConsoleCommandOnEntryFlag create(Session session) + { + return new ConsoleCommandOnEntryFlag(session); + } + } + + protected ConsoleCommandOnEntryFlag(Session session) + { + super(session); + } + + @Override + public boolean onCrossBoundary(Player player, Location from, Location to, ApplicableRegionSet toSet, Set entered, Set exited, MoveType moveType) + { + for(ProtectedRegion region : entered) + { + Set commands = region.getFlag(WorldGuardExtraFlagsPlugin.consoleCommandOnEntry); + if (commands != null) + { + for(String command : commands) + { + WorldGuardExtraFlagsPlugin.getPlugin().getServer().dispatchCommand(WorldGuardExtraFlagsPlugin.getPlugin().getServer().getConsoleSender(), command.substring(1).replace("%username%", player.getName())); + } + } + } + return true; + } +} diff --git a/src/main/java/net/goldtreeservers/worldguardextraflags/flags/ConsoleCommandOnExitFlag.java b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/ConsoleCommandOnExitFlag.java new file mode 100644 index 0000000..b669d42 --- /dev/null +++ b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/ConsoleCommandOnExitFlag.java @@ -0,0 +1,49 @@ +package net.goldtreeservers.worldguardextraflags.flags; + +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; + +public class ConsoleCommandOnExitFlag extends Handler +{ + public static final Factory FACTORY = new Factory(); + public static class Factory extends Handler.Factory + { + @Override + public ConsoleCommandOnExitFlag create(Session session) + { + return new ConsoleCommandOnExitFlag(session); + } + } + + protected ConsoleCommandOnExitFlag(Session session) + { + super(session); + } + + @Override + public boolean onCrossBoundary(Player player, Location from, Location to, ApplicableRegionSet toSet, Set entered, Set exited, MoveType moveType) + { + for(ProtectedRegion region : exited) + { + Set commands = region.getFlag(WorldGuardExtraFlagsPlugin.consoleCommandOnExit); + if (commands != null) + { + for(String command : commands) + { + WorldGuardExtraFlagsPlugin.getPlugin().getServer().dispatchCommand(WorldGuardExtraFlagsPlugin.getPlugin().getServer().getConsoleSender(), command.substring(1).replace("%username%", player.getName())); + } + } + } + return true; + } +} diff --git a/src/main/java/net/goldtreeservers/worldguardextraflags/flags/CustomSetFlag.java b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/CustomSetFlag.java new file mode 100644 index 0000000..769386d --- /dev/null +++ b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/CustomSetFlag.java @@ -0,0 +1,43 @@ +package net.goldtreeservers.worldguardextraflags.flags; + +import java.util.Set; + +import com.google.common.collect.Sets; +import com.sk89q.worldguard.protection.flags.Flag; +import com.sk89q.worldguard.protection.flags.FlagContext; +import com.sk89q.worldguard.protection.flags.InvalidFlagFormat; +import com.sk89q.worldguard.protection.flags.SetFlag; + +public class CustomSetFlag extends SetFlag +{ + public CustomSetFlag(String name, Flag subFlag) + { + super(name, subFlag); + } + + @Override + public Set parseInput(FlagContext context) throws InvalidFlagFormat + { + String input = context.getUserInput(); + if (input.isEmpty()) + { + return Sets.newHashSet(); + } + else + { + Set items = Sets.newHashSet(); + + for (String str : input.split(",(?=([^\"]*\"[^\"]*\")*[^\"]*$)", -1)) + { + if (str.startsWith("\"") && str.endsWith("\"")) + { + str = str.substring(1, str.length() - 1); + } + FlagContext copy = context.copyWith(null, str, null); + items.add(this.getType().parseInput(copy)); + } + + return items; + } + } +} diff --git a/src/main/java/net/goldtreeservers/worldguardextraflags/flags/FlyFlag.java b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/FlyFlag.java new file mode 100644 index 0000000..0a10aae --- /dev/null +++ b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/FlyFlag.java @@ -0,0 +1,97 @@ +package net.goldtreeservers.worldguardextraflags.flags; + +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.WorldGuardExtraFlagsPlugin; + +public class FlyFlag extends FlagValueChangeHandler +{ + public static final Factory FACTORY = new Factory(); + public static class Factory extends Handler.Factory + { + @Override + public FlyFlag create(Session session) + { + return new FlyFlag(session); + } + } + + private Boolean originalFly; + private Boolean currentValue; + + protected FlyFlag(Session session) + { + super(session, WorldGuardExtraFlagsPlugin.fly); + } + + private void updateFly(Player player, State newValue, World world) + { + this.currentValue = newValue == null ? null : newValue == State.ALLOW ? true : false; + + if (!this.getSession().getManager().hasBypass(player, world) && this.currentValue != null) + { + if (player.getAllowFlight() != this.currentValue) + { + if (this.originalFly == null) + { + this.originalFly = player.getAllowFlight(); + } + + player.setAllowFlight(this.currentValue); + } + } + 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; + } + + public Boolean getFlyStatys() + { + return this.currentValue; + } +} diff --git a/src/main/java/net/goldtreeservers/worldguardextraflags/flags/GiveEffectsFlag.java b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/GiveEffectsFlag.java new file mode 100644 index 0000000..08a91db --- /dev/null +++ b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/GiveEffectsFlag.java @@ -0,0 +1,178 @@ +package net.goldtreeservers.worldguardextraflags.flags; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +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; + +public class GiveEffectsFlag extends Handler +{ + public static final Factory FACTORY = new Factory(); + public static class Factory extends Handler.Factory + { + @Override + public GiveEffectsFlag create(Session session) + { + return new GiveEffectsFlag(session); + } + } + + private HashMap originalPotionEffects = new HashMap(); + private HashSet effectsGiven = new HashSet(); + + protected GiveEffectsFlag(Session session) + { + super(session); + } + + @Override + public boolean onCrossBoundary(Player player, Location from, Location to, ApplicableRegionSet toSet, Set entered, Set exited, MoveType moveType) + { + for(ProtectedRegion enterd : entered) + { + Set potionEffects = enterd.getFlag(WorldGuardExtraFlagsPlugin.giveEffects); + if (potionEffects != null) + { + for (PotionEffect potionEffect : potionEffects) + { + if (potionEffect != null) + { + if (player.hasPotionEffect(potionEffect.getType())) + { + if (!this.originalPotionEffects.containsKey(potionEffect.getType().getName())) + { + for(PotionEffect currentPotionEffect : player.getActivePotionEffects()) + { + if (currentPotionEffect.getType().getName().equals(potionEffect.getType().getName())) + { + this.originalPotionEffects.put(potionEffect.getType().getName(), currentPotionEffect); + break; + } + } + } + + player.removePotionEffect(potionEffect.getType()); + } + + this.effectsGiven.add(potionEffect.getType()); + player.addPotionEffect(potionEffect); + } + } + } + } + + for(ProtectedRegion exitd : exited) + { + Set potionEffects = exitd.getFlag(WorldGuardExtraFlagsPlugin.giveEffects); + if (potionEffects != null) + { + for(PotionEffect potionEffect : potionEffects) + { + if (potionEffect != null) + { + this.effectsGiven.remove(potionEffect.getType()); + player.removePotionEffect(potionEffect.getType()); + + PotionEffect oldPotionEffect = this.originalPotionEffects.remove(potionEffect.getType().getName()); + if (oldPotionEffect != null) + { + player.addPotionEffect(oldPotionEffect); + } + } + } + } + } + return true; + } + + @Override + public void tick(Player player, ApplicableRegionSet set) + { + if (this.originalPotionEffects != null) + { + for(PotionEffect oldPotionEffect : this.originalPotionEffects.values().toArray(new PotionEffect[0])) + { + this.originalPotionEffects.remove(oldPotionEffect); + this.originalPotionEffects.put(oldPotionEffect.getType().getName(), new PotionEffect(oldPotionEffect.getType(), oldPotionEffect.getDuration() - 20, oldPotionEffect.getAmplifier(), oldPotionEffect.isAmbient(), oldPotionEffect.hasParticles())); + } + } + + List shouldRemove = new ArrayList(this.effectsGiven); + for(Set potionEffects : set.queryAllValues(WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(player), WorldGuardExtraFlagsPlugin.giveEffects)) + { + if (potionEffects != null) + { + for(PotionEffect potionEffect : potionEffects) + { + if (potionEffect != null) + { + if (player.hasPotionEffect(potionEffect.getType())) + { + for(PotionEffect effect : player.getActivePotionEffects()) + { + if (effect.getType().equals(potionEffect.getType())) + { + if (effect.getAmplifier() != potionEffect.getAmplifier()) + { + player.removePotionEffect(potionEffect.getType()); + } + } + } + + player.addPotionEffect(potionEffect); + } + else + { + player.addPotionEffect(potionEffect); + } + + this.effectsGiven.add(potionEffect.getType()); + shouldRemove.remove(potionEffect.getType()); + } + } + } + } + + for(PotionEffectType effectType : shouldRemove) + { + PotionEffect oldPotionEffect = this.originalPotionEffects.remove(effectType.getName()); + if (oldPotionEffect != null) + { + if (player.hasPotionEffect(effectType)) + { + player.removePotionEffect(effectType); + } + + player.addPotionEffect(oldPotionEffect); + } + } + } + + public void drinkMilk() + { + this.originalPotionEffects.clear(); + } + + public void drinkPotion(Collection effects) + { + for(PotionEffect potionEffect : effects) + { + this.originalPotionEffects.put(potionEffect.getType().getName(), potionEffect); + } + } +} diff --git a/src/main/java/net/goldtreeservers/worldguardextraflags/flags/GlideFlag.java b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/GlideFlag.java new file mode 100644 index 0000000..067eab5 --- /dev/null +++ b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/GlideFlag.java @@ -0,0 +1,92 @@ +package net.goldtreeservers.worldguardextraflags.flags; + +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.WorldGuardExtraFlagsPlugin; + +public class GlideFlag extends FlagValueChangeHandler +{ + public static final Factory FACTORY = new Factory(); + public static class Factory extends Handler.Factory + { + @Override + public GlideFlag create(Session session) + { + return new GlideFlag(session); + } + } + + private Boolean originalGlide; + private Boolean currentValue; + + protected GlideFlag(Session session) + { + super(session, WorldGuardExtraFlagsPlugin.glide); + } + + private void updateGlide(Player player, State newValue, World world) + { + this.currentValue = newValue == null ? null : newValue == State.ALLOW ? true : false; + + if (!this.getSession().getManager().hasBypass(player, world) && this.currentValue != null) + { + if (player.isGliding() != this.currentValue) + { + if (this.originalGlide == null) + { + this.originalGlide = player.isGliding(); + } + + player.setGliding(this.currentValue); + } + } + 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; + } +} diff --git a/src/main/java/net/goldtreeservers/worldguardextraflags/flags/GodmodeFlag.java b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/GodmodeFlag.java new file mode 100644 index 0000000..3865ebc --- /dev/null +++ b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/GodmodeFlag.java @@ -0,0 +1,106 @@ +package net.goldtreeservers.worldguardextraflags.flags; + +import javax.annotation.Nullable; + +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.WorldGuardExtraFlagsPlugin; + +public class GodmodeFlag extends FlagValueChangeHandler +{ + public static final Factory FACTORY = new Factory(); + public static class Factory extends Handler.Factory + { + @Override + public GodmodeFlag create(Session session) + { + return new GodmodeFlag(session); + } + } + + private Boolean isGodmodeEnabled; + private Boolean originalEssentialsGodmode; + + protected GodmodeFlag(Session session) + { + super(session, WorldGuardExtraFlagsPlugin.godmode); + } + + @Nullable + @Override + public State getInvincibility(Player player) + { + if (!this.getSession().getManager().hasBypass(player, player.getWorld())) + { + ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuard().getRegionContainer().createQuery().getApplicableRegions(player.getLocation()); + return regions.queryValue(WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(player), WorldGuardExtraFlagsPlugin.godmode); + } + else + { + return null; + } + } + + public void updateGodmode(Player player, State newValue, World world) + { + if (!this.getSession().getManager().hasBypass(player, world) && newValue != null) + { + if (this.isGodmodeEnabled == null || this.isGodmodeEnabled != (newValue == State.ALLOW ? true : false)) + { + if (WorldGuardExtraFlagsPlugin.isEssentialsEnabled()) + { + if (this.originalEssentialsGodmode == null) + { + this.originalEssentialsGodmode = WorldGuardExtraFlagsPlugin.getEssentialsPlugin().getUser(player).isGodModeEnabledRaw(); + } + + WorldGuardExtraFlagsPlugin.getEssentialsPlugin().getUser(player).setGodModeEnabled(newValue == State.ALLOW ? true : false); + } + } + } + else + { + this.isGodmodeEnabled = null; + + if (this.originalEssentialsGodmode != null) + { + WorldGuardExtraFlagsPlugin.getEssentialsPlugin().getUser(player).setGodModeEnabled(this.originalEssentialsGodmode); + this.originalEssentialsGodmode = null; + } + } + } + + @Override + protected void onInitialValue(Player player, ApplicableRegionSet set, State value) + { + this.updateGodmode(player, value, player.getWorld()); + } + + @Override + protected boolean onSetValue(Player player, Location from, Location to, ApplicableRegionSet toSet, State currentValue, State lastValue, MoveType moveType) + { + this.updateGodmode(player, currentValue, player.getWorld()); + return true; + } + + @Override + protected boolean onAbsentValue(Player player, Location from, Location to, ApplicableRegionSet toSet, State lastValue, MoveType moveType) + { + this.updateGodmode(player, null, player.getWorld()); + return true; + } + + public boolean shouldBlockEvent(Player player, World world) + { + return !this.getSession().getManager().hasBypass(player, world) && this.originalEssentialsGodmode != null; + } +} diff --git a/src/main/java/net/goldtreeservers/worldguardextraflags/flags/PlaySoundsFlag.java b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/PlaySoundsFlag.java new file mode 100644 index 0000000..ee89352 --- /dev/null +++ b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/PlaySoundsFlag.java @@ -0,0 +1,98 @@ +package net.goldtreeservers.worldguardextraflags.flags; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Set; + +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.scheduler.BukkitRunnable; + +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.SoundData; + +public class PlaySoundsFlag extends Handler +{ + public static final Factory FACTORY = new Factory(); + public static class Factory extends Handler.Factory + { + @Override + public PlaySoundsFlag create(Session session) + { + return new PlaySoundsFlag(session); + } + } + + private HashMap> runnables = new HashMap<>(); + + protected PlaySoundsFlag(Session session) + { + super(session); + } + + @Override + public boolean onCrossBoundary(Player player, Location from, Location to, ApplicableRegionSet toSet, Set entered, Set exited, MoveType moveType) + { + for(ProtectedRegion region : entered) + { + Set sounds = region.getFlag(WorldGuardExtraFlagsPlugin.playSounds); + if (sounds != null) + { + List runnables = this.runnables.getOrDefault(region, new ArrayList<>()); + for(SoundData sound : sounds) + { + BukkitRunnable runnable = new BukkitRunnable() + { + @Override + public void run() + { + player.playSound(player.getLocation(), sound.getSound(), Float.MAX_VALUE, 1); + } + + @Override + public void cancel() + { + super.cancel(); + + try + { + player.stopSound(sound.getSound()); + } + catch(Exception ex) + { + + } + } + }; + + runnables.add(runnable); + runnable.runTaskTimer(WorldGuardExtraFlagsPlugin.getPlugin(), 0L, sound.getInterval()); + } + + this.runnables.put(region, runnables); + } + } + + for(ProtectedRegion region : exited) + { + List runnables = this.runnables.remove(region); + if (runnables != null) + { + for(BukkitRunnable runnable : runnables) + { + runnable.cancel(); + } + } + } + return true; + } + + +} diff --git a/src/main/java/net/goldtreeservers/worldguardextraflags/flags/PotionEffectFlag.java b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/PotionEffectFlag.java new file mode 100644 index 0000000..279c18a --- /dev/null +++ b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/PotionEffectFlag.java @@ -0,0 +1,43 @@ +package net.goldtreeservers.worldguardextraflags.flags; + +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; + +import com.sk89q.worldguard.protection.flags.Flag; +import com.sk89q.worldguard.protection.flags.FlagContext; +import com.sk89q.worldguard.protection.flags.InvalidFlagFormat; + +public class PotionEffectFlag extends Flag +{ + public PotionEffectFlag(String name) + { + super(name); + } + + @Override + public Object marshal(PotionEffect o) + { + return o.getType().getName() + " " + o.getAmplifier(); + } + + @Override + public PotionEffect parseInput(FlagContext context) throws InvalidFlagFormat + { + String[] splitd = context.getUserInput().trim().split(" "); + if (splitd.length == 2) + { + return new PotionEffect(PotionEffectType.getByName(splitd[0]), Integer.MAX_VALUE, new Integer(splitd[1])); + } + else + { + throw new InvalidFlagFormat("Please use format: "); + } + } + + @Override + public PotionEffect unmarshal(Object o) + { + String[] splitd = o.toString().split(" "); + return new PotionEffect(PotionEffectType.getByName(splitd[0]), Integer.MAX_VALUE, new Integer(splitd[1])); + } +} diff --git a/src/main/java/net/goldtreeservers/worldguardextraflags/flags/PotionEffectTypeFlag.java b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/PotionEffectTypeFlag.java new file mode 100644 index 0000000..042fc90 --- /dev/null +++ b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/PotionEffectTypeFlag.java @@ -0,0 +1,33 @@ +package net.goldtreeservers.worldguardextraflags.flags; + +import org.bukkit.potion.PotionEffectType; + +import com.sk89q.worldguard.protection.flags.Flag; +import com.sk89q.worldguard.protection.flags.FlagContext; +import com.sk89q.worldguard.protection.flags.InvalidFlagFormat; + +public class PotionEffectTypeFlag extends Flag +{ + public PotionEffectTypeFlag(String name) + { + super(name); + } + + @Override + public Object marshal(PotionEffectType o) + { + return o.getName(); + } + + @Override + public PotionEffectType parseInput(FlagContext context) throws InvalidFlagFormat + { + return PotionEffectType.getByName(context.getUserInput().trim()); + } + + @Override + public PotionEffectType unmarshal(Object o) + { + return PotionEffectType.getByName(o.toString()); + } +} diff --git a/src/main/java/net/goldtreeservers/worldguardextraflags/flags/SoundDataFlag.java b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/SoundDataFlag.java new file mode 100644 index 0000000..c6d187c --- /dev/null +++ b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/SoundDataFlag.java @@ -0,0 +1,42 @@ +package net.goldtreeservers.worldguardextraflags.flags; + +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; + +public class SoundDataFlag extends Flag +{ + public SoundDataFlag(String name) + { + super(name); + } + + @Override + public Object marshal(SoundData o) + { + return o.getSound().toString() + " " + o.getInterval(); + } + + @Override + public SoundData parseInput(FlagContext context) throws InvalidFlagFormat + { + String[] splitd = context.getUserInput().trim().split(" "); + if (splitd.length == 2) + { + return new SoundData(splitd[0], new Integer(splitd[1])); + } + else + { + throw new InvalidFlagFormat("Please use format: "); + } + } + + @Override + public SoundData unmarshal(Object o) + { + String[] splitd = o.toString().split(" "); + return new SoundData(splitd[0], new Integer(splitd[1])); + } +} diff --git a/src/main/java/net/goldtreeservers/worldguardextraflags/flags/TeleportOnEntryFlag.java b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/TeleportOnEntryFlag.java new file mode 100644 index 0000000..3d057a2 --- /dev/null +++ b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/TeleportOnEntryFlag.java @@ -0,0 +1,50 @@ +package net.goldtreeservers.worldguardextraflags.flags; + +import java.util.Set; + +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.metadata.FixedMetadataValue; + +import com.sk89q.worldedit.bukkit.BukkitUtil; +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; + +public class TeleportOnEntryFlag extends Handler +{ + public static final Factory FACTORY = new Factory(); + public static class Factory extends Handler.Factory + { + @Override + public TeleportOnEntryFlag create(Session session) + { + return new TeleportOnEntryFlag(session); + } + } + + protected TeleportOnEntryFlag(Session session) + { + super(session); + } + + @SuppressWarnings("deprecation") + @Override + public boolean onCrossBoundary(Player player, Location from, Location to, ApplicableRegionSet toSet, Set entered, Set exited, MoveType moveType) + { + if (!player.hasMetadata("WorldGuardExtraFlagsWaitingForTeleportationToBeDone")) + { + com.sk89q.worldedit.Location location = toSet.queryValue(WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(player), WorldGuardExtraFlagsPlugin.teleportOnEntry); + if (location != null) + { + player.setMetadata("WorldGuardExtraFlagsWaitingForTeleportationToBeDone", new FixedMetadataValue(WorldGuardExtraFlagsPlugin.getPlugin(), null)); + player.teleport(BukkitUtil.toLocation(location)); + } + } + return true; + } +} diff --git a/src/main/java/net/goldtreeservers/worldguardextraflags/flags/TeleportOnExitFlag.java b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/TeleportOnExitFlag.java new file mode 100644 index 0000000..16d5d6c --- /dev/null +++ b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/TeleportOnExitFlag.java @@ -0,0 +1,54 @@ +package net.goldtreeservers.worldguardextraflags.flags; + +import java.util.Set; + +import org.bukkit.Location; +import org.bukkit.entity.Player; +import org.bukkit.metadata.FixedMetadataValue; + +import com.sk89q.worldedit.bukkit.BukkitUtil; +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; + +public class TeleportOnExitFlag extends Handler +{ + public static final Factory FACTORY = new Factory(); + public static class Factory extends Handler.Factory + { + @Override + public TeleportOnExitFlag create(Session session) + { + return new TeleportOnExitFlag(session); + } + } + + protected TeleportOnExitFlag(Session session) + { + super(session); + } + + @SuppressWarnings("deprecation") + @Override + public boolean onCrossBoundary(Player player, Location from, Location to, ApplicableRegionSet toSet, Set entered, Set exited, MoveType moveType) + { + if (!player.hasMetadata("WorldGuardExtraFlagsWaitingForTeleportationToBeDone")) + { + for(ProtectedRegion region : exited) + { + com.sk89q.worldedit.Location location = region.getFlag(WorldGuardExtraFlagsPlugin.teleportOnExit); + if (location != null) + { + player.setMetadata("WorldGuardExtraFlagsWaitingForTeleportationToBeDone", new FixedMetadataValue(WorldGuardExtraFlagsPlugin.getPlugin(), null)); + player.teleport(BukkitUtil.toLocation(location)); + break; + } + } + } + return true; + } +} diff --git a/src/main/java/net/goldtreeservers/worldguardextraflags/flags/WalkSpeedFlag.java b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/WalkSpeedFlag.java new file mode 100644 index 0000000..137f7fa --- /dev/null +++ b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/WalkSpeedFlag.java @@ -0,0 +1,86 @@ +package net.goldtreeservers.worldguardextraflags.flags; + +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.WorldGuardExtraFlagsPlugin; + +public class WalkSpeedFlag extends FlagValueChangeHandler +{ + public static final Factory FACTORY = new Factory(); + public static class Factory extends Handler.Factory + { + @Override + public WalkSpeedFlag create(Session session) + { + return new WalkSpeedFlag(session); + } + } + + private Float originalWalkSpeed; + + protected WalkSpeedFlag(Session session) + { + super(session, WorldGuardExtraFlagsPlugin.walkSpeed); + } + + 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; + } +} diff --git a/src/main/java/net/goldtreeservers/worldguardextraflags/flags/WorldEditFlag.java b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/WorldEditFlag.java new file mode 100644 index 0000000..3dfda34 --- /dev/null +++ b/src/main/java/net/goldtreeservers/worldguardextraflags/flags/WorldEditFlag.java @@ -0,0 +1,49 @@ +package net.goldtreeservers.worldguardextraflags.flags; + +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.ApplicableRegionSet; +import com.sk89q.worldguard.protection.flags.StateFlag.State; + +import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin; + +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 (WorldGuardExtraFlagsPlugin.getWorldGuard().getSessionManager().hasBypass(player, player.getWorld())) + { + return super.setBlock(location, block); + } + else + { + ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuard().getRegionContainer().createQuery().getApplicableRegions(BukkitUtil.toLocation(player.getWorld(), location)); + State state = regions.queryValue(WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(player), WorldGuardExtraFlagsPlugin.worldEdit); + if (state != State.DENY) + { + return super.setBlock(location, block); + } + else + { + return false; + } + } + } +} diff --git a/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/BlockListener.java b/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/BlockListener.java new file mode 100644 index 0000000..09643b0 --- /dev/null +++ b/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/BlockListener.java @@ -0,0 +1,132 @@ +package net.goldtreeservers.worldguardextraflags.listeners; + +import java.util.Set; + +import org.bukkit.Material; +import org.bukkit.block.Block; +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.EntityBlockFormEvent; + +import com.sk89q.worldguard.bukkit.event.block.BreakBlockEvent; +import com.sk89q.worldguard.bukkit.event.block.PlaceBlockEvent; +import com.sk89q.worldguard.protection.ApplicableRegionSet; +import com.sk89q.worldguard.protection.flags.StateFlag.State; + +import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin; + +public class BlockListener implements Listener +{ + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onEntityBlockFormEvent(EntityBlockFormEvent event) + { + if (WorldGuardExtraFlagsPlugin.isSupportingFrostwalker()) + { + if (event.getNewState().getType() == Material.FROSTED_ICE) + { + ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuard().getRegionContainer().createQuery().getApplicableRegions(event.getNewState().getLocation()); + State state = null; + if (event.getEntity() instanceof Player) + { + state = regions.queryValue(WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(((Player)event.getEntity())), WorldGuardExtraFlagsPlugin.frostwalker); + } + else + { + state = regions.queryValue(null, WorldGuardExtraFlagsPlugin.frostwalker); + } + + if (state == State.DENY) + { + event.setCancelled(true); + } + } + } + } + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false) + public void onBlockPlaceEvent(PlaceBlockEvent event) + { + if (event.getResult() == Result.DEFAULT) + { + Object cause = event.getCause().getRootCause(); + + if (cause instanceof Player) + { + Player player = (Player)cause; + + if (!WorldGuardExtraFlagsPlugin.getWorldGuard().getSessionManager().hasBypass(player, player.getWorld())) + { + for(Block block : event.getBlocks()) + { + ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuard().getRegionContainer().createQuery().getApplicableRegions(block.getLocation()); + + Set state = regions.queryValue(WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(player), WorldGuardExtraFlagsPlugin.allowBlockPlace); + if (state != null && state.contains(block.getType().toString().toUpperCase())) + { + event.setResult(Result.ALLOW); + } + else + { + Set state2 = regions.queryValue(WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(player), WorldGuardExtraFlagsPlugin.denyBlockPlace); + if (state2 != null && state2.contains(block.getType().toString().toUpperCase())) + { + event.setResult(Result.DENY); + return; + } + else + { + event.setResult(Result.DEFAULT); + return; + } + } + } + } + } + } + } + + @EventHandler(priority = EventPriority.LOWEST, ignoreCancelled = false) + public void onBlockBreakEvent(BreakBlockEvent event) + { + if (event.getResult() == Result.DEFAULT) + { + Object cause = event.getCause().getRootCause(); + + if (cause instanceof Player) + { + Player player = (Player)cause; + + if (!WorldGuardExtraFlagsPlugin.getWorldGuard().getSessionManager().hasBypass(player, player.getWorld())) + { + for(Block block : event.getBlocks()) + { + ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuard().getRegionContainer().createQuery().getApplicableRegions(block.getLocation()); + + Set state = regions.queryValue(WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(player), WorldGuardExtraFlagsPlugin.allowBlockBreak); + if (state != null && state.contains(block.getType().toString().toUpperCase())) + { + event.setResult(Result.ALLOW); + } + else + { + Set state2 = regions.queryValue(WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(player), WorldGuardExtraFlagsPlugin.denyBlockBreak); + if (state2 != null && state2.contains(block.getType().toString().toUpperCase())) + { + event.setResult(Result.DENY); + return; + } + else + { + event.setResult(Result.DEFAULT); + return; + } + } + } + } + } + } + } +} diff --git a/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/EntityListener.java b/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/EntityListener.java new file mode 100644 index 0000000..a45eb64 --- /dev/null +++ b/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/EntityListener.java @@ -0,0 +1,56 @@ +package net.goldtreeservers.worldguardextraflags.listeners; + +import org.bukkit.block.Block; +import org.bukkit.entity.LivingEntity; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; +import org.bukkit.event.entity.EntityToggleGlideEvent; +import org.bukkit.event.world.PortalCreateEvent; + +import com.sk89q.worldguard.protection.ApplicableRegionSet; +import com.sk89q.worldguard.protection.flags.StateFlag.State; + +import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin; + +public class EntityListener implements Listener +{ + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onPortalCreateEvent(PortalCreateEvent event) + { + for(Block block : event.getBlocks()) + { + ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuard().getRegionContainer().createQuery().getApplicableRegions(block.getLocation()); + State allowNetherPortals = regions.queryValue(null, WorldGuardExtraFlagsPlugin.netherPortals); + if (allowNetherPortals == State.DENY) + { + event.setCancelled(true); + return; + } + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onEntityToggleGlideEvent(EntityToggleGlideEvent event) + { + if (event.getEntity() instanceof LivingEntity) + { + if (event.getEntity() instanceof Player) + { + if (WorldGuardExtraFlagsPlugin.getWorldGuard().getSessionManager().hasBypass((Player)event.getEntity(), ((Player)event.getEntity()).getWorld())) + { + return; + } + } + + ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuard().getRegionContainer().createQuery().getApplicableRegions(event.getEntity().getLocation()); + State allowGliding = regions.queryValue(event.getEntity() instanceof Player ? WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer((Player)event.getEntity()) : null, WorldGuardExtraFlagsPlugin.glide); + if (allowGliding != null) + { + event.setCancelled(true); + ((LivingEntity)event.getEntity()).setGliding(allowGliding == State.ALLOW); + } + } + } +} diff --git a/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/EssentialsListener.java b/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/EssentialsListener.java new file mode 100644 index 0000000..e3bea56 --- /dev/null +++ b/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/EssentialsListener.java @@ -0,0 +1,21 @@ +package net.goldtreeservers.worldguardextraflags.listeners; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.Listener; + +import net.ess3.api.events.GodStatusChangeEvent; +import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin; +import net.goldtreeservers.worldguardextraflags.flags.GodmodeFlag; + +public class EssentialsListener implements Listener +{ + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onGodStatusChangeEvent(GodStatusChangeEvent event) + { + if (WorldGuardExtraFlagsPlugin.getWorldGuard().getSessionManager().get(event.getController().getBase()).getHandler(GodmodeFlag.class).shouldBlockEvent(event.getController().getBase(), event.getController().getBase().getWorld())) + { + event.setCancelled(true); + } + } +} diff --git a/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/PlayerListener.java b/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/PlayerListener.java new file mode 100644 index 0000000..7b2f4ef --- /dev/null +++ b/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/PlayerListener.java @@ -0,0 +1,232 @@ +package net.goldtreeservers.worldguardextraflags.listeners; + +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +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.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; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; +import org.bukkit.scheduler.BukkitRunnable; +import org.spigotmc.event.player.PlayerSpawnLocationEvent; + +import com.sk89q.worldedit.Location; +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.FlyFlag; +import net.goldtreeservers.worldguardextraflags.flags.GiveEffectsFlag; + +@SuppressWarnings("deprecation") +public class PlayerListener implements Listener +{ + @EventHandler(priority = EventPriority.MONITOR) + public void onPlayerTeleportEvent(PlayerTeleportEvent event) + { + event.getPlayer().removeMetadata("WorldGuardExtraFlagsWaitingForTeleportationToBeDone", WorldGuardExtraFlagsPlugin.getPlugin()); + } + + @EventHandler(priority = EventPriority.HIGHEST) + public void onPlayerDeathEvent(PlayerDeathEvent event) + { + ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuard().getRegionContainer().createQuery().getApplicableRegions(event.getEntity().getLocation()); + Boolean keepInventory = regions.queryValue(WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(event.getEntity()), WorldGuardExtraFlagsPlugin.keepInventory); + if (keepInventory != null && keepInventory) + { + event.setKeepInventory(true); + event.getDrops().clear(); + } + + Boolean keepExp = regions.queryValue(WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(event.getEntity()), WorldGuardExtraFlagsPlugin.keepExp); + if (keepExp != null && keepExp) + { + event.setKeepLevel(true); + event.setDroppedExp(0); + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onAsyncPlayerChatEvent(AsyncPlayerChatEvent event) + { + ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuard().getRegionContainer().createQuery().getApplicableRegions(event.getPlayer().getLocation()); + String prefix = regions.queryValue(WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(event.getPlayer()), WorldGuardExtraFlagsPlugin.chatPrefix); + String suffix = regions.queryValue(WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(event.getPlayer()), WorldGuardExtraFlagsPlugin.chatSuffix); + + if (prefix != null) + { + event.setFormat(prefix + event.getFormat()); + } + + if (suffix != null) + { + event.setFormat(event.getFormat() + suffix); + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onPlayerRespawnEvent(PlayerRespawnEvent event) + { + ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuard().getRegionContainer().createQuery().getApplicableRegions(event.getPlayer().getLocation()); + Location respawnLocation = regions.queryValue(WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(event.getPlayer()), WorldGuardExtraFlagsPlugin.respawnLocation); + if (respawnLocation != null) + { + event.setRespawnLocation(BukkitUtil.toLocation(respawnLocation)); + } + } + + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public void onPlayerItemConsumeEvent(PlayerItemConsumeEvent event) + { + ItemMeta itemMeta = event.getItem().getItemMeta(); + if (itemMeta instanceof PotionMeta) + { + WorldGuardExtraFlagsPlugin.getWorldGuard().getSessionManager().get(event.getPlayer()).getHandler(GiveEffectsFlag.class).drinkPotion(Potion.fromItemStack(event.getItem()).getEffects()); + } + else + { + Material material = event.getItem().getType(); + if (material == Material.MILK_BUCKET) + { + WorldGuardExtraFlagsPlugin.getWorldGuard().getSessionManager().get(event.getPlayer()).getHandler(GiveEffectsFlag.class).drinkMilk(); + ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuard().getRegionContainer().createQuery().getApplicableRegions(event.getPlayer().getLocation()); + + List effects = new ArrayList(); + for(Set potionEffects : regions.queryAllValues(WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(event.getPlayer()), WorldGuardExtraFlagsPlugin.giveEffects)) + { + if (potionEffects != null) + { + for(PotionEffect potionEffect : potionEffects) + { + if (potionEffect != null) + { + effects.add(potionEffect.getType()); + } + } + } + } + } + } + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onPlayerGameModeChangeEvent(PlayerGameModeChangeEvent event) + { + new BukkitRunnable() + { + @Override + public void run() + { + try + { + event.getPlayer().setAllowFlight(WorldGuardExtraFlagsPlugin.getWorldGuard().getSessionManager().get(event.getPlayer()).getHandler(FlyFlag.class).getFlyStatys()); + } + catch(Exception ignored) + { + + } + } + }.runTask(WorldGuardExtraFlagsPlugin.getPlugin()); + } + + @EventHandler(priority = EventPriority.LOWEST) + public void onPlayerInteractEvent(PlayerInteractEvent event) + { + if (WorldGuardExtraFlagsPlugin.isMythicMobsEnabled()) + { + if (event.getAction() == Action.RIGHT_CLICK_AIR || event.getAction() == Action.RIGHT_CLICK_BLOCK) + { + if (event.hasItem()) + { + ItemStack item = event.getItem(); + if (item.getType() == Material.MONSTER_EGG) + { + if (item.getItemMeta().hasLore()) + { + List lore = item.getItemMeta().getLore(); + if (lore.get(0).equals(ChatColor.DARK_GRAY + "" + ChatColor.ITALIC + "A Mythical Egg that can")) + { + MythicMob mm = EggManager.getMythicMobFromEgg(lore.get(2)); + if (mm != null) + { + ApplicableRegionSet regions = WorldGuardExtraFlagsPlugin.getWorldGuard().getRegionContainer().createQuery().getApplicableRegions(event.getAction() == Action.RIGHT_CLICK_BLOCK ? event.getClickedBlock().getLocation() : event.getPlayer().getLocation()); + State state = regions.queryValue(WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(event.getPlayer()), WorldGuardExtraFlagsPlugin.mythicMobsEggs); + if (state == State.DENY) + { + event.setCancelled(true); + event.setUseItemInHand(Result.DENY); + } + } + } + } + } + } + } + } + } + + @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) + public void onPlayerChangedWorldEvent(PlayerChangedWorldEvent event) + { + if (WorldGuardExtraFlagsPlugin.isEssentialsEnabled()) //Essentials how dare u do this to me!?! + { + Player player = event.getPlayer(); + if (player.getGameMode() != GameMode.CREATIVE && !WorldGuardExtraFlagsPlugin.getEssentialsPlugin().getUser(player).isAuthorized("essentials.fly")) + { + //Essentials now turns off flight, fuck him + + try + { + player.setAllowFlight(WorldGuardExtraFlagsPlugin.getWorldGuard().getSessionManager().get(player).getHandler(FlyFlag.class).getFlyStatys()); + } + catch(Exception ignored) + { + + } + } + } + } + + @EventHandler(priority = EventPriority.MONITOR) + public void onPlayerSpawnLocationEvent(PlayerSpawnLocationEvent event) + { + new BukkitRunnable() + { + @Override + public void run() + { + try + { + event.getPlayer().setAllowFlight(WorldGuardExtraFlagsPlugin.getWorldGuard().getSessionManager().get(event.getPlayer()).getHandler(FlyFlag.class).getFlyStatys()); + } + catch(Exception ignored) + { + + } + } + }.runTask(WorldGuardExtraFlagsPlugin.getPlugin()); + } +} diff --git a/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/WorldEditListener.java b/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/WorldEditListener.java new file mode 100644 index 0000000..fb70728 --- /dev/null +++ b/src/main/java/net/goldtreeservers/worldguardextraflags/listeners/WorldEditListener.java @@ -0,0 +1,19 @@ +package net.goldtreeservers.worldguardextraflags.listeners; + +import com.sk89q.worldedit.event.extent.EditSessionEvent; +import com.sk89q.worldedit.util.eventbus.EventHandler; +import com.sk89q.worldedit.util.eventbus.Subscribe; + +import net.goldtreeservers.worldguardextraflags.flags.WorldEditFlag; + +public class WorldEditListener +{ + @Subscribe(priority = EventHandler.Priority.VERY_EARLY) + public void onEditSessionEvent(EditSessionEvent event) + { + if (event.getActor() != null) //Not a player? + { + event.setExtent(new WorldEditFlag(event.getExtent(), event.getActor())); + } + } +} diff --git a/src/main/java/net/goldtreeservers/worldguardextraflags/utils/FaweWorldEditFlag.java b/src/main/java/net/goldtreeservers/worldguardextraflags/utils/FaweWorldEditFlag.java new file mode 100644 index 0000000..ba1b1d0 --- /dev/null +++ b/src/main/java/net/goldtreeservers/worldguardextraflags/utils/FaweWorldEditFlag.java @@ -0,0 +1,86 @@ +package net.goldtreeservers.worldguardextraflags.utils; + +import org.bukkit.Location; +import org.bukkit.entity.Player; + +import com.boydti.fawe.object.FawePlayer; +import com.boydti.fawe.regions.FaweMask; +import com.boydti.fawe.regions.FaweMaskManager; +import com.sk89q.worldedit.BlockVector; +import com.sk89q.worldguard.LocalPlayer; +import com.sk89q.worldguard.protection.ApplicableRegionSet; +import com.sk89q.worldguard.protection.flags.StateFlag.State; +import com.sk89q.worldguard.protection.managers.RegionManager; +import com.sk89q.worldguard.protection.regions.ProtectedRegion; + +import net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin; + +public class FaweWorldEditFlag extends FaweMaskManager +{ + public FaweWorldEditFlag() + { + super("WorldGuardExtraFlags"); + } + + public ProtectedRegion getRegion(final Player player, final Location loc) + { + final com.sk89q.worldguard.LocalPlayer localplayer = WorldGuardExtraFlagsPlugin.getWorldGuard().wrapPlayer(player); + RegionManager manager = WorldGuardExtraFlagsPlugin.getWorldGuard().getRegionManager(player.getWorld()); + final ProtectedRegion global = manager.getRegion("__global__"); + if (global != null && !isDenied(localplayer, global)) + { + return global; + } + + final ApplicableRegionSet regions = manager.getApplicableRegions(player.getLocation()); + for (final ProtectedRegion region : regions) + { + if (!isDenied(localplayer, region)) + { + return region; + } + } + return null; + } + + public boolean isDenied(LocalPlayer localplayer, ProtectedRegion region) + { + return region.getFlag(WorldGuardExtraFlagsPlugin.worldEdit) == State.DENY; + } + + @Override + public FaweMask getMask(FawePlayer fawePlayer) + { + final Player player = fawePlayer.parent; + final Location location = player.getLocation(); + final ProtectedRegion myregion = this.getRegion(player, location); + if (myregion != null) + { + final BlockVector pos1; + final BlockVector pos2; + if (myregion.getId().equals("__global__")) + { + pos1 = new BlockVector(Integer.MIN_VALUE, 0, Integer.MIN_VALUE); + pos2 = new BlockVector(Integer.MAX_VALUE, 255, Integer.MAX_VALUE); + } + else + { + pos1 = new BlockVector(myregion.getMinimumPoint().getBlockX(), myregion.getMinimumPoint().getBlockY(), myregion.getMinimumPoint().getBlockZ()); + pos2 = new BlockVector(myregion.getMaximumPoint().getBlockX(), myregion.getMaximumPoint().getBlockY(), myregion.getMaximumPoint().getBlockZ()); + } + + return new FaweMask(pos1, pos2) + { + @Override + public String getName() + { + return myregion.getId(); + } + }; + } + else + { + return null; + } + } +} diff --git a/src/main/java/net/goldtreeservers/worldguardextraflags/utils/PluginUtils.java b/src/main/java/net/goldtreeservers/worldguardextraflags/utils/PluginUtils.java new file mode 100644 index 0000000..c00ac3d --- /dev/null +++ b/src/main/java/net/goldtreeservers/worldguardextraflags/utils/PluginUtils.java @@ -0,0 +1,11 @@ +package net.goldtreeservers.worldguardextraflags.utils; + +import com.boydti.fawe.FaweAPI; + +public class PluginUtils +{ + public static void registerFAWE() + { + FaweAPI.addMaskManager(new FaweWorldEditFlag()); + } +} diff --git a/src/main/java/net/goldtreeservers/worldguardextraflags/utils/SoundData.java b/src/main/java/net/goldtreeservers/worldguardextraflags/utils/SoundData.java new file mode 100644 index 0000000..b166eae --- /dev/null +++ b/src/main/java/net/goldtreeservers/worldguardextraflags/utils/SoundData.java @@ -0,0 +1,23 @@ +package net.goldtreeservers.worldguardextraflags.utils; + +public class SoundData +{ + private final String sound; + private final int interval; + + public SoundData(String sound, int interval) + { + this.sound = sound; + this.interval = interval; + } + + public String getSound() + { + return this.sound; + } + + public int getInterval() + { + return this.interval; + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml new file mode 100644 index 0000000..4509cdf --- /dev/null +++ b/src/main/resources/plugin.yml @@ -0,0 +1,10 @@ +name: WorldGuardExtraFlags +version: 2.11.0 +description: Add more flags to worldguard to help manage your server easily! +author: isokissa3 +authors: [isokissa3] +website: https://goldtreevers.net +depend: [ WorldGuard ] +softdepend: [ MythicMobs, FastAsyncWorldEdit, Essentials ] + +main: net.goldtreeservers.worldguardextraflags.WorldGuardExtraFlagsPlugin \ No newline at end of file