mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-06-25 02:04:44 +02:00
Allow PlotRateEvent to be cancelled. Fixes #2017
This commit is contained in:
@ -1,15 +1,17 @@
|
||||
package com.plotsquared.nukkit.events;
|
||||
|
||||
import cn.nukkit.event.Cancellable;
|
||||
import cn.nukkit.event.HandlerList;
|
||||
import com.intellectualcrafters.plot.object.Plot;
|
||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||
import com.intellectualcrafters.plot.object.Rating;
|
||||
|
||||
public class PlotRateEvent extends PlotEvent {
|
||||
public class PlotRateEvent extends PlotEvent implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private final PlotPlayer rater;
|
||||
private Rating rating;
|
||||
private boolean cancelled = false;
|
||||
|
||||
public PlotRateEvent(PlotPlayer rater, Rating rating, Plot plot) {
|
||||
super(plot);
|
||||
@ -33,4 +35,11 @@ public class PlotRateEvent extends PlotEvent {
|
||||
this.rating = rating;
|
||||
}
|
||||
|
||||
@Override public void setCancelled(boolean cancelled) {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
@Override public boolean isCancelled() {
|
||||
return this.cancelled;
|
||||
}
|
||||
}
|
||||
|
@ -30,6 +30,8 @@ import com.plotsquared.nukkit.events.PlotMergeEvent;
|
||||
import com.plotsquared.nukkit.events.PlotRateEvent;
|
||||
import com.plotsquared.nukkit.events.PlotUnlinkEvent;
|
||||
import com.plotsquared.nukkit.object.NukkitPlayer;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.UUID;
|
||||
|
||||
@ -129,9 +131,13 @@ public class NukkitEventUtil extends EventUtil {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public Rating callRating(PlotPlayer player, Plot plot, Rating rating) {
|
||||
PlotRateEvent event = new PlotRateEvent(player, rating, plot);
|
||||
plugin.getServer().getPluginManager().callEvent(event);
|
||||
if (event.isCancelled()) {
|
||||
return null;
|
||||
}
|
||||
return event.getRating();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user