Add event to be called when a player tries to buy a carl spin
This commit is contained in:
parent
4f6dfdb856
commit
e6519206af
@ -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<BonusClientData> 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"));
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user