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

@ -3,13 +3,15 @@ package com.plotsquared.bukkit.events;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.Rating;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
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);
@ -38,4 +40,13 @@ public class PlotRateEvent extends PlotEvent {
return handlers;
}
@Override
public boolean isCancelled() {
return this.cancelled;
}
@Override
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
}

View File

@ -31,6 +31,7 @@ import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.UUID;
@ -124,10 +125,13 @@ public class BukkitEventUtil extends EventUtil {
}
@Override
@Nullable
public Rating callRating(PlotPlayer player, Plot plot, Rating rating) {
PlotRateEvent event = new PlotRateEvent(player, rating, plot);
Bukkit.getServer().getPluginManager().callEvent(event);
if (event.isCancelled()) {
return null;
}
return event.getRating();
}
}