diff --git a/Plugins/.idea/misc.xml b/Plugins/.idea/misc.xml index 3a9b4c67e..aeea575e6 100644 --- a/Plugins/.idea/misc.xml +++ b/Plugins/.idea/misc.xml @@ -16,7 +16,7 @@ - + \ No newline at end of file diff --git a/Plugins/.idea/modules.xml b/Plugins/.idea/modules.xml index bcc0470f4..f7936ba2e 100644 --- a/Plugins/.idea/modules.xml +++ b/Plugins/.idea/modules.xml @@ -11,7 +11,6 @@ - diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusAmount.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusAmount.java index d2cfef1f8..bb6d8c9f3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusAmount.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusAmount.java @@ -2,6 +2,8 @@ package mineplex.core.bonuses; import java.util.List; +import org.bukkit.ChatColor; + import mineplex.core.common.util.C; public class BonusAmount @@ -138,6 +140,7 @@ public class BonusAmount public void addLore(List lore) { + lore.add(C.cYellow + "Rewards"); addLore(lore, getTickets(), 0, "Carl Spin Ticket" + (getTickets() > 1 ? "s" : "")); addLore(lore, getCoins(), getBonusCoins(), "Coins"); addLore(lore, getGems(), getBonusGems(), "Gems"); @@ -148,7 +151,7 @@ public class BonusAmount private void addLore(List lore, int amount, int bonus, String suffix) { if (amount > 0) - lore.add(C.cYellow + "Reward: " + C.cWhite + amount + " " + suffix); + lore.add(" " + C.cWhite + amount + " " + suffix); // if (bonus > 0) // lore.add(C.cYellow + "Streak Bonus: " + C.cWhite + bonus + " " + suffix); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java index 9b4a4ee52..81121d59e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusManager.java @@ -43,6 +43,7 @@ import mineplex.core.bonuses.gui.SpinGui; import mineplex.core.poll.PollManager; import mineplex.serverdata.commands.ServerCommandManager; +import org.jooq.DSLContext; import org.jooq.SQLDialect; import org.jooq.impl.DSL; import org.bukkit.Bukkit; @@ -419,35 +420,23 @@ public class BonusManager extends MiniClientPlugin implements I { CarlSpinnerEvent event = new CarlSpinnerEvent(player); Bukkit.getServer().getPluginManager().callEvent(event); - final BonusManager manager = this; if (!event.isCancelled()) { final int accountId = _clientManager.Get(player).getAccountId(); - runAsync(new Runnable() + _repository.attemptAddTickets(accountId, clientData, -1, new Callback() { @Override - public void run() + public void run(Boolean data) { - try + if (data) { - final int newTickets = DSL.using(DBPool.ACCOUNT, SQLDialect.MYSQL).update(Tables.bonus).set(Tables.bonus.tickets, Tables.bonus.tickets.sub(1)). - where(Tables.bonus.accountId.eq(accountId)).returning(Tables.bonus.tickets).fetchOne().getTickets(); - - runSync(new Runnable() - { - @Override - public void run() - { - clientData.setTickets(newTickets); - new SpinGui(getPlugin(), player, _rewardManager, manager).openInventory(); - } - }); + new SpinGui(_plugin, player, _rewardManager, BonusManager.this).openInventory(); } - catch (Exception e) + else { - UtilPlayer.message(player, F.main("Carl", "There was an error processing your request")); + UtilPlayer.message(player, F.main("Carl", "There waa an error processing your request. Try again later")); } } }); @@ -816,6 +805,7 @@ public class BonusManager extends MiniClientPlugin implements I if (canVote(player)) availableRewards++; if (canRank(player)) availableRewards++; if (canDaily(player)) availableRewards++; + if (getPollManager().getNextPoll(_pollManager.Get(player), _clientManager.Get(player).GetRank()) != null) availableRewards++; Hologram hologram; @@ -898,14 +888,15 @@ public class BonusManager extends MiniClientPlugin implements I if (clientData.getHologram() != null) clientData.getHologram().stop(); - runAsync(new Runnable() - { - @Override - public void run() - { - clientData.getRecord().store(); - } - }); + // This shouldnt be necessary anymore +// runAsync(new Runnable() +// { +// @Override +// public void run() +// { +// clientData.getRecord().store(); +// } +// }); super.UnloadPlayer(event); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusRepository.java index d97a76cc5..2606705df 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/BonusRepository.java @@ -7,7 +7,11 @@ import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Timestamp; +import com.sun.org.apache.xpath.internal.operations.Bool; +import mineplex.core.bonuses.gui.SpinGui; import mineplex.core.common.util.Callback; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; import mineplex.core.database.DBPool; import mineplex.core.database.RepositoryBase; import mineplex.core.database.ResultSetCallable; @@ -17,7 +21,9 @@ import mineplex.database.Tables; import mineplex.database.tables.records.BonusRecord; import org.jooq.DSLContext; import org.jooq.Record2; +import org.jooq.SQLDialect; import org.jooq.TableField; +import org.jooq.impl.DSL; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -95,6 +101,42 @@ public class BonusRepository extends RepositoryBase }); } + public void attemptAddTickets(final int accountId, final BonusClientData client, final int tickets, final Callback callback) + { + if (client.getTickets() + tickets < 0) + callback.run(false); + + Bukkit.getScheduler().runTaskAsynchronously(_manager.getPlugin(), new Runnable() + { + @Override + public void run() + { + try + { + DSLContext create = DSL.using(DBPool.ACCOUNT, SQLDialect.MYSQL); + create.update(Tables.bonus).set(Tables.bonus.tickets, Tables.bonus.tickets.add(tickets)). + where(Tables.bonus.accountId.eq(accountId)).execute(); + final int newTickets = create.select(Tables.bonus.tickets).from(Tables.bonus).where(Tables.bonus.accountId.eq(accountId)).fetchOne().value1(); + + Bukkit.getScheduler().runTask(_manager.getPlugin(), new Runnable() + { + @Override + public void run() + { + client.setTickets(newTickets); + callback.run(true); + } + }); + } + catch (Exception e) + { + e.printStackTrace(); + callback.run(false); + } + } + }); + } + public void attemptDailyBonus(final Player player, final Callback result) { final int accountId = _manager.getClientManager().Get(player).getAccountId(); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/commands/TicketCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/commands/TicketCommand.java index 20aa7ad66..62cefef27 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/commands/TicketCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/commands/TicketCommand.java @@ -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,15 +37,28 @@ public class TicketCommand extends CommandBase { try { - int tickets = Integer.parseInt(ticketString); - Plugin.Get(target).setTickets(Plugin.Get(targetName).getTickets() + tickets); - - UtilPlayer.message(caller, F.main("Carl", "You gave " + F.elem(tickets + " Carl Tickets") + " to " + F.name(targetName) + ".")); - - if (target != null) + final int tickets = Integer.parseInt(ticketString); + int accountId = Plugin.getClientManager().getAccountId(target); + Plugin.getRepository().attemptAddTickets(accountId, Plugin.Get(target), tickets, new Callback() { - UtilPlayer.message(target, F.main("Carl", F.name(caller.getName()) + " gave you " + F.elem(tickets + " Carl Tickets") + ".")); - } + @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 && !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) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/DailyBonusButton.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/DailyBonusButton.java index 8efb10fa5..2c09f41c4 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/DailyBonusButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/DailyBonusButton.java @@ -144,9 +144,7 @@ public class DailyBonusButton implements GuiItem, Listener lore.add(" "); lore.add(C.cYellow + "Current Streak: " + C.cWhite + client.getDailyStreak()); - lore.add(C.cYellow + "Streak Bonus: " + C.cWhite + _bonusManager.getDailyMultiplier(_player) + "%"); - lore.add(" "); - lore.add(C.cYellow + "Highest Streak: " + C.cWhite + client.getMaxDailyStreak()); + lore.add(C.cYellow + "Streak Bonus: " + C.cWhite + "+" + _bonusManager.getDailyMultiplier(_player) + "%"); if (client.getDailyTime() != null) { @@ -159,6 +157,8 @@ public class DailyBonusButton implements GuiItem, Listener } } + lore.add(" "); + lore.add(C.cYellow + "Highest Streak: " + C.cWhite + client.getMaxDailyStreak()); StreakRecord streakRecord = _bonusManager.getDailyStreak(); if (streakRecord != null) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/VoteButton.java b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/VoteButton.java index b05c3dad0..50ed5afee 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/VoteButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/bonuses/gui/buttons/VoteButton.java @@ -131,10 +131,7 @@ public class VoteButton implements GuiItem, Listener { lore.add(" "); lore.add(C.cYellow + "Current Streak: " + C.cWhite + client.getVoteStreak()); - lore.add(C.cYellow + "Streak Bonus: " + C.cWhite + _bonusManager.getVoteMultiplyer(_player) + "%"); - lore.add(" "); - lore.add(C.cYellow + "Highest Streak: " + C.cWhite + client.getMaxVoteStreak()); - + lore.add(C.cYellow + "Streak Bonus: " + C.cWhite + "+" + _bonusManager.getVoteMultiplyer(_player) + "%"); if (client.getVoteTime() != null) { long lastBonus = _bonusManager.getLocalTime(client.getVoteTime().getTime()); @@ -146,6 +143,9 @@ public class VoteButton implements GuiItem, Listener { } } + lore.add(" "); + lore.add(C.cYellow + "Highest Streak: " + C.cWhite + client.getMaxVoteStreak()); + StreakRecord streakRecord = _bonusManager.getVoteStreak(); if (streakRecord != null) { @@ -185,4 +185,4 @@ public class VoteButton implements GuiItem, Listener { { return _gui; } -} +} \ No newline at end of file