From d00dc658df44ec55817624042e851b1cf0ac2183 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20S=C3=B6derberg?= Date: Fri, 10 Jul 2020 18:17:44 +0200 Subject: [PATCH] Inject EventDispatcher and PlotListener --- .../plotsquared/bukkit/BukkitPlatform.java | 15 ++++-- .../bukkit/listener/PlayerEvents.java | 16 +++--- .../bukkit/player/BukkitPlayer.java | 16 +++--- .../bukkit/player/BukkitPlayerManager.java | 13 +++-- .../plotsquared/bukkit/util/BukkitUtil.java | 3 +- .../plotsquared/core/{api => }/PlotAPI.java | 3 +- .../com/plotsquared/core/PlotSquared.java | 18 ++++--- .../com/plotsquared/core/command/Add.java | 10 ++-- .../com/plotsquared/core/command/Area.java | 14 ++--- .../com/plotsquared/core/command/Auto.java | 12 +++-- .../com/plotsquared/core/command/Buy.java | 10 ++-- .../com/plotsquared/core/command/Claim.java | 15 ++++-- .../com/plotsquared/core/command/Clear.java | 18 +++---- .../plotsquared/core/command/Continue.java | 11 +++- .../core/command/DatabaseCommand.java | 15 ++++-- .../plotsquared/core/command/DebugExec.java | 11 ++-- .../com/plotsquared/core/command/Delete.java | 15 +++--- .../com/plotsquared/core/command/Deny.java | 7 ++- .../com/plotsquared/core/command/Desc.java | 15 ++++-- .../com/plotsquared/core/command/Dislike.java | 9 +++- .../com/plotsquared/core/command/Done.java | 11 +++- .../com/plotsquared/core/command/Leave.java | 13 +++-- .../com/plotsquared/core/command/Like.java | 12 ++++- .../plotsquared/core/command/MainCommand.java | 54 ++++++++++--------- .../com/plotsquared/core/command/Merge.java | 10 +++- .../com/plotsquared/core/command/Owner.java | 16 ++++-- .../com/plotsquared/core/command/Purge.java | 8 +-- .../com/plotsquared/core/command/Rate.java | 12 ++++- .../com/plotsquared/core/command/Remove.java | 26 +++++---- .../com/plotsquared/core/command/Trust.java | 10 ++-- .../com/plotsquared/core/command/Unlink.java | 11 +++- .../plotsquared/core/database/SQLManager.java | 12 ++++- .../core/generator/ClassicPlotWorld.java | 7 ++- .../core/generator/GridPlotWorld.java | 7 ++- .../plotsquared/core/generator/HybridGen.java | 10 +++- .../core/generator/HybridPlotWorld.java | 7 ++- .../core/generator/SquarePlotWorld.java | 7 ++- .../core/listener/PlotListener.java | 24 +++++---- .../core/player/ConsolePlayer.java | 7 +-- .../plotsquared/core/player/PlotPlayer.java | 8 +-- .../java/com/plotsquared/core/plot/Plot.java | 40 +++++++++----- .../com/plotsquared/core/plot/PlotArea.java | 14 +++-- .../core/plot/expiration/ExpireManager.java | 15 ++++-- .../core/plot/world/SinglePlot.java | 20 +++---- .../core/plot/world/SinglePlotArea.java | 17 ++++-- .../plot/world/SinglePlotAreaManager.java | 7 ++- .../core/util/task/AutoClaimFinishTask.java | 6 +-- 47 files changed, 418 insertions(+), 219 deletions(-) rename Core/src/main/java/com/plotsquared/core/{api => }/PlotAPI.java (98%) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java index a46a4919c..f66beb48f 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/BukkitPlatform.java @@ -94,6 +94,7 @@ import com.plotsquared.core.util.ChatManager; import com.plotsquared.core.util.ChunkManager; import com.plotsquared.core.util.ConsoleColors; import com.plotsquared.core.util.EconHandler; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.InventoryUtil; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.PermHandler; @@ -183,7 +184,10 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl private BukkitPlayerManager playerManager; private EconHandler econ; private PermHandler perm; + private PlotAreaManager plotAreaManager; + private EventDispatcher eventDispatcher; + private PlotListener plotListener; @Override public int[] getServerVersion() { if (this.version == null) { @@ -215,8 +219,11 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl PlotPlayer.registerConverter(Player.class, BukkitUtil::getPlayer); final PlotSquared plotSquared = new PlotSquared(this, "Bukkit"); + this.plotAreaManager = plotSquared.getPlotAreaManager(); - this.playerManager = new BukkitPlayerManager(this.plotAreaManager); + this.eventDispatcher = plotSquared.getEventDispatcher(); + this.plotListener = plotSquared.getPlotListener(); + this.playerManager = new BukkitPlayerManager(this.plotAreaManager, this.eventDispatcher); if (PlotSquared.platform().getServerVersion()[1] < 13) { System.out.println( @@ -897,13 +904,13 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl } @Override public void registerPlayerEvents() { - final PlayerEvents main = new PlayerEvents(this.plotAreaManager); + final PlayerEvents main = new PlayerEvents(this.plotAreaManager, this.eventDispatcher); getServer().getPluginManager().registerEvents(main, this); getServer().getPluginManager().registerEvents(new EntitySpawnListener(), this); if (PaperLib.isPaper() && Settings.Paper_Components.PAPER_LISTENERS) { getServer().getPluginManager().registerEvents(new PaperListener(this.plotAreaManager), this); } - PlotListener.startRunnable(); + this.plotListener.startRunnable(); } @Override public void registerForceFieldEvents() { @@ -1051,7 +1058,7 @@ public final class BukkitPlatform extends JavaPlugin implements Listener, PlotPl } @NotNull @Override public IndependentPlotGenerator getDefaultGenerator() { - return new HybridGen(); + return new HybridGen(this.eventDispatcher, this.plotListener); } @Override public InventoryUtil initInventoryUtil() { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java index 92b3fc99d..05eb89642 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/listener/PlayerEvents.java @@ -101,6 +101,7 @@ import com.plotsquared.core.plot.flag.types.BlockTypeWrapper; import com.plotsquared.core.plot.message.PlotMessage; import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.EntityUtil; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.MathMan; import com.plotsquared.core.util.Permissions; @@ -232,6 +233,7 @@ import java.util.regex.Pattern; new com.sk89q.worldedit.world.entity.EntityType("plotsquared:fake"); private final PlotAreaManager plotAreaManager; + private final EventDispatcher eventDispatcher; private boolean pistonBlocks = true; private float lastRadius; @@ -241,8 +243,10 @@ import java.util.regex.Pattern; private PlayerMoveEvent moveTmp; private String internalVersion; - public PlayerEvents(@NotNull final PlotAreaManager plotAreaManager) { + public PlayerEvents(@NotNull final PlotAreaManager plotAreaManager, @NotNull final EventDispatcher eventDispatcher) { + super(eventDispatcher); this.plotAreaManager = plotAreaManager; + this.eventDispatcher = eventDispatcher; try { fieldPlayer = PlayerEvent.class.getDeclaredField("player"); fieldPlayer.setAccessible(true); @@ -688,7 +692,7 @@ import java.util.regex.Pattern; if (!player.hasPlayedBefore() && player.isOnline()) { player.saveData(); } - PlotSquared.get().getEventDispatcher().doJoinTask(pp); + this.eventDispatcher.doJoinTask(pp); }, 20); if (pp.hasPermission(Captions.PERMISSION_ADMIN_UPDATE_NOTIFICATION.getTranslated()) @@ -711,7 +715,7 @@ import java.util.regex.Pattern; public void playerRespawn(PlayerRespawnEvent event) { Player player = event.getPlayer(); PlotPlayer pp = BukkitUtil.getPlayer(player); - PlotSquared.get().getEventDispatcher().doRespawnTask(pp); + this.eventDispatcher.doRespawnTask(pp); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) @@ -1968,7 +1972,7 @@ import java.util.regex.Pattern; Block block = player.getTargetBlockExact(5, FluidCollisionMode.SOURCE_ONLY); if (block != null && block.getType() != Material.AIR) { Location location = BukkitUtil.getLocation(block.getLocation()); - if (!PlotSquared.get().getEventDispatcher() + if (!this.eventDispatcher .checkPlayerBlockEvent(pp, PlayerBlockEventType.SPAWN_MOB, location, null, true)) { event.setCancelled(true); @@ -2105,7 +2109,7 @@ import java.util.regex.Pattern; return; } } - if (!PlotSquared.get().getEventDispatcher() + if (!this.eventDispatcher .checkPlayerBlockEvent(pp, eventType, location, blocktype1, true)) { event.setCancelled(true); event.setUseInteractedBlock(Event.Result.DENY); @@ -2393,7 +2397,7 @@ import java.util.regex.Pattern; TaskManager.TELEPORT_QUEUE.remove(event.getPlayer().getName()); BukkitPlayer pp = BukkitUtil.getPlayer(event.getPlayer()); pp.unregister(); - PlotListener.logout(pp.getUUID()); + this.logout(pp.getUUID()); } @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java index 7210778a9..b7ca57e81 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayer.java @@ -36,6 +36,7 @@ import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.PlotWeather; import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.EconHandler; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MathMan; import com.plotsquared.core.util.StringMan; import com.sk89q.worldedit.bukkit.BukkitAdapter; @@ -77,16 +78,19 @@ public class BukkitPlayer extends PlotPlayer { * * @param player Bukkit player instance */ - public BukkitPlayer(@NotNull final PlotAreaManager plotAreaManager, @NotNull final Player player) { - this(plotAreaManager, player, false); + public BukkitPlayer(@NotNull final PlotAreaManager plotAreaManager, @NotNull final EventDispatcher eventDispatcher, + @NotNull final Player player) { + this(plotAreaManager, eventDispatcher, player, false); } - public BukkitPlayer(@NotNull final PlotAreaManager plotAreaManager, @NotNull final Player player, final boolean offline) { - this(plotAreaManager, player, offline, true); + public BukkitPlayer(@NotNull final PlotAreaManager plotAreaManager, @NotNull final EventDispatcher eventDispatcher, + @NotNull final Player player, final boolean offline) { + this(plotAreaManager, eventDispatcher, player, offline, true); } - public BukkitPlayer(@NotNull final PlotAreaManager plotAreaManager, @NotNull final Player player, final boolean offline, final boolean realPlayer) { - super(plotAreaManager); + public BukkitPlayer(@NotNull final PlotAreaManager plotAreaManager, @NotNull final + EventDispatcher eventDispatcher, @NotNull final Player player, final boolean offline, final boolean realPlayer) { + super(plotAreaManager, eventDispatcher); this.player = player; this.offline = offline; if (realPlayer) { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayerManager.java b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayerManager.java index fb023ed8f..c6c835a37 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayerManager.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/player/BukkitPlayerManager.java @@ -26,7 +26,9 @@ package com.plotsquared.bukkit.player; import com.plotsquared.core.plot.world.PlotAreaManager; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.PlayerManager; +import lombok.RequiredArgsConstructor; import org.bukkit.Bukkit; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; @@ -37,19 +39,16 @@ import java.util.UUID; /** * Player manager providing {@link BukkitPlayer Bukkit players} */ -public class BukkitPlayerManager extends PlayerManager { +@RequiredArgsConstructor public class BukkitPlayerManager extends PlayerManager { private final PlotAreaManager plotAreaManager; - - public BukkitPlayerManager(@NotNull final PlotAreaManager plotAreaManager) { - this.plotAreaManager = plotAreaManager; - } + private final EventDispatcher eventDispatcher; @NotNull @Override public BukkitPlayer getPlayer(@NotNull final Player object) { try { return getPlayer(object.getUniqueId()); } catch (final NoSuchPlayerException exception) { - return new BukkitPlayer(this.plotAreaManager, object, object.isOnline(), false); + return new BukkitPlayer(this.plotAreaManager, this.eventDispatcher, object, object.isOnline(), false); } } @@ -58,7 +57,7 @@ public class BukkitPlayerManager extends PlayerManager { if (player == null || !player.isOnline()) { throw new NoSuchPlayerException(uuid); } - return new BukkitPlayer(this.plotAreaManager, player); + return new BukkitPlayer(this.plotAreaManager, this.eventDispatcher, player); } @Nullable @Override public BukkitOfflinePlayer getOfflinePlayer(@Nullable final UUID uuid) { diff --git a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java index 1c4dd1f45..8f532e2e9 100644 --- a/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java +++ b/Bukkit/src/main/java/com/plotsquared/bukkit/util/BukkitUtil.java @@ -129,7 +129,8 @@ public class BukkitUtil extends WorldUtil { } final Player player = OfflinePlayerUtil.loadPlayer(op); player.loadData(); - return new BukkitPlayer(PlotSquared.get().getPlotAreaManager(), player, true); + return new BukkitPlayer(PlotSquared.get().getPlotAreaManager(), + PlotSquared.get().getEventDispatcher(), player, true); } /** diff --git a/Core/src/main/java/com/plotsquared/core/api/PlotAPI.java b/Core/src/main/java/com/plotsquared/core/PlotAPI.java similarity index 98% rename from Core/src/main/java/com/plotsquared/core/api/PlotAPI.java rename to Core/src/main/java/com/plotsquared/core/PlotAPI.java index fd56538fb..eb1c99607 100644 --- a/Core/src/main/java/com/plotsquared/core/api/PlotAPI.java +++ b/Core/src/main/java/com/plotsquared/core/PlotAPI.java @@ -23,9 +23,8 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ -package com.plotsquared.core.api; +package com.plotsquared.core; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Caption; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.file.YamlConfiguration; diff --git a/Core/src/main/java/com/plotsquared/core/PlotSquared.java b/Core/src/main/java/com/plotsquared/core/PlotSquared.java index ab9fd2472..eb575f66f 100644 --- a/Core/src/main/java/com/plotsquared/core/PlotSquared.java +++ b/Core/src/main/java/com/plotsquared/core/PlotSquared.java @@ -46,6 +46,7 @@ import com.plotsquared.core.generator.GeneratorWrapper; import com.plotsquared.core.generator.HybridPlotWorld; import com.plotsquared.core.generator.HybridUtils; import com.plotsquared.core.generator.IndependentPlotGenerator; +import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.listener.WESubscriber; import com.plotsquared.core.location.Location; import com.plotsquared.core.player.ConsolePlayer; @@ -166,6 +167,7 @@ public class PlotSquared { private File storageFile; @Getter private PlotAreaManager plotAreaManager; @Getter private EventDispatcher eventDispatcher; + @Getter private PlotListener plotListener; /** * Initialize PlotSquared with the desired Implementation class. @@ -217,9 +219,14 @@ public class PlotSquared { + ".use_THIS.yml"); Captions.load(this.translationFile); + // Create Event utility class + this.eventDispatcher = new EventDispatcher(); + // Create plot listener + this.plotListener = new PlotListener(this.eventDispatcher); + // Setup plotAreaManager if (Settings.Enabled_Components.WORLDS) { - this.plotAreaManager = new SinglePlotAreaManager(); + this.plotAreaManager = new SinglePlotAreaManager(this.eventDispatcher, this.plotListener); } else { this.plotAreaManager = new DefaultPlotAreaManager(); } @@ -254,8 +261,6 @@ public class PlotSquared { if (Settings.Enabled_Components.CHUNK_PROCESSOR) { this.platform.registerChunkProcessor(); } - // Create Event utility class - eventDispatcher = new EventDispatcher(); // create Hybrid utility class HybridUtils.manager = this.platform.initHybridUtils(); // Inventory utility class @@ -427,7 +432,7 @@ public class PlotSquared { private void startExpiryTasks() { if (Settings.Enabled_Components.PLOT_EXPIRY) { - ExpireManager.IMP = new ExpireManager(); + ExpireManager.IMP = new ExpireManager(this.eventDispatcher); ExpireManager.IMP.runAutomatedTask(); for (Settings.Auto_Clear settings : Settings.AUTO_CLEAR.getInstances()) { ExpiryTask task = new ExpiryTask(settings, this.plotAreaManager); @@ -1207,7 +1212,8 @@ public class PlotSquared { split = combinedArgs; } - HybridPlotWorld plotworld = new HybridPlotWorld(world, null, generator, null, null); + HybridPlotWorld plotworld = new HybridPlotWorld(world, null, generator, + null, null, this.eventDispatcher, this.plotListener); for (String element : split) { String[] pair = element.split("="); if (pair.length != 2) { @@ -1420,7 +1426,7 @@ public class PlotSquared { this.platform.shutdown(); //shutdown used instead of disable because no database is set return; } - DBFunc.dbManager = new SQLManager(database, Storage.PREFIX, false); + DBFunc.dbManager = new SQLManager(database, Storage.PREFIX, this.eventDispatcher, this.plotListener); this.plots_tmp = DBFunc.getPlots(); if (plotAreaManager instanceof SinglePlotAreaManager) { SinglePlotArea area = ((SinglePlotAreaManager) plotAreaManager).getArea(); diff --git a/Core/src/main/java/com/plotsquared/core/command/Add.java b/Core/src/main/java/com/plotsquared/core/command/Add.java index 6d86f7532..f1eab4936 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Add.java +++ b/Core/src/main/java/com/plotsquared/core/command/Add.java @@ -25,16 +25,17 @@ */ package com.plotsquared.core.command; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.database.DBFunc; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.TabCompletions; import com.plotsquared.core.util.task.RunnableVal2; import com.plotsquared.core.util.task.RunnableVal3; +import org.jetbrains.annotations.NotNull; import java.util.Collection; import java.util.Collections; @@ -51,8 +52,11 @@ import java.util.concurrent.TimeoutException; requiredType = RequiredType.PLAYER) public class Add extends Command { - public Add() { + private final EventDispatcher eventDispatcher; + + public Add(@NotNull final EventDispatcher eventDispatcher) { super(MainCommand.getInstance(), true); + this.eventDispatcher = eventDispatcher; } @Override @@ -116,7 +120,7 @@ public class Add extends Command { } } plot.addMember(uuid); - PlotSquared.get().getEventDispatcher().callMember(player, plot, uuid, true); + this.eventDispatcher.callMember(player, plot, uuid, true); MainUtil.sendMessage(player, Captions.MEMBER_ADDED); } }, null); diff --git a/Core/src/main/java/com/plotsquared/core/command/Area.java b/Core/src/main/java/com/plotsquared/core/command/Area.java index 2c6c1d51f..ad7fbe9f9 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Area.java +++ b/Core/src/main/java/com/plotsquared/core/command/Area.java @@ -32,6 +32,7 @@ import com.plotsquared.core.configuration.ConfigurationUtil; import com.plotsquared.core.events.TeleportCause; import com.plotsquared.core.generator.AugmentedUtils; import com.plotsquared.core.generator.HybridPlotWorld; +import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.location.Location; import com.plotsquared.core.player.ConsolePlayer; import com.plotsquared.core.player.PlotPlayer; @@ -42,6 +43,7 @@ import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.plot.message.PlotMessage; import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.setup.PlotAreaBuilder; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.MathMan; import com.plotsquared.core.util.Permissions; @@ -66,6 +68,7 @@ import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Region; +import lombok.RequiredArgsConstructor; import org.jetbrains.annotations.NotNull; import java.io.File; @@ -85,13 +88,12 @@ import java.util.Set; aliases = "world", usage = "/plot area ", confirmation = true) +@RequiredArgsConstructor public class Area extends SubCommand { private final PlotAreaManager plotAreaManager; - - public Area(@NotNull final PlotAreaManager plotAreaManager) { - this.plotAreaManager = plotAreaManager; - } + private final EventDispatcher eventDispatcher; + private final PlotListener plotListener; @Override public boolean onCommand(final PlotPlayer player, String[] args) { if (args.length == 0) { @@ -148,7 +150,7 @@ public class Area extends SubCommand { // There's only one plot in the area... final PlotId plotId = new PlotId(1, 1); final HybridPlotWorld hybridPlotWorld = new HybridPlotWorld(player.getLocation().getWorldName(), args[1], - Objects.requireNonNull(PlotSquared.platform()).getDefaultGenerator(), plotId, plotId); + Objects.requireNonNull(PlotSquared.platform()).getDefaultGenerator(), plotId, plotId, this.eventDispatcher, this.plotListener); // Plot size is the same as the region width hybridPlotWorld.PLOT_WIDTH = hybridPlotWorld.SIZE = (short) selectedRegion.getWidth(); // We use a schematic generator @@ -349,7 +351,7 @@ public class Area extends SubCommand { PlotAreaBuilder builder = new PlotAreaBuilder(); builder.worldName(split[0]); final HybridPlotWorld pa = new HybridPlotWorld(builder.worldName(), id, - PlotSquared.platform().getDefaultGenerator(), null, null); + PlotSquared.platform().getDefaultGenerator(), null, null, this.eventDispatcher, this.plotListener); PlotArea other = this.plotAreaManager.getPlotArea(pa.getWorldName(), id); if (other != null && Objects.equals(pa.getId(), other.getId())) { Captions.SETUP_WORLD_TAKEN.send(player, pa.toString()); diff --git a/Core/src/main/java/com/plotsquared/core/command/Auto.java b/Core/src/main/java/com/plotsquared/core/command/Auto.java index 41f08b187..ff405ddd3 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Auto.java +++ b/Core/src/main/java/com/plotsquared/core/command/Auto.java @@ -42,6 +42,7 @@ import com.plotsquared.core.plot.PlotAreaType; import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.EconHandler; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.Expression; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.Permissions; @@ -64,9 +65,11 @@ import java.util.Set; public class Auto extends SubCommand { private final PlotAreaManager plotAreaManager; + private final EventDispatcher eventDispatcher; - public Auto(@NotNull final PlotAreaManager plotAreaManager) { + public Auto(@NotNull final PlotAreaManager plotAreaManager, @NotNull final EventDispatcher eventDispatcher) { this.plotAreaManager = plotAreaManager; + this.eventDispatcher = eventDispatcher; } @Deprecated public static PlotId getNextPlotId(PlotId id, int step) { @@ -144,7 +147,8 @@ public class Auto extends SubCommand { player.setMeta(Auto.class.getName(), true); autoClaimFromDatabase(player, area, start, new RunnableVal() { @Override public void run(final Plot plot) { - TaskManager.IMP.sync(new AutoClaimFinishTask(player, plot, area, schematic)); + TaskManager.IMP.sync(new AutoClaimFinishTask(player, plot, area, schematic, + PlotSquared.get().getEventDispatcher())); } }); } @@ -221,7 +225,7 @@ public class Auto extends SubCommand { // return false; } } - PlayerAutoPlotEvent event = PlotSquared.get().getEventDispatcher() + PlayerAutoPlotEvent event = this.eventDispatcher .callAuto(player, plotarea, schematic, size_x, size_z); if (event.getEventResult() == Result.DENY) { sendMessage(player, Captions.EVENT_DENIED, "Auto claim"); @@ -302,7 +306,7 @@ public class Auto extends SubCommand { } ArrayList plotIds = MainUtil.getPlotSelectionIds(start, end); final PlotId pos1 = plotIds.get(0); - final PlotAutoMergeEvent mergeEvent = PlotSquared.get().getEventDispatcher() + final PlotAutoMergeEvent mergeEvent = this.eventDispatcher .callAutoMerge(plotarea.getPlotAbs(pos1), plotIds); if (!force && mergeEvent.getEventResult() == Result.DENY) { sendMessage(player, Captions.EVENT_DENIED, "Auto merge"); diff --git a/Core/src/main/java/com/plotsquared/core/command/Buy.java b/Core/src/main/java/com/plotsquared/core/command/Buy.java index 1d599d408..b8535a312 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Buy.java +++ b/Core/src/main/java/com/plotsquared/core/command/Buy.java @@ -34,9 +34,11 @@ import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.flag.PlotFlag; import com.plotsquared.core.plot.flag.implementations.PriceFlag; import com.plotsquared.core.util.EconHandler; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.task.RunnableVal2; import com.plotsquared.core.util.task.RunnableVal3; +import org.jetbrains.annotations.NotNull; import java.util.Set; import java.util.concurrent.CompletableFuture; @@ -49,8 +51,11 @@ import java.util.concurrent.CompletableFuture; requiredType = RequiredType.NONE) public class Buy extends Command { - public Buy() { + private final EventDispatcher eventDispatcher; + + public Buy(@NotNull final EventDispatcher eventDispatcher) { super(MainCommand.getInstance(), true); + this.eventDispatcher = eventDispatcher; } @Override @@ -89,8 +94,7 @@ public class Buy extends Command { Captions.PLOT_SOLD.send(owner, plot.getId(), player.getName(), price); } PlotFlag plotFlag = plot.getFlagContainer().getFlag(PriceFlag.class); - PlotFlagRemoveEvent event = - PlotSquared.get().getEventDispatcher().callFlagRemove(plotFlag, plot); + PlotFlagRemoveEvent event = this.eventDispatcher.callFlagRemove(plotFlag, plot); if (event.getEventResult() != Result.DENY) { plot.removeFlag(event.getFlag()); } diff --git a/Core/src/main/java/com/plotsquared/core/command/Claim.java b/Core/src/main/java/com/plotsquared/core/command/Claim.java index bf222d1b3..4677362fd 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Claim.java +++ b/Core/src/main/java/com/plotsquared/core/command/Claim.java @@ -40,10 +40,12 @@ import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.util.EconHandler; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.Expression; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.TaskManager; +import org.jetbrains.annotations.NotNull; @CommandDeclaration(command = "claim", aliases = "c", @@ -54,18 +56,23 @@ import com.plotsquared.core.util.task.TaskManager; usage = "/plot claim") public class Claim extends SubCommand { + private final EventDispatcher eventDispatcher; + + public Claim(@NotNull final EventDispatcher eventDispatcher) { + this.eventDispatcher = eventDispatcher; + } + @Override public boolean onCommand(final PlotPlayer player, String[] args) { String schematic = null; if (args.length >= 1) { schematic = args[0]; } Location location = player.getLocation(); - final Plot plot = location.getPlotAbs(); + Plot plot = location.getPlotAbs(); if (plot == null) { return sendMessage(player, Captions.NOT_IN_PLOT); } - PlayerClaimPlotEvent event = - PlotSquared.get().getEventDispatcher().callClaim(player, plot, schematic); + final PlayerClaimPlotEvent event = this.eventDispatcher.callClaim(player, plot, schematic); schematic = event.getSchematic(); if (event.getEventResult() == Result.DENY) { sendMessage(player, Captions.EVENT_DENIED, "Claim"); @@ -138,7 +145,7 @@ public class Claim extends SubCommand { sendMessage(player, Captions.PLOT_NOT_CLAIMED); plot.setOwnerAbs(null); } else if (area.isAutoMerge()) { - PlotMergeEvent event = PlotSquared.get().getEventDispatcher() + PlotMergeEvent event = Claim.this.eventDispatcher .callMerge(plot, Direction.ALL, Integer.MAX_VALUE, player); if (event.getEventResult() == Result.DENY) { sendMessage(player, Captions.EVENT_DENIED, "Auto merge on claim"); diff --git a/Core/src/main/java/com/plotsquared/core/command/Clear.java b/Core/src/main/java/com/plotsquared/core/command/Clear.java index 9d8279eda..821483629 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Clear.java +++ b/Core/src/main/java/com/plotsquared/core/command/Clear.java @@ -25,7 +25,6 @@ */ package com.plotsquared.core.command; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.backup.BackupManager; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; @@ -37,10 +36,12 @@ import com.plotsquared.core.plot.flag.PlotFlag; import com.plotsquared.core.plot.flag.implementations.AnalysisFlag; import com.plotsquared.core.plot.flag.implementations.DoneFlag; import com.plotsquared.core.queue.GlobalBlockQueue; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.task.RunnableVal2; import com.plotsquared.core.util.task.RunnableVal3; +import org.jetbrains.annotations.NotNull; import java.util.concurrent.CompletableFuture; @@ -56,11 +57,11 @@ import static com.plotsquared.core.command.SubCommand.sendMessage; confirmation = true) public class Clear extends Command { - // Note: To clear a specific plot use /plot clear - // The syntax also works with any command: /plot - - public Clear() { + private final EventDispatcher eventDispatcher; + + public Clear(@NotNull final EventDispatcher eventDispatcher) { super(MainCommand.getInstance(), true); + this.eventDispatcher = eventDispatcher; } @Override @@ -69,8 +70,7 @@ public class Clear extends Command { RunnableVal2 whenDone) throws CommandException { checkTrue(args.length == 0, Captions.COMMAND_SYNTAX, getUsage()); final Plot plot = check(player.getCurrentPlot(), Captions.NOT_IN_PLOT); - Result eventResult = - PlotSquared.get().getEventDispatcher().callClear(plot).getEventResult(); + Result eventResult = this.eventDispatcher.callClear(plot).getEventResult(); if (eventResult == Result.DENY) { sendMessage(player, Captions.EVENT_DENIED, "Clear"); return CompletableFuture.completedFuture(true); @@ -93,7 +93,7 @@ public class Clear extends Command { if (DoneFlag.isDone(plot)) { PlotFlag plotFlag = plot.getFlagContainer().getFlag(DoneFlag.class); - PlotFlagRemoveEvent event = PlotSquared.get().getEventDispatcher() + PlotFlagRemoveEvent event = this.eventDispatcher .callFlagRemove(plotFlag, plot); if (event.getEventResult() != Result.DENY) { plot.removeFlag(event.getFlag()); @@ -102,7 +102,7 @@ public class Clear extends Command { if (!plot.getFlag(AnalysisFlag.class).isEmpty()) { PlotFlag plotFlag = plot.getFlagContainer().getFlag(AnalysisFlag.class); - PlotFlagRemoveEvent event = PlotSquared.get().getEventDispatcher() + PlotFlagRemoveEvent event = this.eventDispatcher .callFlagRemove(plotFlag, plot); if (event.getEventResult() != Result.DENY) { plot.removeFlag(event.getFlag()); diff --git a/Core/src/main/java/com/plotsquared/core/command/Continue.java b/Core/src/main/java/com/plotsquared/core/command/Continue.java index 23f5e93a0..1f619f2a3 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Continue.java +++ b/Core/src/main/java/com/plotsquared/core/command/Continue.java @@ -25,7 +25,6 @@ */ package com.plotsquared.core.command; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.events.PlotFlagRemoveEvent; @@ -34,8 +33,10 @@ import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.flag.PlotFlag; import com.plotsquared.core.plot.flag.implementations.DoneFlag; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.Permissions; +import org.jetbrains.annotations.NotNull; @CommandDeclaration(command = "continue", description = "Continue a plot that was previously marked as done", @@ -44,6 +45,12 @@ import com.plotsquared.core.util.Permissions; requiredType = RequiredType.PLAYER) public class Continue extends SubCommand { + private final EventDispatcher eventDispatcher; + + public Continue(@NotNull final EventDispatcher eventDispatcher) { + this.eventDispatcher = eventDispatcher; + } + @Override public boolean onCommand(PlotPlayer player, String[] args) { Plot plot = player.getCurrentPlot(); if ((plot == null) || !plot.hasOwner()) { @@ -71,7 +78,7 @@ public class Continue extends SubCommand { } PlotFlag plotFlag = plot.getFlagContainer().getFlag(DoneFlag.class); PlotFlagRemoveEvent event = - PlotSquared.get().getEventDispatcher().callFlagRemove(plotFlag, plot); + this.eventDispatcher.callFlagRemove(plotFlag, plot); if (event.getEventResult() == Result.DENY) { sendMessage(player, Captions.EVENT_DENIED, "Done flag removal"); return true; diff --git a/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java b/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java index a1f40039f..d95e05087 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java +++ b/Core/src/main/java/com/plotsquared/core/command/DatabaseCommand.java @@ -31,12 +31,14 @@ import com.plotsquared.core.database.Database; import com.plotsquared.core.database.MySQL; import com.plotsquared.core.database.SQLManager; import com.plotsquared.core.database.SQLite; +import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.plot.world.SinglePlotArea; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.query.PlotQuery; import com.plotsquared.core.util.task.TaskManager; @@ -60,9 +62,14 @@ import java.util.Map.Entry; public class DatabaseCommand extends SubCommand { private final PlotAreaManager plotAreaManager; + private final EventDispatcher eventDispatcher; + private final PlotListener plotListener; - public DatabaseCommand(@NotNull final PlotAreaManager plotAreaManager) { + public DatabaseCommand(@NotNull final PlotAreaManager plotAreaManager, @NotNull final EventDispatcher eventDispatcher, + @NotNull final PlotListener plotListener) { this.plotAreaManager = plotAreaManager; + this.eventDispatcher = eventDispatcher; + this.plotListener = plotListener; } public static void insertPlots(final SQLManager manager, final List plots, @@ -119,8 +126,8 @@ public class DatabaseCommand extends SubCommand { } MainUtil.sendMessage(player, "&6Starting..."); implementation = new SQLite(file); - SQLManager manager = - new SQLManager(implementation, args.length == 3 ? args[2] : "", true); + SQLManager manager = new SQLManager(implementation, args.length == 3 ? args[2] : "", + this.eventDispatcher, this.plotListener); HashMap> map = manager.getPlots(); plots = new ArrayList<>(); for (Entry> entry : map.entrySet()) { @@ -195,7 +202,7 @@ public class DatabaseCommand extends SubCommand { return MainUtil.sendMessage(player, "/plot database [sqlite/mysql]"); } try { - SQLManager manager = new SQLManager(implementation, prefix, true); + SQLManager manager = new SQLManager(implementation, prefix, this.eventDispatcher, this.plotListener); DatabaseCommand.insertPlots(manager, plots, player); return true; } catch (ClassNotFoundException | SQLException e) { diff --git a/Core/src/main/java/com/plotsquared/core/command/DebugExec.java b/Core/src/main/java/com/plotsquared/core/command/DebugExec.java index 481699a3c..1d7c5901f 100644 --- a/Core/src/main/java/com/plotsquared/core/command/DebugExec.java +++ b/Core/src/main/java/com/plotsquared/core/command/DebugExec.java @@ -48,6 +48,7 @@ import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.queue.GlobalBlockQueue; import com.plotsquared.core.util.ChunkManager; import com.plotsquared.core.util.EconHandler; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.MathMan; import com.plotsquared.core.util.SchematicHandler; @@ -85,11 +86,13 @@ import java.util.concurrent.CompletableFuture; public class DebugExec extends SubCommand { private final PlotAreaManager plotAreaManager; + private final EventDispatcher eventDispatcher; private ScriptEngine engine; private Bindings scope; - public DebugExec(@NotNull final PlotAreaManager plotAreaManager) { + public DebugExec(@NotNull final PlotAreaManager plotAreaManager, @NotNull final EventDispatcher eventDispatcher) { this.plotAreaManager = plotAreaManager; + this.eventDispatcher = eventDispatcher; init(); /* try { @@ -170,7 +173,7 @@ public class DebugExec extends SubCommand { this.scope.put("ChunkManager", ChunkManager.manager); this.scope.put("BlockManager", WorldUtil.IMP); this.scope.put("SetupUtils", SetupUtils.manager); - this.scope.put("EventUtil", PlotSquared.get().getEventDispatcher()); + this.scope.put("EventUtil", this.eventDispatcher); this.scope.put("EconHandler", EconHandler.getEconHandler()); this.scope.put("DBFunc", DBFunc.dbManager); this.scope.put("HybridUtils", HybridUtils.manager); @@ -250,7 +253,7 @@ public class DebugExec extends SubCommand { GlobalFlagContainer.getInstance().getFlagFromString(flag); if (flagInstance != null) { for (Plot plot : PlotSquared.get().getBasePlots()) { - PlotFlagRemoveEvent event = PlotSquared.get().getEventDispatcher() + PlotFlagRemoveEvent event = this.eventDispatcher .callFlagRemove(flagInstance, plot); if (event.getEventResult() != Result.DENY) { plot.removeFlag(event.getFlag()); @@ -293,7 +296,7 @@ public class DebugExec extends SubCommand { return true; case "start-expire": if (ExpireManager.IMP == null) { - ExpireManager.IMP = new ExpireManager(); + ExpireManager.IMP = new ExpireManager(this.eventDispatcher); } if (ExpireManager.IMP.runAutomatedTask()) { return MainUtil.sendMessage(player, "Started plot expiry task"); diff --git a/Core/src/main/java/com/plotsquared/core/command/Delete.java b/Core/src/main/java/com/plotsquared/core/command/Delete.java index d2b578757..3404172c4 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Delete.java +++ b/Core/src/main/java/com/plotsquared/core/command/Delete.java @@ -25,7 +25,6 @@ */ package com.plotsquared.core.command; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.events.Result; @@ -34,10 +33,12 @@ import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.util.EconHandler; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.Expression; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.task.TaskManager; +import org.jetbrains.annotations.NotNull; @CommandDeclaration(command = "delete", @@ -50,9 +51,12 @@ import com.plotsquared.core.util.task.TaskManager; confirmation = true) public class Delete extends SubCommand { - // Note: To delete a specific plot use /plot delete - // The syntax also works with any command: /plot - + private final EventDispatcher eventDispatcher; + + public Delete(@NotNull final EventDispatcher eventDispatcher) { + this.eventDispatcher = eventDispatcher; + } + @Override public boolean onCommand(final PlotPlayer player, String[] args) { Location location = player.getLocation(); final Plot plot = location.getPlotAbs(); @@ -62,8 +66,7 @@ public class Delete extends SubCommand { if (!plot.hasOwner()) { return !sendMessage(player, Captions.PLOT_UNOWNED); } - Result eventResult = - PlotSquared.get().getEventDispatcher().callDelete(plot).getEventResult(); + Result eventResult = this.eventDispatcher.callDelete(plot).getEventResult(); if (eventResult == Result.DENY) { sendMessage(player, Captions.EVENT_DENIED, "Delete"); return true; diff --git a/Core/src/main/java/com/plotsquared/core/command/Deny.java b/Core/src/main/java/com/plotsquared/core/command/Deny.java index 3e92def05..db91083e1 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Deny.java +++ b/Core/src/main/java/com/plotsquared/core/command/Deny.java @@ -32,6 +32,7 @@ import com.plotsquared.core.location.Location; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.world.PlotAreaManager; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.TabCompletions; @@ -53,10 +54,12 @@ import java.util.concurrent.TimeoutException; public class Deny extends SubCommand { private final PlotAreaManager plotAreaManager; + private final EventDispatcher eventDispatcher; - public Deny(@NotNull final PlotAreaManager plotAreaManager) { + public Deny(@NotNull final PlotAreaManager plotAreaManager, @NotNull final EventDispatcher eventDispatcher) { super(Argument.PlayerName); this.plotAreaManager = plotAreaManager; + this.eventDispatcher = eventDispatcher; } @Override public boolean onCommand(PlotPlayer player, String[] args) { @@ -99,7 +102,7 @@ public class Deny extends SubCommand { plot.removeTrusted(uuid); } plot.addDenied(uuid); - PlotSquared.get().getEventDispatcher().callDenied(player, plot, uuid, true); + this.eventDispatcher.callDenied(player, plot, uuid, true); if (!uuid.equals(DBFunc.EVERYONE)) { handleKick(PlotSquared.platform().getPlayerManager().getPlayerIfExists(uuid), plot); } else { diff --git a/Core/src/main/java/com/plotsquared/core/command/Desc.java b/Core/src/main/java/com/plotsquared/core/command/Desc.java index f128920e8..a5de2111c 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Desc.java +++ b/Core/src/main/java/com/plotsquared/core/command/Desc.java @@ -25,7 +25,6 @@ */ package com.plotsquared.core.command; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.events.PlotFlagAddEvent; import com.plotsquared.core.events.PlotFlagRemoveEvent; @@ -33,7 +32,9 @@ import com.plotsquared.core.events.Result; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.flag.implementations.DescriptionFlag; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MainUtil; +import org.jetbrains.annotations.NotNull; @CommandDeclaration(command = "setdescription", permission = "plots.set.desc", @@ -44,10 +45,15 @@ import com.plotsquared.core.util.MainUtil; requiredType = RequiredType.PLAYER) public class Desc extends SetCommand { + private final EventDispatcher eventDispatcher; + + public Desc(@NotNull final EventDispatcher eventDispatcher) { + this.eventDispatcher = eventDispatcher; + } + @Override public boolean set(PlotPlayer player, Plot plot, String desc) { if (desc.isEmpty()) { - PlotFlagRemoveEvent event = PlotSquared.get().getEventDispatcher() - .callFlagRemove(plot.getFlagContainer().getFlag(DescriptionFlag.class), plot); + PlotFlagRemoveEvent event = this.eventDispatcher.callFlagRemove(plot.getFlagContainer().getFlag(DescriptionFlag.class), plot); if (event.getEventResult() == Result.DENY) { sendMessage(player, Captions.EVENT_DENIED, "Description removal"); return false; @@ -56,8 +62,7 @@ public class Desc extends SetCommand { MainUtil.sendMessage(player, Captions.DESC_UNSET); return true; } - PlotFlagAddEvent event = PlotSquared.get().getEventDispatcher().callFlagAdd( - plot.getFlagContainer().getFlag(DescriptionFlag.class).createFlagInstance(desc), plot); + PlotFlagAddEvent event = this.eventDispatcher.callFlagAdd(plot.getFlagContainer().getFlag(DescriptionFlag.class).createFlagInstance(desc), plot); if (event.getEventResult() == Result.DENY) { sendMessage(player, Captions.EVENT_DENIED, "Description set"); return false; diff --git a/Core/src/main/java/com/plotsquared/core/command/Dislike.java b/Core/src/main/java/com/plotsquared/core/command/Dislike.java index 410e13b57..503effa12 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Dislike.java +++ b/Core/src/main/java/com/plotsquared/core/command/Dislike.java @@ -26,6 +26,7 @@ package com.plotsquared.core.command; import com.plotsquared.core.player.PlotPlayer; +import org.jetbrains.annotations.NotNull; @CommandDeclaration(command = "dislike", permission = "plots.dislike", @@ -35,8 +36,14 @@ import com.plotsquared.core.player.PlotPlayer; requiredType = RequiredType.PLAYER) public class Dislike extends SubCommand { + private final Like like; + + public Dislike(@NotNull final Like like) { + this.like = like; + } + @Override public boolean onCommand(PlotPlayer player, String[] args) { - return Like.handleLike(player, args, false); + return this.like.handleLike(player, args, false); } } diff --git a/Core/src/main/java/com/plotsquared/core/command/Done.java b/Core/src/main/java/com/plotsquared/core/command/Done.java index 258454f8a..7fa88b40a 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Done.java +++ b/Core/src/main/java/com/plotsquared/core/command/Done.java @@ -25,7 +25,6 @@ */ package com.plotsquared.core.command; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.events.PlotDoneEvent; @@ -39,9 +38,11 @@ import com.plotsquared.core.plot.expiration.ExpireManager; import com.plotsquared.core.plot.expiration.PlotAnalysis; import com.plotsquared.core.plot.flag.PlotFlag; import com.plotsquared.core.plot.flag.implementations.DoneFlag; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.task.RunnableVal; +import org.jetbrains.annotations.NotNull; @CommandDeclaration(command = "done", aliases = {"submit"}, @@ -51,13 +52,19 @@ import com.plotsquared.core.util.task.RunnableVal; requiredType = RequiredType.NONE) public class Done extends SubCommand { + private final EventDispatcher eventDispatcher; + + public Done(@NotNull final EventDispatcher eventDispatcher) { + this.eventDispatcher = eventDispatcher; + } + @Override public boolean onCommand(final PlotPlayer player, String[] args) { Location location = player.getLocation(); final Plot plot = location.getPlotAbs(); if ((plot == null) || !plot.hasOwner()) { return !sendMessage(player, Captions.NOT_IN_PLOT); } - PlotDoneEvent event = PlotSquared.get().getEventDispatcher().callDone(plot); + PlotDoneEvent event = this.eventDispatcher.callDone(plot); if (event.getEventResult() == Result.DENY) { sendMessage(player, Captions.EVENT_DENIED, "Done"); return true; diff --git a/Core/src/main/java/com/plotsquared/core/command/Leave.java b/Core/src/main/java/com/plotsquared/core/command/Leave.java index 3a0d7f09d..bf1fbe604 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Leave.java +++ b/Core/src/main/java/com/plotsquared/core/command/Leave.java @@ -25,13 +25,14 @@ */ package com.plotsquared.core.command; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.task.RunnableVal2; import com.plotsquared.core.util.task.RunnableVal3; +import org.jetbrains.annotations.NotNull; import java.util.UUID; import java.util.concurrent.CompletableFuture; @@ -43,8 +44,12 @@ import java.util.concurrent.CompletableFuture; category = CommandCategory.CLAIMING, requiredType = RequiredType.PLAYER) public class Leave extends Command { - public Leave() { + + private final EventDispatcher eventDispatcher; + + public Leave(@NotNull final EventDispatcher eventDispatcher) { super(MainCommand.getInstance(), true); + this.eventDispatcher = eventDispatcher; } @Override @@ -62,10 +67,10 @@ public class Leave extends Command { UUID uuid = player.getUUID(); if (plot.isAdded(uuid)) { if (plot.removeTrusted(uuid)) { - PlotSquared.get().getEventDispatcher().callTrusted(player, plot, uuid, false); + this.eventDispatcher.callTrusted(player, plot, uuid, false); } if (plot.removeMember(uuid)) { - PlotSquared.get().getEventDispatcher().callMember(player, plot, uuid, false); + this.eventDispatcher.callMember(player, plot, uuid, false); } MainUtil.sendMessage(player, Captions.PLOT_LEFT, player.getName()); } else { diff --git a/Core/src/main/java/com/plotsquared/core/command/Like.java b/Core/src/main/java/com/plotsquared/core/command/Like.java index 216c6524c..92624d342 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Like.java +++ b/Core/src/main/java/com/plotsquared/core/command/Like.java @@ -35,9 +35,11 @@ import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.Rating; import com.plotsquared.core.plot.flag.implementations.DoneFlag; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.task.TaskManager; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Collection; @@ -53,7 +55,13 @@ import java.util.UUID; requiredType = RequiredType.PLAYER) public class Like extends SubCommand { - protected static boolean handleLike(final PlotPlayer player, String[] args, + private final EventDispatcher eventDispatcher; + + public Like(@NotNull final EventDispatcher eventDispatcher) { + this.eventDispatcher = eventDispatcher; + } + + protected boolean handleLike(final PlotPlayer player, String[] args, final boolean like) { final UUID uuid = player.getUUID(); if (args.length == 1) { @@ -125,7 +133,7 @@ public class Like extends SubCommand { } plot.addRating(uuid, new Rating(rating)); final PlotRateEvent event = - PlotSquared.get().getEventDispatcher().callRating(player, plot, new Rating(rating)); + this.eventDispatcher.callRating(player, plot, new Rating(rating)); if (event.getRating() != null) { plot.addRating(uuid, event.getRating()); if (like) { diff --git a/Core/src/main/java/com/plotsquared/core/command/MainCommand.java b/Core/src/main/java/com/plotsquared/core/command/MainCommand.java index 811d0d37d..25fe955c9 100644 --- a/Core/src/main/java/com/plotsquared/core/command/MainCommand.java +++ b/Core/src/main/java/com/plotsquared/core/command/MainCommand.java @@ -28,6 +28,7 @@ package com.plotsquared.core.command; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.Settings; +import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.location.Location; import com.plotsquared.core.player.ConsolePlayer; import com.plotsquared.core.player.PlotPlayer; @@ -35,6 +36,7 @@ import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.util.EconHandler; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.Expression; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.task.RunnableVal2; @@ -62,9 +64,13 @@ public class MainCommand extends Command { public static MainCommand getInstance() { if (instance == null) { instance = new MainCommand(); + final PlotAreaManager plotAreaManager = PlotSquared.get().getPlotAreaManager(); + final EventDispatcher eventDispatcher = PlotSquared.get().getEventDispatcher(); + final PlotListener plotListener = PlotSquared.get().getPlotListener(); + new Caps(); - new Buy(); + new Buy(eventDispatcher); new Save(plotAreaManager); new Load(plotAreaManager); new Confirm(); @@ -72,45 +78,45 @@ public class MainCommand extends Command { new Download(plotAreaManager); new Template(plotAreaManager); new Setup(); - new Area(plotAreaManager); + new Area(plotAreaManager, eventDispatcher, plotListener); new DebugSaveTest(); new DebugLoadTest(); new CreateRoadSchematic(); new DebugAllowUnsafe(); new RegenAllRoads(plotAreaManager); - new Claim(); - new Auto(plotAreaManager); + new Claim(eventDispatcher); + new Auto(plotAreaManager, eventDispatcher); new HomeCommand(plotAreaManager); new Visit(plotAreaManager); new Set(); - new Clear(); - new Delete(); - new Trust(); - new Add(); - new Leave(); - new Deny(plotAreaManager); - new Remove(); + new Clear(eventDispatcher); + new Delete(eventDispatcher); + new Trust(eventDispatcher); + new Add(eventDispatcher); + new Leave(eventDispatcher); + new Deny(plotAreaManager, eventDispatcher); + new Remove(eventDispatcher); new Info(); new Near(); new ListCmd(plotAreaManager); new Debug(plotAreaManager); new SchematicCmd(plotAreaManager); new PluginCmd(); - new Purge(plotAreaManager); + new Purge(plotAreaManager, plotListener); new Reload(plotAreaManager); new Relight(); - new Merge(); + new Merge(eventDispatcher); new DebugPaste(); - new Unlink(); + new Unlink(eventDispatcher); new Kick(plotAreaManager); new Inbox(); new Comment(); - new DatabaseCommand(plotAreaManager); + new DatabaseCommand(plotAreaManager, eventDispatcher, plotListener); new Swap(); new Music(); new DebugRoadRegen(); - new Trust(); - new DebugExec(plotAreaManager); + new Trust(eventDispatcher); + new DebugExec(plotAreaManager, eventDispatcher); new FlagCommand(); new Target(); new Move(plotAreaManager); @@ -118,13 +124,13 @@ public class MainCommand extends Command { new Copy(); new Chat(); new Trim(plotAreaManager); - new Done(); - new Continue(); + new Done(eventDispatcher); + new Continue(eventDispatcher); new Middle(); new Grant(); // Set commands - new Owner(); - new Desc(); + new Owner(eventDispatcher); + new Desc(eventDispatcher); new Biome(); new Alias(); new SetHome(); @@ -133,10 +139,10 @@ public class MainCommand extends Command { new Backup(); if (Settings.Ratings.USE_LIKES) { - new Like(); - new Dislike(); + final Like like = new Like(eventDispatcher); + new Dislike(like); } else { - new Rate(); + new Rate(eventDispatcher); } // Referenced commands diff --git a/Core/src/main/java/com/plotsquared/core/command/Merge.java b/Core/src/main/java/com/plotsquared/core/command/Merge.java index 395f49704..1b23bd10c 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Merge.java +++ b/Core/src/main/java/com/plotsquared/core/command/Merge.java @@ -36,10 +36,12 @@ import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.util.EconHandler; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.Expression; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.StringMan; +import org.jetbrains.annotations.NotNull; import java.util.UUID; @@ -56,6 +58,12 @@ public class Merge extends SubCommand { public static final String[] values = new String[] {"north", "east", "south", "west"}; public static final String[] aliases = new String[] {"n", "e", "s", "w"}; + private final EventDispatcher eventDispatcher; + + public Merge(@NotNull final EventDispatcher eventDispatcher) { + this.eventDispatcher = eventDispatcher; + } + public static String direction(float yaw) { yaw = yaw / 90; int i = Math.round(yaw); @@ -126,7 +134,7 @@ public class Merge extends SubCommand { final int size = plot.getConnectedPlots().size(); int max = Permissions.hasPermissionRange(player, "plots.merge", Settings.Limit.MAX_PLOTS); PlotMergeEvent event = - PlotSquared.get().getEventDispatcher().callMerge(plot, direction, max, player); + this.eventDispatcher.callMerge(plot, direction, max, player); if (event.getEventResult() == Result.DENY) { sendMessage(player, Captions.EVENT_DENIED, "Merge"); return false; diff --git a/Core/src/main/java/com/plotsquared/core/command/Owner.java b/Core/src/main/java/com/plotsquared/core/command/Owner.java index 4176c312f..02e8c45c9 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Owner.java +++ b/Core/src/main/java/com/plotsquared/core/command/Owner.java @@ -33,9 +33,11 @@ import com.plotsquared.core.events.PlotUnlinkEvent; import com.plotsquared.core.events.Result; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.task.TaskManager; +import org.jetbrains.annotations.NotNull; import java.util.Set; import java.util.UUID; @@ -52,6 +54,12 @@ import java.util.function.Consumer; confirmation = true) public class Owner extends SetCommand { + private final EventDispatcher eventDispatcher; + + public Owner(@NotNull final EventDispatcher eventDispatcher) { + this.eventDispatcher = eventDispatcher; + } + @Override public boolean set(final PlotPlayer player, final Plot plot, String value) { if (value == null || value.isEmpty()) { Captions.SET_OWNER_MISSING_PLAYER.send(player); @@ -65,9 +73,8 @@ public class Owner extends SetCommand { Captions.INVALID_PLAYER.send(player, value); return; } - PlotChangeOwnerEvent event = PlotSquared.get().getEventDispatcher() - .callOwnerChange(player, plot, plot.hasOwner() ? plot.getOwnerAbs() : null, uuid, - plot.hasOwner()); + PlotChangeOwnerEvent event = this.eventDispatcher.callOwnerChange(player, plot, plot.hasOwner() ? plot.getOwnerAbs() : null, uuid, + plot.hasOwner()); if (event.getEventResult() == Result.DENY) { sendMessage(player, Captions.EVENT_DENIED, "Owner change"); return; @@ -80,8 +87,7 @@ public class Owner extends SetCommand { true)) { return; } - PlotUnlinkEvent unlinkEvent = PlotSquared.get().getEventDispatcher() - .callUnlink(plot.getArea(), plot, false, false, PlotUnlinkEvent.REASON.NEW_OWNER); + PlotUnlinkEvent unlinkEvent = this.eventDispatcher.callUnlink(plot.getArea(), plot, false, false, PlotUnlinkEvent.REASON.NEW_OWNER); if (unlinkEvent.getEventResult() == Result.DENY) { sendMessage(player, Captions.EVENT_DENIED, "Unlink on owner change"); return; diff --git a/Core/src/main/java/com/plotsquared/core/command/Purge.java b/Core/src/main/java/com/plotsquared/core/command/Purge.java index 7dc8c55bc..969ee6cd5 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Purge.java +++ b/Core/src/main/java/com/plotsquared/core/command/Purge.java @@ -56,9 +56,11 @@ import java.util.concurrent.atomic.AtomicBoolean; public class Purge extends SubCommand { private final PlotAreaManager plotAreaManager; + private final PlotListener plotListener; - public Purge(@NotNull final PlotAreaManager plotAreaManager) { + public Purge(@NotNull final PlotAreaManager plotAreaManager, @NotNull final PlotListener plotListener) { this.plotAreaManager = plotAreaManager; + this.plotListener = plotListener; } @Override public boolean onCommand(final PlotPlayer player, String[] args) { @@ -197,8 +199,8 @@ public class Purge extends SubCommand { plot.removeSign(); } plot.getArea().removePlot(plot.getId()); - for (PlotPlayer pp : plot.getPlayersInPlot()) { - PlotListener.plotEntry(pp, plot); + for (PlotPlayer pp : plot.getPlayersInPlot()) { + Purge.this.plotListener.plotEntry(pp, plot); } } catch (NullPointerException e) { PlotSquared.log( diff --git a/Core/src/main/java/com/plotsquared/core/command/Rate.java b/Core/src/main/java/com/plotsquared/core/command/Rate.java index 23affc37d..f98ecdb3b 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Rate.java +++ b/Core/src/main/java/com/plotsquared/core/command/Rate.java @@ -37,10 +37,12 @@ import com.plotsquared.core.plot.PlotInventory; import com.plotsquared.core.plot.PlotItemStack; import com.plotsquared.core.plot.Rating; import com.plotsquared.core.plot.flag.implementations.DoneFlag; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.MathMan; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.task.TaskManager; +import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.HashMap; @@ -56,6 +58,12 @@ import java.util.UUID; requiredType = RequiredType.PLAYER) public class Rate extends SubCommand { + private final EventDispatcher eventDispatcher; + + public Rate(@NotNull final EventDispatcher eventDispatcher) { + this.eventDispatcher = eventDispatcher; + } + @Override public boolean onCommand(final PlotPlayer player, String[] args) { if (args.length == 1) { switch (args[0].toLowerCase()) { @@ -141,7 +149,7 @@ public class Rate extends SubCommand { index.increment(); if (index.getValue() >= Settings.Ratings.CATEGORIES.size()) { int rV = rating.getValue(); - PlotRateEvent event = PlotSquared.get().getEventDispatcher() + PlotRateEvent event = Rate.this.eventDispatcher .callRating(this.player, plot, new Rating(rV)); if (event.getRating() != null) { plot.addRating(this.player.getUUID(), event.getRating()); @@ -211,7 +219,7 @@ public class Rate extends SubCommand { return; } PlotRateEvent event = - PlotSquared.get().getEventDispatcher().callRating(player, plot, new Rating(rating)); + this.eventDispatcher.callRating(player, plot, new Rating(rating)); if (event.getRating() != null) { plot.addRating(uuid, event.getRating()); sendMessage(player, Captions.RATING_APPLIED, plot.getId().toString()); diff --git a/Core/src/main/java/com/plotsquared/core/command/Remove.java b/Core/src/main/java/com/plotsquared/core/command/Remove.java index 871bd2b60..4178668bc 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Remove.java +++ b/Core/src/main/java/com/plotsquared/core/command/Remove.java @@ -25,15 +25,16 @@ */ package com.plotsquared.core.command; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.database.DBFunc; import com.plotsquared.core.location.Location; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.TabCompletions; +import org.jetbrains.annotations.NotNull; import java.util.Collection; import java.util.Collections; @@ -49,8 +50,11 @@ import java.util.concurrent.TimeoutException; permission = "plots.remove") public class Remove extends SubCommand { - public Remove() { + private final EventDispatcher eventDispatcher; + + public Remove(@NotNull final EventDispatcher eventDispatcher) { super(Argument.PlayerName); + this.eventDispatcher = eventDispatcher; } @Override public boolean onCommand(PlotPlayer player, String[] args) { @@ -81,34 +85,28 @@ public class Remove extends SubCommand { for (UUID uuid : uuids) { if (plot.getTrusted().contains(uuid)) { if (plot.removeTrusted(uuid)) { - PlotSquared.get().getEventDispatcher() - .callTrusted(player, plot, uuid, false); + this.eventDispatcher.callTrusted(player, plot, uuid, false); count++; } } else if (plot.getMembers().contains(uuid)) { if (plot.removeMember(uuid)) { - PlotSquared.get().getEventDispatcher() - .callMember(player, plot, uuid, false); + this.eventDispatcher.callMember(player, plot, uuid, false); count++; } } else if (plot.getDenied().contains(uuid)) { if (plot.removeDenied(uuid)) { - PlotSquared.get().getEventDispatcher() - .callDenied(player, plot, uuid, false); + this.eventDispatcher.callDenied(player, plot, uuid, false); count++; } } else if (uuid == DBFunc.EVERYONE) { if (plot.removeTrusted(uuid)) { - PlotSquared.get().getEventDispatcher() - .callTrusted(player, plot, uuid, false); + this.eventDispatcher.callTrusted(player, plot, uuid, false); count++; } else if (plot.removeMember(uuid)) { - PlotSquared.get().getEventDispatcher() - .callMember(player, plot, uuid, false); + this.eventDispatcher.callMember(player, plot, uuid, false); count++; } else if (plot.removeDenied(uuid)) { - PlotSquared.get().getEventDispatcher() - .callDenied(player, plot, uuid, false); + this.eventDispatcher.callDenied(player, plot, uuid, false); count++; } } diff --git a/Core/src/main/java/com/plotsquared/core/command/Trust.java b/Core/src/main/java/com/plotsquared/core/command/Trust.java index 1c4064543..892205f4d 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Trust.java +++ b/Core/src/main/java/com/plotsquared/core/command/Trust.java @@ -25,16 +25,17 @@ */ package com.plotsquared.core.command; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.database.DBFunc; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.TabCompletions; import com.plotsquared.core.util.task.RunnableVal2; import com.plotsquared.core.util.task.RunnableVal3; +import org.jetbrains.annotations.NotNull; import java.util.Collection; import java.util.Collections; @@ -51,8 +52,11 @@ import java.util.concurrent.TimeoutException; category = CommandCategory.SETTINGS) public class Trust extends Command { - public Trust() { + private final EventDispatcher eventDispatcher; + + public Trust(@NotNull final EventDispatcher eventDispatcher) { super(MainCommand.getInstance(), true); + this.eventDispatcher = eventDispatcher; } @Override @@ -119,7 +123,7 @@ public class Trust extends Command { } } currentPlot.addTrusted(uuid); - PlotSquared.get().getEventDispatcher().callTrusted(player, currentPlot, uuid, true); + this.eventDispatcher.callTrusted(player, currentPlot, uuid, true); MainUtil.sendMessage(player, Captions.TRUSTED_ADDED); } }, null); diff --git a/Core/src/main/java/com/plotsquared/core/command/Unlink.java b/Core/src/main/java/com/plotsquared/core/command/Unlink.java index 1f309df57..424b23819 100644 --- a/Core/src/main/java/com/plotsquared/core/command/Unlink.java +++ b/Core/src/main/java/com/plotsquared/core/command/Unlink.java @@ -25,17 +25,18 @@ */ package com.plotsquared.core.command; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.events.PlotUnlinkEvent; import com.plotsquared.core.events.Result; import com.plotsquared.core.location.Location; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.StringMan; import com.plotsquared.core.util.task.TaskManager; +import org.jetbrains.annotations.NotNull; @CommandDeclaration(command = "unlink", aliases = {"u", "unmerge"}, @@ -46,6 +47,12 @@ import com.plotsquared.core.util.task.TaskManager; confirmation = true) public class Unlink extends SubCommand { + private final EventDispatcher eventDispatcher; + + public Unlink(@NotNull final EventDispatcher eventDispatcher) { + this.eventDispatcher = eventDispatcher; + } + @Override public boolean onCommand(final PlotPlayer player, String[] args) { Location location = player.getLocation(); final Plot plot = location.getPlotAbs(); @@ -69,7 +76,7 @@ public class Unlink extends SubCommand { createRoad = true; } - PlotUnlinkEvent event = PlotSquared.get().getEventDispatcher() + PlotUnlinkEvent event = this.eventDispatcher .callUnlink(plot.getArea(), plot, createRoad, createRoad, PlotUnlinkEvent.REASON.PLAYER_COMMAND); if (event.getEventResult() == Result.DENY) { diff --git a/Core/src/main/java/com/plotsquared/core/database/SQLManager.java b/Core/src/main/java/com/plotsquared/core/database/SQLManager.java index 6bb62e965..ec6c61288 100644 --- a/Core/src/main/java/com/plotsquared/core/database/SQLManager.java +++ b/Core/src/main/java/com/plotsquared/core/database/SQLManager.java @@ -31,6 +31,7 @@ import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.configuration.Storage; +import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.location.BlockLoc; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; @@ -43,6 +44,7 @@ import com.plotsquared.core.plot.flag.FlagParseException; import com.plotsquared.core.plot.flag.GlobalFlagContainer; import com.plotsquared.core.plot.flag.PlotFlag; import com.plotsquared.core.plot.flag.types.BlockTypeListFlag; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.StringMan; import com.plotsquared.core.util.task.RunnableVal; @@ -128,6 +130,9 @@ public class SQLManager implements AbstractDB { private Connection connection; private boolean closed = false; + private final EventDispatcher eventDispatcher; + private final PlotListener plotListener; + /** * Constructor * @@ -136,9 +141,12 @@ public class SQLManager implements AbstractDB { * @throws SQLException * @throws ClassNotFoundException */ - public SQLManager(final Database database, String prefix, boolean debug) + public SQLManager(final Database database, String prefix, + @NotNull final EventDispatcher eventDispatcher, @NotNull final PlotListener plotListener) throws SQLException, ClassNotFoundException { // Private final + this.eventDispatcher = eventDispatcher; + this.plotListener = plotListener; this.database = database; this.connection = database.openConnection(); this.mySQL = database instanceof MySQL; @@ -1828,7 +1836,7 @@ public class SQLManager implements AbstractDB { } Plot p = new Plot(plot_id, user, new HashSet<>(), new HashSet<>(), new HashSet<>(), "", null, null, null, - new boolean[] {false, false, false, false}, time, id); + new boolean[] {false, false, false, false}, time, id, this.eventDispatcher, this.plotListener); HashMap map = newPlots.get(areaID); if (map != null) { Plot last = map.put(p.getId(), p); diff --git a/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotWorld.java b/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotWorld.java index 13b2fb352..52dcf6ccd 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotWorld.java +++ b/Core/src/main/java/com/plotsquared/core/generator/ClassicPlotWorld.java @@ -28,8 +28,10 @@ package com.plotsquared.core.generator; import com.plotsquared.core.configuration.ConfigurationNode; import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.ConfigurationUtil; +import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.plot.BlockBucket; import com.plotsquared.core.plot.PlotId; +import com.plotsquared.core.util.EventDispatcher; import com.sk89q.worldedit.world.block.BlockTypes; import org.jetbrains.annotations.NotNull; @@ -54,8 +56,9 @@ public abstract class ClassicPlotWorld extends SquarePlotWorld { public boolean PLOT_BEDROCK = true; public ClassicPlotWorld(String worldName, String id, - @NotNull IndependentPlotGenerator generator, PlotId min, PlotId max) { - super(worldName, id, generator, min, max); + @NotNull IndependentPlotGenerator generator, PlotId min, PlotId max, @NotNull final + EventDispatcher eventDispatcher, @NotNull final PlotListener plotListener) { + super(worldName, id, generator, min, max, eventDispatcher, plotListener); } /** diff --git a/Core/src/main/java/com/plotsquared/core/generator/GridPlotWorld.java b/Core/src/main/java/com/plotsquared/core/generator/GridPlotWorld.java index 8b753b170..9219cf2b5 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/GridPlotWorld.java +++ b/Core/src/main/java/com/plotsquared/core/generator/GridPlotWorld.java @@ -25,8 +25,10 @@ */ package com.plotsquared.core.generator; +import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotId; +import com.plotsquared.core.util.EventDispatcher; import org.jetbrains.annotations.NotNull; public abstract class GridPlotWorld extends PlotArea { @@ -34,7 +36,8 @@ public abstract class GridPlotWorld extends PlotArea { public short SIZE; public GridPlotWorld(String worldName, String id, @NotNull IndependentPlotGenerator generator, - PlotId min, PlotId max) { - super(worldName, id, generator, min, max); + PlotId min, PlotId max, @NotNull final EventDispatcher eventDispatcher, @NotNull final + PlotListener plotListener) { + super(worldName, id, generator, min, max, eventDispatcher, plotListener); } } diff --git a/Core/src/main/java/com/plotsquared/core/generator/HybridGen.java b/Core/src/main/java/com/plotsquared/core/generator/HybridGen.java index 5a8ace19e..124df6bd4 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridGen.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridGen.java @@ -28,17 +28,23 @@ package com.plotsquared.core.generator; import com.google.common.base.Preconditions; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Settings; +import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.location.Location; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.queue.ScopedLocalBlockQueue; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MathMan; import com.sk89q.worldedit.world.biome.BiomeType; import com.sk89q.worldedit.world.block.BaseBlock; import com.sk89q.worldedit.world.block.BlockTypes; +import lombok.RequiredArgsConstructor; import org.jetbrains.annotations.NotNull; -public class HybridGen extends IndependentPlotGenerator { +@RequiredArgsConstructor public class HybridGen extends IndependentPlotGenerator { + + private final EventDispatcher eventDispatcher; + private final PlotListener plotListener; @Override public String getName() { return PlotSquared.platform().getPluginName(); @@ -220,7 +226,7 @@ public class HybridGen extends IndependentPlotGenerator { } @Override public PlotArea getNewPlotArea(String world, String id, PlotId min, PlotId max) { - return new HybridPlotWorld(world, id, this, min, max); + return new HybridPlotWorld(world, id, this, min, max, this.eventDispatcher, this.plotListener); } @Override public void initialize(PlotArea area) { diff --git a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java index 778cc645a..4394de75e 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java +++ b/Core/src/main/java/com/plotsquared/core/generator/HybridPlotWorld.java @@ -29,12 +29,14 @@ import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.Settings; +import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.location.Location; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.plot.PlotManager; import com.plotsquared.core.plot.schematic.Schematic; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.MathMan; import com.plotsquared.core.util.SchematicHandler; @@ -73,8 +75,9 @@ public class HybridPlotWorld extends ClassicPlotWorld { @Getter private File root = null; public HybridPlotWorld(String worldName, String id, @NotNull IndependentPlotGenerator generator, - PlotId min, PlotId max) { - super(worldName, id, generator, min, max); + PlotId min, PlotId max, @NotNull final EventDispatcher eventDispatcher, @NotNull final + PlotListener plotListener) { + super(worldName, id, generator, min, max, eventDispatcher, plotListener); } public static byte wrap(byte data, int start) { diff --git a/Core/src/main/java/com/plotsquared/core/generator/SquarePlotWorld.java b/Core/src/main/java/com/plotsquared/core/generator/SquarePlotWorld.java index 026b13ddc..8a7f8667b 100644 --- a/Core/src/main/java/com/plotsquared/core/generator/SquarePlotWorld.java +++ b/Core/src/main/java/com/plotsquared/core/generator/SquarePlotWorld.java @@ -27,7 +27,9 @@ package com.plotsquared.core.generator; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.configuration.ConfigurationSection; +import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.plot.PlotId; +import com.plotsquared.core.util.EventDispatcher; import org.jetbrains.annotations.NotNull; public abstract class SquarePlotWorld extends GridPlotWorld { @@ -38,8 +40,9 @@ public abstract class SquarePlotWorld extends GridPlotWorld { public int ROAD_OFFSET_Z = 0; public SquarePlotWorld(String worldName, String id, @NotNull IndependentPlotGenerator generator, - PlotId min, PlotId max) { - super(worldName, id, generator, min, max); + PlotId min, PlotId max, @NotNull final EventDispatcher eventDispatcher, @NotNull final + PlotListener plotListener) { + super(worldName, id, generator, min, max, eventDispatcher, plotListener); } @Override public void loadConfiguration(ConfigurationSection config) { diff --git a/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java b/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java index 055c2e689..5db405f98 100644 --- a/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java +++ b/Core/src/main/java/com/plotsquared/core/listener/PlotListener.java @@ -55,6 +55,7 @@ import com.plotsquared.core.plot.flag.implementations.TimeFlag; import com.plotsquared.core.plot.flag.implementations.TitlesFlag; import com.plotsquared.core.plot.flag.implementations.WeatherFlag; import com.plotsquared.core.plot.flag.types.TimedFlag; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.StringMan; @@ -65,18 +66,21 @@ import com.sk89q.worldedit.world.gamemode.GameMode; import com.sk89q.worldedit.world.gamemode.GameModes; import com.sk89q.worldedit.world.item.ItemType; import com.sk89q.worldedit.world.item.ItemTypes; +import lombok.RequiredArgsConstructor; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.UUID; -public class PlotListener { +@RequiredArgsConstructor public class PlotListener { - private static final HashMap feedRunnable = new HashMap<>(); - private static final HashMap healRunnable = new HashMap<>(); + private final HashMap feedRunnable = new HashMap<>(); + private final HashMap healRunnable = new HashMap<>(); - public static void startRunnable() { + private final EventDispatcher eventDispatcher; + + public void startRunnable() { TaskManager.runTaskRepeat(() -> { if (!healRunnable.isEmpty()) { for (Iterator> iterator = @@ -123,7 +127,7 @@ public class PlotListener { }, 20); } - public static boolean plotEntry(final PlotPlayer player, final Plot plot) { + public boolean plotEntry(final PlotPlayer player, final Plot plot) { if (plot.isDenied(player.getUUID()) && !Permissions .hasPermission(player, "plots.admin.entry.denied")) { return false; @@ -136,7 +140,7 @@ public class PlotListener { ExpireManager.IMP.handleEntry(player, plot); } player.setMeta(PlotPlayer.META_LAST_PLOT, plot); - PlotSquared.get().getEventDispatcher().callEntry(player, plot); + this.eventDispatcher.callEntry(player, plot); if (plot.hasOwner()) { // This will inherit values from PlotArea final TitlesFlag.TitlesFlagValue titleFlag = plot.getFlag(TitlesFlag.class); @@ -215,7 +219,7 @@ public class PlotListener { PlotFlag plotFlag = GlobalFlagContainer.getInstance().getFlag(TimeFlag.class); PlotFlagRemoveEvent event = - PlotSquared.get().getEventDispatcher().callFlagRemove(plotFlag, plot); + this.eventDispatcher.callFlagRemove(plotFlag, plot); if (event.getEventResult() != Result.DENY) { plot.removeFlag(event.getFlag()); } @@ -293,9 +297,9 @@ public class PlotListener { return true; } - public static boolean plotExit(final PlotPlayer player, Plot plot) { + public boolean plotExit(final PlotPlayer player, Plot plot) { Object previous = player.deleteMeta(PlotPlayer.META_LAST_PLOT); - PlotSquared.get().getEventDispatcher().callLeave(player, plot); + this.eventDispatcher.callLeave(player, plot); if (plot.hasOwner()) { PlotArea pw = plot.getArea(); if (pw == null) { @@ -383,7 +387,7 @@ public class PlotListener { return true; } - public static void logout(UUID uuid) { + public void logout(UUID uuid) { feedRunnable.remove(uuid); healRunnable.remove(uuid); } diff --git a/Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java b/Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java index bd3ab8b4b..2ef277bac 100644 --- a/Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java +++ b/Core/src/main/java/com/plotsquared/core/player/ConsolePlayer.java @@ -33,6 +33,7 @@ import com.plotsquared.core.location.Location; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotWeather; import com.plotsquared.core.plot.world.PlotAreaManager; +import com.plotsquared.core.util.EventDispatcher; import com.sk89q.worldedit.extension.platform.Actor; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.world.gamemode.GameMode; @@ -46,8 +47,8 @@ public class ConsolePlayer extends PlotPlayer { private static ConsolePlayer instance; - private ConsolePlayer(final PlotAreaManager plotAreaManager) { - super(plotAreaManager); + private ConsolePlayer(final PlotAreaManager plotAreaManager, @NotNull final EventDispatcher eventDispatcher) { + super(plotAreaManager, eventDispatcher); final PlotArea[] areas = plotAreaManager.getAllPlotAreas(); final PlotArea area; if (areas.length > 0) { @@ -69,7 +70,7 @@ public class ConsolePlayer extends PlotPlayer { public static ConsolePlayer getConsole() { if (instance == null) { - instance = new ConsolePlayer(PlotSquared.get().getPlotAreaManager()); + instance = new ConsolePlayer(PlotSquared.get().getPlotAreaManager(), PlotSquared.get().getEventDispatcher()); instance.teleport(instance.getLocation()); } return instance; diff --git a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java index 144e1b622..7f3a52f4c 100644 --- a/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java +++ b/Core/src/main/java/com/plotsquared/core/player/PlotPlayer.java @@ -26,7 +26,6 @@ package com.plotsquared.core.player; import com.google.common.base.Preconditions; -import com.plotsquared.core.PlotPlatform; import com.plotsquared.core.PlotSquared; import com.plotsquared.core.command.CommandCaller; import com.plotsquared.core.command.RequiredType; @@ -47,6 +46,7 @@ import com.plotsquared.core.plot.world.PlotAreaManager; import com.plotsquared.core.plot.world.SinglePlotArea; import com.plotsquared.core.plot.world.SinglePlotAreaManager; import com.plotsquared.core.util.EconHandler; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.Permissions; import com.plotsquared.core.util.query.PlotQuery; import com.plotsquared.core.util.task.RunnableVal; @@ -90,9 +90,11 @@ public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer private int hash; private final PlotAreaManager plotAreaManager; + private final EventDispatcher eventDispatcher; - public PlotPlayer(@NotNull final PlotAreaManager plotAreaManager) { + public PlotPlayer(@NotNull final PlotAreaManager plotAreaManager, @NotNull final EventDispatcher eventDispatcher) { this.plotAreaManager = plotAreaManager; + this.eventDispatcher = eventDispatcher; } public static PlotPlayer from(@NonNull final T object) { @@ -583,7 +585,7 @@ public abstract class PlotPlayer

implements CommandCaller, OfflinePlotPlayer removePersistentMeta("quitLoc"); } if (plot != null) { - PlotSquared.get().getEventDispatcher().callLeave(this, plot); + this.eventDispatcher.callLeave(this, plot); } if (Settings.Enabled_Components.BAN_DELETER && isBanned()) { for (Plot owned : getPlots()) { diff --git a/Core/src/main/java/com/plotsquared/core/plot/Plot.java b/Core/src/main/java/com/plotsquared/core/plot/Plot.java index 4da56f47f..127d0e3a2 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/Plot.java +++ b/Core/src/main/java/com/plotsquared/core/plot/Plot.java @@ -55,6 +55,7 @@ import com.plotsquared.core.plot.flag.implementations.KeepFlag; import com.plotsquared.core.plot.schematic.Schematic; import com.plotsquared.core.queue.GlobalBlockQueue; import com.plotsquared.core.queue.LocalBlockQueue; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.MathMan; import com.plotsquared.core.util.Permissions; @@ -123,6 +124,9 @@ public class Plot { private static Set regions_cache; @NotNull private final PlotId id; + @NotNull private final EventDispatcher eventDispatcher; + @NotNull private final PlotListener plotListener; + /** * Plot flag container */ @@ -193,8 +197,9 @@ public class Plot { * @param owner the plot owner * @see Plot#getPlot(Location) for existing plots */ - public Plot(PlotArea area, @NotNull PlotId id, UUID owner) { - this(area, id, owner, 0); + public Plot(final PlotArea area, @NotNull final PlotId id, final UUID owner, + @NotNull final EventDispatcher eventDispatcher, @NotNull final PlotListener plotListener) { + this(area, id, owner, 0, eventDispatcher, plotListener); } /** @@ -205,8 +210,9 @@ public class Plot { * @param id the plot id * @see Plot#getPlot(Location) for existing plots */ - public Plot(@NotNull PlotArea area, @NotNull PlotId id) { - this(area, id, null, 0); + public Plot(@NotNull final PlotArea area, @NotNull final PlotId id, + @NotNull final EventDispatcher eventDispatcher, @NotNull final PlotListener plotListener) { + this(area, id, null, 0, eventDispatcher, plotListener); } /** @@ -220,12 +226,15 @@ public class Plot { * @param temp Represents whatever the database manager needs it to * @see Plot#getPlot(Location) for existing plots */ - public Plot(PlotArea area, @NotNull PlotId id, UUID owner, int temp) { + public Plot(final PlotArea area, @NotNull final PlotId id, final UUID owner, final int temp, + @NotNull final EventDispatcher eventDispatcher, @NotNull final PlotListener plotListener) { this.area = area; this.id = id; this.owner = owner; this.temp = temp; this.flagContainer.setParentContainer(area.getFlagContainer()); + this.eventDispatcher = eventDispatcher; + this.plotListener = plotListener; } /** @@ -240,7 +249,8 @@ public class Plot { */ public Plot(@NotNull PlotId id, UUID owner, HashSet trusted, HashSet members, HashSet denied, String alias, BlockLoc position, Collection> flags, - PlotArea area, boolean[] merged, long timestamp, int temp) { + PlotArea area, boolean[] merged, long timestamp, int temp, + @NotNull final EventDispatcher eventDispatcher, @NotNull final PlotListener plotListener) { this.id = id; this.area = area; this.owner = owner; @@ -261,6 +271,8 @@ public class Plot { } } } + this.eventDispatcher = eventDispatcher; + this.plotListener = plotListener; } /** @@ -925,7 +937,7 @@ public class Plot { if (isDelete) { this.removeSign(); } - PlotUnlinkEvent event = PlotSquared.get().getEventDispatcher() + PlotUnlinkEvent event = this.eventDispatcher .callUnlink(getArea(), this, true, !isDelete, isDelete ? PlotUnlinkEvent.REASON.DELETE : PlotUnlinkEvent.REASON.CLEAR); if (event.getEventResult() != Result.DENY) { @@ -1325,7 +1337,7 @@ public class Plot { for (Plot current : getConnectedPlots()) { List> players = current.getPlayersInPlot(); for (PlotPlayer pp : players) { - PlotListener.plotExit(pp, current); + this.plotListener.plotExit(pp, current); } if (Settings.Backup.DELETE_ON_UNCLAIM) { @@ -1339,7 +1351,7 @@ public class Plot { current.setOwnerAbs(null); current.settings = null; for (PlotPlayer pp : players) { - PlotListener.plotEntry(pp, current); + this.plotListener.plotEntry(pp, current); } } return true; @@ -1816,7 +1828,7 @@ public class Plot { PlotArea plotworld = Plot.this.area; if (notify && plotworld.isAutoMerge()) { PlotPlayer player = WorldUtil.IMP.wrapPlayer(uuid); - PlotMergeEvent event = PlotSquared.get().getEventDispatcher() + PlotMergeEvent event = this.eventDispatcher .callMerge(this, Direction.ALL, Integer.MAX_VALUE, player); if (event.getEventResult() == Result.DENY) { sendMessage(player, Captions.EVENT_DENIED, "Auto merge on claim"); @@ -2906,8 +2918,8 @@ public class Plot { public void reEnter() { TaskManager.runTaskLater(() -> { for (PlotPlayer pp : Plot.this.getPlayersInPlot()) { - PlotListener.plotExit(pp, Plot.this); - PlotListener.plotEntry(pp, Plot.this); + this.plotListener.plotExit(pp, Plot.this); + this.plotListener.plotEntry(pp, Plot.this); } }, 1); } @@ -2977,7 +2989,7 @@ public class Plot { Consumer resultConsumer) { Plot plot = this.getBasePlot(false); Result result = - PlotSquared.get().getEventDispatcher().callTeleport(player, player.getLocation(), plot) + this.eventDispatcher.callTeleport(player, player.getLocation(), plot) .getEventResult(); if (result == Result.DENY) { sendMessage(player, Captions.EVENT_DENIED, "Teleport"); @@ -3049,7 +3061,7 @@ public class Plot { */ public boolean setComponent(String component, Pattern blocks) { PlotComponentSetEvent event = - PlotSquared.get().getEventDispatcher().callComponentSet(this, component, blocks); + this.eventDispatcher.callComponentSet(this, component, blocks); component = event.getComponent(); blocks = event.getPattern(); return this.getManager().setComponent(this.getId(), component, blocks); diff --git a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java index e56446108..af5a169e4 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java +++ b/Core/src/main/java/com/plotsquared/core/plot/PlotArea.java @@ -37,6 +37,7 @@ import com.plotsquared.core.configuration.ConfigurationUtil; import com.plotsquared.core.configuration.Settings; import com.plotsquared.core.generator.GridPlotWorld; import com.plotsquared.core.generator.IndependentPlotGenerator; +import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.location.Direction; import com.plotsquared.core.location.Location; import com.plotsquared.core.location.PlotLoc; @@ -49,6 +50,7 @@ import com.plotsquared.core.plot.flag.implementations.DoneFlag; import com.plotsquared.core.queue.GlobalBlockQueue; import com.plotsquared.core.queue.LocalBlockQueue; import com.plotsquared.core.util.EconHandler; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.Expression; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.MathMan; @@ -133,9 +135,13 @@ public abstract class PlotArea { @Getter private final FlagContainer roadFlagContainer = new FlagContainer(GlobalFlagContainer.getInstance()); + private final EventDispatcher eventDispatcher; + private final PlotListener plotListener; + public PlotArea(@NotNull final String worldName, @Nullable final String id, @NotNull IndependentPlotGenerator generator, @Nullable final PlotId min, - @Nullable final PlotId max) { + @Nullable final PlotId max, @NotNull final EventDispatcher eventDispatcher, + @NotNull final PlotListener plotListener) { this.worldName = worldName; this.id = id; this.plotManager = createManager(); @@ -152,6 +158,8 @@ public abstract class PlotArea { this.max = max; } this.worldHash = worldName.hashCode(); + this.eventDispatcher = eventDispatcher; + this.plotListener = plotListener; } @NotNull protected abstract PlotManager createManager(); @@ -649,7 +657,7 @@ public abstract class PlotArea { || id.y > this.max.y)) { return null; } - return new Plot(this, id); + return new Plot(this, id, this.eventDispatcher, this.plotListener); } return plot; } @@ -661,7 +669,7 @@ public abstract class PlotArea { || id.y > this.max.y)) { return null; } - return new Plot(this, id); + return new Plot(this, id, this.eventDispatcher, this.plotListener); } return plot.getBasePlot(false); } diff --git a/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpireManager.java b/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpireManager.java index bb8a73291..882bed76f 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpireManager.java +++ b/Core/src/main/java/com/plotsquared/core/plot/expiration/ExpireManager.java @@ -42,12 +42,14 @@ import com.plotsquared.core.plot.flag.PlotFlag; import com.plotsquared.core.plot.flag.implementations.AnalysisFlag; import com.plotsquared.core.plot.flag.implementations.KeepFlag; import com.plotsquared.core.plot.message.PlotMessage; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.MainUtil; import com.plotsquared.core.util.StringMan; import com.plotsquared.core.util.query.PlotQuery; import com.plotsquared.core.util.task.RunnableVal; import com.plotsquared.core.util.task.RunnableVal3; import com.plotsquared.core.util.task.TaskManager; +import org.jetbrains.annotations.NotNull; import java.util.ArrayDeque; import java.util.ArrayList; @@ -66,17 +68,20 @@ public class ExpireManager { public static ExpireManager IMP; private final ConcurrentHashMap dates_cache; private final ConcurrentHashMap account_age_cache; + private final EventDispatcher eventDispatcher; private volatile HashSet plotsToDelete; private ArrayDeque tasks; + /** * 0 = stopped, 1 = stopping, 2 = running */ private int running; - public ExpireManager() { - tasks = new ArrayDeque<>(); - dates_cache = new ConcurrentHashMap<>(); - account_age_cache = new ConcurrentHashMap<>(); + public ExpireManager(@NotNull final EventDispatcher eventDispatcher) { + this.tasks = new ArrayDeque<>(); + this.dates_cache = new ConcurrentHashMap<>(); + this.account_age_cache = new ConcurrentHashMap<>(); + this.eventDispatcher = eventDispatcher; } public void addTask(ExpiryTask task) { @@ -402,7 +407,7 @@ public class ExpireManager { public void deleteWithMessage(Plot plot, Runnable whenDone) { if (plot.isMerged()) { - PlotUnlinkEvent event = PlotSquared.get().getEventDispatcher() + PlotUnlinkEvent event = this.eventDispatcher .callUnlink(plot.getArea(), plot, true, false, PlotUnlinkEvent.REASON.EXPIRE_DELETE); if (event.getEventResult() != Result.DENY) { diff --git a/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlot.java b/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlot.java index a57fe7d3d..3434c1ac1 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlot.java +++ b/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlot.java @@ -25,12 +25,14 @@ */ package com.plotsquared.core.plot.world; +import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.location.BlockLoc; import com.plotsquared.core.location.Location; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; import com.plotsquared.core.plot.PlotId; import com.plotsquared.core.plot.flag.PlotFlag; +import com.plotsquared.core.util.EventDispatcher; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.regions.CuboidRegion; import org.jetbrains.annotations.NotNull; @@ -47,23 +49,17 @@ public class SinglePlot extends Plot { new CuboidRegion(BlockVector3.at(Integer.MIN_VALUE, Integer.MIN_VALUE, Integer.MIN_VALUE), BlockVector3.at(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE))); - public SinglePlot(PlotArea area, PlotId id, UUID owner) { - super(area, id, owner); - } - - public SinglePlot(PlotArea area, PlotId id) { - super(area, id); - } - - public SinglePlot(PlotArea area, PlotId id, UUID owner, int temp) { - super(area, id, owner, temp); + public SinglePlot(PlotArea area, PlotId id, @NotNull final EventDispatcher eventDispatcher, @NotNull final + PlotListener plotListener) { + super(area, id, eventDispatcher, plotListener); } public SinglePlot(PlotId id, UUID owner, HashSet trusted, HashSet members, HashSet denied, String alias, BlockLoc position, Collection> flags, - PlotArea area, boolean[] merged, long timestamp, int temp) { + PlotArea area, boolean[] merged, long timestamp, int temp, + @NotNull final EventDispatcher eventDispatcher, @NotNull final PlotListener plotListener) { super(id, owner, trusted, members, denied, alias, position, flags, area, merged, timestamp, - temp); + temp, eventDispatcher, plotListener); } @Override public String getWorldName() { diff --git a/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotArea.java b/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotArea.java index 3364c8b2d..06c15182c 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotArea.java +++ b/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotArea.java @@ -31,6 +31,7 @@ import com.plotsquared.core.configuration.ConfigurationSection; import com.plotsquared.core.configuration.ConfigurationUtil; import com.plotsquared.core.generator.GridPlotWorld; import com.plotsquared.core.generator.SingleWorldGenerator; +import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.location.Location; import com.plotsquared.core.location.PlotLoc; import com.plotsquared.core.plot.Plot; @@ -41,6 +42,7 @@ import com.plotsquared.core.plot.PlotSettings; import com.plotsquared.core.plot.flag.FlagContainer; import com.plotsquared.core.setup.PlotAreaBuilder; import com.plotsquared.core.setup.SettingsNodesWrapper; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.SetupUtils; import com.plotsquared.core.util.WorldUtil; import com.plotsquared.core.util.task.RunnableVal; @@ -56,8 +58,13 @@ public class SinglePlotArea extends GridPlotWorld { public boolean VOID = false; - public SinglePlotArea(@NotNull final PlotAreaManager plotAreaManager) { - super("*", null, new SingleWorldGenerator(plotAreaManager), null, null); + private final EventDispatcher eventDispatcher; + private final PlotListener plotListener; + + public SinglePlotArea(@NotNull final PlotAreaManager plotAreaManager, @NotNull final EventDispatcher eventDispatcher, @NotNull final PlotListener plotListener) { + super("*", null, new SingleWorldGenerator(plotAreaManager), null, null, eventDispatcher, plotListener); + this.eventDispatcher = eventDispatcher; + this.plotListener = plotListener; this.setAllowSigns(false); this.setDefaultHome(new PlotLoc(Integer.MAX_VALUE, Integer.MAX_VALUE)); } @@ -200,7 +207,7 @@ public class SinglePlotArea extends GridPlotWorld { final FlagContainer oldContainer = p.getFlagContainer(); p = new SinglePlot(p.getId(), p.getOwnerAbs(), p.getTrusted(), p.getMembers(), p.getDenied(), s.getAlias(), s.getPosition(), null, this, s.getMerged(), - p.getTimestamp(), p.temp); + p.getTimestamp(), p.temp, this.eventDispatcher, this.plotListener); p.getFlagContainer().addAll(oldContainer); return p; @@ -209,7 +216,7 @@ public class SinglePlotArea extends GridPlotWorld { @Nullable public Plot getPlotAbs(@NotNull final PlotId id) { Plot plot = getOwnedPlotAbs(id); if (plot == null) { - return new SinglePlot(this, id); + return new SinglePlot(this, id, this.eventDispatcher, this.plotListener); } return plot; } @@ -218,7 +225,7 @@ public class SinglePlotArea extends GridPlotWorld { // TODO Plot plot = getOwnedPlotAbs(id); if (plot == null) { - return new SinglePlot(this, id); + return new SinglePlot(this, id, this.eventDispatcher, this.plotListener); } return plot.getBasePlot(false); } diff --git a/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotAreaManager.java b/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotAreaManager.java index 36d3d09ab..c478d8663 100644 --- a/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotAreaManager.java +++ b/Core/src/main/java/com/plotsquared/core/plot/world/SinglePlotAreaManager.java @@ -27,8 +27,10 @@ package com.plotsquared.core.plot.world; import com.plotsquared.core.collection.ArrayUtil; import com.plotsquared.core.generator.SingleWorldGenerator; +import com.plotsquared.core.listener.PlotListener; import com.plotsquared.core.location.Location; import com.plotsquared.core.plot.PlotArea; +import com.plotsquared.core.util.EventDispatcher; import com.plotsquared.core.util.SetupUtils; import com.sk89q.worldedit.regions.CuboidRegion; import org.jetbrains.annotations.NotNull; @@ -40,8 +42,9 @@ public class SinglePlotAreaManager extends DefaultPlotAreaManager { private SinglePlotArea area; private PlotArea[] all; - public SinglePlotAreaManager() { - this.area = new SinglePlotArea(this); + public SinglePlotAreaManager(@NotNull final EventDispatcher eventDispatcher, @NotNull final + PlotListener plotListener) { + this.area = new SinglePlotArea(this, eventDispatcher, plotListener); this.array = new SinglePlotArea[] {area}; this.all = new PlotArea[] {area}; SetupUtils.generators.put("PlotSquared:single", diff --git a/Core/src/main/java/com/plotsquared/core/util/task/AutoClaimFinishTask.java b/Core/src/main/java/com/plotsquared/core/util/task/AutoClaimFinishTask.java index 41f167fd9..1ac9c81e8 100644 --- a/Core/src/main/java/com/plotsquared/core/util/task/AutoClaimFinishTask.java +++ b/Core/src/main/java/com/plotsquared/core/util/task/AutoClaimFinishTask.java @@ -25,7 +25,6 @@ */ package com.plotsquared.core.util.task; -import com.plotsquared.core.PlotSquared; import com.plotsquared.core.command.Auto; import com.plotsquared.core.configuration.Captions; import com.plotsquared.core.events.PlotMergeEvent; @@ -34,6 +33,7 @@ import com.plotsquared.core.location.Direction; import com.plotsquared.core.player.PlotPlayer; import com.plotsquared.core.plot.Plot; import com.plotsquared.core.plot.PlotArea; +import com.plotsquared.core.util.EventDispatcher; import lombok.RequiredArgsConstructor; import static com.plotsquared.core.util.MainUtil.sendMessage; @@ -45,6 +45,7 @@ public final class AutoClaimFinishTask extends RunnableVal { private final Plot plot; private final PlotArea area; private final String schematic; + private final EventDispatcher eventDispatcher; @Override public void run(Object value) { player.deleteMeta(Auto.class.getName()); @@ -54,8 +55,7 @@ public final class AutoClaimFinishTask extends RunnableVal { } plot.claim(player, true, schematic, false); if (area.isAutoMerge()) { - PlotMergeEvent event = PlotSquared.get().getEventDispatcher() - .callMerge(plot, Direction.ALL, Integer.MAX_VALUE, player); + PlotMergeEvent event = this.eventDispatcher.callMerge(plot, Direction.ALL, Integer.MAX_VALUE, player); if (event.getEventResult() == Result.DENY) { sendMessage(player, Captions.EVENT_DENIED, "Auto merge"); } else {