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

@ -122,12 +122,15 @@ public class Rate extends SubCommand {
if (index.getValue() >= Settings.Ratings.CATEGORIES.size()) {
int rV = rating.getValue();
Rating result = EventUtil.manager.callRating(this.player, plot, new Rating(rV));
plot.addRating(this.player.getUUID(), result);
sendMessage(this.player, C.RATING_APPLIED, plot.getId().toString());
if (Permissions.hasPermission(this.player, C.PERMISSION_COMMENT)) {
Command command = MainCommand.getInstance().getCommand(Comment.class);
if (command != null) {
MainUtil.sendMessage(this.player, C.COMMENT_THIS, command.getUsage());
if (result != null) {
plot.addRating(this.player.getUUID(), result);
sendMessage(this.player, C.RATING_APPLIED, plot.getId().toString());
if (Permissions.hasPermission(this.player, C.PERMISSION_COMMENT)) {
Command command = MainCommand.getInstance().getCommand(Comment.class);
if (command != null) {
MainUtil.sendMessage(this.player, C.COMMENT_THIS,
command.getUsage());
}
}
}
return false;
@ -189,8 +192,10 @@ public class Rate extends SubCommand {
return;
}
Rating result = EventUtil.manager.callRating(player, plot, new Rating(rating));
plot.addRating(uuid, result);
sendMessage(player, C.RATING_APPLIED, plot.getId().toString());
if (result != null) {
plot.addRating(uuid, result);
sendMessage(player, C.RATING_APPLIED, plot.getId().toString());
}
}
};
if (plot.getSettings().ratings == null) {

View File

@ -18,6 +18,7 @@ import com.intellectualcrafters.plot.object.Rating;
import com.intellectualcrafters.plot.util.expiry.ExpireManager;
import com.plotsquared.listener.PlayerBlockEventType;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.UUID;
@ -26,6 +27,14 @@ public abstract class EventUtil {
public static EventUtil manager = null;
/**
* Submit a plot rate event and return the updated rating
* @param player Player that rated the plot
* @param plot Plot that was rated
* @param rating Rating given to the plot
* @return Updated rating or null if the event was cancelled
*/
@Nullable
public abstract Rating callRating(PlotPlayer player, Plot plot, Rating rating);
public abstract boolean callClaim(PlotPlayer player, Plot plot, boolean auto);