From 58dbe96bd889c5d473f19f277e23247f296f8495 Mon Sep 17 00:00:00 2001 From: mindw0rm Date: Thu, 19 Sep 2019 10:40:47 +0200 Subject: [PATCH 1/5] Added a plot flag 'untrusted visit', that allows /plot visit for untrusted players without the permission plot.visit.other. --- .../intellectualsites/plotsquared/plot/commands/Visit.java | 4 +++- .../github/intellectualsites/plotsquared/plot/flag/Flags.java | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Visit.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Visit.java index ea5647b66..5c38ea63f 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Visit.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/commands/Visit.java @@ -5,6 +5,7 @@ import com.github.intellectualsites.plotsquared.commands.CommandDeclaration; import com.github.intellectualsites.plotsquared.plot.PlotSquared; import com.github.intellectualsites.plotsquared.plot.config.Captions; import com.github.intellectualsites.plotsquared.plot.config.Settings; +import com.github.intellectualsites.plotsquared.plot.flag.Flags; import com.github.intellectualsites.plotsquared.plot.object.*; import com.github.intellectualsites.plotsquared.plot.util.MainUtil; import com.github.intellectualsites.plotsquared.plot.util.MathMan; @@ -129,7 +130,8 @@ import java.util.concurrent.CompletableFuture; return CompletableFuture.completedFuture(false); } } else { - if (!Permissions.hasPermission(player, Captions.PERMISSION_VISIT_OTHER)) { + if (!Permissions.hasPermission(player, Captions.PERMISSION_VISIT_OTHER) && + !Flags.UNTRUSTED_VISIT.isTrue(plot)) { Captions.NO_PERMISSION.send(player, Captions.PERMISSION_VISIT_OTHER); return CompletableFuture.completedFuture(false); } diff --git a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java index fc203a00b..d3f98041c 100644 --- a/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java +++ b/Core/src/main/java/com/github/intellectualsites/plotsquared/plot/flag/Flags.java @@ -121,6 +121,7 @@ public final class Flags { public static final BooleanFlag SLEEP = new BooleanFlag("sleep"); public static final TeleportDenyFlag DENY_TELEPORT = new TeleportDenyFlag("deny-teleport"); public static final BooleanFlag DENY_EXIT = new BooleanFlag("deny-exit"); + public static final BooleanFlag UNTRUSTED_VISIT = new BooleanFlag("untrusted-visit"); private static final HashMap> flags; From 5315e1e3379a20e7bb6c1e73f281ea2f4057745b Mon Sep 17 00:00:00 2001 From: mindw0rm Date: Thu, 10 Oct 2019 20:12:15 +0200 Subject: [PATCH 2/5] let untrusted-visit override deny-teleport --- .../plotsquared/bukkit/listeners/PlayerEvents.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java index f2e8f363a..909b26214 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java @@ -697,7 +697,11 @@ import java.util.regex.Pattern; Plot plot = area.getPlot(location); if (plot != null) { final boolean result = Flags.DENY_TELEPORT.allowsTeleport(plotPlayer, plot); - if (!result) { + // there is one possibility to still allow teleportation: + // to is identical to the plot's home location, and untrusted-visit is true + // i.e. untrusted-visit can override deny-teleport + // this is acceptable, because otherwise it wouldn't make sense to have both flags set + if (!result && !(Flags.UNTRUSTED_VISIT.isTrue(plot) && plot.getHome().equals(location))) { MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_ENTRY_DENIED); event.setCancelled(true); From 0bcaaf3c0b059bbc4a1ad8234320b46ed83b0d8a Mon Sep 17 00:00:00 2001 From: mindw0rm Date: Thu, 10 Oct 2019 20:11:54 +0200 Subject: [PATCH 3/5] copy yaw and pitch when converting between Bukkit Location and PlotSquared Location --- .../plotsquared/bukkit/util/BukkitUtil.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java index ebf67e075..06eb60cd7 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java @@ -212,12 +212,14 @@ import java.util.Set; public static Location getLocation(@NonNull final org.bukkit.Location location) { return new Location(location.getWorld().getName(), MathMan.roundInt(location.getX()), - MathMan.roundInt(location.getY()), MathMan.roundInt(location.getZ())); + MathMan.roundInt(location.getY()), MathMan.roundInt(location.getZ()), + location.getYaw(), location.getPitch()); } public static org.bukkit.Location getLocation(@NonNull final Location location) { return new org.bukkit.Location(getWorld(location.getWorld()), location.getX(), - location.getY(), location.getZ()); + location.getY(), location.getZ(), + location.getYaw(), location.getPitch()); } public static World getWorld(@NonNull final String string) { From dd715a9c8a8fe3f842237d1237edf3f0cbc4fc08 Mon Sep 17 00:00:00 2001 From: mindw0rm Date: Fri, 18 Oct 2019 07:51:01 +0200 Subject: [PATCH 4/5] Revert "copy yaw and pitch when converting between Bukkit Location and PlotSquared Location" Undo this since I can't guarantee that there aren't side effects. --- .../plotsquared/bukkit/util/BukkitUtil.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java index 06eb60cd7..ebf67e075 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java @@ -212,14 +212,12 @@ import java.util.Set; public static Location getLocation(@NonNull final org.bukkit.Location location) { return new Location(location.getWorld().getName(), MathMan.roundInt(location.getX()), - MathMan.roundInt(location.getY()), MathMan.roundInt(location.getZ()), - location.getYaw(), location.getPitch()); + MathMan.roundInt(location.getY()), MathMan.roundInt(location.getZ())); } public static org.bukkit.Location getLocation(@NonNull final Location location) { return new org.bukkit.Location(getWorld(location.getWorld()), location.getX(), - location.getY(), location.getZ(), - location.getYaw(), location.getPitch()); + location.getY(), location.getZ()); } public static World getWorld(@NonNull final String string) { From 20957a75d5b14cd2ae129e326c2003731b14602f Mon Sep 17 00:00:00 2001 From: mindw0rm Date: Fri, 18 Oct 2019 08:02:44 +0200 Subject: [PATCH 5/5] use a new Location convert function to ensure that there will be no side effects --- .../plotsquared/bukkit/listeners/PlayerEvents.java | 2 +- .../plotsquared/bukkit/util/BukkitUtil.java | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java index 909b26214..c10a7eacf 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/listeners/PlayerEvents.java @@ -701,7 +701,7 @@ import java.util.regex.Pattern; // to is identical to the plot's home location, and untrusted-visit is true // i.e. untrusted-visit can override deny-teleport // this is acceptable, because otherwise it wouldn't make sense to have both flags set - if (!result && !(Flags.UNTRUSTED_VISIT.isTrue(plot) && plot.getHome().equals(location))) { + if (!result && !(Flags.UNTRUSTED_VISIT.isTrue(plot) && plot.getHome().equals(BukkitUtil.getLocationFull(to)))) { MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, Captions.PERMISSION_ADMIN_ENTRY_DENIED); event.setCancelled(true); diff --git a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java index ebf67e075..a6f49ca66 100644 --- a/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java +++ b/Bukkit/src/main/java/com/github/intellectualsites/plotsquared/bukkit/util/BukkitUtil.java @@ -215,6 +215,12 @@ import java.util.Set; MathMan.roundInt(location.getY()), MathMan.roundInt(location.getZ())); } + public static Location getLocationFull(@NonNull final org.bukkit.Location location) { + return new Location(location.getWorld().getName(), MathMan.roundInt(location.getX()), + MathMan.roundInt(location.getY()), MathMan.roundInt(location.getZ()), + location.getYaw(), location.getPitch()); + } + public static org.bukkit.Location getLocation(@NonNull final Location location) { return new org.bukkit.Location(getWorld(location.getWorld()), location.getX(), location.getY(), location.getZ());