Merge branch 'master' of ssh://184.154.0.242:7999/min/Mineplex

This commit is contained in:
CoderTim 2014-08-04 00:00:12 -04:00
commit 39e23c16f0
16 changed files with 655 additions and 581 deletions

View File

@ -2,7 +2,7 @@ package mineplex.core.portal.Commands;
import org.bukkit.entity.Player;
import mineplex.core.command.*;
import mineplex.core.command.CommandBase;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.Callback;

View File

@ -0,0 +1,19 @@
package mineplex.core.shop.item;
import org.bukkit.entity.Player;
public abstract class SingleButton implements IButton
{
public abstract void Clicked(Player player);
public void ClickedLeft(Player player)
{
Clicked(player);
}
public void ClickedRight(Player player)
{
Clicked(player);
}
}

View File

@ -12,7 +12,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Sound;
@ -25,6 +24,7 @@ import org.bukkit.event.entity.EntityPortalEvent;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerPortalEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.util.Vector;
@ -62,6 +62,8 @@ import mineplex.hub.server.ui.ServerNpcShop;
public class ServerManager extends MiniPlugin
{
private static final Long FREE_PORTAL_TIMER = 35000L;
private CoreClientManager _clientManager;
private DonationManager _donationManager;
private Portal _portal;
@ -78,6 +80,9 @@ public class ServerManager extends MiniPlugin
private NautHashMap<String, Long> _serverUpdate = new NautHashMap<String, Long>();
private NautHashMap<Vector, String> _serverPortalLocations = new NautHashMap<Vector, String>();
// Join Time for Free Players Timer
private NautHashMap<String, Long> _freeJoinTime = new NautHashMap<String, Long>();
private QueueShop _domShop;
private QuickShop _quickShop;
private LobbyShop _lobbyShop;
@ -103,7 +108,6 @@ public class ServerManager extends MiniPlugin
LoadServers();
new ServerManagerUpdater(this);
_quickShop = new QuickShop(this, clientManager, donationManager, "Quick Menu");
_lobbyShop = new LobbyShop(this, clientManager, donationManager, "Lobby Menu");
//_domShop = new new QueueShop(_queueManager, clientManager, donationManager, "Dominate");
@ -132,16 +136,39 @@ public class ServerManager extends MiniPlugin
return;
}
Player player = (Player)event.getEntity();
if (!_hubManager.CanPortal(player))
{
UtilAction.velocity(player, UtilAlg.getTrajectory(player.getLocation(), _hubManager.GetSpawn()), 1, true, 0.8, 0, 1, true);
return;
}
final Player player = (Player)event.getEntity();
if (!Recharge.Instance.use(player, "Portal Server", 1000, false, false))
return;
long timeUntilPortal = getMillisecondsUntilPortal(player);
if (!_hubManager.CanPortal(player) || timeUntilPortal > 0)
{
if (timeUntilPortal > 0)
{
player.playSound(player.getEyeLocation(), Sound.CHICKEN_EGG_POP, 2, 2);
UtilPlayer.message(player, F.main("Server Portal", "You cannot join a server for " + C.cGreen + UtilTime.convertString(timeUntilPortal, 0, TimeUnit.SECONDS)));
}
UtilAction.velocity(player, UtilAlg.getTrajectory(player.getLocation(), _hubManager.GetSpawn()), 1.5, true, 0.8, 0, 1.0, true);
// Need to set their velocity again a tick later
// Setting Y-Velocity while in a portal doesn't seem to do anything... Science!
_plugin.getServer().getScheduler().runTask(_plugin, new Runnable()
{
@Override
public void run()
{
if (player != null && player.isOnline())
{
UtilAction.velocity(player, UtilAlg.getTrajectory(player.getLocation(), _hubManager.GetSpawn()), 1, true, 0.5, 0, 1.0, true);
}
}
});
return;
}
String serverName = _serverPortalLocations.get(player.getLocation().getBlock().getLocation().toVector());
@ -159,6 +186,7 @@ public class ServerManager extends MiniPlugin
try
{
Collections.sort(serverList, new ServerSorter(slots));
boolean hasUltra = _clientManager.Get(player).GetRank().Has(Rank.ULTRA);
for (ServerInfo serverInfo : serverList)
{
@ -175,7 +203,7 @@ public class ServerManager extends MiniPlugin
exception.printStackTrace();
}
player.sendMessage(F.main("Server Portal", "There are currently no joinable servers!"));
UtilPlayer.message(player, F.main("Server Portal", "There are currently no joinable servers!"));
}
}
@ -209,6 +237,17 @@ public class ServerManager extends MiniPlugin
{
event.getPlayer().getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.COMPASS.getId(), (byte)0, 1, ChatColor.GREEN + "Game Menu"));
event.getPlayer().getInventory().addItem(ItemStackFactory.Instance.CreateStack(Material.WATCH.getId(), (byte)0, 1, ChatColor.GREEN + "Lobby Menu"));
if (_clientManager.Get(event.getPlayer()).GetRank() == Rank.ALL)
{
_freeJoinTime.put(event.getPlayer().getName(), System.currentTimeMillis());
}
}
@EventHandler
public void playerQuit(PlayerQuitEvent event)
{
_freeJoinTime.remove(event.getPlayer().getName());
}
@EventHandler(priority = EventPriority.LOWEST)
@ -223,6 +262,36 @@ public class ServerManager extends MiniPlugin
_lobbyShop.attemptShopOpen(event.getPlayer());
}
}
public Long getMillisecondsUntilPortal(Player player)
{
// Party party = _partyManager.GetParty(player);
long timeLeft = 0;
if (_freeJoinTime.containsKey(player.getName()))
{
timeLeft = (_freeJoinTime.get(player.getName()) - System.currentTimeMillis()) + FREE_PORTAL_TIMER;
if (timeLeft <= 0)
{
_freeJoinTime.remove(player.getName());
timeLeft = 0;
}
}
// if (party != null)
// {
// if (player.getName().equals(party.GetLeader()))
// {
// for (Player partyPlayer : party.GetPlayersOnline())
// {
// if (!partyPlayer.equals(player))
// timeLeft = Math.max(timeLeft, getMillisecondsUntilPortal(partyPlayer));
// }
// }
// }
return timeLeft;
}
public void RemoveServer(String serverName)
{

View File

@ -1,180 +0,0 @@
package mineplex.hub.server;
import java.io.File;
import java.io.FileInputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.FileUtils;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import mineplex.core.common.util.NautHashMap;
import mineplex.core.logger.Logger;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
public class ServerManagerUpdater implements Listener
{
private ServerManager _plugin;
private NautHashMap<String, String> _jarMd5Map = new NautHashMap<String, String>();
private File _updateDirectory;
private boolean _needUpdate = false;
public ServerManagerUpdater(ServerManager plugin)
{
_plugin = plugin;
getCurrentMd5s();
boolean windows = System.getProperty("os.name").startsWith("Windows");
_updateDirectory = new File((windows ? "C:" : File.separator + "home" + File.separator + "mineplex") + File.separator + "update" + File.separator + "lobby");
_updateDirectory.mkdirs();
plugin.GetPluginManager().registerEvents(this, plugin.GetPlugin());
}
private void getCurrentMd5s()
{
File serverManagerDat = new File("ServerManager.dat");
FileInputStream fis = null;
try
{
fis = new FileInputStream(serverManagerDat);
_jarMd5Map.put(serverManagerDat.getName(), DigestUtils.md5Hex(fis));
}
catch (Exception ex)
{
Logger.Instance.log(ex);
System.out.println("ServerManagerUpdater: Error parsing ServerManager dat md5's");
ex.printStackTrace();
}
finally
{
if (fis != null)
{
try
{
fis.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
}
@EventHandler
public void checkForNewFiles(UpdateEvent event)
{
if (event.getType() != UpdateType.FAST)
return;
FilenameFilter statsFilter = new FilenameFilter()
{
public boolean accept(File paramFile, String paramString)
{
if (paramString.endsWith("dat"))
{
return true;
}
return false;
}
};
for (File f : _updateDirectory.listFiles(statsFilter))
{
FileInputStream fis = null;
try
{
if (_jarMd5Map.containsKey(f.getName()))
{
fis = new FileInputStream(f);
String md5 = DigestUtils.md5Hex(fis);
if (!md5.equals(_jarMd5Map.get(f.getName())))
{
_needUpdate = true;
}
}
}
catch (Exception ex)
{
Logger.Instance.log(ex);
System.out.println("ServerManagerUpdater: Error parsing dat md5's");
ex.printStackTrace();
}
finally
{
if (fis != null)
{
try
{
fis.close();
}
catch (IOException e)
{
e.printStackTrace();
}
}
}
}
if (_needUpdate)
{
updateFiles();
}
}
private void updateFiles()
{
_needUpdate = false;
boolean windows = System.getProperty("os.name").startsWith("Windows");
File updateDir = new File((windows ? "C:" : File.separator + "home" + File.separator + "mineplex") + File.separator + "update" + File.separator + "lobby");
File currentDir = new File(".");
updateDir.mkdirs();
FilenameFilter statsFilter = new FilenameFilter()
{
public boolean accept(File paramFile, String paramString)
{
if (paramString.endsWith("dat"))
{
return true;
}
return false;
}
};
for (File f : updateDir.listFiles(statsFilter))
{
try
{
FileUtils.copyFileToDirectory(f, currentDir);
}
catch (Exception ex)
{
Logger.Instance.log(ex);
System.out.println("ServerManagerUpdater: Error updating dats");
ex.printStackTrace();
}
}
getCurrentMd5s();
_plugin.LoadServers();
}
}

View File

@ -4,189 +4,286 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import mineplex.core.account.CoreClientManager;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilTime;
import mineplex.core.donation.DonationManager;
import mineplex.core.logger.Logger;
import mineplex.core.shop.item.ShopItem;
import mineplex.core.shop.item.SingleButton;
import mineplex.core.shop.page.ShopPageBase;
import mineplex.hub.server.ServerInfo;
import mineplex.hub.server.ServerManager;
import mineplex.hub.server.ServerSorter;
import mineplex.hub.server.ui.button.JoinServerButton;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.entity.Player;
public class ServerNpcPage extends ShopPageBase<ServerManager, ServerNpcShop> implements IServerPage
{
// Shop Item Messages
private static final String MESSAGE_SHOP_URL = ChatColor.RESET + "www.mineplex.com/shop";
private static final String MESSAGE_BETA_GET_ULTRA = ChatColor.RESET + C.Line + "Get Ultra to join Beta servers!";
private static final String MESSAGE_JOIN = ChatColor.RESET + C.Line + "Click to Join";
private static final String MESSAGE_IN_PROGRESS = ChatColor.RESET + C.Line + "Game in Progress.";
private static final String MESSAGE_SPECTATE = ChatColor.RESET + C.Line + "Click to Spectate";
private static final String MESSAGE_WAIT = ChatColor.RESET + C.Line + "and wait for next game!";
private static final String MESSAGE_FULL_GET_ULTRA = ChatColor.RESET + C.Line + "Get Ultra to join full servers!";
private static final String MESSAGE_RESTARTING = ChatColor.RESET + C.Line + "This server will be open shortly!";
private String _serverNpcKey;
private boolean _onMainPage = true;
public ServerNpcPage(ServerManager plugin, ServerNpcShop shop, CoreClientManager clientManager, DonationManager donationManager, String name, Player player, String serverNpcKey)
{
super(plugin, shop, clientManager, donationManager, name, player, 54);
_serverNpcKey = serverNpcKey;
BuildPage();
}
@Override
protected void BuildPage()
{
{
List<ServerInfo> serverList = new ArrayList<ServerInfo>(Plugin.GetServerList(_serverNpcKey));
int slots = 1;
int slotsNeeded = 1;
if (serverList.size() > 0)
{
slots = Plugin.GetRequiredSlots(Player, serverList.get(0).ServerType);
slotsNeeded = Plugin.GetRequiredSlots(Player, serverList.get(0).ServerType);
}
try
{
Collections.sort(serverList, new ServerSorter(slots));
Collections.sort(serverList, new ServerSorter(slotsNeeded));
}
catch (Exception exception)
{
Logger.Instance.log(exception);
exception.printStackTrace();
}
int slot = 10;
int greenCount = 0;
int yellowCount = 0;
String openFull = ChatColor.RESET + C.Line + "Get Ultra to join full servers!";
String beta = ChatColor.RESET + C.Line + "Get Ultra to join Beta servers!";
String openFullUltra = ChatColor.RESET + C.Line + "Click to join!";
for (ServerInfo serverInfo : serverList)
if (_onMainPage)
{
boolean ownsUltraPackage = DonationManager.Get(Player.getName()).OwnsUnknownPackage(serverInfo.ServerType + " ULTRA") || Client.GetRank().Has(Rank.ULTRA);
String inProgress = (serverInfo.Game == null || serverInfo.ServerType.equalsIgnoreCase("Competitive")) ? (ChatColor.RESET + C.Line + "Game in progress.") : (ChatColor.RESET + C.Line + "Click to spectate");
String inProgressLine2 = (serverInfo.Game == null || serverInfo.ServerType.equalsIgnoreCase("Competitive")) ? null : (ChatColor.RESET + C.Line + "and wait for next game!");
Material status = Material.REDSTONE_BLOCK;
List<String> lore = new ArrayList<String>();
if (slot >= 53)
break;
if ((serverInfo.MOTD.contains("Starting") || serverInfo.MOTD.contains("Recruiting") || serverInfo.MOTD.contains("Waiting") || serverInfo.MOTD.contains("Cup")) && slot < 15 && (serverInfo.MaxPlayers - serverInfo.CurrentPlayers) >= slots)
buildAvailableServerPage(serverList, slotsNeeded);
}
else
{
buildInProgressServerPage(serverList, slotsNeeded);
}
}
private void showClock(long milliseconds)
{
int seconds = (int) (milliseconds / 1000);
String timeLeft = UtilTime.convertString(milliseconds, 0, UtilTime.TimeUnit.SECONDS);
byte data = (byte) (milliseconds - (seconds * 1000) > 500 ? 15 : 14);
ShopItem item = new ShopItem(Material.WOOL, data, ChatColor.RESET + C.Bold + "Free Server Timer", null, new String[] {
ChatColor.RESET + C.cGreen + timeLeft + " Remaining...",
ChatColor.RESET + "",
ChatColor.RESET + C.cYellow + "Free players must wait a short time",
ChatColor.RESET + C.cYellow + "to help lighten the load on our servers.",
ChatColor.RESET + "",
ChatColor.RESET + C.cAqua + "Ultra and Hero players have",
ChatColor.RESET + C.cAqua + "instant access to our servers!",
ChatColor.RESET + "",
ChatColor.RESET + "Visit " + C.cGreen + "www.mineplex.com/shop" + C.cWhite + " for Premium!"
}, seconds, false, false);
AddItem(22, item);
}
private void clearPage()
{
for (int i = 0; i < getSize(); i++)
{
setItem(i, null);
}
}
private ShopItem buildShopItem(ServerInfo serverInfo, int slotsNeeded)
{
boolean ownsUltraPackage = DonationManager.Get(Player.getName()).OwnsUnknownPackage(serverInfo.ServerType + " ULTRA") || Client.GetRank().Has(Rank.ULTRA);
Material status = Material.REDSTONE_BLOCK;
List<String> lore = new ArrayList<String>();
String inProgress = (serverInfo.Game == null || serverInfo.ServerType.equalsIgnoreCase("Competitive")) ? MESSAGE_IN_PROGRESS : MESSAGE_SPECTATE;
String wait = (serverInfo.Game == null || serverInfo.ServerType.equalsIgnoreCase("Competitive")) ? null : MESSAGE_WAIT;
if (isStarting(serverInfo) && (serverInfo.MaxPlayers - serverInfo.CurrentPlayers) >= slotsNeeded)
status = Material.EMERALD_BLOCK;
else if (isInProgress(serverInfo))
status = Material.GOLD_BLOCK;
lore.add(ChatColor.RESET + "");
if (serverInfo.Game != null)
lore.add(ChatColor.RESET + C.cYellow + "Game: " + C.cWhite + serverInfo.Game);
if (serverInfo.Map != null && !serverInfo.ServerType.equalsIgnoreCase("Competitive"))
lore.add(ChatColor.RESET + C.cYellow + "Map: " + C.cWhite + serverInfo.Map);
lore.add(ChatColor.RESET + C.cYellow + "Players: " + C.cWhite + serverInfo.CurrentPlayers + "/" + serverInfo.MaxPlayers);
lore.add(ChatColor.RESET + "");
lore.add(ChatColor.RESET + serverInfo.MOTD);
if (serverInfo.Name.contains("BETA") && !ownsUltraPackage)
{
lore.add(MESSAGE_BETA_GET_ULTRA);
}
else
{
if (isInProgress(serverInfo))
{
if (greenCount > 0 && serverInfo.MaxPlayers == serverInfo.CurrentPlayers)
continue;
slot += 1;
status = Material.EMERALD_BLOCK;
lore.add(ChatColor.RESET + "");
if (serverInfo.Game != null)
lore.add(ChatColor.RESET + "" + ChatColor.YELLOW + "Game: " + ChatColor.WHITE + serverInfo.Game);
if (serverInfo.Map != null && !serverInfo.ServerType.equalsIgnoreCase("Competitive"))
lore.add(ChatColor.RESET + "" + ChatColor.YELLOW + "Map: " + ChatColor.WHITE + serverInfo.Map);
lore.add(ChatColor.RESET + "" + ChatColor.YELLOW + "Players: " + ChatColor.WHITE + serverInfo.CurrentPlayers + "/" + serverInfo.MaxPlayers);
lore.add(ChatColor.RESET + "");
lore.add(ChatColor.RESET + serverInfo.MOTD);
if (serverInfo.Name.contains("BETA") && !ownsUltraPackage)
if (serverInfo.MOTD.contains("Restarting"))
{
lore.add(beta);
status = Material.IRON_BLOCK;
lore.add(MESSAGE_RESTARTING);
}
else
{
if (serverInfo.CurrentPlayers >= serverInfo.MaxPlayers)
if (serverInfo.Game.equalsIgnoreCase("Survival Games"))
{
if (serverInfo.Game.equalsIgnoreCase("Survival Games"))
lore.add(ChatColor.RESET + C.Line + "Full Survival Games servers");
lore.add(ChatColor.RESET + C.Line + "cannot be joined.");
}
else
{
if (!ownsUltraPackage)
{
lore.add(ChatColor.RESET + C.Line + "Full Survival Games servers");
lore.add(ChatColor.RESET + C.Line + "cannot be joined.");
lore.add(MESSAGE_FULL_GET_ULTRA);
}
else
{
if (!ownsUltraPackage)
lore.add(openFull);
else
lore.add(openFullUltra);
lore.add(inProgress);
if (wait != null)
lore.add(wait);
}
}
else
{
lore.add(ChatColor.RESET + C.Line + "Click to join!");
}
}
greenCount++;
}
else if (serverInfo.MOTD.contains("In") || serverInfo.MOTD.contains("Restarting"))
{
if (slot <= 15)
slot = 27;
else
slot++;
status = Material.GOLD_BLOCK;
lore.add(ChatColor.RESET + "");
if (serverInfo.Game != null)
lore.add(ChatColor.RESET + "" + ChatColor.YELLOW + "Game: " + ChatColor.WHITE + serverInfo.Game);
if (serverInfo.Map != null && !serverInfo.ServerType.equalsIgnoreCase("Competitive"))
lore.add(ChatColor.RESET + "" + ChatColor.YELLOW + "Map: " + ChatColor.WHITE + serverInfo.Map);
lore.add(ChatColor.RESET + "" + ChatColor.YELLOW + "Players: " + ChatColor.WHITE + serverInfo.CurrentPlayers + "/" + serverInfo.MaxPlayers);
lore.add(ChatColor.RESET + "");
lore.add(ChatColor.RESET + serverInfo.MOTD);
if (serverInfo.MOTD.contains("Restarting"))
{
lore.add(ChatColor.RESET + C.Line + "This server will be open shortly!");
status = Material.IRON_BLOCK;
}
else if (serverInfo.CurrentPlayers >= serverInfo.MaxPlayers)
{
if (!Client.GetRank().Has(Rank.ULTRA) || ownsUltraPackage)
lore.add(openFull);
else
{
lore.add(inProgress);
if (inProgressLine2 != null)
lore.add(inProgressLine2);
}
}
else
{
lore.add(inProgress);
if (inProgressLine2 != null)
lore.add(inProgressLine2);
}
yellowCount++;
}
else
continue;
AddButton(slot, new ShopItem(status, ChatColor.UNDERLINE + "" + ChatColor.BOLD + "" + ChatColor.WHITE + "Server " + serverInfo.Name.substring(serverInfo.Name.indexOf('-') + 1), lore.toArray(new String[lore.size()]), Math.max(1, serverInfo.CurrentPlayers), false), new JoinServerButton(this, serverInfo));
{
if (serverInfo.CurrentPlayers >= serverInfo.MaxPlayers && !ownsUltraPackage)
{
lore.add(MESSAGE_FULL_GET_ULTRA);
}
else
{
lore.add(MESSAGE_JOIN);
}
}
}
while (greenCount < 3)
return new ShopItem(status, ChatColor.RESET + C.cGreen + C.Line + C.Bold + "Server " + serverInfo.Name.split("-")[1], lore.toArray(new String[lore.size()]), serverInfo.CurrentPlayers, false);
}
private void buildAvailableServerPage(List<ServerInfo> serverList, int slotsNeeded)
{
int greenCount = 0;
int yellowCount = 0;
int greenStartSlot = 19;
boolean showGreen = true;
long portalTime = Plugin.getMillisecondsUntilPortal(Player);
if (portalTime > 0)
{
setItem(9 + ((greenCount + 1) * 2), null);
greenCount++;
showClock(portalTime);
showGreen = false;
}
while (yellowCount < 18)
for (ServerInfo serverInfo : serverList)
{
setItem(yellowCount + 27, null);
yellowCount++;
int slot = greenCount + greenStartSlot;
if (isStarting(serverInfo) && hasEnoughSlots(serverInfo, slotsNeeded) && greenCount < 7)
{
if (showGreen)
{
ShopItem shopItem = buildShopItem(serverInfo, slotsNeeded);
greenCount++;
AddButton(slot, shopItem, new JoinServerButton(this, serverInfo));
}
}
else if (isInProgress(serverInfo))
{
yellowCount++;
}
}
AddButton(40, new ShopItem(Material.GOLD_BLOCK, C.cAqua + yellowCount++ + " Games In Progress", new String[]{MESSAGE_SPECTATE}, yellowCount > 64 ? 1 : yellowCount, false), new SingleButton()
{
@Override
public void Clicked(Player player)
{
_onMainPage = false;
}
});
// Clear empty slots
if (showGreen)
{
for (int i = greenCount + greenStartSlot; i < greenStartSlot + 7; i++)
{
setItem(i, null);
}
}
}
private boolean isStarting(ServerInfo serverInfo)
{
return (serverInfo.MOTD.contains("Starting") || serverInfo.MOTD.contains("Recruiting") || serverInfo.MOTD.contains("Waiting") || serverInfo.MOTD.contains("Cup"));
}
private boolean isInProgress(ServerInfo serverInfo)
{
return serverInfo.MOTD.contains("In") || serverInfo.MOTD.contains("Restarting");
}
private boolean hasEnoughSlots(ServerInfo serverInfo, int slotsNeeded)
{
return (serverInfo.MaxPlayers - serverInfo.CurrentPlayers) >= slotsNeeded;
}
private void buildInProgressServerPage(List<ServerInfo> serverList, int slotsNeeded)
{
int slot = 9;
for (ServerInfo serverInfo : serverList)
{
if (isInProgress(serverInfo) && slot < getSize())
{
ShopItem shopItem = buildShopItem(serverInfo, slotsNeeded);
AddButton(slot, shopItem, new JoinServerButton(this, serverInfo));
slot++;
}
}
AddButton(4, new ShopItem(Material.BED, C.cGray + " \u21FD Go Back", new String[] { }, 1, false), new SingleButton()
{
@Override
public void Clicked(Player player)
{
clearPage();
_onMainPage = true;
}
});
while (slot < getSize())
{
setItem(slot, null);
slot++;
}
}

View File

@ -2,12 +2,11 @@ package mineplex.hub.server.ui.button;
import org.bukkit.entity.Player;
import mineplex.core.shop.item.IButton;
import mineplex.core.shop.item.SingleButton;
import mineplex.hub.server.ServerInfo;
import mineplex.hub.server.ui.IServerPage;
import mineplex.hub.server.ui.ServerNpcPage;
public class JoinServerButton implements IButton
public class JoinServerButton extends SingleButton
{
private IServerPage _page;
private ServerInfo _serverInfo;
@ -17,15 +16,9 @@ public class JoinServerButton implements IButton
_page = page;
_serverInfo = serverInfo;
}
@Override
public void ClickedLeft(Player player)
{
_page.SelectServer(player, _serverInfo);
}
@Override
public void ClickedRight(Player player)
public void Clicked(Player player)
{
_page.SelectServer(player, _serverInfo);
}

View File

@ -10,26 +10,84 @@ public class GroupStatusData
private int _totalCount = 0;
private int _joinableCount = 0;
private int _freeServerNum = 0;
private int _freeTotalCount = 0;
private int _freeJoinableCount = 0;
public int Players;
public int MaxPlayers;
public int MaxServerNumber;
public List<ServerStatusData> EmptyServers = new ArrayList<ServerStatusData>();
public List<ServerStatusData> KillServers = new ArrayList<ServerStatusData>();
public HashMap<Integer, ServerStatusData> Servers = new HashMap<Integer, ServerStatusData>();
public HashMap<Integer, ServerStatusData> FreeServers = new HashMap<Integer, ServerStatusData>();
public void addServer(ServerStatusData serverStatusData)
{
if (Servers.containsKey(Integer.parseInt(serverStatusData.Name.split("-")[1])))
boolean free = serverStatusData.Name.contains("FREE");
checkForDuplicate(free ? FreeServers : Servers, serverStatusData, free);
Players += serverStatusData.Players;
MaxPlayers += serverStatusData.MaxPlayers;
if (serverStatusData.Motd != null && (serverStatusData.Motd.contains("Starting") || serverStatusData.Motd.contains("Recruiting") || serverStatusData.Motd.contains("Waiting") || serverStatusData.Motd.contains("Cup") || serverStatusData.Motd.isEmpty() || serverStatusData.Motd.equals("")))
{
ServerStatusData existingServer = Servers.get(Integer.parseInt(serverStatusData.Name.split("-")[1]));
if (serverStatusData.Players < serverStatusData.MaxPlayers)
{
// Lobby joinable checking
if (serverStatusData.Motd.isEmpty() || serverStatusData.Motd.equals(""))
{
if (serverStatusData.MaxPlayers - serverStatusData.Players > 20)
{
if (free)
_freeJoinableCount++;
else
_joinableCount++;
}
}
else
{
if (free)
_freeJoinableCount++;
else
_joinableCount++;
}
}
}
if (free)
_freeTotalCount++;
else
_totalCount++;
if (serverStatusData.Empty)
{
EmptyServers.add(serverStatusData);
}
if (free)
{
FreeServers.put(Integer.parseInt(serverStatusData.Name.split("-")[1]), serverStatusData);
}
else
{
Servers.put(Integer.parseInt(serverStatusData.Name.split("-")[1]), serverStatusData);
}
}
private boolean checkForDuplicate(HashMap<Integer, ServerStatusData> serverMap, ServerStatusData serverStatusData, boolean free)
{
if (serverMap.containsKey(Integer.parseInt(serverStatusData.Name.split("-")[1])))
{
ServerStatusData existingServer = serverMap.get(Integer.parseInt(serverStatusData.Name.split("-")[1]));
int existingCount = existingServer.Players;
int newCount = serverStatusData.Players;
if (newCount == 0 || newCount < existingCount)
{
KillServers.add(serverStatusData);
return;
return true;
}
else if (existingCount == 0 || newCount > existingCount)
{
@ -45,71 +103,67 @@ public class GroupStatusData
if (existingServer.Motd.isEmpty() || existingServer.Motd.equals(""))
{
if (serverStatusData.MaxPlayers - serverStatusData.Players > 20)
_joinableCount--;
{
if (free)
_freeJoinableCount--;
else
_joinableCount--;
}
}
else
{
_joinableCount--;
if (free)
_freeJoinableCount--;
else
_joinableCount--;
}
}
}
}
}
Players += serverStatusData.Players;
MaxPlayers += serverStatusData.MaxPlayers;
if (serverStatusData.Motd != null && (serverStatusData.Motd.contains("Starting") || serverStatusData.Motd.contains("Recruiting") || serverStatusData.Motd.contains("Waiting") || serverStatusData.Motd.contains("Cup") || serverStatusData.Motd.isEmpty() || serverStatusData.Motd.equals("")))
{
if (serverStatusData.Players < serverStatusData.MaxPlayers)
{
// Lobby joinable checking
if (serverStatusData.Motd.isEmpty() || serverStatusData.Motd.equals(""))
{
if (serverStatusData.MaxPlayers - serverStatusData.Players > 20)
{
_joinableCount++;
}
}
else
{
_joinableCount++;
}
}
}
_totalCount++;
if (serverStatusData.Empty)
{
EmptyServers.add(serverStatusData);
}
Servers.put(Integer.parseInt(serverStatusData.Name.split("-")[1]), serverStatusData);
}
public int getTotalServers()
{
return _totalCount;
}
public int getJoinableCount()
{
return _joinableCount;
return false;
}
public int getNextServerNumber()
public int getTotalServers(boolean free)
{
_serverNum++;
return free ? _freeTotalCount : _totalCount;
}
public int getJoinableCount(boolean free)
{
return free ? _freeJoinableCount : _joinableCount;
}
public int getNextServerNumber(boolean free)
{
if (free)
_freeServerNum++;
else
_serverNum++;
while (true)
{
if (!Servers.containsKey(_serverNum))
{
return _serverNum;
if (free)
{
if (!FreeServers.containsKey(_freeServerNum))
break;
}
else
{
if (!Servers.containsKey(_serverNum))
break;
}
_serverNum++;
if (free)
_freeServerNum++;
else
_serverNum++;
}
if (free)
return _freeServerNum;
else
return _serverNum;
}
}

View File

@ -24,7 +24,7 @@ public class Repository
private static String CREATE_DYNAMIC_TABLE = "CREATE TABLE IF NOT EXISTS DynamicServers (id INT NOT NULL AUTO_INCREMENT, serverName VARCHAR(256), address VARCHAR(256), privateAddress VARCHAR(256), US BOOLEAN NOT NULL DEFAULT 'true', PRIMARY KEY (id));";
private static String RETRIEVE_AVAILABLE_SERVERS = "SELECT DynamicServers.serverName, DynamicServers.address, DynamicServers.privateAddress, DynamicServers.US, DynamicServers.availableCpu, DynamicServers.availableRam, ServerStatus.serverGroup, COUNT(*) As serverCount FROM DynamicServers LEFT JOIN ServerStatus ON ServerStatus.address = DynamicServers.privateAddress WHERE DynamicServers.US = ? GROUP BY DynamicServers.address, ServerStatus.serverGroup;";
private static String RETRIEVE_SERVERGROUP_STATUSES = "SELECT ServerStatus.serverName, serverGroup, motd, DynamicServers.address, ServerStatus.address, ServerStatus.port, players, maxPlayers, case when TIME_TO_SEC(TIMEDIFF(now(), ServerStatus.lastTimeWithPlayers)) > 300 then 1 else 0 end as empty, now(), updated FROM ServerStatus INNER JOIN DynamicServers ON ServerStatus.address = DynamicServers.privateAddress WHERE DynamicServers.US = ?";
private static String RETRIEVE_SERVER_GROUP_DATA = "SELECT groupName, prefix, scriptName, requiredRam, cpuRequired, requiredTotal, requiredJoinable FROM ServerGroups;";
private static String RETRIEVE_SERVER_GROUP_DATA = "SELECT groupName, prefix, scriptName, requiredRam, cpuRequired, requiredTotal, requiredJoinable, arcadeGroup, worldZip, plugin, configPath, minPlayers, maxPlayers, pvp, tournament, generateFreeVersions, games, serverType, addNoCheat, portSection FROM ServerGroups;";
private static String DELETE_SERVER_STATUS = "DELETE FROM ServerStatus WHERE address = ? AND port = ? AND serverName = ?;";
public static Connection connection;
@ -361,6 +361,19 @@ public class Repository
serverGroupData.RequiredCPU = resultSet.getInt(5);
serverGroupData.RequiredTotalServers = resultSet.getInt(6);
serverGroupData.RequiredJoinableServers = resultSet.getInt(7);
serverGroupData.ArcadeGroup = resultSet.getBoolean(8);
serverGroupData.WorldZip = resultSet.getString(9);
serverGroupData.Plugin = resultSet.getString(10);
serverGroupData.ConfigPath = resultSet.getString(11);
serverGroupData.MinPlayers = resultSet.getInt(12);
serverGroupData.MaxPlayers = resultSet.getInt(13);
serverGroupData.Pvp = resultSet.getBoolean(14);
serverGroupData.Tournament = resultSet.getBoolean(15);
serverGroupData.GenerateFreeVersions = resultSet.getBoolean(16);
serverGroupData.Games = resultSet.getString(17);
serverGroupData.ServerType = resultSet.getString(18);
serverGroupData.AddNoCheat = resultSet.getBoolean(19);
serverGroupData.PortSection = resultSet.getInt(20);
if (!serverGroupMap.containsKey(serverGroupData.Name))
serverGroupMap.put(serverGroupData.Name, serverGroupData);

View File

@ -9,9 +9,18 @@ public class ServerGroupData
public int RequiredCPU;
public int RequiredTotalServers;
public int RequiredJoinableServers;
public void printInfo()
{
System.out.println("ServerGroupData - Name:" + Name + " Prefix:" + Prefix + " ScriptName:" + ScriptName + " RAM:" + RequiredRAM + " CPU:" + RequiredCPU + " ReqTotal:" + RequiredTotalServers + " ReqJoin:" + RequiredJoinableServers);
}
public int PortSection;
public boolean ArcadeGroup;
public String WorldZip;
public String Plugin;
public String ConfigPath;
public int MinPlayers;
public int MaxPlayers;
public boolean Pvp;
public boolean Tournament;
public boolean GenerateFreeVersions;
public String Games;
public String ServerType;
public boolean AddNoCheat;
}

View File

@ -68,154 +68,92 @@ public class ServerMonitor
HashMap<String, GroupStatusData> groupStatusList = _repository.retrieveGroupStatusData();
for (ServerStatusData statusData : _repository.retrieveOldServerStatuses())
{
/*
if (us)
{
if (!serverTracker.containsKey(statusData.Name))
{
restartServer(statusData);
serverTracker.put(statusData.Name, new AbstractMap.SimpleEntry<String, Long>(statusData.Address, System.currentTimeMillis()));
}
else if (System.currentTimeMillis() - serverTracker.get(statusData.Name).getValue() > 15000)
{
serverTracker.remove(statusData.Name);
System.out.println("-=[SERVER RESTART TOO SLOW]=- " + statusData.Name + " (Putting back in restart queue)");
}
}
else
*/
{
killServer(statusData);
}
/*
if (us)
{
// Remove successfully restarted US servers
for (GroupStatusData groupStatus : groupStatusList.values())
{
for (ServerStatusData serverToKill : groupStatus.Servers.values())
List<DynamicServerData> dynamicServers = new ArrayList<DynamicServerData>(_repository.retrieveDynamicServers());
if (_count % 15 == 0)
{
_badServers.clear();
for (DynamicServerData serverData : dynamicServers)
{
if (isServerOffline(serverData))
{
if (serverTracker.containsKey(serverToKill.Name))
serverTracker.remove(serverToKill.Name);
System.out.println("------=[OFFLINE]=------=[" + serverData.Name + ":" + serverData.Address + "]=------=[OFFLINE]=------");
log(serverData.Name + ":" + serverData.Address + " is OFFLINE.");
_badServers.put(serverData.Name, true);
}
}
}
else
for (Iterator<DynamicServerData> iterator = dynamicServers.iterator(); iterator.hasNext();)
{
*/
List<DynamicServerData> dynamicServers = new ArrayList<DynamicServerData>(_repository.retrieveDynamicServers());
DynamicServerData serverData = iterator.next();
if (_count % 15 == 0)
{
_badServers.clear();
for (DynamicServerData serverData : dynamicServers)
{
if (isServerOffline(serverData))
{
System.out.println("------=[OFFLINE]=------=[" + serverData.Name + ":" + serverData.Address + "]=------=[OFFLINE]=------");
log(serverData.Name + ":" + serverData.Address + " is OFFLINE.");
_badServers.put(serverData.Name, true);
}
}
}
for (Iterator<DynamicServerData> iterator = dynamicServers.iterator(); iterator.hasNext();)
if (_badServers.containsKey(serverData.Name))
iterator.remove();
}
for (GroupStatusData groupStatus : groupStatusList.values())
{
for (ServerStatusData serverToKill : groupStatus.KillServers)
{
DynamicServerData serverData = iterator.next();
if (_badServers.containsKey(serverData.Name))
iterator.remove();
}
for (GroupStatusData groupStatus : groupStatusList.values())
{
for (ServerStatusData serverToKill : groupStatus.KillServers)
{
System.out.println("----DUPLICATE SERVER----> " + serverToKill.Address + ", " + serverToKill.Name);
log("Duplicate server " + serverToKill.Name + ":" + serverToKill.Address + " is being killed.");
killServer(serverToKill);
}
for (ServerStatusData serverToKill : groupStatus.Servers.values())
{
if (serverTracker.containsKey(serverToKill.Name))
serverTracker.remove(serverToKill.Name);
}
System.out.println("----DUPLICATE SERVER----> " + serverToKill.Address + ", " + serverToKill.Name);
log("Duplicate server " + serverToKill.Name + ":" + serverToKill.Address + " is being killed.");
killServer(serverToKill);
}
for (Iterator<Entry<String, Entry<String, Long>>> iterator = serverTracker.entrySet().iterator(); iterator.hasNext();)
for (ServerStatusData serverToKill : groupStatus.Servers.values())
{
Entry<String, Entry<String, Long>> entry = iterator.next();
if (System.currentTimeMillis() - entry.getValue().getValue() > 15000)
{
System.out.println("-=[SERVER STARTUP TOO SLOW]=- " + entry.getKey());
ServerStatusData serverToKill = new ServerStatusData();
serverToKill.Name = entry.getKey();
serverToKill.Address = entry.getValue().getKey();
log("Server startup too slow " + serverToKill.Name + ":" + serverToKill.Address + " is being killed.");
killServer(serverToKill);
iterator.remove();
}
if (serverTracker.containsKey(serverToKill.Name))
serverTracker.remove(serverToKill.Name);
}
for (ServerGroupData serverGroup : serverGroups)
for (ServerStatusData serverToKill : groupStatus.FreeServers.values())
{
if (!groupStatusList.containsKey(serverGroup.Name))
{
groupStatusList.put(serverGroup.Name, new GroupStatusData());
}
GroupStatusData groupStatus = groupStatusList.get(serverGroup.Name);
int serversToAdd = Math.max(serverGroup.RequiredTotalServers - groupStatus.getTotalServers(), serverGroup.RequiredJoinableServers - groupStatus.getJoinableCount());
int serversToKill = (groupStatus.getTotalServers() > serverGroup.RequiredTotalServers && groupStatus.getJoinableCount() > serverGroup.RequiredJoinableServers) ? Math.min(groupStatus.getJoinableCount() - serverGroup.RequiredJoinableServers, groupStatus.EmptyServers.size()) : 0;
// Minimum 1500 slot bufferzone
if (serverGroup.Name.equalsIgnoreCase("Lobby"))
{
if (groupStatus.MaxPlayers - groupStatus.Players < 1500)
serversToAdd = serverGroup.RequiredJoinableServers;
}
while (serversToAdd > 0)
{
int serverNum = groupStatus.getNextServerNumber();
Collections.sort(dynamicServers, new DynamicServerSorter());
DynamicServerData bestServer = getBestDynamicServer(dynamicServers, serverGroup);
if (bestServer == null)
{
System.out.println("No best dynamic server available for group " + serverGroup.Name);
break;
}
if (serverTracker.containsKey(serverGroup.Prefix + "-" + serverNum))
System.out.println("[WAITING] On " + serverGroup.Prefix + "-" + serverNum + " to finish starting...");
else
{
startServer(bestServer, serverGroup, serverNum);
serverTracker.put(serverGroup.Prefix + "-" + serverNum, new AbstractMap.SimpleEntry<String, Long>(bestServer.Address, System.currentTimeMillis()));
}
serversToAdd--;
}
while (serversToKill > 0)
{
System.out.println("[" + groupStatus.EmptyServers.get(0).Name + ":" + groupStatus.EmptyServers.get(0).Address + "] Killing " + serverGroup.Name + " Req Total: " + serverGroup.RequiredTotalServers + " Req Joinable: " + serverGroup.RequiredJoinableServers + " | Actual Total: " + groupStatus.getTotalServers() + " Actual Joinable: " + groupStatus.getJoinableCount());
log("Excess server " + groupStatus.EmptyServers.get(0).Name + ":" + groupStatus.EmptyServers.get(0).Address + " is being killed.");
killServer(groupStatus.EmptyServers.remove(0));
serversToKill--;
}
if (serverTracker.containsKey(serverToKill.Name))
serverTracker.remove(serverToKill.Name);
}
//}
}
for (Iterator<Entry<String, Entry<String, Long>>> iterator = serverTracker.entrySet().iterator(); iterator.hasNext();)
{
Entry<String, Entry<String, Long>> entry = iterator.next();
if (System.currentTimeMillis() - entry.getValue().getValue() > 15000)
{
System.out.println("-=[SERVER STARTUP TOO SLOW]=- " + entry.getKey());
ServerStatusData serverToKill = new ServerStatusData();
serverToKill.Name = entry.getKey();
serverToKill.Address = entry.getValue().getKey();
log("Server startup too slow " + serverToKill.Name + ":" + serverToKill.Address + " is being killed.");
killServer(serverToKill);
iterator.remove();
}
}
for (ServerGroupData serverGroup : serverGroups)
{
if (!groupStatusList.containsKey(serverGroup.Name))
{
groupStatusList.put(serverGroup.Name, new GroupStatusData());
}
GroupStatusData groupStatus = groupStatusList.get(serverGroup.Name);
handleGroupChanges(dynamicServers, serverTracker, serverGroup, groupStatus, false);
if (serverGroup.GenerateFreeVersions && _count % 6 == 0)
{
handleGroupChanges(dynamicServers, serverTracker, serverGroup, groupStatus, true);
}
}
int processWaits = 0;
@ -281,6 +219,53 @@ public class ServerMonitor
}
}
private static void handleGroupChanges(List<DynamicServerData> dynamicServers, HashMap<String, Entry<String, Long>> serverTracker, ServerGroupData serverGroup, GroupStatusData groupStatus, boolean free)
{
int serversToAdd = Math.max(serverGroup.RequiredTotalServers - groupStatus.getTotalServers(free), serverGroup.RequiredJoinableServers - groupStatus.getJoinableCount(free));
int serversToKill = (groupStatus.getTotalServers(free) > serverGroup.RequiredTotalServers && groupStatus.getJoinableCount(free) > serverGroup.RequiredJoinableServers) ? Math.min(groupStatus.getJoinableCount(free) - serverGroup.RequiredJoinableServers, groupStatus.EmptyServers.size()) : 0;
if (free)
serversToAdd = Math.min(1, serversToAdd);
// Minimum 1500 slot bufferzone
if (serverGroup.Name.equalsIgnoreCase("Lobby"))
{
if (groupStatus.MaxPlayers - groupStatus.Players < 1500)
serversToAdd = serverGroup.RequiredJoinableServers;
}
while (serversToAdd > 0)
{
int serverNum = groupStatus.getNextServerNumber(free);
Collections.sort(dynamicServers, new DynamicServerSorter());
DynamicServerData bestServer = getBestDynamicServer(dynamicServers, serverGroup);
if (bestServer == null)
{
System.out.println("No best dynamic server available for group " + serverGroup.Name);
break;
}
if (serverTracker.containsKey(serverGroup.Prefix + "-" + serverNum + (free ? "-FREE" : "")))
System.out.println("[WAITING] On " + serverGroup.Prefix + "-" + serverNum + " to finish starting...");
else
{
startServer(bestServer, serverGroup, serverNum, free);
serverTracker.put(serverGroup.Prefix + "-" + serverNum + (free ? "-FREE" : ""), new AbstractMap.SimpleEntry<String, Long>(bestServer.Address, System.currentTimeMillis()));
}
serversToAdd--;
}
while (serversToKill > 0)
{
System.out.println("[" + groupStatus.EmptyServers.get(0).Name + ":" + groupStatus.EmptyServers.get(0).Address + "] Killing " + serverGroup.Name + " " + (free ? "FREE" : "PREMIUM") + " Req Total: " + serverGroup.RequiredTotalServers + " Req Joinable: " + serverGroup.RequiredJoinableServers + " | Actual Total: " + groupStatus.getTotalServers(free) + " Actual Joinable: " + groupStatus.getJoinableCount(free));
log("Excess server " + groupStatus.EmptyServers.get(0).Name + ":" + groupStatus.EmptyServers.get(0).Address + " is being killed.");
killServer(groupStatus.EmptyServers.remove(0));
serversToKill--;
}
}
private static void killServer(final ServerStatusData serverToKill, final boolean announce)
{
String cmd = "/home/mineplex/easyRemoteKillServer.sh";
@ -413,19 +398,19 @@ public class ServerMonitor
killServer(serverToKill, true);
}
private static void startServer(final DynamicServerData serverSpace, final ServerGroupData serverGroup, final int serverNum)
private static void startServer(final DynamicServerData serverSpace, final ServerGroupData serverGroup, final int serverNum, final boolean free)
{
String cmd = "/home/mineplex/easyRemoteStartServer.sh";
String cmd = "/home/mineplex/easyRemoteStartServerCustom.sh";
ProcessRunner pr = new ProcessRunner(new String[] {"/bin/sh", cmd, serverSpace.Address, serverSpace.PrivateAddress, serverGroup.ScriptName, serverGroup.Prefix + "-" + serverNum, "1", serverSpace.US ? "us" : "eu"});
ProcessRunner pr = new ProcessRunner(new String[] {"/bin/sh", cmd, serverSpace.Address, serverSpace.PrivateAddress, serverGroup.PortSection + serverNum + "", serverGroup.RequiredRAM + "", serverGroup.WorldZip, serverGroup.Plugin, serverGroup.ConfigPath, serverGroup.Name, serverGroup.Prefix + "-" + serverNum, serverGroup.MinPlayers + "", serverGroup.MaxPlayers + "", serverGroup.Pvp + "", serverGroup.Tournament + "", free + "", serverSpace.US ? "true" : "false", serverGroup.ArcadeGroup + "", serverGroup.Games, serverGroup.ServerType, serverGroup.AddNoCheat + ""});
pr.start(new GenericRunnable<Boolean>()
{
public void run(Boolean error)
{
if (error)
System.out.println("[" + serverSpace.Name + ":" + serverSpace.Address + "] Errored " + serverGroup.Name + "(" + serverGroup.Prefix + "-" + serverNum + ")");
System.out.println("[" + serverSpace.Name + ":" + serverSpace.Address + "] Errored " + serverGroup.Name + "(" + serverGroup.Prefix + "-" + serverNum + (free ? "-FREE" : "") + ")");
else
System.out.println("[" + serverSpace.Name + ":" + serverSpace.Address + "] Added " + serverGroup.Name + "(" + serverGroup.Prefix + "-" + serverNum + ")");
System.out.println("[" + serverSpace.Name + ":" + serverSpace.Address + "] Added " + serverGroup.Name + "(" + serverGroup.Prefix + "-" + serverNum + (free ? "-FREE" : "") + ")");
}
});

View File

@ -367,6 +367,11 @@ public class ArcadeManager extends MiniPlugin implements IRelation
{
return _statsManager;
}
public ServerStatusManager GetServerStatusManager()
{
return _serverStatusManager;
}
public ChatColor GetColor(Player player)
{

View File

@ -1,15 +1,5 @@
package nautilus.game.arcade.kit;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import nautilus.game.arcade.ArcadeFormat;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.events.PlayerKitGiveEvent;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
@ -22,6 +12,15 @@ import org.bukkit.entity.Skeleton.SkeletonType;
import org.bukkit.event.Listener;
import org.bukkit.inventory.ItemStack;
import mineplex.core.common.util.C;
import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import nautilus.game.arcade.ArcadeFormat;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.events.PlayerKitGiveEvent;
public abstract class Kit implements Listener
{
public ArcadeManager Manager;
@ -29,6 +28,7 @@ public abstract class Kit implements Listener
private String _kitName;
private String[] _kitDesc;
private KitAvailability _kitAvailability;
private int _cost;
private Perk[] _kitPerks;
@ -36,19 +36,25 @@ public abstract class Kit implements Listener
protected ItemStack _itemInHand;
protected Material _displayItem;
public Kit(ArcadeManager manager, String name, KitAvailability kitAvailability, String[] kitDesc, Perk[] kitPerks, EntityType entityType, ItemStack itemInHand)
{
this(manager, name, kitAvailability, kitAvailability.getDefaultCost(), kitDesc, kitPerks, entityType, itemInHand);
}
public Kit(ArcadeManager manager, String name, KitAvailability kitAvailability, int cost, String[] kitDesc, Perk[] kitPerks, EntityType entityType, ItemStack itemInHand)
{
Manager = manager;
_kitName = name;
_kitDesc = kitDesc;
_kitPerks = kitPerks;
for (Perk perk : _kitPerks)
perk.SetHost(this);
_kitAvailability = kitAvailability;
_cost = cost;
_entityType = entityType;
_itemInHand = itemInHand;
@ -129,7 +135,7 @@ public abstract class Kit implements Listener
LivingEntity entity = (LivingEntity) Manager.GetCreature().SpawnEntity(loc, type);
entity.setRemoveWhenFarAway(false);
entity.setCustomName(GetAvailability().GetColor() + GetName() + " Kit" + (GetAvailability() == KitAvailability.Blue ? ChatColor.GRAY + " (" + ChatColor.WHITE + "Ultra" + ChatColor.GRAY + ")" : ""));
entity.setCustomName(GetAvailability().GetColor() + GetName() + " Kit" + (GetAvailability() == KitAvailability.Blue ? ChatColor.GRAY + " (" + ChatColor.WHITE + "Premium" + ChatColor.GRAY + ")" : ""));
entity.setCustomNameVisible(true);
entity.getEquipment().setItemInHand(_itemInHand);
@ -185,7 +191,7 @@ public abstract class Kit implements Listener
public int GetCost()
{
return 2000;
return _cost;
}
public Material getDisplayMaterial()

View File

@ -21,4 +21,20 @@ public enum KitAvailability
{
return _color;
}
public int getDefaultCost()
{
int cost = 0;
switch (this)
{
case Blue:
cost = 5000;
break;
default:
cost = 2000;
}
return cost;
}
}

View File

@ -156,11 +156,13 @@ public class GameGemManager implements Listener
if (total <= 0)
total = 1;
/*
if (Manager.GetClients().Get(player).GetRank().Has(Rank.HERO))
total = total * 3;
else if (Manager.GetClients().Get(player).GetRank().Has(Rank.ULTRA) || Manager.GetDonation().Get(player.getName()).OwnsUnknownPackage(Manager.GetServerConfig().ServerType + " ULTRA"))
total = total * 2;
*/
if (DoubleGem)
total = total * 2;
@ -207,6 +209,7 @@ public class GameGemManager implements Listener
earnedGems = (int) (earnedGems * game.GemMultiplier);
//Hero / Ultra Boost
/*
if (Manager.GetClients().Get(player).GetRank().Has(Rank.HERO))
{
UtilPlayer.message(player, F.elem(C.cGreen + "+" + (earnedGems*2) + " Gems") + " for " + F.elem(C.cPurple + "Hero Rank 3x Gems"));
@ -217,6 +220,7 @@ public class GameGemManager implements Listener
UtilPlayer.message(player, F.elem(C.cGreen + "+" + earnedGems + " Gems") + " for " + F.elem(C.cAqua + "Ultra Rank 2x Gems"));
earnedGems = earnedGems * 2;
}
*/
//Double Gem
if (DoubleGem)

View File

@ -11,10 +11,10 @@ import org.bukkit.ChatColor;
import org.bukkit.Color;
import org.bukkit.DyeColor;
import org.bukkit.FireworkEffect;
import org.bukkit.FireworkEffect.Type;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.World;
import org.bukkit.FireworkEffect.Type;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.Creature;
@ -41,9 +41,9 @@ import mineplex.core.common.util.UtilEnt;
import mineplex.core.common.util.UtilInv;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilText;
import mineplex.core.common.util.UtilText.TextAlign;
import mineplex.core.common.util.UtilTime;
import mineplex.core.common.util.UtilWorld;
import mineplex.core.common.util.UtilText.TextAlign;
import mineplex.core.donation.Donor;
import mineplex.core.packethandler.IPacketRunnable;
import mineplex.core.packethandler.PacketHandler;
@ -55,14 +55,14 @@ import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.events.GameStateChangeEvent;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import net.minecraft.server.v1_7_R3.DataWatcher;
import net.minecraft.server.v1_7_R3.Packet;
import net.minecraft.server.v1_7_R3.PacketPlayOutSpawnEntityLiving;
import net.minecraft.server.v1_7_R3.PacketPlayOutEntityMetadata;
import net.minecraft.server.v1_7_R3.PacketPlayOutSpawnEntityLiving;
import net.minecraft.server.v1_7_R3.WatchableObject;
public class GameLobbyManager implements IPacketRunnable, Listener
@ -977,18 +977,15 @@ public class GameLobbyManager implements IPacketRunnable, Listener
System.out.println("Manager.GetServerConfig() is null");
}
if (client.GetRank().Has(Rank.ULTRA) || donor.OwnsUnknownPackage(game.GetName() + " " + ent.GetKit().GetName()) || donor.OwnsUnknownPackage(Manager.GetServerConfig().ServerType + " ULTRA") || ent.GetKit().GetAvailability() == KitAvailability.Free)
if (ent.GetKit().GetAvailability() == KitAvailability.Free || //Free
donor.OwnsUnknownPackage(Manager.GetGame().GetName() + " " + ent.GetKit().GetName())) //Green or Blue
{
entityName = ent.GetKit().GetAvailability().GetColor() + entityName;
}
else
{
entityName = ChatColor.RED + C.Bold + entityName;
if (ent.GetKit().GetAvailability() != KitAvailability.Blue)
entityName += ChatColor.RESET + " " + ChatColor.WHITE + C.Line + ent.GetKit().GetCost() + " Gems";
else
entityName += ChatColor.RESET + " " + ChatColor.WHITE + C.Line + "Ultra";
entityName += ChatColor.RESET + " (" + ent.GetKit().GetAvailability().GetColor() + ent.GetKit().GetCost() + " Gems" + ChatColor.RESET + ")";
}
return entityName;

View File

@ -2,28 +2,6 @@ package nautilus.game.arcade.managers;
import java.util.ArrayList;
import mineplex.core.account.CoreClient;
import mineplex.core.common.CurrencyType;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.donation.Donor;
import mineplex.core.shop.page.ConfirmationPage;
import mineplex.minecraft.game.core.combat.event.CombatDeathEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.shop.ArcadeShop;
import nautilus.game.arcade.shop.KitPackage;
import net.minecraft.server.v1_7_R3.PacketPlayOutEntityMetadata;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
import org.bukkit.Location;
import org.bukkit.Sound;
@ -42,6 +20,25 @@ import org.bukkit.event.player.PlayerInteractEntityEvent;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import mineplex.core.common.CurrencyType;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.donation.Donor;
import mineplex.core.shop.page.ConfirmationPage;
import mineplex.minecraft.game.core.combat.event.CombatDeathEvent;
import mineplex.minecraft.game.core.damage.CustomDamageEvent;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.game.Game;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.game.GameTeam;
import nautilus.game.arcade.kit.Kit;
import nautilus.game.arcade.kit.KitAvailability;
import nautilus.game.arcade.shop.ArcadeShop;
import nautilus.game.arcade.shop.KitPackage;
import net.minecraft.server.v1_7_R3.PacketPlayOutEntityMetadata;
public class GamePlayerManager implements Listener
{
ArcadeManager Manager;
@ -314,15 +311,14 @@ public class GamePlayerManager implements Listener
if (!Manager.GetGame().HasKit(kit))
return;
CoreClient client = Manager.GetClients().Get(player);
Donor donor = Manager.GetDonation().Get(player.getName());
if (kit.GetAvailability() == KitAvailability.Free || client.GetRank().Has(Rank.ULTRA) || donor.OwnsUnknownPackage(Manager.GetServerConfig().ServerType + " ULTRA") || donor.OwnsUnknownPackage(Manager.GetGame().GetName() + " " + kit.GetName()))
if (kit.GetAvailability() == KitAvailability.Free || //Free
donor.OwnsUnknownPackage(Manager.GetGame().GetName() + " " + kit.GetName())) //Green or Blue
{
Manager.GetGame().SetKit(player, kit, true);
}
else if (kit.GetAvailability() == KitAvailability.Green && donor.GetBalance(CurrencyType.Gems) > kit.GetCost())
else if ((kit.GetAvailability() == KitAvailability.Green || kit.GetAvailability() == KitAvailability.Blue) && donor.GetBalance(CurrencyType.Gems) > kit.GetCost())
{
Manager.GetShop().OpenPageForPlayer(player, new ConfirmationPage<ArcadeManager, ArcadeShop>(
Manager, Manager.GetShop(), Manager.GetClients(), Manager.GetDonation(), new Runnable()
@ -341,16 +337,7 @@ public class GamePlayerManager implements Listener
{
player.playSound(player.getLocation(), Sound.NOTE_BASS, 2f, 0.5f);
if (kit.GetAvailability() == KitAvailability.Blue)
{
UtilPlayer.message(player, F.main("Kit", "This kit requires " + F.elem(C.cAqua + "Ultra") + "."));
UtilPlayer.message(player, F.main("Kit", "Purchase at " + F.elem(C.cYellow + "www.mineplex.com/shop")));
}
else
{
UtilPlayer.message(player, F.main("Kit", "You do not have enough " + F.elem(C.cGreen + "Gems") + "."));
UtilPlayer.message(player, F.main("Kit", "Purchase more at " + F.elem(C.cYellow + "www.mineplex.com/shop")));
}
UtilPlayer.message(player, F.main("Kit", "You do not have enough " + F.elem(C.cGreen + "Gems") + "."));
}
}