Fix PlotDeleteEvent and PlotMergeEvent not being called.

Replaced current PlotMergeEvent with PlotAutoMergeEvent (called when a plot is merged on /plot auto). And made PlotMergeEvent be called for /plot merge command.
This commit is contained in:
dordsor21 2019-01-10 17:29:25 +00:00
parent aff5476110
commit 446c47d148
15 changed files with 313 additions and 60 deletions

View file

@ -0,0 +1,62 @@
package com.plotsquared.bukkit.events;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import org.bukkit.World;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import java.util.ArrayList;
public class PlotAutoMergeEvent extends PlotEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private final ArrayList<PlotId> plots;
private final World world;
private boolean cancelled;
/**
* PlotMergeEvent: Called when plots are merged
*
* @param world World in which the event occurred
* @param plot Plot that was merged
* @param plots A list of plots involved in the event
*/
public PlotAutoMergeEvent(World world, Plot plot, ArrayList<PlotId> plots) {
super(plot);
this.world = world;
this.plots = plots;
}
public static HandlerList getHandlerList() {
return handlers;
}
/**
* Get the plots being added.
*
* @return Plot
*/
public ArrayList<PlotId> getPlots() {
return this.plots;
}
public World getWorld() {
return this.world;
}
@Override
public HandlerList getHandlers() {
return handlers;
}
@Override
public boolean isCancelled() {
return this.cancelled;
}
@Override
public void setCancelled(boolean b) {
this.cancelled = b;
}
}

View file

@ -2,15 +2,17 @@ package com.plotsquared.bukkit.events;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList; import org.bukkit.event.HandlerList;
/** /**
* Called when a plot is deleted * Called when a plot is deleted
* *
*/ */
public class PlotDeleteEvent extends PlotEvent { public class PlotDeleteEvent extends PlotEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
private boolean cancelled;
public PlotDeleteEvent(Plot plot) { public PlotDeleteEvent(Plot plot) {
super(plot); super(plot);
@ -42,4 +44,12 @@ public class PlotDeleteEvent extends PlotEvent {
public HandlerList getHandlers() { public HandlerList getHandlers() {
return handlers; return handlers;
} }
@Override public boolean isCancelled() {
return this.cancelled;
}
@Override public void setCancelled(boolean b) {
this.cancelled = b;
}
} }

View file

@ -11,7 +11,8 @@ import java.util.ArrayList;
public class PlotMergeEvent extends PlotEvent implements Cancellable { public class PlotMergeEvent extends PlotEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
private final ArrayList<PlotId> plots; private final int dir;
private final int max;
private final World world; private final World world;
private boolean cancelled; private boolean cancelled;
@ -20,25 +21,26 @@ public class PlotMergeEvent extends PlotEvent implements Cancellable {
* *
* @param world World in which the event occurred * @param world World in which the event occurred
* @param plot Plot that was merged * @param plot Plot that was merged
* @param plots A list of plots involved in the event * @param dir The direction of the merge
* @param max Max merge size
*/ */
public PlotMergeEvent(World world, Plot plot, ArrayList<PlotId> plots) { public PlotMergeEvent(World world, Plot plot, final int dir, final int max) {
super(plot); super(plot);
this.world = world; this.world = world;
this.plots = plots; this.dir = dir;
this.max = max;
} }
public static HandlerList getHandlerList() { public static HandlerList getHandlerList() {
return handlers; return handlers;
} }
/** public int getDir() {
* Get the plots being added. return this.dir;
* }
* @return Plot
*/ public int getMax() {
public ArrayList<PlotId> getPlots() { return this.max;
return this.plots;
} }
public World getWorld() { public World getWorld() {

View file

@ -55,8 +55,8 @@ public class BukkitEventUtil extends EventUtil {
} }
@Override @Override
public void callDelete(Plot plot) { public boolean callDelete(Plot plot) {
callEvent(new PlotDeleteEvent(plot)); return callEvent(new PlotDeleteEvent(plot));
} }
@Override @Override
@ -70,8 +70,13 @@ public class BukkitEventUtil extends EventUtil {
} }
@Override @Override
public boolean callMerge(Plot plot, ArrayList<PlotId> plots) { public boolean callMerge(Plot plot, int dir, int max) {
return callEvent(new PlotMergeEvent(BukkitUtil.getWorld(plot.getWorldName()), plot, plots)); return callEvent(new PlotMergeEvent(BukkitUtil.getWorld(plot.getWorldName()), plot, dir, max));
}
@Override
public boolean callAutoMerge(Plot plot, ArrayList<PlotId> plots) {
return callEvent(new PlotAutoMergeEvent(BukkitUtil.getWorld(plot.getWorldName()), plot, plots));
} }
@Override @Override

View file

@ -788,9 +788,18 @@ public class Plot {
} }
public boolean clear(boolean checkRunning, final boolean isDelete, final Runnable whenDone) { public boolean clear(boolean checkRunning, final boolean isDelete, final Runnable whenDone) {
if (checkRunning && this.getRunning() != 0 || !EventUtil.manager.callClear(this)) { if (checkRunning && this.getRunning() != 0) {
return false; return false;
} }
if (isDelete) {
if(!EventUtil.manager.callDelete(this)) {
return false;
}
} else {
if(!EventUtil.manager.callClear(this)) {
return false;
}
}
final HashSet<RegionWrapper> regions = this.getRegions(); final HashSet<RegionWrapper> regions = this.getRegions();
final Set<Plot> plots = this.getConnectedPlots(); final Set<Plot> plots = this.getConnectedPlots();
final ArrayDeque<Plot> queue = new ArrayDeque<>(plots); final ArrayDeque<Plot> queue = new ArrayDeque<>(plots);
@ -2157,6 +2166,9 @@ public class Plot {
if (this.owner == null) { if (this.owner == null) {
return false; return false;
} }
if(!EventUtil.manager.callMerge(this, dir, max)) {
return false;
}
HashSet<Plot> visited = new HashSet<>(); HashSet<Plot> visited = new HashSet<>();
HashSet<PlotId> merged = new HashSet<>(); HashSet<PlotId> merged = new HashSet<>();
Set<Plot> connected = this.getConnectedPlots(); Set<Plot> connected = this.getConnectedPlots();

View file

@ -817,7 +817,7 @@ public abstract class PlotArea {
PlotId pos2 = plotIds.get(plotIds.size() - 1); PlotId pos2 = plotIds.get(plotIds.size() - 1);
PlotManager manager = getPlotManager(); PlotManager manager = getPlotManager();
boolean result = EventUtil.manager.callMerge(getPlotAbs(pos1), plotIds); boolean result = EventUtil.manager.callAutoMerge(getPlotAbs(pos1), plotIds);
if (!result) { if (!result) {
return false; return false;
} }

View file

@ -45,7 +45,7 @@ public abstract class EventUtil {
public abstract boolean callClear(Plot plot); public abstract boolean callClear(Plot plot);
public abstract void callDelete(Plot plot); public abstract boolean callDelete(Plot plot);
public abstract boolean callFlagAdd(Flag flag, Plot plot); public abstract boolean callFlagAdd(Flag flag, Plot plot);
@ -53,7 +53,9 @@ public abstract class EventUtil {
public abstract boolean callFlagRemove(Flag<?> flag, Object value, PlotCluster cluster); public abstract boolean callFlagRemove(Flag<?> flag, Object value, PlotCluster cluster);
public abstract boolean callMerge(Plot plot, ArrayList<PlotId> plots); public abstract boolean callMerge(Plot plot, int dir, int max);
public abstract boolean callAutoMerge(Plot plot, ArrayList<PlotId> plots);
public abstract boolean callUnlink(PlotArea area, ArrayList<PlotId> plots); public abstract boolean callUnlink(PlotArea area, ArrayList<PlotId> plots);

View file

@ -32,7 +32,9 @@ public class EventUtilTest extends EventUtil {
return false; return false;
} }
@Override public void callDelete(Plot plot) {} @Override public boolean callDelete(Plot plot) {
return false;
}
@Override public boolean callFlagAdd(Flag flag, Plot plot) { @Override public boolean callFlagAdd(Flag flag, Plot plot) {
return true; return true;
@ -46,7 +48,11 @@ public class EventUtilTest extends EventUtil {
return true; return true;
} }
@Override public boolean callMerge(Plot plot, ArrayList<PlotId> plots) { @Override public boolean callMerge(Plot plot, int dir, int max) {
return false;
}
@Override public boolean callAutoMerge(Plot plot, ArrayList<PlotId> plots) {
return false; return false;
} }

View file

@ -0,0 +1,61 @@
package com.plotsquared.nukkit.events;
import cn.nukkit.event.Cancellable;
import com.intellectualcrafters.plot.object.Plot;
import cn.nukkit.event.HandlerList;
import cn.nukkit.level.Level;
import com.intellectualcrafters.plot.object.PlotId;
import java.util.ArrayList;
public class PlotAutoMergeEvent extends PlotEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private final ArrayList<PlotId> plots;
private final Level world;
private boolean cancelled;
/**
* PlotMergeEvent: Called when plots are merged
*
* @param world World in which the event occurred
* @param plot Plot that was merged
* @param plots A list of plots involved in the event
*/
public PlotAutoMergeEvent(Level world, Plot plot, ArrayList<PlotId> plots) {
super(plot);
this.world = world;
this.plots = plots;
}
public static HandlerList getHandlerList() {
return handlers;
}
/**
* Get the plots being added.
*
* @return Plot
*/
public ArrayList<PlotId> getPlots() {
return this.plots;
}
public Level getWorld() {
return this.world;
}
public HandlerList getHandlers() {
return handlers;
}
@Override
public boolean isCancelled() {
return this.cancelled;
}
@Override
public void setCancelled(boolean b) {
this.cancelled = b;
}
}

View file

@ -4,13 +4,12 @@ import cn.nukkit.event.Cancellable;
import cn.nukkit.event.HandlerList; import cn.nukkit.event.HandlerList;
import cn.nukkit.level.Level; import cn.nukkit.level.Level;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import java.util.ArrayList;
public class PlotMergeEvent extends PlotEvent implements Cancellable { public class PlotMergeEvent extends PlotEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList(); private static final HandlerList handlers = new HandlerList();
private final ArrayList<PlotId> plots; private final int dir;
private final int max;
private final Level world; private final Level world;
private boolean cancelled; private boolean cancelled;
@ -19,31 +18,32 @@ public class PlotMergeEvent extends PlotEvent implements Cancellable {
* *
* @param world World in which the event occurred * @param world World in which the event occurred
* @param plot Plot that was merged * @param plot Plot that was merged
* @param plots A list of plots involved in the event * @param dir The direction of the merge
* @param max Max merge size
*/ */
public PlotMergeEvent(Level world, Plot plot, ArrayList<PlotId> plots) { public PlotMergeEvent(Level world, Plot plot, final int dir, final int max) {
super(plot); super(plot);
this.world = world; this.world = world;
this.plots = plots; this.dir = dir;
this.max = max;
} }
public static HandlerList getHandlers() { public static HandlerList getHandlers() {
return handlers; return handlers;
} }
/**
* Get the plots being added.
*
* @return Plot
*/
public ArrayList<PlotId> getPlots() {
return this.plots;
}
public Level getLevel() { public Level getLevel() {
return this.world; return this.world;
} }
public int getDir() {
return this.dir;
}
public int getMax() {
return this.max;
}
@Override @Override
public boolean isCancelled() { public boolean isCancelled() {
return this.cancelled; return this.cancelled;

View file

@ -61,8 +61,8 @@ public class NukkitEventUtil extends EventUtil {
} }
@Override @Override
public void callDelete(Plot plot) { public boolean callDelete(Plot plot) {
callEvent(new PlotDeleteEvent(plot)); return callEvent(new PlotDeleteEvent(plot));
} }
@Override @Override
@ -76,8 +76,13 @@ public class NukkitEventUtil extends EventUtil {
} }
@Override @Override
public boolean callMerge(Plot plot, ArrayList<PlotId> plots) { public boolean callMerge(Plot plot, int dir, int max) {
return callEvent(new PlotMergeEvent(NukkitUtil.getWorld(plot.getWorldName()), plot, plots)); return callEvent(new PlotMergeEvent(NukkitUtil.getWorld(plot.getWorldName()), plot, dir, max));
}
@Override
public boolean callAutoMerge(Plot plot, ArrayList<PlotId> plots) {
return callEvent(new PlotAutoMergeEvent(NukkitUtil.getWorld(plot.getWorldName()), plot, plots));
} }
@Override @Override

View file

@ -0,0 +1,68 @@
package com.plotsquared.sponge.events;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId;
import org.spongepowered.api.event.Cancellable;
import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.event.impl.AbstractEvent;
import org.spongepowered.api.world.World;
import java.util.ArrayList;
public class PlotAutoMergeEvent extends AbstractEvent implements Cancellable {
private final ArrayList<PlotId> plots;
private final World world;
private Plot plot;
private boolean cancelled;
/**
* PlotMergeEvent: Called when plots are merged
*
* @param world World in which the event occurred
* @param plot Plot that was merged
* @param plots A list of plots involved in the event
*/
public PlotAutoMergeEvent(World world, Plot plot, ArrayList<PlotId> plots) {
this.world = world;
this.plots = plots;
this.plot = plot;
}
/**
* Get the plots being added.
*
* @return Plot
*/
public ArrayList<PlotId> getPlots() {
return this.plots;
}
/**
* Get the main plot
*
* @return Plot
*/
public Plot getPlot() {
return plot;
}
public World getWorld() {
return this.world;
}
@Override
public boolean isCancelled() {
return this.cancelled;
}
@Override
public void setCancelled(boolean b) {
this.cancelled = b;
}
@Override
public Cause getCause() {
return null;
}
}

View file

@ -1,13 +1,15 @@
package com.plotsquared.sponge.events; package com.plotsquared.sponge.events;
import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.Plot;
import org.spongepowered.api.event.Cancellable;
import org.spongepowered.api.event.cause.Cause; import org.spongepowered.api.event.cause.Cause;
import org.spongepowered.api.event.impl.AbstractEvent; import org.spongepowered.api.event.impl.AbstractEvent;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
public class PlotDeleteEvent extends AbstractEvent { public class PlotDeleteEvent extends AbstractEvent implements Cancellable {
private final Plot plot; private final Plot plot;
private boolean cancelled;
/** /**
* PlotDeleteEvent: Called when a plot is deleted * PlotDeleteEvent: Called when a plot is deleted
@ -35,7 +37,17 @@ public class PlotDeleteEvent extends AbstractEvent {
public String getWorld() { public String getWorld() {
return plot.getWorldName(); return plot.getWorldName();
} }
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(final boolean cancel) {
cancelled = cancel;
}
@Override @Override
public Cause getCause() { public Cause getCause() {
return null; return null;

View file

@ -11,29 +11,32 @@ import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
public class PlotMergeEvent extends AbstractEvent implements Cancellable { public class PlotMergeEvent extends AbstractEvent implements Cancellable {
private final ArrayList<PlotId> plots;
private boolean cancelled; private boolean cancelled;
private Plot plot; private Plot plot;
private final int dir;
private final int max;
private World world; private World world;
/** /**
* PlotMergeEvent: Called when plots are merged * PlotMergeEvent: Called when plots are merged
* *
* @param world World in which the event occurred * @param world World in which the event occurred
* @param plot Plot that was merged * @param dir The direction of the merge
* @param plots A list of plots involved in the event * @param max Max merge size
*/ */
public PlotMergeEvent(final World world, final Plot plot, final ArrayList<PlotId> plots) { public PlotMergeEvent(World world, Plot plot, final int dir, final int max) {
this.plots = plots; this.world = world;
this.dir = dir;
this.max = max;
this.plot = plot;
} }
/** public int getDir() {
* Get the plots being added; return this.dir;
* }
* @return Plot
*/ public int getMax() {
public ArrayList<PlotId> getPlots() { return this.max;
return plots;
} }
/** /**

View file

@ -51,8 +51,8 @@ public class SpongeEventUtil extends EventUtil {
} }
@Override @Override
public void callDelete(Plot plot) { public boolean callDelete(Plot plot) {
callEvent(new PlotDeleteEvent(plot)); return callEvent(new PlotDeleteEvent(plot));
} }
@Override @Override
@ -66,8 +66,13 @@ public class SpongeEventUtil extends EventUtil {
} }
@Override @Override
public boolean callMerge(Plot plot, ArrayList<PlotId> plots) { public boolean callMerge(Plot plot, int dir, int max) {
return callEvent(new PlotMergeEvent(SpongeUtil.getWorld(plot.getWorldName()), plot, plots)); return callEvent(new PlotMergeEvent(SpongeUtil.getWorld(plot.getWorldName()), plot, dir, max));
}
@Override
public boolean callAutoMerge(Plot plot, ArrayList<PlotId> plots) {
return callEvent(new PlotAutoMergeEvent(SpongeUtil.getWorld(plot.getWorldName()), plot, plots));
} }
@Override @Override