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:
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user