mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-21 12:46:46 +01:00
Always call plot events through the event dispatcher (#3479)
This commit is contained in:
parent
10bb520f3a
commit
d06a827e31
@ -126,7 +126,7 @@ public class Done extends SubCommand {
|
||||
long flagValue = System.currentTimeMillis() / 1000;
|
||||
PlotFlag<?, ?> plotFlag = plot.getFlagContainer().getFlag(DoneFlag.class)
|
||||
.createFlagInstance(Long.toString(flagValue));
|
||||
PlotFlagAddEvent event = new PlotFlagAddEvent(plotFlag, plot);
|
||||
PlotFlagAddEvent event = eventDispatcher.callFlagAdd(plotFlag, plot);
|
||||
if (event.getEventResult() == Result.DENY) {
|
||||
player.sendMessage(TranslatableCaption.of("events.event_denied"));
|
||||
return;
|
||||
|
@ -25,6 +25,7 @@
|
||||
*/
|
||||
package com.plotsquared.core.command;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import com.plotsquared.core.PlotSquared;
|
||||
import com.plotsquared.core.configuration.Settings;
|
||||
import com.plotsquared.core.configuration.caption.CaptionUtility;
|
||||
@ -44,6 +45,7 @@ import com.plotsquared.core.plot.flag.InternalFlag;
|
||||
import com.plotsquared.core.plot.flag.PlotFlag;
|
||||
import com.plotsquared.core.plot.flag.types.IntegerFlag;
|
||||
import com.plotsquared.core.plot.flag.types.ListFlag;
|
||||
import com.plotsquared.core.util.EventDispatcher;
|
||||
import com.plotsquared.core.util.MathMan;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.plotsquared.core.util.StringComparison;
|
||||
@ -79,8 +81,12 @@ import java.util.stream.Stream;
|
||||
@SuppressWarnings("unused")
|
||||
public final class FlagCommand extends Command {
|
||||
|
||||
public FlagCommand() {
|
||||
private final EventDispatcher eventDispatcher;
|
||||
|
||||
@Inject
|
||||
public FlagCommand(final @NonNull EventDispatcher eventDispatcher) {
|
||||
super(MainCommand.getInstance(), true);
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
}
|
||||
|
||||
private static boolean sendMessage(PlotPlayer<?> player) {
|
||||
@ -335,7 +341,7 @@ public final class FlagCommand extends Command {
|
||||
return;
|
||||
}
|
||||
Plot plot = player.getLocation().getPlotAbs();
|
||||
PlotFlagAddEvent event = new PlotFlagAddEvent(plotFlag, plot);
|
||||
PlotFlagAddEvent event = eventDispatcher.callFlagAdd(plotFlag, plot);
|
||||
if (event.getEventResult() == Result.DENY) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("events.event_denied"),
|
||||
@ -394,7 +400,7 @@ public final class FlagCommand extends Command {
|
||||
return;
|
||||
}
|
||||
Plot plot = player.getLocation().getPlotAbs();
|
||||
PlotFlagAddEvent event = new PlotFlagAddEvent(plotFlag, plot);
|
||||
PlotFlagAddEvent event = eventDispatcher.callFlagAdd(plotFlag, plot);
|
||||
if (event.getEventResult() == Result.DENY) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("events.event_denied"),
|
||||
@ -463,7 +469,7 @@ public final class FlagCommand extends Command {
|
||||
return;
|
||||
}
|
||||
final Plot plot = player.getLocation().getPlotAbs();
|
||||
PlotFlagRemoveEvent event = new PlotFlagRemoveEvent(flag, plot);
|
||||
PlotFlagRemoveEvent event = eventDispatcher.callFlagRemove(flag, plot);
|
||||
if (event.getEventResult() == Result.DENY) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("events.event_denied"),
|
||||
@ -516,7 +522,7 @@ public final class FlagCommand extends Command {
|
||||
}
|
||||
} else {
|
||||
PlotFlag<?, ?> plotFlag = parsedFlag.createFlagInstance(list);
|
||||
PlotFlagAddEvent addEvent = new PlotFlagAddEvent(plotFlag, plot);
|
||||
PlotFlagAddEvent addEvent = eventDispatcher.callFlagAdd(plotFlag, plot);
|
||||
if (addEvent.getEventResult() == Result.DENY) {
|
||||
player.sendMessage(
|
||||
TranslatableCaption.of("events.event_denied"),
|
||||
|
@ -38,10 +38,12 @@ import com.plotsquared.core.plot.PlotInventory;
|
||||
import com.plotsquared.core.plot.PlotItemStack;
|
||||
import com.plotsquared.core.plot.flag.PlotFlag;
|
||||
import com.plotsquared.core.plot.flag.implementations.MusicFlag;
|
||||
import com.plotsquared.core.util.EventDispatcher;
|
||||
import com.plotsquared.core.util.InventoryUtil;
|
||||
import com.plotsquared.core.util.Permissions;
|
||||
import com.sk89q.worldedit.world.item.ItemTypes;
|
||||
import net.kyori.adventure.text.minimessage.Template;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Arrays;
|
||||
@ -63,10 +65,12 @@ public class Music extends SubCommand {
|
||||
);
|
||||
|
||||
private final InventoryUtil inventoryUtil;
|
||||
private final EventDispatcher eventDispatcher;
|
||||
|
||||
@Inject
|
||||
public Music(final @Nullable InventoryUtil inventoryUtil) {
|
||||
public Music(final @Nullable InventoryUtil inventoryUtil, final @NonNull EventDispatcher eventDispatcher) {
|
||||
this.inventoryUtil = inventoryUtil;
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -104,7 +108,7 @@ public class Music extends SubCommand {
|
||||
if (item.getType() == ItemTypes.BEDROCK) {
|
||||
PlotFlag<?, ?> plotFlag = plot.getFlagContainer().getFlag(MusicFlag.class)
|
||||
.createFlagInstance(item.getType());
|
||||
PlotFlagRemoveEvent event = new PlotFlagRemoveEvent(plotFlag, plot);
|
||||
PlotFlagRemoveEvent event = eventDispatcher.callFlagRemove(plotFlag, plot);
|
||||
if (event.getEventResult() == Result.DENY) {
|
||||
getPlayer().sendMessage(
|
||||
TranslatableCaption.of("events.event_denied"),
|
||||
@ -121,7 +125,7 @@ public class Music extends SubCommand {
|
||||
} else if (item.getName().toLowerCase(Locale.ENGLISH).contains("disc")) {
|
||||
PlotFlag<?, ?> plotFlag = plot.getFlagContainer().getFlag(MusicFlag.class)
|
||||
.createFlagInstance(item.getType());
|
||||
PlotFlagAddEvent event = new PlotFlagAddEvent(plotFlag, plot);
|
||||
PlotFlagAddEvent event = eventDispatcher.callFlagAdd(plotFlag, plot);
|
||||
if (event.getEventResult() == Result.DENY) {
|
||||
getPlayer().sendMessage(
|
||||
TranslatableCaption.of("events.event_denied"),
|
||||
|
@ -45,6 +45,7 @@ import com.plotsquared.core.queue.ChunkQueueCoordinator;
|
||||
import com.plotsquared.core.queue.GlobalBlockQueue;
|
||||
import com.plotsquared.core.queue.QueueCoordinator;
|
||||
import com.plotsquared.core.util.ChunkManager;
|
||||
import com.plotsquared.core.util.EventDispatcher;
|
||||
import com.plotsquared.core.util.MathMan;
|
||||
import com.plotsquared.core.util.RegionManager;
|
||||
import com.plotsquared.core.util.RegionUtil;
|
||||
@ -93,6 +94,7 @@ public class HybridUtils {
|
||||
private final GlobalBlockQueue blockQueue;
|
||||
private final WorldUtil worldUtil;
|
||||
private final SchematicHandler schematicHandler;
|
||||
private final EventDispatcher eventDispatcher;
|
||||
|
||||
@Inject
|
||||
public HybridUtils(
|
||||
@ -100,13 +102,15 @@ public class HybridUtils {
|
||||
final @NonNull ChunkManager chunkManager,
|
||||
final @NonNull GlobalBlockQueue blockQueue,
|
||||
final @NonNull WorldUtil worldUtil,
|
||||
final @NonNull SchematicHandler schematicHandler
|
||||
final @NonNull SchematicHandler schematicHandler,
|
||||
final @NonNull EventDispatcher eventDispatcher
|
||||
) {
|
||||
this.plotAreaManager = plotAreaManager;
|
||||
this.chunkManager = chunkManager;
|
||||
this.blockQueue = blockQueue;
|
||||
this.worldUtil = worldUtil;
|
||||
this.schematicHandler = schematicHandler;
|
||||
this.eventDispatcher = eventDispatcher;
|
||||
}
|
||||
|
||||
public void regeneratePlotWalls(final PlotArea area) {
|
||||
@ -348,7 +352,7 @@ public class HybridUtils {
|
||||
result.add(whenDone.value.variety_sd);
|
||||
PlotFlag<?, ?> plotFlag = GlobalFlagContainer.getInstance().getFlag(AnalysisFlag.class).createFlagInstance(
|
||||
result);
|
||||
PlotFlagAddEvent event = new PlotFlagAddEvent(plotFlag, origin);
|
||||
PlotFlagAddEvent event = eventDispatcher.callFlagAdd(plotFlag, origin);
|
||||
if (event.getEventResult() == Result.DENY) {
|
||||
return;
|
||||
}
|
||||
|
@ -359,7 +359,7 @@ public class ExpireManager {
|
||||
.getFlag(AnalysisFlag.class)
|
||||
.createFlagInstance(changed.asList());
|
||||
PlotFlagAddEvent event =
|
||||
new PlotFlagAddEvent(plotFlag, newPlot);
|
||||
eventDispatcher.callFlagAdd(plotFlag, plot);
|
||||
if (event.getEventResult() == Result.DENY) {
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user