mirror of
https://github.com/TotalFreedomMC/TF-PlotSquared.git
synced 2025-05-06 10:14:39 +00:00
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:
parent
aff5476110
commit
446c47d148
15 changed files with 313 additions and 60 deletions
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -2,15 +2,17 @@ package com.plotsquared.bukkit.events;
|
|||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
/**
|
||||
* 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 boolean cancelled;
|
||||
|
||||
public PlotDeleteEvent(Plot plot) {
|
||||
super(plot);
|
||||
|
@ -42,4 +44,12 @@ public class PlotDeleteEvent extends PlotEvent {
|
|||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@Override public boolean isCancelled() {
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
@Override public void setCancelled(boolean b) {
|
||||
this.cancelled = b;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,8 @@ import java.util.ArrayList;
|
|||
public class PlotMergeEvent extends PlotEvent implements Cancellable {
|
||||
|
||||
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 boolean cancelled;
|
||||
|
||||
|
@ -20,25 +21,26 @@ public class PlotMergeEvent extends PlotEvent implements Cancellable {
|
|||
*
|
||||
* @param world World in which the event occurred
|
||||
* @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);
|
||||
this.world = world;
|
||||
this.plots = plots;
|
||||
this.dir = dir;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plots being added.
|
||||
*
|
||||
* @return Plot
|
||||
*/
|
||||
public ArrayList<PlotId> getPlots() {
|
||||
return this.plots;
|
||||
public int getDir() {
|
||||
return this.dir;
|
||||
}
|
||||
|
||||
public int getMax() {
|
||||
return this.max;
|
||||
}
|
||||
|
||||
public World getWorld() {
|
||||
|
|
|
@ -55,8 +55,8 @@ public class BukkitEventUtil extends EventUtil {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void callDelete(Plot plot) {
|
||||
callEvent(new PlotDeleteEvent(plot));
|
||||
public boolean callDelete(Plot plot) {
|
||||
return callEvent(new PlotDeleteEvent(plot));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -70,8 +70,13 @@ public class BukkitEventUtil extends EventUtil {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean callMerge(Plot plot, ArrayList<PlotId> plots) {
|
||||
return callEvent(new PlotMergeEvent(BukkitUtil.getWorld(plot.getWorldName()), plot, plots));
|
||||
public boolean callMerge(Plot plot, int dir, int max) {
|
||||
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
|
||||
|
|
|
@ -788,9 +788,18 @@ public class Plot {
|
|||
}
|
||||
|
||||
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;
|
||||
}
|
||||
if (isDelete) {
|
||||
if(!EventUtil.manager.callDelete(this)) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if(!EventUtil.manager.callClear(this)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
final HashSet<RegionWrapper> regions = this.getRegions();
|
||||
final Set<Plot> plots = this.getConnectedPlots();
|
||||
final ArrayDeque<Plot> queue = new ArrayDeque<>(plots);
|
||||
|
@ -2157,6 +2166,9 @@ public class Plot {
|
|||
if (this.owner == null) {
|
||||
return false;
|
||||
}
|
||||
if(!EventUtil.manager.callMerge(this, dir, max)) {
|
||||
return false;
|
||||
}
|
||||
HashSet<Plot> visited = new HashSet<>();
|
||||
HashSet<PlotId> merged = new HashSet<>();
|
||||
Set<Plot> connected = this.getConnectedPlots();
|
||||
|
|
|
@ -817,7 +817,7 @@ public abstract class PlotArea {
|
|||
PlotId pos2 = plotIds.get(plotIds.size() - 1);
|
||||
PlotManager manager = getPlotManager();
|
||||
|
||||
boolean result = EventUtil.manager.callMerge(getPlotAbs(pos1), plotIds);
|
||||
boolean result = EventUtil.manager.callAutoMerge(getPlotAbs(pos1), plotIds);
|
||||
if (!result) {
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -45,7 +45,7 @@ public abstract class EventUtil {
|
|||
|
||||
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);
|
||||
|
||||
|
@ -53,7 +53,9 @@ public abstract class EventUtil {
|
|||
|
||||
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);
|
||||
|
||||
|
|
|
@ -32,7 +32,9 @@ public class EventUtilTest extends EventUtil {
|
|||
return false;
|
||||
}
|
||||
|
||||
@Override public void callDelete(Plot plot) {}
|
||||
@Override public boolean callDelete(Plot plot) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override public boolean callFlagAdd(Flag flag, Plot plot) {
|
||||
return true;
|
||||
|
@ -46,7 +48,11 @@ public class EventUtilTest extends EventUtil {
|
|||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -4,13 +4,12 @@ import cn.nukkit.event.Cancellable;
|
|||
import cn.nukkit.event.HandlerList;
|
||||
import cn.nukkit.level.Level;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class PlotMergeEvent extends PlotEvent implements Cancellable {
|
||||
|
||||
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 boolean cancelled;
|
||||
|
||||
|
@ -19,31 +18,32 @@ public class PlotMergeEvent extends PlotEvent implements Cancellable {
|
|||
*
|
||||
* @param world World in which the event occurred
|
||||
* @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);
|
||||
this.world = world;
|
||||
this.plots = plots;
|
||||
this.dir = dir;
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plots being added.
|
||||
*
|
||||
* @return Plot
|
||||
*/
|
||||
public ArrayList<PlotId> getPlots() {
|
||||
return this.plots;
|
||||
}
|
||||
|
||||
public Level getLevel() {
|
||||
return this.world;
|
||||
}
|
||||
|
||||
public int getDir() {
|
||||
return this.dir;
|
||||
}
|
||||
|
||||
public int getMax() {
|
||||
return this.max;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return this.cancelled;
|
||||
|
|
|
@ -61,8 +61,8 @@ public class NukkitEventUtil extends EventUtil {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void callDelete(Plot plot) {
|
||||
callEvent(new PlotDeleteEvent(plot));
|
||||
public boolean callDelete(Plot plot) {
|
||||
return callEvent(new PlotDeleteEvent(plot));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -76,8 +76,13 @@ public class NukkitEventUtil extends EventUtil {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean callMerge(Plot plot, ArrayList<PlotId> plots) {
|
||||
return callEvent(new PlotMergeEvent(NukkitUtil.getWorld(plot.getWorldName()), plot, plots));
|
||||
public boolean callMerge(Plot plot, int dir, int max) {
|
||||
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
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -1,13 +1,15 @@
|
|||
package com.plotsquared.sponge.events;
|
||||
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import org.spongepowered.api.event.Cancellable;
|
||||
import org.spongepowered.api.event.cause.Cause;
|
||||
import org.spongepowered.api.event.impl.AbstractEvent;
|
||||
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
|
||||
public class PlotDeleteEvent extends AbstractEvent {
|
||||
public class PlotDeleteEvent extends AbstractEvent implements Cancellable {
|
||||
private final Plot plot;
|
||||
private boolean cancelled;
|
||||
|
||||
/**
|
||||
* PlotDeleteEvent: Called when a plot is deleted
|
||||
|
@ -35,7 +37,17 @@ public class PlotDeleteEvent extends AbstractEvent {
|
|||
public String getWorld() {
|
||||
return plot.getWorldName();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(final boolean cancel) {
|
||||
cancelled = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Cause getCause() {
|
||||
return null;
|
||||
|
|
|
@ -11,29 +11,32 @@ import com.intellectualcrafters.plot.object.Plot;
|
|||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
|
||||
public class PlotMergeEvent extends AbstractEvent implements Cancellable {
|
||||
private final ArrayList<PlotId> plots;
|
||||
private boolean cancelled;
|
||||
private Plot plot;
|
||||
private final int dir;
|
||||
private final int max;
|
||||
private World world;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @param dir The direction of the merge
|
||||
* @param max Max merge size
|
||||
*/
|
||||
public PlotMergeEvent(final World world, final Plot plot, final ArrayList<PlotId> plots) {
|
||||
this.plots = plots;
|
||||
public PlotMergeEvent(World world, Plot plot, final int dir, final int max) {
|
||||
this.world = world;
|
||||
this.dir = dir;
|
||||
this.max = max;
|
||||
this.plot = plot;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the plots being added;
|
||||
*
|
||||
* @return Plot
|
||||
*/
|
||||
public ArrayList<PlotId> getPlots() {
|
||||
return plots;
|
||||
|
||||
public int getDir() {
|
||||
return this.dir;
|
||||
}
|
||||
|
||||
public int getMax() {
|
||||
return this.max;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -51,8 +51,8 @@ public class SpongeEventUtil extends EventUtil {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void callDelete(Plot plot) {
|
||||
callEvent(new PlotDeleteEvent(plot));
|
||||
public boolean callDelete(Plot plot) {
|
||||
return callEvent(new PlotDeleteEvent(plot));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -66,8 +66,13 @@ public class SpongeEventUtil extends EventUtil {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean callMerge(Plot plot, ArrayList<PlotId> plots) {
|
||||
return callEvent(new PlotMergeEvent(SpongeUtil.getWorld(plot.getWorldName()), plot, plots));
|
||||
public boolean callMerge(Plot plot, int dir, int max) {
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue