diff --git a/src/main/java/com/intellectualcrafters/plot/commands/Rate.java b/src/main/java/com/intellectualcrafters/plot/commands/Rate.java index 71e20e08a..bf147c449 100644 --- a/src/main/java/com/intellectualcrafters/plot/commands/Rate.java +++ b/src/main/java/com/intellectualcrafters/plot/commands/Rate.java @@ -39,6 +39,7 @@ import com.intellectualcrafters.plot.object.PlotInventory; import com.intellectualcrafters.plot.object.PlotItemStack; import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.Rating; +import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MathMan; import com.intellectualcrafters.plot.util.TaskManager; @@ -121,14 +122,9 @@ public class Rate extends SubCommand { index.increment(); if (index.intValue() >= Settings.RATING_CATEGORIES.size()) { close(); - // handle ratings int rV = rating.intValue(); - // CALL THE EVENT - PlotRateEvent rateEvent = new PlotRateEvent(player, new Rating(rV), plot); - Bukkit.getPluginManager().callEvent(rateEvent); - // DONE CALLING THE EVENT - // set rating - plot.getSettings().ratings.put(player.getUUID(), rateEvent.getRating().getAggregate()); + Rating result = EventUtil.manager.callRating(player, plot, new Rating(rV)); + plot.getSettings().ratings.put(player.getUUID(), result.getAggregate()); DBFunc.setRating(plot, player.getUUID(), rV); sendMessage(player, C.RATING_APPLIED, plot.getId().toString()); sendMessage(player, C.RATING_APPLIED, plot.getId().toString()); @@ -192,8 +188,10 @@ public class Rate extends SubCommand { sendMessage(player, C.RATING_ALREADY_EXISTS, plot.getId().toString()); return; } - plot.getSettings().ratings.put(uuid, rating); - DBFunc.setRating(plot, uuid, rating); + Rating result = EventUtil.manager.callRating(player, plot, new Rating(rating)); + int resultVal = result.getAggregate(); + plot.getSettings().ratings.put(uuid, resultVal); + DBFunc.setRating(plot, uuid, resultVal); sendMessage(player, C.RATING_APPLIED, plot.getId().toString()); } }; diff --git a/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java b/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java index 7b537ad4a..2a7411ec4 100644 --- a/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java +++ b/src/main/java/com/intellectualcrafters/plot/util/EventUtil.java @@ -14,6 +14,7 @@ import com.intellectualcrafters.plot.object.PlotBlock; import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.Rating; import com.plotsquared.bukkit.listeners.PlayerBlockEventType; public abstract class EventUtil { @@ -29,6 +30,8 @@ public abstract class EventUtil { PS.get().IMP.unregister(player); } + public abstract Rating callRating(final PlotPlayer player, final Plot plot, final Rating rating); + public abstract boolean callClaim(final PlotPlayer player, final Plot plot, final boolean auto); public abstract boolean callTeleport(final PlotPlayer player, Location from, final Plot plot); diff --git a/src/main/java/com/plotsquared/bukkit/util/BukkitEventUtil.java b/src/main/java/com/plotsquared/bukkit/util/BukkitEventUtil.java index e71c14598..54a05fe47 100644 --- a/src/main/java/com/plotsquared/bukkit/util/BukkitEventUtil.java +++ b/src/main/java/com/plotsquared/bukkit/util/BukkitEventUtil.java @@ -14,6 +14,7 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.Rating; import com.intellectualcrafters.plot.util.EventUtil; import com.plotsquared.bukkit.events.ClusterFlagRemoveEvent; import com.plotsquared.bukkit.events.PlayerClaimPlotEvent; @@ -28,6 +29,7 @@ import com.plotsquared.bukkit.events.PlotDeleteEvent; import com.plotsquared.bukkit.events.PlotFlagAddEvent; import com.plotsquared.bukkit.events.PlotFlagRemoveEvent; import com.plotsquared.bukkit.events.PlotMergeEvent; +import com.plotsquared.bukkit.events.PlotRateEvent; import com.plotsquared.bukkit.events.PlotUnlinkEvent; import com.plotsquared.bukkit.object.BukkitPlayer; @@ -117,5 +119,12 @@ public class BukkitEventUtil extends EventUtil { public boolean callFlagRemove(Flag flag, PlotCluster cluster) { return callEvent(new ClusterFlagRemoveEvent(flag, cluster)); } + + @Override + public Rating callRating(PlotPlayer player, Plot plot, Rating rating) { + PlotRateEvent event = new PlotRateEvent(player, rating, plot); + Bukkit.getServer().getPluginManager().callEvent(event); + return event.getRating(); + } } diff --git a/src/main/java/com/plotsquared/sponge/util/SpongeEventUtil.java b/src/main/java/com/plotsquared/sponge/util/SpongeEventUtil.java index 28492860d..4631c15fd 100644 --- a/src/main/java/com/plotsquared/sponge/util/SpongeEventUtil.java +++ b/src/main/java/com/plotsquared/sponge/util/SpongeEventUtil.java @@ -13,6 +13,7 @@ import com.intellectualcrafters.plot.object.Plot; import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotPlayer; +import com.intellectualcrafters.plot.object.Rating; import com.intellectualcrafters.plot.util.EventUtil; import com.plotsquared.sponge.SpongeMain; import com.plotsquared.sponge.events.ClusterFlagRemoveEvent; @@ -28,6 +29,7 @@ import com.plotsquared.sponge.events.PlotDeleteEvent; import com.plotsquared.sponge.events.PlotFlagAddEvent; import com.plotsquared.sponge.events.PlotFlagRemoveEvent; import com.plotsquared.sponge.events.PlotMergeEvent; +import com.plotsquared.sponge.events.PlotRateEvent; import com.plotsquared.sponge.events.PlotUnlinkEvent; public class SpongeEventUtil extends EventUtil { @@ -115,5 +117,12 @@ public class SpongeEventUtil extends EventUtil { public boolean callFlagRemove(Flag flag, PlotCluster cluster) { return callEvent(new ClusterFlagRemoveEvent(flag, cluster)); } + + @Override + public Rating callRating(PlotPlayer player, Plot plot, Rating rating) { + PlotRateEvent event = new PlotRateEvent(player, rating, plot); + events.post(event); + return event.getRating(); + } }