Merge branch 'breaking' into UntrustedVisit

This commit is contained in:
mindw0rm 2019-10-23 20:51:59 +02:00 committed by GitHub
commit cb1767347b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 37 deletions

View File

@ -679,41 +679,38 @@ import java.util.regex.Pattern;
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onTeleport(PlayerTeleportEvent event) { public void onTeleport(PlayerTeleportEvent event) {
if (event.getTo() == null || event.getFrom() == null || !event.getFrom().getWorld() final Object lastLoc =
.equals(event.getTo().getWorld())) { BukkitUtil.getPlayer(event.getPlayer()).deleteMeta(PlotPlayer.META_LOCATION);
final Object lastLoc = final Object lastPlot =
BukkitUtil.getPlayer(event.getPlayer()).deleteMeta(PlotPlayer.META_LOCATION); BukkitUtil.getPlayer(event.getPlayer()).deleteMeta(PlotPlayer.META_LAST_PLOT);
final Object lastPlot = org.bukkit.Location to = event.getTo();
BukkitUtil.getPlayer(event.getPlayer()).deleteMeta(PlotPlayer.META_LAST_PLOT); if (to != null) {
org.bukkit.Location to = event.getTo(); Player player = event.getPlayer();
if (to != null) { PlotPlayer plotPlayer = PlotPlayer.wrap(player);
Player player = event.getPlayer(); Location location = BukkitUtil.getLocation(to);
PlotPlayer plotPlayer = PlotPlayer.wrap(player); PlotArea area = location.getPlotArea();
Location location = BukkitUtil.getLocation(to); if (area == null) {
PlotArea area = location.getPlotArea(); return;
if (area == null) { }
return; Plot plot = area.getPlot(location);
} if (plot != null) {
Plot plot = area.getPlot(location); final boolean result = Flags.DENY_TELEPORT.allowsTeleport(plotPlayer, plot);
if (plot != null) { // there is one possibility to still allow teleportation:
final boolean result = Flags.DENY_TELEPORT.allowsTeleport(plotPlayer, plot); // to is identical to the plot's home location, and untrusted-visit is true
// there is one possibility to still allow teleportation: // i.e. untrusted-visit can override deny-teleport
// to is identical to the plot's home location, and untrusted-visit is true // this is acceptable, because otherwise it wouldn't make sense to have both flags set
// i.e. untrusted-visit can override deny-teleport if (!result && !(Flags.UNTRUSTED_VISIT.isTrue(plot) && plot.getHome().equals(BukkitUtil.getLocationFull(to)))) {
// this is acceptable, because otherwise it wouldn't make sense to have both flags set MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT,
if (!result && !(Flags.UNTRUSTED_VISIT.isTrue(plot) && plot.getHome().equals(BukkitUtil.getLocationFull(to)))) { Captions.PERMISSION_ADMIN_ENTRY_DENIED);
MainUtil.sendMessage(plotPlayer, Captions.NO_PERMISSION_EVENT, event.setCancelled(true);
Captions.PERMISSION_ADMIN_ENTRY_DENIED); if (lastLoc != null) {
event.setCancelled(true); plotPlayer.setMeta(PlotPlayer.META_LOCATION, lastLoc);
if (lastLoc != null) {
plotPlayer.setMeta(PlotPlayer.META_LOCATION, lastLoc);
}
if (lastPlot != null) {
plotPlayer.setMeta(PlotPlayer.META_LAST_PLOT, lastPlot);
}
} else {
plotEntry(plotPlayer, plot);
} }
if (lastPlot != null) {
plotPlayer.setMeta(PlotPlayer.META_LAST_PLOT, lastPlot);
}
} else {
plotEntry(plotPlayer, plot);
} }
} }
} }

View File

@ -22,14 +22,14 @@ public class TeleportDenyFlag extends EnumFlag {
result = !plot.getMembers().contains(player.getUUID()); result = !plot.getMembers().contains(player.getUUID());
break; break;
case "nonmembers": case "nonmembers":
result = !plot.isAdded(player.getUUID()); result = plot.isAdded(player.getUUID());
break; break;
case "nontrusted": case "nontrusted":
result = !plot.getTrusted().contains(player.getUUID()) && !plot result = plot.getTrusted().contains(player.getUUID()) || plot
.isOwner(player.getUUID()); .isOwner(player.getUUID());
break; break;
case "nonowners": case "nonowners":
result = !plot.isOwner(player.getUUID()); result = plot.isOwner(player.getUUID());
break; break;
default: default:
return true; return true;