Lets hope everything works!

This commit is contained in:
Shaun Bennett 2015-08-12 03:00:07 -05:00
parent e8963cc2af
commit 30f20801c7
8 changed files with 227 additions and 132 deletions

View File

@ -58,6 +58,7 @@ import org.bukkit.entity.Entity;
import org.bukkit.entity.Item; import org.bukkit.entity.Item;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.entity.EntityDamageByEntityEvent;
import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerJoinEvent; import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
@ -128,6 +129,8 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
private StreakRecord _dailyStreak; private StreakRecord _dailyStreak;
private StreakRecord _voteStreak; private StreakRecord _voteStreak;
private ArrayList<String> _voteList;
/** /**
* THIS SHOULD ONLY BE USED FOR VOTIFIER! * THIS SHOULD ONLY BE USED FOR VOTIFIER!
*/ */
@ -140,6 +143,10 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
_clientManager = clientManager; _clientManager = clientManager;
_donationManager = donationManager; _donationManager = donationManager;
_voteList = new ArrayList<String>();
_voteList.add("http://vote1.mineplex.com");
_voteList.add("http://vote2.mineplex.com");
updateOffSet(); updateOffSet();
} }
@ -162,7 +169,10 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
_pollManager = pollManager; _pollManager = pollManager;
_statsManager = statsManager; _statsManager = statsManager;
// Hope to god this works! _voteList = new ArrayList<String>();
_voteList.add("http://vote1.mineplex.com");
_voteList.add("http://vote2.mineplex.com");
_canVote = true; _canVote = true;
if (npcManager != null) if (npcManager != null)
@ -515,7 +525,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
{ {
if (client.getVoteStreak() > 0 && client.getVoteTime() != null) if (client.getVoteStreak() > 0 && client.getVoteTime() != null)
{ {
long lastBonus = getLocalTime(client.getDailyTime().getTime()); long lastBonus = getLocalTime(client.getVoteTime().getTime());
long timeLeft = getStreakTimeRemaining(lastBonus, BonusManager.VOTE_STREAK_RESET_TIME); long timeLeft = getStreakTimeRemaining(lastBonus, BonusManager.VOTE_STREAK_RESET_TIME);
if (timeLeft < 0) if (timeLeft < 0)
@ -796,6 +806,23 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
} }
} }
@EventHandler
public void openGui(EntityDamageByEntityEvent event)
{
if (!_enabled)
return;
if (event.getDamager() instanceof Player)
{
Player player = (Player) event.getDamager();
if (event.getEntity().equals(_carlNpc.getEntity()))
{
updateDailyStreak(player);
new BonusGui(_plugin, player, this, _rewardManager).openInventory();
}
}
}
public static long getNextVoteTime(long time) { public static long getNextVoteTime(long time) {
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
@ -853,7 +880,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
int availableRewards = 0; int availableRewards = 0;
if (canVote(player)) availableRewards++; if (canVote(player)) availableRewards++;
if (canRank(player) && _clientManager.hasRank(player, Rank.ULTRA)) availableRewards++; if (canRank(player) && _clientManager.hasRank(player, Rank.ULTRA) && isPastAugust()) availableRewards++;
if (canDaily(player)) availableRewards++; if (canDaily(player)) availableRewards++;
if (getPollManager().getNextPoll(_pollManager.Get(player), _clientManager.Get(player).GetRank()) != null) availableRewards++; if (getPollManager().getNextPoll(_pollManager.Get(player), _clientManager.Get(player).GetRank()) != null) availableRewards++;
@ -1045,7 +1072,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
{ {
if (Recharge.Instance.use(player, "Carl Inform", 240000, false, false)) if (Recharge.Instance.use(player, "Carl Inform", 240000, false, false))
{ {
if(_pollManager.hasPoll(player) || canVote(player) || canRank(player) || canDaily(player)) if(_pollManager.hasPoll(player) || canVote(player) || (canRank(player) && _clientManager.hasRank(player, Rank.ULTRA) && isPastAugust()) || canDaily(player))
{ {
if(_showCarl.containsKey(player.getName())) if(_showCarl.containsKey(player.getName()))
UtilPlayer.message(player, C.cDGreen + C.Bold + "Carl the Creeper>" + C.cGreen + " Hey " + player.getName().replace("s", "sss") + "! I have sssome amazing rewardsss for you! Come sssee me!"); UtilPlayer.message(player, C.cDGreen + C.Bold + "Carl the Creeper>" + C.cGreen + " Hey " + player.getName().replace("s", "sss") + "! I have sssome amazing rewardsss for you! Come sssee me!");
@ -1053,4 +1080,30 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
} }
} }
} }
public String getVoteLink()
{
long sqlTime = getSqlTime();
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(sqlTime);
int date = calendar.get(Calendar.DAY_OF_YEAR);
int index = date % _voteList.size();
return _voteList.get(index);
}
/**
* Used for disabling rank rewards during first month of release
* @return
*/
public boolean isPastAugust()
{
Calendar calendar = Calendar.getInstance();
calendar.setTimeZone(TIMEZONE);
calendar.setTimeInMillis(getSqlTime());
if (calendar.get(Calendar.YEAR) == 2015 && calendar.get(Calendar.MONTH) == Calendar.AUGUST)
return false;
return true;
}
} }

View File

@ -6,9 +6,12 @@ import java.sql.Date;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.sql.Types;
import java.util.Map;
import com.sun.org.apache.xpath.internal.operations.Bool; import com.sun.org.apache.xpath.internal.operations.Bool;
import mineplex.core.bonuses.gui.SpinGui; import mineplex.core.bonuses.gui.SpinGui;
import mineplex.core.common.Pair;
import mineplex.core.common.util.Callback; import mineplex.core.common.util.Callback;
import mineplex.core.common.util.F; import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer; import mineplex.core.common.util.UtilPlayer;
@ -289,7 +292,7 @@ public class BonusRepository extends RepositoryBase
}); });
} }
public void attemptVoteBonus(final int accountId, final Callback<Date> result) public void attemptVoteBonus(final int accountId, final Callback<Pair<Boolean, Date>> result)
{ {
final int coins = 0; final int coins = 0;
final int gems = 0; final int gems = 0;
@ -307,12 +310,12 @@ public class BonusRepository extends RepositoryBase
callableStatement.setInt(1, accountId); callableStatement.setInt(1, accountId);
callableStatement.setInt(2, coins); callableStatement.setInt(2, coins);
callableStatement.setInt(3, gems); callableStatement.setInt(3, gems);
callableStatement.registerOutParameter(4, java.sql.Types.DATE); callableStatement.registerOutParameter(4, Types.BOOLEAN);
callableStatement.registerOutParameter(5, Types.DATE);
callableStatement.executeUpdate(); callableStatement.executeUpdate();
final boolean pass = callableStatement.getBoolean(4); final boolean pass = callableStatement.getBoolean(4);
final Date date = callableStatement.getDate(5); final Date date = callableStatement.getDate(5);
Bukkit.getScheduler().runTask(plug, new Runnable() { Bukkit.getScheduler().runTask(plug, new Runnable() {
@ -321,8 +324,7 @@ public class BonusRepository extends RepositoryBase
public void run() public void run()
{ {
// _manager.Get(player).setVoteTime(date); // _manager.Get(player).setVoteTime(date);
result.run(date); result.run(Pair.create(pass, date));
} }
}); });
} catch (Exception e) { } catch (Exception e) {

View File

@ -4,6 +4,7 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.bonuses.BonusAmount;
import mineplex.core.bonuses.BonusManager; import mineplex.core.bonuses.BonusManager;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilText; import mineplex.core.common.util.UtilText;
@ -94,7 +95,11 @@ public class PollButton extends SimpleGui implements GuiItem {
i++; i++;
} }
lore.add(""); lore.add("");
lore.add(C.cYellow + "Reward:" + C.cWhite + " 500 Gems"); BonusAmount amount = new BonusAmount();
amount.setCoins(_poll.getCoinReward());
amount.setGems(_poll.getCoinReward());
amount.addLore(lore);
// lore.add(C.cYellow + "Reward:" + C.cWhite + " 500 Gems");
lore.add(""); lore.add("");
lore.add(C.cGreen + "Click to go to the vote page!"); lore.add(C.cGreen + "Click to go to the vote page!");
return ItemStackFactory.Instance.CreateStack(Material.BOOK_AND_QUILL, (byte) 0, 1, C.cGreen + C.Bold + "Vote on Poll", lore); return ItemStackFactory.Instance.CreateStack(Material.BOOK_AND_QUILL, (byte) 0, 1, C.cGreen + C.Bold + "Vote on Poll", lore);
@ -130,7 +135,10 @@ public class PollButton extends SimpleGui implements GuiItem {
i++; i++;
} }
lore.add(""); lore.add("");
lore.add(C.cYellow + "Reward:" + C.cWhite + " 500 Gems"); BonusAmount amount = new BonusAmount();
amount.setCoins(_poll.getCoinReward());
amount.setGems(_poll.getCoinReward());
amount.addLore(lore);
return new SimpleGuiItem(ItemStackFactory.Instance.CreateStack(Material.BOOK_AND_QUILL, (byte) 0, 1, ChatColor.GREEN + C.cGreen + C.Bold + "Vote on Poll", return new SimpleGuiItem(ItemStackFactory.Instance.CreateStack(Material.BOOK_AND_QUILL, (byte) 0, 1, ChatColor.GREEN + C.cGreen + C.Bold + "Vote on Poll",
lore)); lore));

View File

@ -78,7 +78,7 @@ public class RankBonusButton implements GuiItem, Listener {
@Override @Override
public void click(ClickType clickType) public void click(ClickType clickType)
{ {
if (isAvailable()) { if (isAvailable() && _bonusManager.isPastAugust()) {
_item = ItemStackFactory.Instance.CreateStack(Material.LAPIS_BLOCK, (byte)0, 1, ChatColor.BLUE + "Processing..."); _item = ItemStackFactory.Instance.CreateStack(Material.LAPIS_BLOCK, (byte)0, 1, ChatColor.BLUE + "Processing...");
refreshItem(); refreshItem();
new LoadingWindow(getPlugin(), getPlayer(), 6*9); new LoadingWindow(getPlugin(), getPlayer(), 6*9);
@ -144,6 +144,8 @@ public class RankBonusButton implements GuiItem, Listener {
String itemName; String itemName;
byte data = 0; byte data = 0;
if (_bonusManager.isPastAugust())
{
if (!hasRank) if (!hasRank)
{ {
material = Material.REDSTONE_BLOCK; material = Material.REDSTONE_BLOCK;
@ -182,6 +184,16 @@ public class RankBonusButton implements GuiItem, Listener {
BonusAmount bonusAmount = _bonusManager.getRankBonusAmount(_player); BonusAmount bonusAmount = _bonusManager.getRankBonusAmount(_player);
bonusAmount.addLore(lore); bonusAmount.addLore(lore);
} }
}
else
{
itemName = C.cRed + ChatColor.BOLD + "Rank Monthly Bonus";
material = Material.REDSTONE_BLOCK;
lore.add(" ");
lore.add(ChatColor.RESET + "You can claim your Monthly Bonus");
lore.add(ChatColor.RESET + "here, starting from September!");
}
_item = new ShopItem(material, itemName, lore.toArray(new String[0]), 1, false, false); _item = new ShopItem(material, itemName, lore.toArray(new String[0]), 1, false, false);
} }

View File

@ -51,7 +51,7 @@ public class VoteButton implements GuiItem, Listener {
public void setup() public void setup()
{ {
//TODO get url from db //TODO get url from db
_url = "http://minecraftservers.org/vote/121070"; _url = _bonusManager.getVoteLink();
setItem(); setItem();
Bukkit.getPluginManager().registerEvents(this, getPlugin()); Bukkit.getPluginManager().registerEvents(this, getPlugin());

View File

@ -149,6 +149,7 @@ public class PollManager extends MiniDbClientPlugin<PlayerPollData>
{ {
final String name = player.getName(); final String name = player.getName();
final UUID uuid = player.getUniqueId(); final UUID uuid = player.getUniqueId();
final int accountId = getClientManager().getAccountId(player);
// First update answer locally so we know it was answered // First update answer locally so we know it was answered
Get(player).addAnswer(poll.getId(), answer); Get(player).addAnswer(poll.getId(), answer);
@ -163,6 +164,13 @@ public class PollManager extends MiniDbClientPlugin<PlayerPollData>
{ {
// Poll response successful, give coins // Poll response successful, give coins
_donationManager.RewardGems(new Callback<Boolean>() _donationManager.RewardGems(new Callback<Boolean>()
{
@Override
public void run(Boolean completed)
{
if (completed)
{
_donationManager.RewardCoins(new Callback<Boolean>()
{ {
@Override @Override
public void run(Boolean completed) public void run(Boolean completed)
@ -175,13 +183,17 @@ public class PollManager extends MiniDbClientPlugin<PlayerPollData>
@Override @Override
public void run() public void run()
{ {
UtilPlayer.message(player, F.main("Poll", "Thanks for your response!")); UtilPlayer.message(player, F.main("Carl", "Thanks for your response!"));
player.playSound(player.getEyeLocation(), Sound.LEVEL_UP, 1F, 0); player.playSound(player.getEyeLocation(), Sound.LEVEL_UP, 1F, 0);
UtilPlayer.message(player, F.main("Gem", "You received " + F.elem(poll.getCoinReward() + "") + " Gems!")); UtilPlayer.message(player, F.main("Carl", "You received " + F.elem(poll.getCoinReward() + "") + " Gems!"));
UtilPlayer.message(player, F.main("Carl", "You received " + F.elem(poll.getCoinReward() + "") + " Coins!"));
} }
}); });
} }
} }
}, "Poll", name, accountId, poll.getCoinReward());
}
}
}, "Poll", name, uuid, poll.getCoinReward()); }, "Poll", name, uuid, poll.getCoinReward());
} }
} }

View File

@ -93,6 +93,12 @@ public class ServerManager
public static RedisConfig getConfig(String fileName) public static RedisConfig getConfig(String fileName)
{ {
if (_config == null) if (_config == null)
_config = loadConfig(fileName);
return _config;
}
public static RedisConfig loadConfig(String fileName)
{ {
try try
{ {
@ -110,12 +116,12 @@ public class ServerManager
} }
_config = new RedisConfig(connections); return new RedisConfig(connections);
} }
else else
{ {
log(fileName + " not found at " + configFile.toPath().toString()); log(fileName + " not found at " + configFile.toPath().toString());
_config = new RedisConfig(); return new RedisConfig();
} }
} }
catch (Exception exception) catch (Exception exception)
@ -124,9 +130,7 @@ public class ServerManager
log("---Unable To Parse Redis Configuration File---"); log("---Unable To Parse Redis Configuration File---");
} }
} return null;
return _config;
} }
/** /**

View File

@ -13,6 +13,7 @@ import mineplex.core.account.CoreClientManager;
import mineplex.core.bonuses.BonusAmount; import mineplex.core.bonuses.BonusAmount;
import mineplex.core.bonuses.BonusClientData; import mineplex.core.bonuses.BonusClientData;
import mineplex.core.bonuses.BonusManager; import mineplex.core.bonuses.BonusManager;
import mineplex.core.common.Pair;
import mineplex.core.common.util.Callback; import mineplex.core.common.util.Callback;
import mineplex.core.common.util.UUIDFetcher; import mineplex.core.common.util.UUIDFetcher;
import mineplex.core.database.DBPool; import mineplex.core.database.DBPool;
@ -45,8 +46,8 @@ public class VotifierManager extends MiniPlugin
private RedisConfig _usConfig; private RedisConfig _usConfig;
private RedisConfig _euConfig; private RedisConfig _euConfig;
private RedisDataRepository<PlayerStatus> _usPlayerRepo; // private RedisDataRepository<PlayerStatus> _usPlayerRepo;
private RedisDataRepository<PlayerStatus> _euPlayerRepo; // private RedisDataRepository<PlayerStatus> _euPlayerRepo;
private JedisPool _usWritePool; private JedisPool _usWritePool;
private JedisPool _euWritePool; private JedisPool _euWritePool;
@ -58,13 +59,13 @@ public class VotifierManager extends MiniPlugin
_donationManager = donationManager; _donationManager = donationManager;
_bonusManager = bonusManager; _bonusManager = bonusManager;
_usConfig = ServerManager.getConfig("us-redis.dat"); _usConfig = ServerManager.loadConfig("us-redis.dat");
_euConfig = ServerManager.getConfig("eu-redis.dat"); _euConfig = ServerManager.loadConfig("eu-redis.dat");
_usPlayerRepo = new RedisDataRepository<PlayerStatus>(_usConfig.getConnection(true, "DefaultConnection"), // _usPlayerRepo = new RedisDataRepository<PlayerStatus>(_usConfig.getConnection(true, "DefaultConnection"),
_usConfig.getConnection(false, "DefaultConnection"), Region.US, PlayerStatus.class, "playerStatus"); // _usConfig.getConnection(false, "DefaultConnection"), Region.US, PlayerStatus.class, "playerStatus");
_euPlayerRepo = new RedisDataRepository<PlayerStatus>(_euConfig.getConnection(true, "DefaultConnection"), // _euPlayerRepo = new RedisDataRepository<PlayerStatus>(_euConfig.getConnection(true, "DefaultConnection"),
_euConfig.getConnection(false, "DefaultConnection"), Region.EU, PlayerStatus.class, "playerStatus"); // _euConfig.getConnection(false, "DefaultConnection"), Region.EU, PlayerStatus.class, "playerStatus");
_usWritePool = Utility.generatePool(_usConfig.getConnection(true, "DefaultConnection")); _usWritePool = Utility.generatePool(_usConfig.getConnection(true, "DefaultConnection"));
_euWritePool = Utility.generatePool(_euConfig.getConnection(true, "DefaultConnection")); _euWritePool = Utility.generatePool(_euConfig.getConnection(true, "DefaultConnection"));
@ -98,6 +99,7 @@ public class VotifierManager extends MiniPlugin
public void run(Integer gems) public void run(Integer gems)
{ {
notifyServer(playerName, gems, false); notifyServer(playerName, gems, false);
notifyServer(playerName, gems, true);
} }
}); });
System.out.println(); System.out.println();
@ -146,7 +148,7 @@ public class VotifierManager extends MiniPlugin
publishCommand(command, writePool); publishCommand(command, writePool);
} }
private void awardBonus(final String playerName, UUID uuid, final Callback<Integer> onComplete) private void awardBonus(final String playerName, final UUID uuid, final Callback<Integer> onComplete)
{ {
DSLContext create = DSL.using(DBPool.ACCOUNT, SQLDialect.MYSQL); DSLContext create = DSL.using(DBPool.ACCOUNT, SQLDialect.MYSQL);
@ -158,6 +160,13 @@ public class VotifierManager extends MiniPlugin
final BonusAmount amount = _bonusManager.getVoteBonusAmount(client); final BonusAmount amount = _bonusManager.getVoteBonusAmount(client);
_bonusManager.getRepository().attemptVoteBonus(accountId, new Callback<Pair<Boolean, Date>>()
{
@Override
public void run(Pair<Boolean, Date> pair)
{
if (pair.getLeft())
{
// Reward Amount // Reward Amount
if (amount.getTickets() > 0) if (amount.getTickets() > 0)
client.setTickets(client.getTickets() + amount.getTickets()); client.setTickets(client.getTickets() + amount.getTickets());
@ -194,16 +203,7 @@ public class VotifierManager extends MiniPlugin
// Check if we need to reset vote streak // Check if we need to reset vote streak
_bonusManager.updateVoteStreak(client); _bonusManager.updateVoteStreak(client);
client.getRecord().setVotetime(pair.getRight());
// Update time
_bonusManager.getRepository().attemptVoteBonus(accountId, new Callback<Date>()
{
@Override
public void run(Date data)
{
if (data != null)
{
client.getRecord().setVotetime(data);
// Update Streak // Update Streak
_bonusManager.incrementVoteStreak(client); _bonusManager.incrementVoteStreak(client);
@ -212,6 +212,10 @@ public class VotifierManager extends MiniPlugin
System.out.println("Awarded carl ticket to " + playerName); System.out.println("Awarded carl ticket to " + playerName);
onComplete.run(amount.getTotalGems()); onComplete.run(amount.getTotalGems());
} }
else
{
System.out.println(playerName + " attempted to vote, vote bonus returned false!");
}
} }
}); });
} }