This commit is contained in:
boy0001 2015-08-08 17:36:02 +10:00
parent 64063463ec
commit a2b29da39d
4 changed files with 28 additions and 9 deletions

View File

@ -39,6 +39,7 @@ import com.intellectualcrafters.plot.object.PlotInventory;
import com.intellectualcrafters.plot.object.PlotItemStack; import com.intellectualcrafters.plot.object.PlotItemStack;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.Rating; import com.intellectualcrafters.plot.object.Rating;
import com.intellectualcrafters.plot.util.EventUtil;
import com.intellectualcrafters.plot.util.MainUtil; import com.intellectualcrafters.plot.util.MainUtil;
import com.intellectualcrafters.plot.util.MathMan; import com.intellectualcrafters.plot.util.MathMan;
import com.intellectualcrafters.plot.util.TaskManager; import com.intellectualcrafters.plot.util.TaskManager;
@ -121,14 +122,9 @@ public class Rate extends SubCommand {
index.increment(); index.increment();
if (index.intValue() >= Settings.RATING_CATEGORIES.size()) { if (index.intValue() >= Settings.RATING_CATEGORIES.size()) {
close(); close();
// handle ratings
int rV = rating.intValue(); int rV = rating.intValue();
// CALL THE EVENT Rating result = EventUtil.manager.callRating(player, plot, new Rating(rV));
PlotRateEvent rateEvent = new PlotRateEvent(player, new Rating(rV), plot); plot.getSettings().ratings.put(player.getUUID(), result.getAggregate());
Bukkit.getPluginManager().callEvent(rateEvent);
// DONE CALLING THE EVENT
// set rating
plot.getSettings().ratings.put(player.getUUID(), rateEvent.getRating().getAggregate());
DBFunc.setRating(plot, player.getUUID(), rV); DBFunc.setRating(plot, player.getUUID(), rV);
sendMessage(player, C.RATING_APPLIED, plot.getId().toString()); sendMessage(player, C.RATING_APPLIED, plot.getId().toString());
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()); sendMessage(player, C.RATING_ALREADY_EXISTS, plot.getId().toString());
return; return;
} }
plot.getSettings().ratings.put(uuid, rating); Rating result = EventUtil.manager.callRating(player, plot, new Rating(rating));
DBFunc.setRating(plot, uuid, rating); int resultVal = result.getAggregate();
plot.getSettings().ratings.put(uuid, resultVal);
DBFunc.setRating(plot, uuid, resultVal);
sendMessage(player, C.RATING_APPLIED, plot.getId().toString()); sendMessage(player, C.RATING_APPLIED, plot.getId().toString());
} }
}; };

View File

@ -14,6 +14,7 @@ import com.intellectualcrafters.plot.object.PlotBlock;
import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.Rating;
import com.plotsquared.bukkit.listeners.PlayerBlockEventType; import com.plotsquared.bukkit.listeners.PlayerBlockEventType;
public abstract class EventUtil { public abstract class EventUtil {
@ -29,6 +30,8 @@ public abstract class EventUtil {
PS.get().IMP.unregister(player); 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 callClaim(final PlotPlayer player, final Plot plot, final boolean auto);
public abstract boolean callTeleport(final PlotPlayer player, Location from, final Plot plot); public abstract boolean callTeleport(final PlotPlayer player, Location from, final Plot plot);

View File

@ -14,6 +14,7 @@ import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.Rating;
import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.EventUtil;
import com.plotsquared.bukkit.events.ClusterFlagRemoveEvent; import com.plotsquared.bukkit.events.ClusterFlagRemoveEvent;
import com.plotsquared.bukkit.events.PlayerClaimPlotEvent; 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.PlotFlagAddEvent;
import com.plotsquared.bukkit.events.PlotFlagRemoveEvent; import com.plotsquared.bukkit.events.PlotFlagRemoveEvent;
import com.plotsquared.bukkit.events.PlotMergeEvent; import com.plotsquared.bukkit.events.PlotMergeEvent;
import com.plotsquared.bukkit.events.PlotRateEvent;
import com.plotsquared.bukkit.events.PlotUnlinkEvent; import com.plotsquared.bukkit.events.PlotUnlinkEvent;
import com.plotsquared.bukkit.object.BukkitPlayer; import com.plotsquared.bukkit.object.BukkitPlayer;
@ -117,5 +119,12 @@ public class BukkitEventUtil extends EventUtil {
public boolean callFlagRemove(Flag flag, PlotCluster cluster) { public boolean callFlagRemove(Flag flag, PlotCluster cluster) {
return callEvent(new ClusterFlagRemoveEvent(flag, 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();
}
} }

View File

@ -13,6 +13,7 @@ import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotCluster; import com.intellectualcrafters.plot.object.PlotCluster;
import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.object.PlotId;
import com.intellectualcrafters.plot.object.PlotPlayer; import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.Rating;
import com.intellectualcrafters.plot.util.EventUtil; import com.intellectualcrafters.plot.util.EventUtil;
import com.plotsquared.sponge.SpongeMain; import com.plotsquared.sponge.SpongeMain;
import com.plotsquared.sponge.events.ClusterFlagRemoveEvent; 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.PlotFlagAddEvent;
import com.plotsquared.sponge.events.PlotFlagRemoveEvent; import com.plotsquared.sponge.events.PlotFlagRemoveEvent;
import com.plotsquared.sponge.events.PlotMergeEvent; import com.plotsquared.sponge.events.PlotMergeEvent;
import com.plotsquared.sponge.events.PlotRateEvent;
import com.plotsquared.sponge.events.PlotUnlinkEvent; import com.plotsquared.sponge.events.PlotUnlinkEvent;
public class SpongeEventUtil extends EventUtil { public class SpongeEventUtil extends EventUtil {
@ -115,5 +117,12 @@ public class SpongeEventUtil extends EventUtil {
public boolean callFlagRemove(Flag flag, PlotCluster cluster) { public boolean callFlagRemove(Flag flag, PlotCluster cluster) {
return callEvent(new ClusterFlagRemoveEvent(flag, 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();
}
} }