Update carl spin button to consume tickets, Updates to Votifier Plugin, Redis Vote Command, Various bug fixes

This commit is contained in:
Shaun Bennett 2015-08-08 06:35:25 -05:00
parent f76d9b0d37
commit 4f6dfdb856
13 changed files with 342 additions and 40 deletions

View File

@ -1,17 +0,0 @@
package mineplex.core.votifier;
import java.util.UUID;
import mineplex.serverdata.commands.ServerCommand;
public class RedisVotifierCommand extends ServerCommand
{
private UUID _voterUUID;
public RedisVotifierCommand()
{
}
}

View File

@ -0,0 +1,23 @@
package mineplex.core.votifier;
import java.util.UUID;
import mineplex.serverdata.commands.ServerCommand;
public class VotifierCommand extends ServerCommand
{
private String _playerName;
public VotifierCommand(String playerName, String targetServer)
{
super(targetServer);
_playerName = playerName;
}
public String getPlayerName()
{
return _playerName;
}
}

View File

@ -143,7 +143,6 @@ public class BonusAmount
addLore(lore, getGems(), getBonusGems(), "Gems");
addLore(lore, getGold(), getBonusGold(), "Gold");
addLore(lore, getExperience(), getBonusExperience(), "Experience");
lore.add(" ");
}
private void addLore(List<String> lore, int amount, int bonus, String suffix)

View File

@ -23,10 +23,14 @@ import mineplex.core.npc.NpcManager;
import mineplex.core.reward.RewardManager;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.core.votifier.VotifierCommand;
import mineplex.hub.bonuses.commands.GuiCommand;
import mineplex.hub.bonuses.gui.BonusGui;
import mineplex.database.tables.records.BonusRecord;
import mineplex.hub.bonuses.gui.SpinGui;
import mineplex.serverdata.commands.ServerCommandManager;
import org.bukkit.Bukkit;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.LivingEntity;
@ -87,6 +91,10 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
private RewardManager _rewardManager;
private Npc _carlNpc;
// Streak
private StreakRecord _dailyStreak;
private StreakRecord _voteStreak;
public BonusManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, NpcManager npcManager, HologramManager hologramManager, RewardManager rewardManager)
{
super("Bonus", plugin);
@ -102,7 +110,11 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
clientManager.addStoredProcedureLoginProcessor(this);
ServerCommandManager.getInstance().registerCommandType("VotifierCommand", VotifierCommand.class,
new VoteHandler(this));
updateOffSet();
updateStreakRecord();
}
@Override
@ -121,6 +133,51 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
updateOffSet();
}
@EventHandler
public void updateStreak(UpdateEvent event)
{
if (event.getType() != UpdateType.MIN_16)
return;
updateStreakRecord();
}
private void updateStreakRecord()
{
_repository.getDailyStreakRecord(new Callback<StreakRecord>()
{
@Override
public void run(StreakRecord data)
{
_dailyStreak = data;
}
});
_repository.getVoteStreakRecord(new Callback<StreakRecord>()
{
@Override
public void run(StreakRecord data)
{
_voteStreak = data;
}
});
}
public StreakRecord getDailyStreak()
{
return _dailyStreak;
}
public StreakRecord getVoteStreak()
{
return _voteStreak;
}
public void handleVote(Player player)
{
Bukkit.broadcastMessage("Recieved Vote: " + player.getName());
}
// DAILY BONUS
public static final long TIME_BETWEEN_BONUSES = 1000 * 60 * 60 * 20;
@ -186,6 +243,41 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
}
});
}
public void attemptCarlSpin(final Player player)
{
final BonusClientData clientData = Get(player);
if (clientData.getTickets() > 0)
{
clientData.setTickets(clientData.getTickets() - 1);
runAsync(new Runnable()
{
@Override
public void run()
{
int modified = clientData.getRecord().store();
if (modified == 1)
{
runSync(new Runnable()
{
@Override
public void run()
{
new SpinGui(getPlugin(), player, _rewardManager).openInventory();
}
});
}
else
{
UtilPlayer.message(player, F.main("Carl", "There was an error processing your request"));
}
}
});
}
}
public long timeTillRankBonus(Player player)
{
@ -275,8 +367,6 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
{
BonusAmount amount = new BonusAmount();
amount.setTickets(1);
amount.setBonusCoins(100);
amount.setBonusExperience(100);
return amount;
}
@ -330,7 +420,7 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
public void awardBonus(final Player player, BonusAmount amount)
{
BonusClientData bonusClient = Get(player);
final BonusClientData bonusClient = Get(player);
CoreClient coreClient = _clientManager.Get(player);
final int gems = amount.getTotalGems();
@ -399,7 +489,14 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
if (tickets > 0)
{
bonusClient.setTickets(tickets + bonusClient.getTickets());
// TODO database save
runAsync(new Runnable()
{
@Override
public void run()
{
bonusClient.getRecord().store();
}
});
UtilPlayer.message(player, F.main("Bonus", "Rewarded " + F.elem(tickets + " Carl Spin Ticket")));
}

View File

@ -16,6 +16,8 @@ import mineplex.core.recharge.Recharge;
import mineplex.database.Tables;
import mineplex.database.tables.records.BonusRecord;
import org.jooq.DSLContext;
import org.jooq.Record2;
import org.jooq.TableField;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
@ -57,6 +59,42 @@ public class BonusRepository extends RepositoryBase
return record;
}
public void getDailyStreakRecord(Callback<StreakRecord> callback)
{
getStreakRecord(Tables.bonus.maxDailyStreak, callback);
}
public void getVoteStreakRecord(Callback<StreakRecord> callback)
{
getStreakRecord(Tables.bonus.maxVoteStreak, callback);
}
private void getStreakRecord(final TableField<BonusRecord, Integer> field, final Callback<StreakRecord> callback)
{
Bukkit.getScheduler().runTaskAsynchronously(_manager.getPlugin(), new Runnable()
{
@Override
public void run()
{
final Record2<String, Integer> record = jooq().select(Tables.accounts.name, field)
.from(Tables.bonus.join(Tables.accounts).on(Tables.bonus.accountId.eq(Tables.accounts.id)))
.orderBy(field.desc()).limit(1).fetchOne();
Bukkit.getScheduler().runTask(_manager.getPlugin(), new Runnable()
{
@Override
public void run()
{
if (record.value1() != null && record.value2() != null)
{
callback.run(new StreakRecord(record.value1(), record.value2()));
}
}
});
}
});
}
public void attemptDailyBonus(final Player player, final Callback<Boolean> result)
{
if (!Recharge.Instance.usable(player, "AttemptDailyBonus")) {
@ -123,6 +161,33 @@ public class BonusRepository extends RepositoryBase
});
}
@Deprecated
public void attemptPurchaseSpin(final Player player, final Callback<Boolean> result)
{
final int accountId = _manager.getClientManager().Get(player).getAccountId();
Bukkit.getScheduler().runTaskAsynchronously(_manager.getPlugin(), new Runnable()
{
@Override
public void run()
{
final int newTickets = jooq().update(Tables.bonus).set(Tables.bonus.tickets, Tables.bonus.tickets.sub(-1)).
where(Tables.bonus.accountId.eq(accountId)).returning(Tables.bonus.tickets).fetchOne().getTickets();
Bukkit.getScheduler().runTask(_manager.getPlugin(), new Runnable()
{
@Override
public void run()
{
}
});
}
});
}
public void attemptRankBonus(final Player player, final Callback<Boolean> result)
{
if (!Recharge.Instance.usable(player, "AttemptRankBonus")) {

View File

@ -0,0 +1,23 @@
package mineplex.hub.bonuses;
public class StreakRecord
{
private String _playerName;
private int _streak;
public StreakRecord(String playerName, int streak)
{
_playerName = playerName;
_streak = streak;
}
public String getPlayerName()
{
return _playerName;
}
public int getStreak()
{
return _streak;
}
}

View File

@ -0,0 +1,31 @@
package mineplex.hub.bonuses;
import org.bukkit.entity.Player;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.votifier.VotifierCommand;
import mineplex.serverdata.commands.CommandCallback;
import mineplex.serverdata.commands.ServerCommand;
public class VoteHandler implements CommandCallback
{
private BonusManager _bonusManager;
public VoteHandler(BonusManager bonusManager)
{
_bonusManager = bonusManager;
}
@Override
public void run(ServerCommand command)
{
VotifierCommand v = ((VotifierCommand) command);
Player player = UtilPlayer.searchExact(v.getPlayerName());
if (player != null)
{
_bonusManager.handleVote(player);
}
}
}

View File

@ -28,7 +28,7 @@ public class BonusGui extends SimpleGui
setItem(15, new DailyBonusButton(getPlugin(), player, this, manager));
setItem(31, new CarlSpinButton(getPlugin(), player, rewardManager));
setItem(31, new CarlSpinButton(getPlugin(), player, manager, rewardManager));
}
@Override

View File

@ -1,5 +1,7 @@
package mineplex.hub.bonuses.gui.buttons;
import java.util.ArrayList;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
@ -7,22 +9,25 @@ import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin;
import mineplex.core.common.util.C;
import mineplex.core.gui.GuiItem;
import mineplex.core.reward.RewardManager;
import mineplex.core.shop.item.ShopItem;
import mineplex.hub.bonuses.gui.SpinGui;
import mineplex.hub.bonuses.BonusClientData;
import mineplex.hub.bonuses.BonusManager;
public class CarlSpinButton implements GuiItem
{
private Plugin _plugin;
private Player _player;
private BonusManager _bonusManager;
private RewardManager _rewardManager;
public CarlSpinButton(Plugin plugin, Player player, RewardManager rewardManager)
public CarlSpinButton(Plugin plugin, Player player, BonusManager bonusManager, RewardManager rewardManager)
{
_plugin = plugin;
_player = player;
_bonusManager = bonusManager;
_rewardManager = rewardManager;
}
@ -40,14 +45,40 @@ public class CarlSpinButton implements GuiItem
@Override
public void click(ClickType clickType)
{
new SpinGui(_plugin, _player, _rewardManager).openInventory();
BonusClientData client = _bonusManager.Get(_player);
int tickets = client.getTickets();
if (tickets > 0)
{
_bonusManager.attemptCarlSpin(_player);
}
// new SpinGui(_plugin, _player, _rewardManager).openInventory();
}
@Override
public ItemStack getObject()
{
ShopItem item = new ShopItem(Material.SKULL_ITEM, (byte) 4, "Carl's Spinner", new String[] {ChatColor.RESET + "Try your Luck!" }, 1, false, false);
BonusClientData client = _bonusManager.Get(_player);
int tickets = client.getTickets();
return item;
String name = (tickets > 0 ? C.cGreen : C.cRed) + C.Bold + "Carl's Spinner";
ArrayList<String> lore = new ArrayList<String>();
Material material = Material.SKULL_ITEM;
byte data = (byte) 4;
lore.add(" ");
if (tickets > 0)
{
lore.add(ChatColor.RESET + "Click to Spin");
}
else
{
lore.add(ChatColor.RESET + "You need a Carl Spin Ticket to Spin");
}
lore.add(" ");
lore.add(ChatColor.YELLOW + "Your Tickets: " + C.cWhite + tickets);
return new ShopItem(material, data, name, lore.toArray(new String[0]), 1, false, false);
}
}

View File

@ -19,6 +19,7 @@ import mineplex.core.updater.event.UpdateEvent;
import mineplex.hub.bonuses.BonusAmount;
import mineplex.hub.bonuses.BonusClientData;
import mineplex.hub.bonuses.BonusManager;
import mineplex.hub.bonuses.StreakRecord;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -139,6 +140,7 @@ public class DailyBonusButton implements GuiItem, Listener
BonusAmount bonusAmount = _bonusManager.getDailyBonusAmount(_player);
bonusAmount.addLore(lore);
lore.add(" ");
lore.add(C.cYellow + "Current Streak: " + C.cWhite + client.getDailyStreak());
lore.add(C.cYellow + "Highest Streak: " + C.cWhite + client.getMaxDailyStreak());
@ -154,9 +156,13 @@ public class DailyBonusButton implements GuiItem, Listener
}
}
lore.add(" ");
lore.add(C.cYellow + "Record Holder: " + C.cWhite + "Phinary");
lore.add(C.cYellow + "Streak: " + C.cWhite + "420");
StreakRecord streakRecord = _bonusManager.getDailyStreak();
if (streakRecord != null)
{
lore.add(" ");
lore.add(C.cYellow + "Record: " + C.cWhite + streakRecord.getPlayerName());
lore.add(C.cYellow + "Streak: " + C.cWhite + streakRecord.getStreak());
}
_item = new ShopItem(material, itemName, lore.toArray(new String[0]), 1, false, false);

View File

@ -17,6 +17,8 @@ import mineplex.core.updater.event.UpdateEvent;
import mineplex.hub.bonuses.BonusAmount;
import mineplex.hub.bonuses.BonusClientData;
import mineplex.hub.bonuses.BonusManager;
import mineplex.hub.bonuses.StreakRecord;
import net.minecraft.server.v1_7_R4.ChatSerializer;
import net.minecraft.server.v1_7_R4.IChatBaseComponent;
import net.minecraft.server.v1_7_R4.PacketPlayOutChat;
@ -134,6 +136,7 @@ public class VoteButton implements GuiItem, Listener {
BonusAmount bonusAmount = _bonusManager.getVoteBonusAmount(_player);
bonusAmount.addLore(lore);
lore.add(" ");
lore.add(C.cYellow + "Current Streak: " + C.cWhite + client.getVoteStreak());
lore.add(C.cYellow + "Highest Streak: " + C.cWhite + client.getMaxVoteStreak());
@ -149,9 +152,13 @@ public class VoteButton implements GuiItem, Listener {
}
}
lore.add(" ");
lore.add(C.cYellow + "Record Holder: " + C.cWhite + "Phinary");
lore.add(C.cYellow + "Streak: " + C.cWhite + "420");
StreakRecord streakRecord = _bonusManager.getVoteStreak();
if (streakRecord != null)
{
lore.add(" ");
lore.add(C.cYellow + "Record: " + C.cWhite + streakRecord.getPlayerName());
lore.add(C.cYellow + "Streak: " + C.cWhite + streakRecord.getStreak());
}
_item = new ShopItem(material, itemName, lore.toArray(new String[0]), 1, false, false);
}

View File

@ -16,6 +16,7 @@
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module" module-name="Mineplex.ServerData" />
<orderEntry type="module" module-name="Mineplex.Core" />
<orderEntry type="library" name="craftbukkit" level="project" />
</component>

View File

@ -8,27 +8,63 @@ import com.vexsoftware.votifier.model.VotifierEvent;
import mineplex.core.MiniPlugin;
import mineplex.core.account.CoreClientManager;
import mineplex.core.donation.DonationManager;
import mineplex.core.votifier.RedisVotifierCommand;
import mineplex.core.votifier.VotifierCommand;
import mineplex.serverdata.Region;
import mineplex.serverdata.commands.ServerCommandManager;
import mineplex.serverdata.data.PlayerStatus;
import mineplex.serverdata.redis.RedisDataRepository;
import mineplex.serverdata.servers.ServerManager;
/**
* Created by shaun on 15-08-05.
*/
public class VotifierManager extends MiniPlugin
{
private RedisDataRepository<PlayerStatus> _usPlayerRepo;
private RedisDataRepository<PlayerStatus> _euPlayerRepo;
public VotifierManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager)
{
super("Votifier", plugin);
_usPlayerRepo = new RedisDataRepository<PlayerStatus>(ServerManager.getMasterConnection(), ServerManager.getSlaveConnection(),
Region.US, PlayerStatus.class, "playerStatus");
_euPlayerRepo = new RedisDataRepository<PlayerStatus>(ServerManager.getMasterConnection(), ServerManager.getSlaveConnection(),
Region.EU, PlayerStatus.class, "playerStatus");
ServerCommandManager.getInstance().registerCommandType("VotifierCommand", VotifierCommand.class);
}
@EventHandler
public void handleVote(VotifierEvent event)
{
Vote vote = event.getVote();
RedisVotifierCommand command = new RedisVotifierCommand();
System.out.println("New Vote: " + vote.getUsername());
PlayerStatus usStatus = _usPlayerRepo.getElement(vote.getUsername());
// VotifierCommand command = new VotifierCommand(vote.getUsername(), "PhiTest-1");
// command.publish();
if (usStatus != null)
{
System.out.println("Found on US Server: " + usStatus.getServer());
VotifierCommand command = new VotifierCommand(vote.getUsername(), usStatus.getServer());
command.publish();
}
else
{
System.out.println("Not found on US Server!");
}
PlayerStatus euStatus = _euPlayerRepo.getElement(vote.getUsername());
if (euStatus != null)
{
System.out.println("Found on EU Server: " + euStatus.getServer());
}
else
{
System.out.println("Not found on EU Server!");
}
}
}