From aa81704f802d04b58505fb5a4a231da814bbc28a Mon Sep 17 00:00:00 2001 From: boy0001 Date: Thu, 2 Oct 2014 22:54:49 +1000 Subject: [PATCH] We should fix up the event system Some of it is my fault. Half the events don't get called properly, or aren't cancellable when they say they are. Tell me your ideas for how we should sort out this mess. --- .../plot/SetBlockFast.java | 7 +- .../plot/events/PlotClearEvent.java | 71 +++++++++++++++++++ .../plot/events/PlotDeleteEvent.java | 2 +- .../plot/listeners/WorldEditListener.java | 2 +- 4 files changed, 78 insertions(+), 4 deletions(-) create mode 100644 PlotSquared/src/com/intellectualcrafters/plot/events/PlotClearEvent.java diff --git a/PlotSquared/src/com/intellectualcrafters/plot/SetBlockFast.java b/PlotSquared/src/com/intellectualcrafters/plot/SetBlockFast.java index f9279dae4..be4b4f166 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/SetBlockFast.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/SetBlockFast.java @@ -2,6 +2,8 @@ package com.intellectualcrafters.plot; import static com.intellectualcrafters.plot.ReflectionUtils.getRefClass; +import org.bukkit.Bukkit; + import com.intellectualcrafters.plot.ReflectionUtils.RefClass; import com.intellectualcrafters.plot.ReflectionUtils.RefMethod; @@ -40,8 +42,9 @@ public class SetBlockFast { } public static void update(org.bukkit.entity.Player player) { - for (int cx = -8; cx < 8; cx++) { - for (int cz = -8; cz < 8; cz++) { + int distance = Bukkit.getViewDistance()+1; + for (int cx = -distance; cx < distance; cx++) { + for (int cz = -distance; cz < distance; cz++) { player.getWorld().refreshChunk(player.getLocation().getChunk().getX() + cx, player.getLocation().getChunk().getZ() + cz); } } diff --git a/PlotSquared/src/com/intellectualcrafters/plot/events/PlotClearEvent.java b/PlotSquared/src/com/intellectualcrafters/plot/events/PlotClearEvent.java new file mode 100644 index 000000000..331a10195 --- /dev/null +++ b/PlotSquared/src/com/intellectualcrafters/plot/events/PlotClearEvent.java @@ -0,0 +1,71 @@ +/* + * Copyright (c) IntellectualCrafters - 2014. + * You are not allowed to distribute and/or monetize any of our intellectual property. + * IntellectualCrafters is not affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. + * + * >> File = PlotClearEvent.java + * >> Generated by: Citymonstret at 2014-08-09 15:21 + */ + +package com.intellectualcrafters.plot.events; + +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +import com.intellectualcrafters.plot.PlotId; + +/** + * Called when a plot is cleared + */ +public class PlotClearEvent extends Event implements Cancellable { + private static HandlerList handlers = new HandlerList(); + private boolean cancelled; + + private PlotId id; + private String world; + /** + * PlotDeleteEvent: Called when a plot is cleared + * @param world + * @param id + */ + public PlotClearEvent(String world, PlotId id) { + this.id = id; + this.world = world; + } + + /** + * Get the PlotId + * @return PlotId + */ + public PlotId getPlotId() { + return this.id; + } + + /** + * Get the world name + * @return String + */ + public String getWorld() { + return this.world; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } + + @Override + public boolean isCancelled() { + return this.cancelled; + } + + @Override + public void setCancelled(boolean b) { + this.cancelled = b; + } +} diff --git a/PlotSquared/src/com/intellectualcrafters/plot/events/PlotDeleteEvent.java b/PlotSquared/src/com/intellectualcrafters/plot/events/PlotDeleteEvent.java index ab1e021e4..9828543b7 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/events/PlotDeleteEvent.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/events/PlotDeleteEvent.java @@ -3,7 +3,7 @@ * You are not allowed to distribute and/or monetize any of our intellectual property. * IntellectualCrafters is not affiliated with Mojang AB. Minecraft is a trademark of Mojang AB. * - * >> File = PlayerClaimPlotEvent.java + * >> File = PlotDeleteEvent.java * >> Generated by: Citymonstret at 2014-08-09 15:21 */ diff --git a/PlotSquared/src/com/intellectualcrafters/plot/listeners/WorldEditListener.java b/PlotSquared/src/com/intellectualcrafters/plot/listeners/WorldEditListener.java index 543c89916..379d58189 100644 --- a/PlotSquared/src/com/intellectualcrafters/plot/listeners/WorldEditListener.java +++ b/PlotSquared/src/com/intellectualcrafters/plot/listeners/WorldEditListener.java @@ -57,7 +57,7 @@ public class WorldEditListener implements Listener { } Plot plot = PlotHelper.getCurrentPlot(b.getLocation()); if (plot != null) { - if ((plot != null) && (plot.helpers.contains(DBFunc.everyone) || plot.helpers.contains(p.getUniqueId()))) { + if ((plot != null) && plot.hasOwner() && plot.helpers!=null && (plot.helpers.contains(DBFunc.everyone) || plot.helpers.contains(p.getUniqueId()))) { PWE.setMask(p, l); } }