From e6519206af6623cd0f16188a3b2c5cac3a39ef61 Mon Sep 17 00:00:00 2001 From: Shaun Bennett Date: Sat, 8 Aug 2015 16:29:03 -0500 Subject: [PATCH] Add event to be called when a player tries to buy a carl spin --- .../mineplex/hub/bonuses/BonusManager.java | 45 +++++++++------- .../hub/bonuses/event/CarlSpinnerEvent.java | 54 +++++++++++++++++++ 2 files changed, 80 insertions(+), 19 deletions(-) create mode 100644 Plugins/Mineplex.Hub/src/mineplex/hub/bonuses/event/CarlSpinnerEvent.java diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/bonuses/BonusManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/bonuses/BonusManager.java index b4bd57948..817db72db 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/bonuses/BonusManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/bonuses/BonusManager.java @@ -25,6 +25,7 @@ import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; import mineplex.core.votifier.VotifierCommand; import mineplex.hub.bonuses.commands.GuiCommand; +import mineplex.hub.bonuses.event.CarlSpinnerEvent; import mineplex.hub.bonuses.gui.BonusGui; import mineplex.database.tables.records.BonusRecord; import mineplex.hub.bonuses.gui.SpinGui; @@ -250,32 +251,38 @@ public class BonusManager extends MiniClientPlugin implements I if (clientData.getTickets() > 0) { - clientData.setTickets(clientData.getTickets() - 1); + CarlSpinnerEvent event = new CarlSpinnerEvent(player); + Bukkit.getServer().getPluginManager().callEvent(event); - runAsync(new Runnable() + if (!event.isCancelled()) { - @Override - public void run() - { - int modified = clientData.getRecord().store(); + clientData.setTickets(clientData.getTickets() - 1); - if (modified == 1) + runAsync(new Runnable() + { + @Override + public void run() { - runSync(new Runnable() + int modified = clientData.getRecord().store(); + + if (modified == 1) { - @Override - public void run() + runSync(new Runnable() { - new SpinGui(getPlugin(), player, _rewardManager).openInventory(); - } - }); + @Override + public void run() + { + new SpinGui(getPlugin(), player, _rewardManager).openInventory(); + } + }); + } + else + { + UtilPlayer.message(player, F.main("Carl", "There was an error processing your request")); + } } - else - { - UtilPlayer.message(player, F.main("Carl", "There was an error processing your request")); - } - } - }); + }); + } } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/bonuses/event/CarlSpinnerEvent.java b/Plugins/Mineplex.Hub/src/mineplex/hub/bonuses/event/CarlSpinnerEvent.java new file mode 100644 index 000000000..fed71229b --- /dev/null +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/bonuses/event/CarlSpinnerEvent.java @@ -0,0 +1,54 @@ +package mineplex.hub.bonuses.event; + +import org.bukkit.entity.Player; +import org.bukkit.event.Cancellable; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; + +/** + * Called when a player attempts to purchase a spin through carl + */ +public class CarlSpinnerEvent extends Event implements Cancellable +{ + private static final HandlerList handlers = new HandlerList(); + + private Player _player; + private boolean _cancelled; + + public CarlSpinnerEvent(Player player) + { + _player = player; + } + + public HandlerList getHandlers() + { + return handlers; + } + + public static HandlerList getHandlerList() + { + return handlers; + } + + public Player getPlayer() + { + return _player; + } + + public void setPlayer(Player player) + { + _player = player; + } + + @Override + public boolean isCancelled() + { + return _cancelled; + } + + @Override + public void setCancelled(boolean b) + { + _cancelled = b; + } +}