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:10:25 +00:00
parent e47b4fef20
commit 3bbd97e7e1
8 changed files with 109 additions and 29 deletions

View File

@ -0,0 +1,56 @@
package com.github.intellectualsites.plotsquared.bukkit.events;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotId;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.World;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import javax.annotation.Nonnull;
import java.util.Collections;
import java.util.List;
/**
* Event called when plots are automatically merged with /plot auto
* {@inheritDoc}
*/
public final class PlotAutoMergeEvent extends PlotEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private final List<PlotId> plots;
@Getter private final World world;
@Getter @Setter private boolean cancelled;
/**
* PlotAutoMergeEvent: Called when plots are automatically merged with /plot auto
*
* @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(@Nonnull final World world, @Nonnull final Plot plot,
@Nonnull final List<PlotId> plots) {
super(plot);
this.world = world;
this.plots = plots;
}
public static HandlerList getHandlerList() {
return handlers;
}
/**
* Get the plots being added.
*
* @return Unmodifiable list containing the merging plots
*/
public List<PlotId> getPlots() {
return Collections.unmodifiableList(this.plots);
}
@Override public HandlerList getHandlers() {
return handlers;
}
}

View File

@ -2,14 +2,16 @@ package com.github.intellectualsites.plotsquared.bukkit.events;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.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);
@ -20,7 +22,7 @@ public class PlotDeleteEvent extends PlotEvent {
}
/**
* Get the PlotId
* Get the PlotId.
*
* @return PlotId
*/
@ -29,7 +31,7 @@ public class PlotDeleteEvent extends PlotEvent {
}
/**
* Get the world name
* Get the world name.
*
* @return String
*/
@ -40,4 +42,12 @@ public class PlotDeleteEvent extends PlotEvent {
@Override public HandlerList getHandlers() {
return handlers;
}
@Override public boolean isCancelled() {
return this.cancelled;
}
@Override public void setCancelled(boolean b) {
this.cancelled = b;
}
}

View File

@ -1,7 +1,6 @@
package com.github.intellectualsites.plotsquared.bukkit.events;
import com.github.intellectualsites.plotsquared.plot.object.Plot;
import com.github.intellectualsites.plotsquared.plot.object.PlotId;
import lombok.Getter;
import lombok.Setter;
import org.bukkit.World;
@ -9,8 +8,6 @@ import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
import javax.annotation.Nonnull;
import java.util.Collections;
import java.util.List;
/**
* Event called when several plots are merged
@ -19,7 +16,8 @@ import java.util.List;
public final class PlotMergeEvent extends PlotEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private final List<PlotId> plots;
@Getter private final int dir;
@Getter private final int max;
@Getter private final World world;
@Getter @Setter private boolean cancelled;
@ -28,28 +26,21 @@ public final 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(@Nonnull final World world, @Nonnull final Plot plot,
@Nonnull final List<PlotId> plots) {
@Nonnull final int dir, @Nonnull 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 Unmodifiable list containing the merging plots
*/
public List<PlotId> getPlots() {
return Collections.unmodifiableList(this.plots);
}
@Override public HandlerList getHandlers() {
return handlers;
}

View File

@ -48,8 +48,8 @@ public final class BukkitEventUtil extends EventUtil {
return callEvent(new PlotClearEvent(plot));
}
@Override public void callDelete(Plot plot) {
callEvent(new PlotDeleteEvent(plot));
@Override public boolean callDelete(Plot plot) {
return callEvent(new PlotDeleteEvent(plot));
}
@Override public boolean callFlagAdd(Flag flag, Plot plot) {
@ -60,8 +60,12 @@ public final class BukkitEventUtil extends EventUtil {
return callEvent(new PlotFlagRemoveEvent(flag, plot));
}
@Override public boolean callMerge(Plot plot, List<PlotId> plots) {
return callEvent(new PlotMergeEvent(BukkitUtil.getWorld(plot.getWorldName()), plot, plots));
@Override 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, List<PlotId> plots) {
return callEvent(new PlotAutoMergeEvent(BukkitUtil.getWorld(plot.getWorldName()), plot, plots));
}
@Override public boolean callUnlink(PlotArea area, List<PlotId> plots) {