Reworked Monthly bonuses so they always succeed and it logs them.

This commit is contained in:
Jonathan Williams 2016-04-03 01:36:30 -05:00
parent e4b2492b35
commit 401127caa9
2 changed files with 35 additions and 19 deletions

View File

@ -33,6 +33,7 @@ import mineplex.core.donation.GiveDonorData;
import mineplex.core.facebook.FacebookManager;
import mineplex.core.hologram.Hologram;
import mineplex.core.hologram.HologramManager;
import mineplex.core.inventory.ClientItem;
import mineplex.core.inventory.InventoryManager;
import mineplex.core.npc.Npc;
import mineplex.core.npc.NpcManager;
@ -474,6 +475,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
{
if (timeTillRankBonus(player) > 0)
result.run(false);
getRepository().attemptRankBonus(player, new Callback<Boolean>()
{
@Override
@ -734,31 +736,35 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
if (oldChests > 0)
{
_inventoryManager.addItemToInventory(player, TreasureType.OLD.getItemName(), oldChests);
//_inventoryManager.addItemToInventory(player, TreasureType.OLD.getItemName(), oldChests);
UtilPlayer.message(player, F.main("Carl", "Rewarded " + F.elem(oldChests + " Old Chests")));
_inventoryManager.Get(player).addItem(new ClientItem(_inventoryManager.getItem(TreasureType.OLD.getItemName()), mythicalChests));
}
if (ancientChests > 0)
{
UtilPlayer.message(player, F.main("Carl", "Rewarded " + F.elem(ancientChests + " Ancient Chests")));
_inventoryManager.addItemToInventory(player, TreasureType.ANCIENT.getItemName(), ancientChests);
//_inventoryManager.addItemToInventory(player, TreasureType.ANCIENT.getItemName(), ancientChests);
_inventoryManager.Get(player).addItem(new ClientItem(_inventoryManager.getItem(TreasureType.ANCIENT.getItemName()), mythicalChests));
}
if (mythicalChests > 0)
{
UtilPlayer.message(player, F.main("Carl", "Rewarded " + F.elem(mythicalChests + " Mythical Chests")));
_inventoryManager.addItemToInventory(player, TreasureType.MYTHICAL.getItemName(), mythicalChests);
//_inventoryManager.addItemToInventory(player, TreasureType.MYTHICAL.getItemName(), mythicalChests);
_inventoryManager.Get(player).addItem(new ClientItem(_inventoryManager.getItem(TreasureType.MYTHICAL.getItemName()), mythicalChests));
}
if (gems > 0)
{
UtilPlayer.message(player, F.main("Carl", "Rewarded " + F.elem(gems + " Gems")));
_gemQueue.add(new GiveDonorData(null, player.getName(), "Treasure", player.getUniqueId(), coreClient.getAccountId(), gems));
//_gemQueue.add(new GiveDonorData(null, player.getName(), "Treasure", player.getUniqueId(), coreClient.getAccountId(), gems));
}
if (gold > 0)
{
UtilPlayer.message(player, F.main("Carl", "Rewarded " + F.elem(gold + " Gold")));
/*
_donationManager.rewardGold(new Callback<Boolean>()
{
@Override
@ -773,12 +779,13 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
}
}
}, "Earned", player.getName(), coreClient.getAccountId(), gold, true);
*/
}
if (coins > 0)
{
UtilPlayer.message(player, F.main("Carl", "Rewarded " + F.elem(coins + " Treasure Shards")));
_coinQueue.add(new GiveDonorData(null, player.getName(), "Treasure", player.getUniqueId(), coreClient.getAccountId(), coins));
//_coinQueue.add(new GiveDonorData(null, player.getName(), "Treasure", player.getUniqueId(), coreClient.getAccountId(), coins));
}
if (tickets > 0)

View File

@ -259,42 +259,48 @@ public class BonusRepository extends MinecraftRepository
public void attemptRankBonus(final Player player, final Callback<Boolean> result)
{
if (!Recharge.Instance.usable(player, "AttemptRankBonus")) {
if (!Recharge.Instance.usable(player, "AttemptRankBonus"))
{
result.run(false);
return;
}
final int accountId = _manager.getClientManager().Get(player).getAccountId();
final int coins = _manager.getRankBonusAmount(player).getCoins();
final int gems = _manager.getRankBonusAmount(player).getGems();
final int mythicalChestChange = _manager.getRankBonusAmount(player).getMythicalChests();
if (!_manager.getRankBonusAmount(player).isGreaterThanZero()) {
if (!_manager.getRankBonusAmount(player).isGreaterThanZero())
{
result.run(false);
return;
}
final JavaPlugin plug = _manager.getPlugin();
Bukkit.getScheduler().runTaskAsynchronously(plug, new Runnable() {
Bukkit.getScheduler().runTaskAsynchronously(plug, new Runnable()
{
@Override
public void run()
{
try (Connection connection = getConnection();
CallableStatement callableStatement = connection.prepareCall("{call check_rank(?, ?, ?, ?, ?)}")) {
CallableStatement callableStatement = connection.prepareCall("{call rankBonus(?, ?, ?, ?, ?, ?)}"))
{
callableStatement.setInt(1, accountId);
callableStatement.setInt(2, coins);
callableStatement.setInt(3, 0);
callableStatement.registerOutParameter(4, java.sql.Types.BOOLEAN);
callableStatement.registerOutParameter(5, java.sql.Types.DATE);
callableStatement.setInt(3, gems);
callableStatement.setInt(4, mythicalChestChange);
callableStatement.registerOutParameter(5, java.sql.Types.BOOLEAN);
callableStatement.registerOutParameter(6, java.sql.Types.DATE);
callableStatement.executeUpdate();
final boolean pass = callableStatement.getBoolean(4);
final boolean pass = callableStatement.getBoolean(5);
final Date date = callableStatement.getDate(5);
Bukkit.getScheduler().runTask(plug, new Runnable() {
final Date date = callableStatement.getDate(6);
Bukkit.getScheduler().runTask(plug, new Runnable()
{
@Override
public void run()
{
@ -311,9 +317,12 @@ public class BonusRepository extends MinecraftRepository
}
}
});
} catch (Exception e) {
}
catch (Exception e)
{
Recharge.Instance.use(player, "AttemptRankBonus", 1000 * 30, false, false);
e.printStackTrace();
System.out.println("Error : " + e.getMessage());
result.run(false);
}
}