From ef60aeb017cdd33ef7ddb2d41b800975d44a18dd Mon Sep 17 00:00:00 2001 From: manuelgu Date: Wed, 25 May 2016 20:54:26 +0200 Subject: [PATCH 1/5] Minor change to issue template --- .github/ISSUE_TEMPLATE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 8e1322977..c15ba3171 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -7,6 +7,6 @@ Make sure you've completed the following steps (put an X between of brackets): - [] Include `/plot debugpaste` -- [] Made sure there aren't duplicates of this report [(Use Search)](https://github.com/IntellectualSites/PlotSquared/issues) +- [] Made sure there aren't duplicates of this report [(Use Search)](https://github.com/IntellectualSites/PlotSquared/issues?utf8=%E2%9C%93&q=is%3Aissue) - [] Made sure you're using an updated version of PlotSquared - [] Made sure the bug/error isn't caused by any other plugin From ceb8fb9fa3ea962e96a7eaaf90976512849174f0 Mon Sep 17 00:00:00 2001 From: manuelgu Date: Wed, 25 May 2016 21:49:55 +0200 Subject: [PATCH 2/5] Implement PlotComponentSetEvent --- .../bukkit/events/PlotComponentSetEvent.java | 56 +++++++++++++++++++ .../bukkit/listeners/PlayerEvents.java | 1 - .../bukkit/util/BukkitEventUtil.java | 6 ++ .../plot/generator/ClassicPlotManager.java | 10 +++- .../plot/util/EventUtil.java | 2 + .../plot/util/EventUtilTest.java | 4 +- .../sponge/events/PlotComponentSetEvent.java | 54 ++++++++++++++++++ .../sponge/util/SpongeEventUtil.java | 6 ++ 8 files changed, 136 insertions(+), 3 deletions(-) create mode 100644 Bukkit/src/main/java/com/plotsquared/bukkit/events/PlotComponentSetEvent.java create mode 100644 Sponge/src/main/java/com/plotsquared/sponge/events/PlotComponentSetEvent.java diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/events/PlotComponentSetEvent.java b/Bukkit/src/main/java/com/plotsquared/bukkit/events/PlotComponentSetEvent.java new file mode 100644 index 000000000..8a2d42d60 --- /dev/null +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/events/PlotComponentSetEvent.java @@ -0,0 +1,56 @@ +package com.plotsquared.bukkit.events; + +import com.intellectualcrafters.plot.object.Plot; +import com.intellectualcrafters.plot.object.PlotId; +import org.bukkit.event.HandlerList; + +/** + * Called when a plot component is set + * + */ +public class PlotComponentSetEvent extends PlotEvent { + + private static final HandlerList handlers = new HandlerList(); + private final String component; + + public PlotComponentSetEvent(Plot plot, String component) { + super(plot); + this.component = component; + } + + public static HandlerList getHandlerList() { + return handlers; + } + + /** + * Get the PlotId + * + * @return PlotId + */ + public PlotId getPlotId() { + return getPlot().getId(); + } + + /** + * Get the world name + * + * @return String + */ + public String getWorld() { + return getPlot().getArea().worldname; + } + + /** + * Get the component which was set + * + * @return Component name + */ + public String getComponent() { + return this.component; + } + + @Override + public HandlerList getHandlers() { + return handlers; + } +} 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 1de494d9e..d2c155023 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listeners/PlayerEvents.java @@ -109,7 +109,6 @@ import org.bukkit.plugin.Plugin; import org.bukkit.projectiles.BlockProjectileSource; import org.bukkit.projectiles.ProjectileSource; import org.bukkit.util.Vector; - import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEventUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEventUtil.java index eaf3c0e17..c28a0a78c 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEventUtil.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitEventUtil.java @@ -18,6 +18,7 @@ import com.plotsquared.bukkit.events.PlayerPlotHelperEvent; import com.plotsquared.bukkit.events.PlayerPlotTrustedEvent; import com.plotsquared.bukkit.events.PlayerTeleportToPlotEvent; import com.plotsquared.bukkit.events.PlotClearEvent; +import com.plotsquared.bukkit.events.PlotComponentSetEvent; import com.plotsquared.bukkit.events.PlotDeleteEvent; import com.plotsquared.bukkit.events.PlotFlagAddEvent; import com.plotsquared.bukkit.events.PlotFlagRemoveEvent; @@ -57,6 +58,11 @@ public class BukkitEventUtil extends EventUtil { return callEvent(new PlayerTeleportToPlotEvent(getPlayer(player), from, plot)); } + @Override + public boolean callComponentSet(Plot plot, String component) { + return callEvent(new PlotComponentSetEvent(plot, component)); + } + @Override public boolean callClear(Plot plot) { return callEvent(new PlotClearEvent(plot)); diff --git a/Core/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotManager.java b/Core/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotManager.java index 4d06944d7..4fe810e5d 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotManager.java @@ -7,9 +7,9 @@ import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PseudoRandom; import com.intellectualcrafters.plot.object.RegionWrapper; +import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.SetQueue; - import java.util.ArrayList; /** @@ -22,27 +22,35 @@ public class ClassicPlotManager extends SquarePlotManager { switch (component) { case "floor": setFloor(plotworld, plotid, blocks); + EventUtil.manager.callComponentSet(plotworld.getPlot(plotid), component); return true; case "wall": setWallFilling(plotworld, plotid, blocks); + EventUtil.manager.callComponentSet(plotworld.getPlot(plotid), component); return true; case "all": setAll(plotworld, plotid, blocks); + EventUtil.manager.callComponentSet(plotworld.getPlot(plotid), component); return true; case "air": setAir(plotworld, plotid, blocks); + EventUtil.manager.callComponentSet(plotworld.getPlot(plotid), component); return true; case "main": setMain(plotworld, plotid, blocks); + EventUtil.manager.callComponentSet(plotworld.getPlot(plotid), component); return true; case "middle": setMiddle(plotworld, plotid, blocks); + EventUtil.manager.callComponentSet(plotworld.getPlot(plotid), component); return true; case "outline": setOutline(plotworld, plotid, blocks); + EventUtil.manager.callComponentSet(plotworld.getPlot(plotid), component); return true; case "border": setWall(plotworld, plotid, blocks); + EventUtil.manager.callComponentSet(plotworld.getPlot(plotid), component); return true; } return false; diff --git a/Core/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java b/Core/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java index dae7611e8..87fd8f4c6 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java @@ -31,6 +31,8 @@ public abstract class EventUtil { public abstract boolean callTeleport(PlotPlayer player, Location from, Plot plot); + public abstract boolean callComponentSet(Plot plot, String component); + public abstract boolean callClear(Plot plot); public abstract void callDelete(Plot plot); diff --git a/Core/src/test/java/com/intellectualcrafters/plot/util/EventUtilTest.java b/Core/src/test/java/com/intellectualcrafters/plot/util/EventUtilTest.java index e093b9b9e..314f7572a 100644 --- a/Core/src/test/java/com/intellectualcrafters/plot/util/EventUtilTest.java +++ b/Core/src/test/java/com/intellectualcrafters/plot/util/EventUtilTest.java @@ -26,6 +26,8 @@ public class EventUtilTest extends EventUtil { return false; } + @Override public boolean callComponentSet(Plot plot, String component) { return false; } + @Override public boolean callClear(Plot plot) { return false; } @@ -61,4 +63,4 @@ public class EventUtilTest extends EventUtil { @Override public void callTrusted(PlotPlayer initiator, Plot plot, UUID player, boolean added) {} @Override public void callMember(PlotPlayer initiator, Plot plot, UUID player, boolean added) {} -} \ No newline at end of file +} diff --git a/Sponge/src/main/java/com/plotsquared/sponge/events/PlotComponentSetEvent.java b/Sponge/src/main/java/com/plotsquared/sponge/events/PlotComponentSetEvent.java new file mode 100644 index 000000000..4558368a3 --- /dev/null +++ b/Sponge/src/main/java/com/plotsquared/sponge/events/PlotComponentSetEvent.java @@ -0,0 +1,54 @@ +package com.plotsquared.sponge.events; + +import com.intellectualcrafters.plot.object.Plot; +import org.spongepowered.api.event.cause.Cause; +import org.spongepowered.api.event.impl.AbstractEvent; + +import com.intellectualcrafters.plot.object.PlotId; + +public class PlotComponentSetEvent extends AbstractEvent { + private final Plot plot; + private final String component; + + /** + * PlotDeleteEvent: Called when a plot is deleted + * + * @param plot The plot that was deleted + */ + public PlotComponentSetEvent(Plot plot, String component) { + this.plot = plot; + this.component = component; + } + + /** + * Get the PlotId + * + * @return PlotId + */ + public PlotId getPlotId() { + return this.plot.getId(); + } + + /** + * Get the world name + * + * @return String + */ + public String getWorld() { + return this.plot.getArea().worldname; + } + + /** + * Get the component which was set + * + * @return Component name + */ + public String getComponent() { + return this.component; + } + + @Override + public Cause getCause() { + return null; + } +} diff --git a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeEventUtil.java b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeEventUtil.java index a9d7ff585..d5f07d5d3 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeEventUtil.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/util/SpongeEventUtil.java @@ -19,6 +19,7 @@ import com.plotsquared.sponge.events.PlayerPlotHelperEvent; import com.plotsquared.sponge.events.PlayerPlotTrustedEvent; import com.plotsquared.sponge.events.PlayerTeleportToPlotEvent; import com.plotsquared.sponge.events.PlotClearEvent; +import com.plotsquared.sponge.events.PlotComponentSetEvent; import com.plotsquared.sponge.events.PlotDeleteEvent; import com.plotsquared.sponge.events.PlotFlagAddEvent; import com.plotsquared.sponge.events.PlotFlagRemoveEvent; @@ -52,6 +53,11 @@ public class SpongeEventUtil extends EventUtil { public boolean callTeleport(PlotPlayer player, Location from, Plot plot) { return callEvent(new PlayerTeleportToPlotEvent(SpongeUtil.getPlayer(player), from, plot)); } + + @Override + public boolean callComponentSet(Plot plot, String component) { + return callEvent(new PlotComponentSetEvent(plot, component)); + } @Override public boolean callClear(Plot plot) { From 4078f0708b92555ee28898fe57584450998e926e Mon Sep 17 00:00:00 2001 From: manuelgu Date: Sat, 28 May 2016 00:29:27 +0200 Subject: [PATCH 3/5] Proper javadoc for event --- .../com/plotsquared/sponge/events/PlotComponentSetEvent.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Sponge/src/main/java/com/plotsquared/sponge/events/PlotComponentSetEvent.java b/Sponge/src/main/java/com/plotsquared/sponge/events/PlotComponentSetEvent.java index 4558368a3..d0cdd4e1d 100644 --- a/Sponge/src/main/java/com/plotsquared/sponge/events/PlotComponentSetEvent.java +++ b/Sponge/src/main/java/com/plotsquared/sponge/events/PlotComponentSetEvent.java @@ -11,9 +11,10 @@ public class PlotComponentSetEvent extends AbstractEvent { private final String component; /** - * PlotDeleteEvent: Called when a plot is deleted + * PlotDeleteEvent: Called when a plot component is set * - * @param plot The plot that was deleted + * @param plot The plot + * @param component The component which was set */ public PlotComponentSetEvent(Plot plot, String component) { this.plot = plot; From ec4839ec3fe598afb1f3c74e14d3c34ef512ea07 Mon Sep 17 00:00:00 2001 From: manuelgu Date: Sat, 28 May 2016 01:09:13 +0200 Subject: [PATCH 4/5] Move event calling to Plot class --- .../java/com/intellectualcrafters/plot/commands/Set.java | 2 +- .../plot/generator/ClassicPlotManager.java | 9 --------- .../java/com/intellectualcrafters/plot/object/Plot.java | 7 +++++-- 3 files changed, 6 insertions(+), 12 deletions(-) diff --git a/Core/src/main/java/com/intellectualcrafters/plot/commands/Set.java b/Core/src/main/java/com/intellectualcrafters/plot/commands/Set.java index bed827fd0..a2d558f76 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/commands/Set.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/commands/Set.java @@ -111,7 +111,7 @@ public class Set extends SubCommand { } plot.addRunning(); for (Plot current : plot.getConnectedPlots()) { - manager.setComponent(plotworld, current.getId(), component, blocks); + current.setComponent(component, blocks); } MainUtil.sendMessage(plr, C.GENERATING_COMPONENT); SetQueue.IMP.addTask(new Runnable() { diff --git a/Core/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotManager.java b/Core/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotManager.java index 4fe810e5d..b98df658e 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotManager.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/generator/ClassicPlotManager.java @@ -7,7 +7,6 @@ import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PseudoRandom; import com.intellectualcrafters.plot.object.RegionWrapper; -import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.SetQueue; import java.util.ArrayList; @@ -22,35 +21,27 @@ public class ClassicPlotManager extends SquarePlotManager { switch (component) { case "floor": setFloor(plotworld, plotid, blocks); - EventUtil.manager.callComponentSet(plotworld.getPlot(plotid), component); return true; case "wall": setWallFilling(plotworld, plotid, blocks); - EventUtil.manager.callComponentSet(plotworld.getPlot(plotid), component); return true; case "all": setAll(plotworld, plotid, blocks); - EventUtil.manager.callComponentSet(plotworld.getPlot(plotid), component); return true; case "air": setAir(plotworld, plotid, blocks); - EventUtil.manager.callComponentSet(plotworld.getPlot(plotid), component); return true; case "main": setMain(plotworld, plotid, blocks); - EventUtil.manager.callComponentSet(plotworld.getPlot(plotid), component); return true; case "middle": setMiddle(plotworld, plotid, blocks); - EventUtil.manager.callComponentSet(plotworld.getPlot(plotid), component); return true; case "outline": setOutline(plotworld, plotid, blocks); - EventUtil.manager.callComponentSet(plotworld.getPlot(plotid), component); return true; case "border": setWall(plotworld, plotid, blocks); - EventUtil.manager.callComponentSet(plotworld.getPlot(plotid), component); return true; } return false; 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 50a2c8283..162333cea 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -18,12 +18,12 @@ import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.Permissions; import com.intellectualcrafters.plot.util.SchematicHandler; import com.intellectualcrafters.plot.util.SetQueue; +import com.intellectualcrafters.plot.util.StringMan; import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.WorldUtil; import com.plotsquared.listener.PlotListener; - -import java.awt.Rectangle; +import java.awt.*; import java.awt.geom.Area; import java.awt.geom.PathIterator; import java.io.File; @@ -2600,6 +2600,9 @@ public class Plot { * @return */ public boolean setComponent(String component, PlotBlock[] blocks) { + if (StringMan.isEqualToAny(component, getManager().getPlotComponents(this.area, this.getId()))) { + EventUtil.manager.callComponentSet(this, component); + } return this.getManager().setComponent(this.area, this.getId(), component, blocks); } From d7b2881778e5f318e6ed4ce0332bc6dd9ae81bd4 Mon Sep 17 00:00:00 2001 From: manuelgu Date: Sat, 28 May 2016 01:12:05 +0200 Subject: [PATCH 5/5] Don't * import --- .../main/java/com/intellectualcrafters/plot/object/Plot.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 162333cea..566f297ed 100644 --- a/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java +++ b/Core/src/main/java/com/intellectualcrafters/plot/object/Plot.java @@ -23,7 +23,7 @@ import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.UUIDHandler; import com.intellectualcrafters.plot.util.WorldUtil; import com.plotsquared.listener.PlotListener; -import java.awt.*; +import java.awt.Rectangle; import java.awt.geom.Area; import java.awt.geom.PathIterator; import java.io.File;