From 491cc50440cc9ad0d3360a63265185c44de14086 Mon Sep 17 00:00:00 2001 From: Jesse Boyd Date: Mon, 13 Mar 2017 18:45:37 +1100 Subject: [PATCH] Fixes #1528 --- .../sponge/listener/MainListener.java | 49 ++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java b/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java index 8a6037db2..5c0d690af 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/listener/MainListener.java @@ -494,11 +494,58 @@ public class MainListener { }); } + @Listener + public void onBlockPlace(ChangeBlockEvent.Pre event) { + Player player = SpongeUtil.getCause(event.getCause(), Player.class); + if (player == null) { + return; + } + PlotPlayer pp = SpongeUtil.getPlayer(player); + World world = event.getTargetWorld(); + String worldName = world.getName(); + if (!PS.get().hasPlotArea(worldName)) { + return; + } + List> locs = event.getLocations(); + org.spongepowered.api.world.Location first = locs.get(0); + Location loc = SpongeUtil.getLocation(worldName, first); + PlotArea area = loc.getPlotArea(); + if (area == null) { + return; + } + Plot plot = area.getPlot(loc); + if (plot == null) { + if (!Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_ROAD, true)) { + event.setCancelled(true); + return; + } + if (plot.hasOwner()) { + if (plot.isAdded(pp.getUUID()) || Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_OTHER)) { + return; + } else { + com.google.common.base.Optional> place = plot.getFlag(Flags.PLACE); + BlockState state = first.getBlock(); + if (!place.isPresent() || !place.get().contains(SpongeUtil.getPlotBlock(state))) { + MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_OTHER); + event.setCancelled(true); + return; + } + } + } else { + if (Permissions.hasPermission(pp, C.PERMISSION_ADMIN_BUILD_UNOWNED)) { + return; + } + MainUtil.sendMessage(pp, C.NO_PERMISSION_EVENT, C.PERMISSION_ADMIN_BUILD_UNOWNED); + event.setCancelled(true); + return; + } + } + } + @Listener public void onBlockPlace(ChangeBlockEvent.Place event) { Player player = SpongeUtil.getCause(event.getCause(), Player.class); if (player == null) { - //SpongeUtil.printCause("place", event.getCause()); return; } PlotPlayer pp = SpongeUtil.getPlayer(player);