Work on booster gui, display wait time

This commit is contained in:
Shaun Bennett 2016-06-10 17:17:43 -05:00
parent ceb4de8b35
commit e6920b4549
12 changed files with 115 additions and 72 deletions

View File

@ -66,12 +66,24 @@ public class Booster
public boolean isActive() public boolean isActive()
{ {
return getEndTime().after(new Date()); Date now = new Date();
return getStartTime().before(now) && getEndTime().after(now);
} }
public long getTimeRemaining() public long getTimeRemaining()
{ {
return Math.max(0, getEndTime().getTime() - System.currentTimeMillis()); if (isActive())
{
return Math.max(0, getEndTime().getTime() - System.currentTimeMillis());
}
else if (getEndTime().after(new Date()))
{
return _duration * 1000L;
}
else
{
return 0;
}
} }
public String getTimeRemainingString() public String getTimeRemainingString()

View File

@ -1,12 +0,0 @@
package mineplex.core.boosters;
import mineplex.core.game.GameDisplay;
/**
* @author Shaun Bennett
*/
public enum BoosterCategory
{
}

View File

@ -36,15 +36,17 @@ public class BoosterManager extends MiniPlugin
private BoosterTipManager _tipManager; private BoosterTipManager _tipManager;
private BoosterShop _shop; private BoosterShop _shop;
private String _boosterGroup;
private long _cacheLastUpdated; private long _cacheLastUpdated;
private Map<String, List<Booster>> _boosterCache = new HashMap<>(); private Map<String, List<Booster>> _boosterCache = new HashMap<>();
public BoosterManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager) public BoosterManager(JavaPlugin plugin, String boosterGroup, CoreClientManager clientManager, DonationManager donationManager, InventoryManager inventoryManager)
{ {
super("Booster Manager", plugin); super("Booster Manager", plugin);
_repository = new BoosterRepository(); _repository = new BoosterRepository();
_boosterGroup = boosterGroup;
_clientManager = clientManager; _clientManager = clientManager;
_donationManager = donationManager; _donationManager = donationManager;
_inventoryManager = inventoryManager; _inventoryManager = inventoryManager;
@ -120,6 +122,7 @@ public class BoosterManager extends MiniPlugin
private void tickBoosterCache() private void tickBoosterCache()
{ {
List<Event> events = new ArrayList<>(3);
for (Map.Entry<String, List<Booster>> entry : _boosterCache.entrySet()) for (Map.Entry<String, List<Booster>> entry : _boosterCache.entrySet())
{ {
Iterator<Booster> iterator = entry.getValue().iterator(); Iterator<Booster> iterator = entry.getValue().iterator();
@ -131,16 +134,17 @@ public class BoosterManager extends MiniPlugin
{ {
iterator.remove(); iterator.remove();
removedOne = true; removedOne = true;
System.out.println("booster removed from tick"); events.add(new BoosterDeactivateEvent(entry.getKey(), booster));
Bukkit.getPluginManager().callEvent(new BoosterDeactivateEvent(entry.getKey(), booster));
} }
else else
{ {
if (removedOne) Bukkit.getPluginManager().callEvent(new BoosterActivateEvent(entry.getKey(), booster)); if (removedOne) events.add(new BoosterActivateEvent(entry.getKey(), booster));
break; break;
} }
} }
} }
events.forEach(Bukkit.getPluginManager()::callEvent);
} }
@EventHandler @EventHandler
@ -152,6 +156,31 @@ public class BoosterManager extends MiniPlugin
tickBoosterCache(); tickBoosterCache();
} }
public List<Booster> getBoosters()
{
return _boosterCache.get(_boosterGroup);
}
public long getBoostTime()
{
return getBoostTime(_boosterGroup);
}
public long getBoostTime(String boosterGroup)
{
long time = 0;
List<Booster> boosters = _boosterCache.get(boosterGroup);
if (boosters != null && boosters.size() > 0)
{
for (Booster booster : boosters)
{
time += booster.getTimeRemaining();
}
}
return time;
}
public Booster getActiveBoosterFromCache(String boosterGroup) public Booster getActiveBoosterFromCache(String boosterGroup)
{ {
List<Booster> boosters = _boosterCache.get(boosterGroup); List<Booster> boosters = _boosterCache.get(boosterGroup);
@ -227,7 +256,7 @@ public class BoosterManager extends MiniPlugin
*/ */
public boolean canActivateBoosters() public boolean canActivateBoosters()
{ {
return true; return _boosterGroup != null && _boosterGroup.length() > 0;
} }
public static void main(String[] args) throws IOException, URISyntaxException, InterruptedException public static void main(String[] args) throws IOException, URISyntaxException, InterruptedException

View File

@ -1,9 +1,9 @@
package mineplex.core.boosters.gui; package mineplex.core.boosters.gui;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.boosters.BoosterCategory;
import mineplex.core.boosters.BoosterManager; import mineplex.core.boosters.BoosterManager;
import mineplex.core.common.util.C; import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilTime;
import mineplex.core.donation.DonationManager; import mineplex.core.donation.DonationManager;
import mineplex.core.shop.item.ShopItem; import mineplex.core.shop.item.ShopItem;
import mineplex.core.shop.page.ShopPageBase; import mineplex.core.shop.page.ShopPageBase;
@ -17,9 +17,9 @@ import java.util.ArrayList;
*/ */
public class BoosterPage extends ShopPageBase<BoosterManager, BoosterShop> public class BoosterPage extends ShopPageBase<BoosterManager, BoosterShop>
{ {
public BoosterPage(BoosterManager plugin, BoosterShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player, BoosterCategory category) public BoosterPage(BoosterManager plugin, BoosterShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player)
{ {
super(plugin, shop, clientManager, donationManager, "Booster", player); super(plugin, shop, clientManager, donationManager, "Boosters", player, 9);
buildPage(); buildPage();
} }
@ -29,12 +29,23 @@ public class BoosterPage extends ShopPageBase<BoosterManager, BoosterShop>
{ {
ArrayList<String> lore = new ArrayList<>(); ArrayList<String> lore = new ArrayList<>();
int count = getPlugin().getAvailableBoosterCount(getPlayer());
lore.add(" "); lore.add(" ");
lore.add(C.cWhite + "You Own: " + getPlugin().getAvailableBoosterCount(getPlayer())); lore.add(C.cWhite + "You Own: " + getPlugin().getAvailableBoosterCount(getPlayer()));
if (getPlugin().canActivateBoosters()) if (getPlugin().canActivateBoosters() && count > 0)
{ {
lore.add(" "); lore.add(" ");
lore.add(C.cWhite + "Click to Activate"); lore.add(C.cWhite + "Click to Activate");
long waitTime = getPlugin().getBoostTime();
if (waitTime == 0)
{
lore.add(C.cWhite + "Booster would activate " + C.cGreen + "now");
}
else
{
lore.add(C.cWhite + "Booster would activate in " + C.cGreen + UtilTime.convertString(waitTime, 1, UtilTime.TimeUnit.FIT));
}
} }
ShopItem booster = new ShopItem(Material.SUGAR, "Game Booster", lore.toArray(new String[0]), 0, false, false); ShopItem booster = new ShopItem(Material.SUGAR, "Game Booster", lore.toArray(new String[0]), 0, false, false);

View File

@ -14,12 +14,12 @@ public class BoosterShop extends ShopBase<BoosterManager>
{ {
public BoosterShop(BoosterManager plugin, CoreClientManager clientManager, DonationManager donationManager) public BoosterShop(BoosterManager plugin, CoreClientManager clientManager, DonationManager donationManager)
{ {
super(plugin, clientManager, donationManager, "Boosters"); super(plugin, clientManager, donationManager, "Booster Keeper");
} }
@Override @Override
protected ShopPageBase<BoosterManager, ? extends ShopBase<BoosterManager>> buildPagesFor(Player player) protected ShopPageBase<BoosterManager, ? extends ShopBase<BoosterManager>> buildPagesFor(Player player)
{ {
return new MenuPage(getPlugin(), this, getClientManager(), getDonationManager(), player); return new BoosterPage(getPlugin(), this, getClientManager(), getDonationManager(), player);
} }
} }

View File

@ -1,37 +0,0 @@
package mineplex.core.boosters.gui;
import mineplex.core.account.CoreClientManager;
import mineplex.core.boosters.Booster;
import mineplex.core.boosters.BoosterManager;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;
import mineplex.core.common.util.UtilSkull;
import mineplex.core.common.util.UtilTime;
import mineplex.core.donation.DonationManager;
import mineplex.core.shop.item.ShopItem;
import mineplex.core.shop.page.ShopPageBase;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.List;
/**
* @author Shaun Bennett
*/
public class MenuPage extends ShopPageBase<BoosterManager,BoosterShop>
{
public MenuPage(BoosterManager plugin, BoosterShop shop, CoreClientManager clientManager, DonationManager donationManager, Player player)
{
super(plugin, shop, clientManager, donationManager, "Boosters", player);
buildPage();
}
@Override
protected void buildPage()
{
}
}

View File

@ -1,5 +1,6 @@
package mineplex.hub; package mineplex.hub;
import com.avaje.ebean.config.ServerConfig;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -113,7 +114,7 @@ public class Hub extends JavaPlugin implements IRelation
BlockRestore blockRestore = new BlockRestore(this); BlockRestore blockRestore = new BlockRestore(this);
DonationManager donationManager = new DonationManager(this, clientManager, webServerAddress); DonationManager donationManager = new DonationManager(this, clientManager, webServerAddress);
new ServerConfiguration(this, clientManager); ServerConfiguration serverConfiguration = new ServerConfiguration(this, clientManager);
//Other Modules //Other Modules
PacketHandler packetHandler = new PacketHandler(this); PacketHandler packetHandler = new PacketHandler(this);
@ -154,7 +155,8 @@ public class Hub extends JavaPlugin implements IRelation
CustomDataManager customDataManager = new CustomDataManager(this, clientManager); CustomDataManager customDataManager = new CustomDataManager(this, clientManager);
PersonalServerManager personalServerManager = new PersonalServerManager(this, clientManager); PersonalServerManager personalServerManager = new PersonalServerManager(this, clientManager);
BoosterManager boosterManager = new BoosterManager(this, clientManager, donationManager, inventoryManager); String boosterGroup = serverConfiguration.getServerGroup().getBoosterGroup();
BoosterManager boosterManager = new BoosterManager(this, boosterGroup, clientManager, donationManager, inventoryManager);
HubManager hubManager = new HubManager(this, blockRestore, clientManager, incognito, donationManager, inventoryManager, conditionManager, disguiseManager, new TaskManager(this, clientManager, webServerAddress), portal, partyManager, preferenceManager, petManager, pollManager, statsManager, achievementManager, new HologramManager(this, packetHandler), npcManager, personalServerManager, packetHandler, punish, serverStatusManager, customDataManager, boosterManager); HubManager hubManager = new HubManager(this, blockRestore, clientManager, incognito, donationManager, inventoryManager, conditionManager, disguiseManager, new TaskManager(this, clientManager, webServerAddress), portal, partyManager, preferenceManager, petManager, pollManager, statsManager, achievementManager, new HologramManager(this, packetHandler), npcManager, personalServerManager, packetHandler, punish, serverStatusManager, customDataManager, boosterManager);
QueueManager queueManager = new QueueManager(this, clientManager, donationManager, new EloManager(this, clientManager), partyManager); QueueManager queueManager = new QueueManager(this, clientManager, donationManager, new EloManager(this, clientManager), partyManager);

View File

@ -388,6 +388,8 @@ public class ServerGroup
_dataMap.put("host", _host); _dataMap.put("host", _host);
_dataMap.put("region", _region.name()); _dataMap.put("region", _region.name());
_dataMap.put("teamServerKey", _teamServerKey); _dataMap.put("teamServerKey", _teamServerKey);
_dataMap.put("modes", _modes);
_dataMap.put("boosterGroup", _boosterGroup);
_dataMap.put("portalBottomCornerLocation", _portalBottomCornerLocation); _dataMap.put("portalBottomCornerLocation", _portalBottomCornerLocation);
_dataMap.put("portalTopCornerLocation", _portalTopCornerLocation); _dataMap.put("portalTopCornerLocation", _portalTopCornerLocation);
_dataMap.put("npcName", _npcName); _dataMap.put("npcName", _npcName);

View File

@ -165,7 +165,7 @@ public class Arcade extends JavaPlugin
PetManager petManager = new PetManager(this, _clientManager, _donationManager, inventoryManager, disguiseManager, creature, blockRestore, webServerAddress); PetManager petManager = new PetManager(this, _clientManager, _donationManager, inventoryManager, disguiseManager, creature, blockRestore, webServerAddress);
MountManager mountManager = new MountManager(this, _clientManager, _donationManager, blockRestore, disguiseManager); MountManager mountManager = new MountManager(this, _clientManager, _donationManager, blockRestore, disguiseManager);
GadgetManager gadgetManager = new GadgetManager(this, _clientManager, _donationManager, inventoryManager, mountManager, petManager, preferenceManager, disguiseManager, blockRestore, projectileManager, achievementManager, packetHandler, hologramManager); GadgetManager gadgetManager = new GadgetManager(this, _clientManager, _donationManager, inventoryManager, mountManager, petManager, preferenceManager, disguiseManager, blockRestore, projectileManager, achievementManager, packetHandler, hologramManager);
BoosterManager boosterManager = new BoosterManager(this, _clientManager, _donationManager, inventoryManager); BoosterManager boosterManager = new BoosterManager(this, _serverConfiguration.getServerGroup().getBoosterGroup(), _clientManager, _donationManager, inventoryManager);
CosmeticManager cosmeticManager = new CosmeticManager(this, _clientManager, _donationManager, inventoryManager, gadgetManager, mountManager, petManager, null, boosterManager); CosmeticManager cosmeticManager = new CosmeticManager(this, _clientManager, _donationManager, inventoryManager, gadgetManager, mountManager, petManager, null, boosterManager);
cosmeticManager.setInterfaceSlot(7); cosmeticManager.setInterfaceSlot(7);
cosmeticManager.disableTeamArmor(); cosmeticManager.disableTeamArmor();

View File

@ -319,7 +319,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
new ValentinesGiftManager(plugin, clientManager, _bonusManager.getRewardManager(), inventoryManager, _cosmeticManager.getGadgetManager(), statsManager); new ValentinesGiftManager(plugin, clientManager, _bonusManager.getRewardManager(), inventoryManager, _cosmeticManager.getGadgetManager(), statsManager);
new GameTestingManager(this); new GameTestingManager(this);
new PlayerDisguiseManager(plugin, _clientManager); new PlayerDisguiseManager(plugin, _clientManager);
new GameBoosterManager(plugin, boosterManager, disguiseManager, hologramManager, serverConfig.BoosterGroup); new GameBoosterManager(plugin, boosterManager, disguiseManager, hologramManager, npcManager, serverConfig.BoosterGroup);
// Game Addons // Game Addons
new CompassAddon(plugin, this); new CompassAddon(plugin, this);

View File

@ -11,13 +11,17 @@ import mineplex.core.disguise.DisguiseManager;
import mineplex.core.disguise.disguises.DisguisePlayer; import mineplex.core.disguise.disguises.DisguisePlayer;
import mineplex.core.hologram.Hologram; import mineplex.core.hologram.Hologram;
import mineplex.core.hologram.HologramManager; import mineplex.core.hologram.HologramManager;
import mineplex.core.npc.Npc;
import mineplex.core.npc.NpcManager;
import mineplex.core.profileCache.ProfileCacheManager; import mineplex.core.profileCache.ProfileCacheManager;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.database.tables.records.NpcsRecord;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.ArmorStand; import org.bukkit.entity.ArmorStand;
import org.bukkit.entity.EntityType;
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.entity.EntityDamageByEntityEvent;
@ -35,20 +39,39 @@ public class BoosterPodium extends MiniPlugin
private GameBoosterManager _gameBoosterManager; private GameBoosterManager _gameBoosterManager;
private DisguiseManager _disguiseManager; private DisguiseManager _disguiseManager;
private HologramManager _hologramManager; private HologramManager _hologramManager;
private NpcManager _npcManager;
private Location _podiumLocation; private Location _podiumLocation;
private Booster _activeBooster; private Booster _activeBooster;
private Npc _npc;
private boolean _npcAlive;
private Location _npcLocation;
private ArmorStand _activeArmorStand; private ArmorStand _activeArmorStand;
private Hologram _hologram; private Hologram _hologram;
public BoosterPodium(JavaPlugin plugin, GameBoosterManager gameBoosterManager, DisguiseManager disguiseManager, HologramManager hologramManager, Location podiumLocation) public BoosterPodium(JavaPlugin plugin, GameBoosterManager gameBoosterManager, DisguiseManager disguiseManager, HologramManager hologramManager, NpcManager npcManager, Location podiumLocation)
{ {
super("Booster Podium - " + podiumLocation.toString(), plugin); super("Booster Podium - " + podiumLocation.toString(), plugin);
_gameBoosterManager = gameBoosterManager; _gameBoosterManager = gameBoosterManager;
_disguiseManager = disguiseManager; _disguiseManager = disguiseManager;
_hologramManager = hologramManager; _hologramManager = hologramManager;
_npcManager = npcManager;
_podiumLocation = podiumLocation; _podiumLocation = podiumLocation;
_npcLocation = podiumLocation.clone().add(0, 1, 0);
NpcsRecord npcsRecord = new NpcsRecord();
npcsRecord.setServer(_npcManager.getServerName());
npcsRecord.setName(C.cGreen + "Booster Keeper");
npcsRecord.setWorld(_npcLocation.getWorld().getName());
npcsRecord.setX(_npcLocation.getX());
npcsRecord.setY(_npcLocation.getY());
npcsRecord.setZ(_npcLocation.getZ());
npcsRecord.setRadius(0D);
npcsRecord.setEntityType(EntityType.VILLAGER.name());
npcsRecord.setAdult(true);
_npcAlive = false;
_npc = new Npc(npcManager, npcsRecord);
setPodium(_podiumLocation, Material.EMERALD_BLOCK.getId(), (byte) 0); setPodium(_podiumLocation, Material.EMERALD_BLOCK.getId(), (byte) 0);
updateNpcs(); updateNpcs();
@ -59,13 +82,18 @@ public class BoosterPodium extends MiniPlugin
Booster activeBooster = _gameBoosterManager.getActiveBooster(); Booster activeBooster = _gameBoosterManager.getActiveBooster();
if (activeBooster != null) if (activeBooster != null)
{ {
if (_npcAlive)
{
_npcManager.removeFakeNpc(_npc);
_npcAlive = false;
}
if (_activeArmorStand != null) if (_activeArmorStand != null)
{ {
_activeArmorStand.remove(); _activeArmorStand.remove();
} }
Location armorStandLocation = _podiumLocation.clone().add(0, 1.5, 0); ArmorStand armorStand = _podiumLocation.getWorld().spawn(_npcLocation, ArmorStand.class);
ArmorStand armorStand = _podiumLocation.getWorld().spawn(armorStandLocation, ArmorStand.class);
armorStand.setVisible(true); armorStand.setVisible(true);
armorStand.setCustomNameVisible(false); armorStand.setCustomNameVisible(false);
armorStand.setCustomName(""); armorStand.setCustomName("");
@ -83,7 +111,7 @@ public class BoosterPodium extends MiniPlugin
if (_hologram == null) if (_hologram == null)
{ {
_hologram = new Hologram(_hologramManager, armorStandLocation.clone().add(0, 1.75, 0), getHologramText(activeBooster)); _hologram = new Hologram(_hologramManager, _npcLocation.clone().add(0, 2, 0), getHologramText(activeBooster));
_hologram.start(); _hologram.start();
} }
@ -124,6 +152,13 @@ public class BoosterPodium extends MiniPlugin
_hologram.stop(); _hologram.stop();
_hologram = null; _hologram = null;
} }
if (!_npcAlive)
{
_npcManager.spawnNpc(_npc);
_npcManager.addFakeNpc(_npc);
_npcAlive = true;
}
} }
} }

View File

@ -13,6 +13,7 @@ import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilWorld; import mineplex.core.common.util.UtilWorld;
import mineplex.core.disguise.DisguiseManager; import mineplex.core.disguise.DisguiseManager;
import mineplex.core.hologram.HologramManager; import mineplex.core.hologram.HologramManager;
import mineplex.core.npc.NpcManager;
import nautilus.game.arcade.game.GameServerConfig; import nautilus.game.arcade.game.GameServerConfig;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
@ -32,7 +33,7 @@ public class GameBoosterManager extends MiniPlugin
private BoosterManager _boosterManager; private BoosterManager _boosterManager;
private BoosterPodium _boosterPodium; private BoosterPodium _boosterPodium;
public GameBoosterManager(JavaPlugin plugin, BoosterManager boosterManager, DisguiseManager disguiseManager, HologramManager hologramManager, String boosterGroup) public GameBoosterManager(JavaPlugin plugin, BoosterManager boosterManager, DisguiseManager disguiseManager, HologramManager hologramManager, NpcManager npcManager, String boosterGroup)
{ {
super("Arcade Boosters", plugin); super("Arcade Boosters", plugin);
@ -41,7 +42,7 @@ public class GameBoosterManager extends MiniPlugin
if (boosterGroup != null && boosterGroup.length() > 0) if (boosterGroup != null && boosterGroup.length() > 0)
{ {
_boosterPodium = new BoosterPodium(plugin, this, disguiseManager, hologramManager, new Location(UtilWorld.getWorld("world"), 0, 101.5, -12)); _boosterPodium = new BoosterPodium(plugin, this, disguiseManager, hologramManager, npcManager, new Location(UtilWorld.getWorld("world"), 0, 101.5, -12));
} }
} }