Allow PlotRateEvent to be cancelled. Fixes #2017

This commit is contained in:
sauilitired
2018-08-19 23:12:59 +02:00
parent 4b8c434669
commit 01a927ccad
8 changed files with 75 additions and 13 deletions

View File

@ -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;
}
}

View File

@ -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();
}