Inject EventDispatcher and PlotListener

This commit is contained in:
Alexander Söderberg 2020-07-10 18:17:44 +02:00
parent 2dab7c8dda
commit d00dc658df
47 changed files with 418 additions and 219 deletions

View File

@ -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() {

View File

@ -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<Player> 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)

View File

@ -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<Player> {
*
* @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) {

View File

@ -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<BukkitPlayer, Player> {
@RequiredArgsConstructor public class BukkitPlayerManager extends PlayerManager<BukkitPlayer, Player> {
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<BukkitPlayer, Player> {
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) {

View File

@ -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);
}
/**

View File

@ -23,9 +23,8 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
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;

View File

@ -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();

View File

@ -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);

View File

@ -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 <create|info|list|tp|regen>",
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());

View File

@ -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<Plot>() {
@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<PlotId> 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");

View File

@ -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());
}

View File

@ -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");

View File

@ -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 <plot> clear
// The syntax also works with any command: /plot <plot> <command>
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<Command, CommandResult> 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());

View File

@ -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;

View File

@ -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<Plot> 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<String, HashMap<PlotId, Plot>> map = manager.getPlots();
plots = new ArrayList<>();
for (Entry<String, HashMap<PlotId, Plot>> 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) {

View File

@ -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");

View File

@ -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 <plot> delete
// The syntax also works with any command: /plot <plot> <command>
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;

View File

@ -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 {

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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;

View File

@ -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 {

View File

@ -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) {

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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(

View File

@ -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());

View File

@ -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++;
}
}

View File

@ -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);

View File

@ -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) {

View File

@ -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<PlotId, Plot> map = newPlots.get(areaID);
if (map != null) {
Plot last = map.put(p.getId(), p);

View File

@ -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);
}
/**

View File

@ -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);
}
}

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

@ -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<UUID, Interval> feedRunnable = new HashMap<>();
private static final HashMap<UUID, Interval> healRunnable = new HashMap<>();
private final HashMap<UUID, Interval> feedRunnable = new HashMap<>();
private final HashMap<UUID, Interval> healRunnable = new HashMap<>();
public static void startRunnable() {
private final EventDispatcher eventDispatcher;
public void startRunnable() {
TaskManager.runTaskRepeat(() -> {
if (!healRunnable.isEmpty()) {
for (Iterator<Map.Entry<UUID, Interval>> 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);
}

View File

@ -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<Actor> {
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<Actor> {
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;

View File

@ -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<P> 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 <T> PlotPlayer<T> from(@NonNull final T object) {
@ -583,7 +585,7 @@ public abstract class PlotPlayer<P> 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()) {

View File

@ -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<CuboidRegion> 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<UUID> trusted, HashSet<UUID> members,
HashSet<UUID> denied, String alias, BlockLoc position, Collection<PlotFlag<?, ?>> 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<PlotPlayer<?>> 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<Boolean> 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);

View File

@ -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);
}

View File

@ -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<UUID, Long> dates_cache;
private final ConcurrentHashMap<UUID, Long> account_age_cache;
private final EventDispatcher eventDispatcher;
private volatile HashSet<Plot> plotsToDelete;
private ArrayDeque<ExpiryTask> 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) {

View File

@ -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<UUID> trusted, HashSet<UUID> members,
HashSet<UUID> denied, String alias, BlockLoc position, Collection<PlotFlag<?, ?>> 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() {

View File

@ -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);
}

View File

@ -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",

View File

@ -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<Object> {
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<Object> {
}
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 {