Update vote button

This commit is contained in:
Shaun Bennett 2015-08-06 21:59:21 -05:00
parent be18dc1bf5
commit 5f435a079e
2 changed files with 73 additions and 118 deletions

View File

@ -268,6 +268,15 @@ public class BonusManager extends MiniClientPlugin<BonusClientData> implements I
return amount;
}
public BonusAmount getVoteBonusAmount(Player player)
{
BonusAmount amount = new BonusAmount();
amount.setTickets(1);
amount.setBonusCoins(100);
amount.setBonusExperience(100);
return amount;
}
public BonusAmount getRankBonusAmount(Player player)
{
Rank rank = _clientManager.Get(player).GetRank();

View File

@ -1,13 +1,21 @@
package mineplex.hub.bonuses.gui.buttons;
import java.util.ArrayList;
import mineplex.core.common.jsonchat.ClickEvent;
import mineplex.core.common.jsonchat.JsonMessage;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilTime.TimeUnit;
import mineplex.core.gui.GuiItem;
import mineplex.core.gui.ItemRefresher;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.shop.item.ShopItem;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import mineplex.hub.bonuses.BonusAmount;
import mineplex.hub.bonuses.BonusClientData;
import mineplex.hub.bonuses.BonusManager;
import net.minecraft.server.v1_7_R4.ChatSerializer;
import net.minecraft.server.v1_7_R4.IChatBaseComponent;
@ -29,8 +37,6 @@ public class VoteButton implements GuiItem, Listener {
private ItemStack _item;
private long bonusTime;
private String _url;
private Player _player;
@ -51,14 +57,9 @@ public class VoteButton implements GuiItem, Listener {
public void setup()
{
//TODO get url from db
_url = "http://minecraftservers.org/server/121070";
_url = "http://minecraftservers.org/vote/121070";
this.bonusTime = _bonusManager.nextVoteTime(getPlayer());
//if (_url != null)
Bukkit.getPluginManager().registerEvents(this, getPlugin());
setItem();
}
@Override
@ -77,22 +78,14 @@ public class VoteButton implements GuiItem, Listener {
getPlayer().playSound(getPlayer().getLocation(), Sound.NOTE_PLING, 1, 1.6f);
// TODO This probably needs to be redone, I just looked stuff up and
// pasted it together
UtilPlayer.message(getPlayer(), "=============================================");
UtilPlayer.message(getPlayer(), C.cRed + "------------------------------------------------");
UtilPlayer.message(getPlayer(), "");
IChatBaseComponent comp = ChatSerializer.a("{\"text\":\"" + " " + "\",\"extra\":[{\"text\":\"" + ChatColor.GREEN
+ "---==Click to vote==---\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"" + ChatColor.GREEN
+ _url.replace("http://", "").replace("https://", "") + "\"},\"clickEvent\":{\"action\":\"open_url\",\"value\":\"" + _url
+ "\"}}]}");
UtilPlayer.sendPacket(_player, new PacketPlayOutChat(comp, true));
new JsonMessage("Click to Open in Web Browser").click(ClickEvent.OPEN_URL, _url).sendToPlayer(getPlayer());
new JsonMessage(C.cGreen + _url).click(ClickEvent.OPEN_URL, _url).sendToPlayer(getPlayer());
UtilPlayer.message(getPlayer(), "");
UtilPlayer.message(getPlayer(), "=============================================");
UtilPlayer.message(getPlayer(), C.cRed + "------------------------------------------------");
@ -105,37 +98,67 @@ public class VoteButton implements GuiItem, Listener {
}
}
@EventHandler
public void onUpdate(UpdateEvent event)
{
if (!event.getType().equals(UpdateType.SEC))
return;
setItem();
}
@Override
public ItemStack getObject()
{
return _item;
}
public void refreshItem() {
getGui().refreshItem(this);
}
public void setItem()
private void setItem()
{
if (isAvailable()) {
_item = ItemStackFactory.Instance.CreateStack(Material.JUKEBOX, (byte) 0, 1, ChatColor.GREEN + "Click to vote!");
} else {
_item = ItemStackFactory.Instance.CreateStack(Material.REDSTONE_BLOCK, (byte) 0, 1, ChatColor.RED + "Next link in:", new String[] {ChatColor.WHITE + UtilTime.convertString(timeLeft(), 0, TimeUnit.FIT) });
ArrayList<String> lore = new ArrayList<String>();
Material material;
String itemName;
byte data = 0;
if (isAvailable())
{
material = Material.CHEST;
itemName = C.cGreen + C.Bold + "Vote Bonus";
lore.add(" ");
lore.add(ChatColor.RESET + "Click to Vote!");
}
refreshItem();
else
{
material = Material.REDSTONE_BLOCK;
itemName = C.cRed + C.Bold + "Vote Bonus";
lore.add(" ");
lore.add(ChatColor.RESET + "Next vote in " + UtilTime.convertString(timeLeft(), 0, TimeUnit.FIT) + "!");
}
lore.add(" ");
BonusClientData client = _bonusManager.Get(_player);
BonusAmount bonusAmount = _bonusManager.getVoteBonusAmount(_player);
bonusAmount.addLore(lore);
lore.add(C.cYellow + "Current Streak: " + C.cWhite + client.getVoteStreak());
lore.add(C.cYellow + "Highest Streak: " + C.cWhite + client.getMaxVoteStreak());
if (client.getVoteTime() != null)
{
long lastBonus = _bonusManager.getLocalTime(client.getVoteTime().getTime());
long timeLeft = _bonusManager.getStreakTimeRemaining(lastBonus, BonusManager.STREAK_RESET_TIME);
if (timeLeft > 0)
{
lore.add(C.cYellow + "Streak Reset: " + C.cWhite + UtilTime.convertString(timeLeft, 1, TimeUnit.FIT));
}
}
lore.add(" ");
lore.add(C.cYellow + "Record Holder: " + C.cWhite + "Phinary");
lore.add(C.cYellow + "Streak: " + C.cWhite + "420");
_item = new ShopItem(material, itemName, lore.toArray(new String[0]), 1, false, false);
}
public long timeLeft()
{
return this.bonusTime - System.currentTimeMillis();
return _bonusManager.nextVoteTime(getPlayer()) - System.currentTimeMillis();
}
public boolean isAvailable()
@ -160,80 +183,3 @@ public class VoteButton implements GuiItem, Listener {
return _gui;
}
}
/*implements GuiItem {
private ItemStack _item;
private String _url;
private Player _player;
public VoteButton(Player player)
{
this._player = player;
//TODO get url from somewhere
_url = "http://minecraftservers.org/server/121070";
//TODO check if claimed
boolean claimed = false;
if (_url == null)
_item = ItemStackFactory.Instance.CreateStack(Material.REDSTONE_BLOCK, (byte) 0, 1, ChatColor.RED + "Nothing to vote for!");
else if (claimed) {
_item = ItemStackFactory.Instance.CreateStack(Material.REDSTONE_BLOCK, (byte) 0, 1, ChatColor.RED + "You have already voted!");
_url = null;
} else
_item = ItemStackFactory.Instance.CreateStack(Material.JUKEBOX, (byte) 0, 1, ChatColor.GREEN + "Click to vote!");
}
@Override
public void setup()
{
}
@Override
public void close()
{
}
@Override
public void click(ClickType clickType)
{
if (_url == null) {
getPlayer().playSound(getPlayer().getLocation(), Sound.ITEM_BREAK, 1, 10);
return;
}
getPlayer().playSound(getPlayer().getLocation(), Sound.NOTE_PLING, 1, 1.6f);
// TODO This probably needs to be redone, I just looked stuff up and
// pasted it together
IChatBaseComponent comp = ChatSerializer.a("{\"text\":\"" + ChatColor.BLUE + "Vote> \",\"extra\":[{\"text\":\"" + ChatColor.GREEN
+ "Click to vote!\",\"hoverEvent\":{\"action\":\"show_text\",\"value\":\"" + ChatColor.GREEN
+ _url.replace("http://", "").replace("https://", "") + "\"},\"clickEvent\":{\"action\":\"open_url\",\"value\":\"" + _url
+ "\"}}]}");
UtilPlayer.sendPacket(_player, new PacketPlayOutChat(comp, true));
getPlayer().closeInventory();
}
@Override
public ItemStack getObject()
{
return _item;
}
public Player getPlayer()
{
return _player;
}
}
*/