From b9ad75ad847af9416e3de752593f606b184fb0ee Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Wed, 29 Jun 2016 21:22:55 +1000 Subject: [PATCH] Add teleport flag --- .../bukkit/listeners/PlayerEvents.java | 6 +++ .../plot/commands/MainCommand.java | 9 ++++- .../plot/flag/EnumFlag.java | 31 +++++++++++++++ .../intellectualcrafters/plot/flag/Flags.java | 3 +- .../plot/flag/TeleportDenyFlag.java | 38 +++++++++++++++++++ .../plot/object/Plot.java | 16 +++++--- build.gradle | 2 +- 7 files changed, 96 insertions(+), 9 deletions(-) create mode 100644 Core/src/main/java/com/intellectualcrafters/plot/flag/EnumFlag.java create mode 100644 Core/src/main/java/com/intellectualcrafters/plot/flag/TeleportDenyFlag.java diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java index 2ff26fcfd..3cecf4b40 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -1668,6 +1668,9 @@ public class PlayerEvents extends PlotListener implements Listener { return; } } else if (lastPlot != null && now.equals(lastPlot)) { + if (!Flags.DENY_TELEPORT.allowsTeleport(pp, lastPlot)) { + event.setTo(BukkitUtil.getLocation(lastPlot.getSide())); + } return; } else if (!plotEntry(pp, now) && this.tmpTeleport) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED); @@ -1738,6 +1741,9 @@ public class PlayerEvents extends PlotListener implements Listener { return; } } else if (lastPlot != null && now.equals(lastPlot)) { + if (!Flags.DENY_TELEPORT.allowsTeleport(pp, lastPlot)) { + event.setTo(BukkitUtil.getLocation(lastPlot.getSide())); + } return; } else if (!plotEntry(pp, now) && this.tmpTeleport) { MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_ENTRY_DENIED); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java index 20b897f0d..0ce752e57 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java @@ -225,9 +225,16 @@ public class MainCommand extends Command { } try { super.execute(player, args, confirm, whenDone); + } catch (CommandException e) { + throw e; } catch (Throwable e) { e.printStackTrace(); - C.ERROR.send(player, e.getLocalizedMessage()); + String message = e.getLocalizedMessage(); + if (message != null) { + C.ERROR.send(player, message); + } else { + C.ERROR.send(player); + } } // Reset command scope // if (tp && !(player instanceof ConsolePlayer)) { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/EnumFlag.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/EnumFlag.java new file mode 100644 index 000000000..c6f8a8ab6 --- /dev/null +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/EnumFlag.java @@ -0,0 +1,31 @@ +package com.intellectualcrafters.plot.flag; + +import com.intellectualcrafters.plot.util.StringMan; +import java.util.Arrays; +import java.util.HashSet; + +public class EnumFlag extends Flag { + private final HashSet values; + + public EnumFlag(String name, String... values) { + super(name); + this.values = new HashSet<>(Arrays.asList(values)); + } + + @Override + public String valueToString(Object value) { + return value.toString(); + } + + @Override public String parseValue(String value) { + value = value.toLowerCase(); + if (values.contains(value)) { + return value; + } + return null; + } + + @Override public String getValueDescription() { + return "Must be one of: " + StringMan.getString(values); + } +} \ No newline at end of file diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/Flags.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/Flags.java index f107152f4..fc991ea21 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/flag/Flags.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/Flags.java @@ -6,7 +6,6 @@ import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.RunnableVal; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MathMan; - import java.lang.reflect.Field; import java.util.Collection; import java.util.Collections; @@ -114,6 +113,8 @@ public final class Flags { } }; public static final BooleanFlag SLEEP = new BooleanFlag("sleep"); + public static final TeleportDenyFlag DENY_TELEPORT = new TeleportDenyFlag("teleport-deny"); + private static final HashMap> flags; static { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/flag/TeleportDenyFlag.java b/Core/src/main/java/com/intellectualcrafters/plot/flag/TeleportDenyFlag.java new file mode 100644 index 000000000..a991968d5 --- /dev/null +++ b/Core/src/main/java/com/intellectualcrafters/plot/flag/TeleportDenyFlag.java @@ -0,0 +1,38 @@ +package com.intellectualcrafters.plot.flag; + +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotPlayer; + +public class TeleportDenyFlag extends EnumFlag { + public TeleportDenyFlag(String name) { + super(name, "trusted", "members", "nonmembers", "nontrusted", "nonowners"); + } + + public boolean allowsTeleport(PlotPlayer player, Plot plot) { + String value = plot.getFlag(this, null); + if (value == null || !plot.hasOwner()) { + return true; + } + boolean result; + switch (plot.getFlag(this, null)) { + case "trusted": + result = !plot.getTrusted().contains(player.getUUID()); + break; + case "members": + result =!plot.getMembers().contains(player.getUUID()); + break; + case "nonmembers": + result =!plot.isAdded(player.getUUID()); + break; + case "nontrusted": + result =!plot.getTrusted().contains(player.getUUID()) && !plot.isOwner(player.getUUID()); + break; + case "nonowners": + result =!plot.isOwner(player.getUUID()); + break; + default: + return true; + } + return result || player.hasPermission("plots.admin.entry.denied"); + } +} diff --git a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java index 78e5867ac..bb0e3cb42 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -1109,6 +1109,15 @@ public class Plot { return loc; } + public Location getSide() { + RegionWrapper largest = getLargestRegion(); + int x = (largest.maxX >> 1) - (largest.minX >> 1) + largest.minX; + int z = largest.minZ - 1; + PlotManager manager = getManager(); + int y = Math.max(WorldUtil.IMP.getHighestBlock(area.worldname, x, z), manager.getSignLoc(area, this).getY()); + return new Location(area.worldname, x, y + 1, z); + } + /** * Return the home location for the plot * @return Home location @@ -1169,12 +1178,7 @@ public class Plot { return new Location(plot.area.worldname, x, y + 1, z); } // Side - RegionWrapper largest = plot.getLargestRegion(); - int x = (largest.maxX >> 1) - (largest.minX >> 1) + largest.minX; - int z = largest.minZ - 1; - PlotManager manager = plot.getManager(); - int y = Math.max(WorldUtil.IMP.getHighestBlock(plot.area.worldname, x, z), manager.getSignLoc(plot.area, plot).getY()); - return new Location(plot.area.worldname, x, y + 1, z); + return plot.getSide(); } public double getVolume() { diff --git a/build.gradle b/build.gradle index 576d06dbb..9574b550b 100644 --- a/build.gradle +++ b/build.gradle @@ -19,7 +19,7 @@ ext { git = Grgit.open() revision = "-${git.head().abbreviatedId}" } -version = "3.4.4-SNAPSHOT-${revision}" +version = "3.4.4-SNAPSHOT${revision}" description = """PlotSquared""" subprojects {