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,11 +3,14 @@ package com.plotsquared.sponge.events;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.Rating;
import org.spongepowered.api.event.Cancellable;
public class PlotRateEvent extends PlotEvent implements Cancellable {
public class PlotRateEvent extends PlotEvent {
private final PlotPlayer rater;
private Rating rating;
private boolean cancelled = false;
public PlotRateEvent(final PlotPlayer rater, final Rating rating, final Plot plot) {
super(plot);
this.rater = rater;
@ -25,4 +28,14 @@ public class PlotRateEvent extends PlotEvent {
public Rating getRating() {
return rating;
}
@Override
public boolean isCancelled() {
return this.cancelled;
}
@Override
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
}

View File

@ -29,6 +29,7 @@ import com.plotsquared.sponge.events.PlotUnlinkEvent;
import org.spongepowered.api.event.Event;
import org.spongepowered.api.event.EventManager;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.UUID;
@ -120,9 +121,13 @@ public class SpongeEventUtil extends EventUtil {
}
@Override
@Nullable
public Rating callRating(PlotPlayer player, Plot plot, Rating rating) {
PlotRateEvent event = new PlotRateEvent(player, rating, plot);
this.events.post(event);
if (event.isCancelled()) {
return null;
}
return event.getRating();
}