Fix ticket command rollback >:D

This commit is contained in:
Shaun Bennett 2015-08-13 11:03:12 -05:00
parent 5fa9135b08
commit bd7317cf7b
1 changed files with 22 additions and 8 deletions

View File

@ -2,6 +2,7 @@ package mineplex.core.bonuses.commands;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.bonuses.BonusManager;
@ -36,16 +37,29 @@ public class TicketCommand extends CommandBase<BonusManager>
{
try
{
int tickets = Integer.parseInt(ticketString);
Plugin.Get(target).setTickets(Plugin.Get(targetName).getTickets() + tickets);
final int tickets = Integer.parseInt(ticketString);
int accountId = Plugin.getClientManager().getAccountId(target);
Plugin.getRepository().attemptAddTickets(accountId, Plugin.Get(target), tickets, new Callback<Boolean>()
{
@Override
public void run(Boolean data)
{
if (data)
{
UtilPlayer.message(caller, F.main("Carl", "You gave " + F.elem(tickets + " Carl Tickets") + " to " + F.name(targetName) + "."));
if (target != null)
if (target != null && !target.equals(caller))
{
UtilPlayer.message(target, F.main("Carl", F.name(caller.getName()) + " gave you " + F.elem(tickets + " Carl Tickets") + "."));
}
}
else
{
UtilPlayer.message(caller, F.main("Carl", "Failed to give tickets. Try again later!"));
}
}
});
}
catch (Exception e)
{
UtilPlayer.message(caller, F.main("Carl", "Invalid Ticket Amount"));