This commit is contained in:
Shaun Bennett 2015-08-12 00:56:20 -05:00
parent 8e4ae35256
commit 99a94251fd
7 changed files with 59 additions and 34 deletions

View File

@ -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<String> 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<String> 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);

View File

@ -375,7 +375,8 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
// DAILY BONUS
public static final long TIME_BETWEEN_BONUSES = 1000 * 60 * 60 * 20;
public static final long STREAK_RESET_TIME = 1000 * 60 * 60 * 12;
public static final long DAILY_STREAK_RESET_TIME = 1000 * 60 * 60 * 12;
public static final long VOTE_STREAK_RESET_TIME = 1000 * 60 * 60 * 24;
public void attemptDailyBonus(final Player player, final BonusAmount amount, final Callback<Boolean> result)
{
@ -496,7 +497,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
if (client.getDailyStreak() > 0 && client.getDailyTime() != null)
{
long lastBonus = getLocalTime(client.getDailyTime().getTime());
long timeLeft = getStreakTimeRemaining(lastBonus, BonusManager.STREAK_RESET_TIME);
long timeLeft = getStreakTimeRemaining(lastBonus, BonusManager.DAILY_STREAK_RESET_TIME);
if (timeLeft < 0)
{
@ -505,6 +506,25 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
}
}
public void updateVoteStreak(Player player)
{
updateVoteStreak(Get(player));
}
public void updateVoteStreak(BonusClientData client)
{
if (client.getVoteStreak() > 0 && client.getVoteTime() != null)
{
long lastBonus = getLocalTime(client.getDailyTime().getTime());
long timeLeft = getStreakTimeRemaining(lastBonus, BonusManager.VOTE_STREAK_RESET_TIME);
if (timeLeft < 0)
{
client.setVoteStreak(0);
}
}
}
public void incrementDailyStreak(Player player)
{
BonusClientData data = Get(player);
@ -666,6 +686,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
if (gems > 0)
{
UtilPlayer.message(player, F.main("Carl", "Rewarded " + F.elem(gems + " Gems")));
_donationManager.RewardGems(new Callback<Boolean>()
{
@Override
@ -673,18 +694,18 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
{
if (data)
{
UtilPlayer.message(player, F.main("Carl", "Rewarded " + F.elem(gems + " Gems")));
}
else
{
UtilPlayer.message(player, F.main("Carl", "Failed to process Gems"));
}
}
}, "BonusManager", player.getName(), player.getUniqueId(), gems, true);
}, "Earned", player.getName(), player.getUniqueId(), gems, true);
}
if (gold > 0)
{
UtilPlayer.message(player, F.main("Carl", "Rewarded " + F.elem(gold + " Gold")));
_donationManager.RewardGold(new Callback<Boolean>()
{
@Override
@ -692,18 +713,18 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
{
if (data)
{
UtilPlayer.message(player, F.main("Carl", "Rewarded " + F.elem(gold + " Gold")));
}
else
{
UtilPlayer.message(player, F.main("Carl", "Failed to process Gold"));
}
}
}, "BonusManager", player.getName(), coreClient.getAccountId(), gold, true);
}, "Earned", player.getName(), coreClient.getAccountId(), gold, true);
}
if (coins > 0)
{
UtilPlayer.message(player, F.main("Carl", "Rewarded " + F.elem(coins + " Coins")));
_donationManager.RewardCoins(new Callback<Boolean>()
{
@Override
@ -711,18 +732,18 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
{
if (data)
{
UtilPlayer.message(player, F.main("Carl", "Rewarded " + F.elem(coins + " Coins")));
}
else
{
UtilPlayer.message(player, F.main("Carl", "Failed to process Coins"));
}
}
}, "BonusManager", player.getName(), coreClient.getAccountId(), coins, true);
}, "Earned", player.getName(), coreClient.getAccountId(), coins, true);
}
if (tickets > 0)
{
UtilPlayer.message(player, F.main("Carl", "Rewarded " + F.elem(tickets + " Carl Spin Ticket")));
final int accountId = _clientManager.Get(player).getAccountId();
runAsync(new Runnable()
{
@ -739,7 +760,6 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
public void run()
{
bonusClient.setTickets(newTickets);
UtilPlayer.message(player, F.main("Carl", "Rewarded " + F.elem(tickets + " Carl Spin Ticket")));
}
});
}
@ -757,7 +777,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
_statsManager.incrementStat(player, "Global.ExpEarned", experience);
UtilPlayer.message(player, F.main("Carl", "Rewarded " + F.elem(experience + " Experience")));
}
UtilPlayer.message(player, F.main("Carl", "Come back tomorrow for more!"));
}
@ -897,15 +917,16 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
@EventHandler
public void updateCreeper(UpdateEvent event)
{
if (event.getType() != UpdateType.SEC || !_enabled)
if (event.getType() != UpdateType.FASTER || !_enabled)
return;
for (Player player : UtilServer.getPlayers())
{
String prefix = _visualTick % 2 == 0 ? C.cAqua : C.cDAqua;
updateCreeperVisual(player, false, prefix);
_visualTick++;
}
_visualTick++;
}
@Override

View File

@ -152,7 +152,7 @@ public class DailyBonusButton implements GuiItem, Listener
if (client.getDailyTime() != null)
{
long lastBonus = _bonusManager.getLocalTime(client.getDailyTime().getTime());
long timeLeft = _bonusManager.getStreakTimeRemaining(lastBonus, BonusManager.STREAK_RESET_TIME);
long timeLeft = _bonusManager.getStreakTimeRemaining(lastBonus, BonusManager.DAILY_STREAK_RESET_TIME);
if (timeLeft > 0)
{

View File

@ -135,7 +135,7 @@ public class VoteButton implements GuiItem, Listener {
if (client.getVoteTime() != null)
{
long lastBonus = _bonusManager.getLocalTime(client.getVoteTime().getTime());
long timeLeft = _bonusManager.getStreakTimeRemaining(lastBonus, BonusManager.STREAK_RESET_TIME);
long timeLeft = _bonusManager.getStreakTimeRemaining(lastBonus, BonusManager.VOTE_STREAK_RESET_TIME);
if (timeLeft > 0)
{

View File

@ -25,7 +25,7 @@ public class VoteHandler implements CommandCallback
if (player != null)
{
_bonusManager.handleVote(player, v.getGemsRecieved());
_bonusManager.handleVote(player, v.getGemsReceived());
}
}
}

View File

@ -1,20 +1,18 @@
package mineplex.core.bonuses.redis;
import java.util.UUID;
import mineplex.serverdata.commands.ServerCommand;
public class VotifierCommand extends ServerCommand
{
private String _playerName;
private int _gemsRecieved;
private int _gemsReceived;
public VotifierCommand(String playerName, int gemsRecieved, String... targetServer)
public VotifierCommand(String playerName, int gemsReceived, String... targetServer)
{
super(targetServer);
_playerName = playerName;
_gemsRecieved = gemsRecieved;
_gemsReceived = gemsReceived;
}
public String getPlayerName()
@ -22,9 +20,9 @@ public class VotifierCommand extends ServerCommand
return _playerName;
}
public int getGemsRecieved()
public int getGemsReceived()
{
return _gemsRecieved;
return _gemsReceived;
}
}

View File

@ -92,12 +92,12 @@ public class VotifierManager extends MiniPlugin
System.out.println("Loaded " + playerName + " with uuid " + uuid);
System.out.println("Attempting to award bonus");
awardBonus(playerName, uuid, new Runnable()
awardBonus(playerName, uuid, new Callback<Integer>()
{
@Override
public void run()
public void run(Integer gems)
{
notifyServer(playerName, false);
notifyServer(playerName, gems, false);
}
});
System.out.println();
@ -138,15 +138,15 @@ public class VotifierManager extends MiniPlugin
// notifyServer(playerName, true);
}
private void notifyServer(String playerName, boolean eu)
private void notifyServer(String playerName, int gems, boolean eu)
{
JedisPool writePool = eu ? _euWritePool : _usWritePool;
VotifierCommand command = new VotifierCommand(playerName);
VotifierCommand command = new VotifierCommand(playerName, gems);
publishCommand(command, writePool);
}
private void awardBonus(final String playerName, UUID uuid, final Runnable onComplete)
private void awardBonus(final String playerName, UUID uuid, final Callback<Integer> onComplete)
{
DSLContext create = DSL.using(DBPool.ACCOUNT, SQLDialect.MYSQL);
@ -162,7 +162,7 @@ public class VotifierManager extends MiniPlugin
if (amount.getTickets() > 0)
client.setTickets(client.getTickets() + amount.getTickets());
if (amount.getGems() > 0)
if (amount.getTotalGems() > 0)
{
_donationManager.RewardGems(new Callback<Boolean>()
{
@ -174,10 +174,10 @@ public class VotifierManager extends MiniPlugin
else
System.out.println("Failed to give " + amount.getGems() + " gems to " + playerName);
}
}, "Votifier", playerName, uuid, amount.getGems());
}, "Votifier", playerName, uuid, amount.getTotalGems());
}
if (amount.getCoins() > 0)
if (amount.getTotalCoins() > 0)
{
_donationManager.RewardCoins(new Callback<Boolean>()
{
@ -189,9 +189,12 @@ public class VotifierManager extends MiniPlugin
else
System.out.println("Failed to give " + amount.getGems() + " coins to " + playerName);
}
}, "Votifier", playerName, accountId, amount.getCoins());
}, "Votifier", playerName, accountId, amount.getTotalCoins());
}
// Check if we need to reset vote streak
_bonusManager.updateVoteStreak(client);
// Update time
_bonusManager.getRepository().attemptVoteBonus(accountId, new Callback<Date>()
{
@ -207,7 +210,7 @@ public class VotifierManager extends MiniPlugin
client.getRecord().store();
System.out.println("Awarded carl ticket to " + playerName);
onComplete.run();
onComplete.run(amount.getTotalGems());
}
}
});