Merge branch 'master' of ssh://184.154.0.242:7999/min/Mineplex
This commit is contained in:
commit
41189b9838
@ -87,23 +87,10 @@ public abstract class ShopBase<PluginType extends MiniPlugin> implements Listene
|
||||
|
||||
private boolean attemptShopOpen(Player player, LivingEntity entity)
|
||||
{
|
||||
if (!_openedShop.contains(player.getName()) && entity.isCustomNameVisible() && entity.getCustomName() != null && ChatColor.stripColor(entity.getCustomName()).equalsIgnoreCase(ChatColor.stripColor(_name)))
|
||||
{
|
||||
if (!canOpenShop(player))
|
||||
return false;
|
||||
|
||||
_openedShop.add(player.getName());
|
||||
|
||||
openShopForPlayer(player);
|
||||
if (!_playerPageMap.containsKey(player.getName()))
|
||||
{
|
||||
_playerPageMap.put(player.getName(), buildPagesFor(player));
|
||||
}
|
||||
|
||||
openPageForPlayer(player, getOpeningPageForPlayer(player));
|
||||
|
||||
return true;
|
||||
}
|
||||
if (entity.isCustomNameVisible() && entity.getCustomName() != null && ChatColor.stripColor(entity.getCustomName()).equalsIgnoreCase(ChatColor.stripColor(_name)))
|
||||
{
|
||||
return attemptShopOpen(player);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -116,10 +116,8 @@ public class ServerStatusManager extends MiniPlugin
|
||||
if (event.getType() != UpdateType.FASTER)
|
||||
return;
|
||||
|
||||
if (!_enabled)
|
||||
return;
|
||||
|
||||
saveServerStatus();
|
||||
if (_enabled)
|
||||
saveServerStatus();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -139,19 +137,6 @@ public class ServerStatusManager extends MiniPlugin
|
||||
if (server != null && !server.getPublicAddress().equalsIgnoreCase(serverSnapshot.getPublicAddress()))
|
||||
{
|
||||
timeout = -DEFAULT_SERVER_TIMEOUT;
|
||||
/*
|
||||
ProcessRunner pr = new ProcessRunner(new String[] {"/bin/sh", "/home/mineplex/config/killServer.sh", serverSnapshot.getName()});
|
||||
pr.start(new GenericRunnable<Boolean>()
|
||||
{
|
||||
public void run(Boolean error)
|
||||
{
|
||||
if (error)
|
||||
log("Error Killing myself.");
|
||||
else
|
||||
log("It worked.");
|
||||
}
|
||||
});
|
||||
*/
|
||||
}
|
||||
|
||||
_repository.updataServerStatus(serverSnapshot, timeout);
|
||||
|
@ -10,4 +10,9 @@ public class ServerInfo
|
||||
public String ServerType;
|
||||
public String Game;
|
||||
public boolean HostedByStaff;
|
||||
|
||||
public int getAvailableSlots()
|
||||
{
|
||||
return MaxPlayers - CurrentPlayers;
|
||||
}
|
||||
}
|
@ -10,6 +10,7 @@ import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
@ -56,6 +57,7 @@ import mineplex.hub.queue.QueueManager;
|
||||
import mineplex.hub.queue.ui.QueueShop;
|
||||
import mineplex.hub.server.ui.LobbyShop;
|
||||
import mineplex.hub.server.ui.QuickShop;
|
||||
import mineplex.hub.server.ui.ServerCountSorter;
|
||||
import mineplex.hub.server.ui.ServerNpcShop;
|
||||
import mineplex.serverdata.data.MinecraftServer;
|
||||
import mineplex.serverdata.data.ServerGroup;
|
||||
@ -64,6 +66,10 @@ public class ServerManager extends MiniPlugin
|
||||
{
|
||||
private static final Long FREE_PORTAL_TIMER = 20000L;
|
||||
private static final Long BETA_PORTAL_TIMER = 120000L;
|
||||
private static final Random random = new Random();
|
||||
|
||||
public final int TOP_SERVERS = 3; // The number of top contending servers for auto-joining games
|
||||
public final int MIN_SLOTS_REQUIRED = 12; // The number of slots the max server must have for auto-join
|
||||
|
||||
private CoreClientManager _clientManager;
|
||||
private DonationManager _donationManager;
|
||||
@ -314,7 +320,11 @@ public class ServerManager extends MiniPlugin
|
||||
public void AddServerNpc(String serverNpcName, String...serverTag)
|
||||
{
|
||||
addServerGroup(serverNpcName, serverTag);
|
||||
_serverNpcShopMap.put(serverNpcName, new ServerNpcShop(this, _clientManager, _donationManager, serverNpcName));
|
||||
|
||||
// TODO: Determine whether server group is team based or not
|
||||
boolean teamBased = false;
|
||||
|
||||
_serverNpcShopMap.put(serverNpcName, new ServerNpcShop(this, _clientManager, _donationManager, serverNpcName, teamBased));
|
||||
}
|
||||
|
||||
public void RemoveServerNpc(String serverNpcName)
|
||||
@ -396,7 +406,6 @@ public class ServerManager extends MiniPlugin
|
||||
|
||||
_retrieving = true;
|
||||
|
||||
|
||||
_statusManager.retrieveServerGroups(new Callback<Collection<ServerGroup>>()
|
||||
{
|
||||
public void run(final Collection<ServerGroup> serverGroups)
|
||||
@ -522,6 +531,70 @@ public class ServerManager extends MiniPlugin
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Select a {@code serverType} for a {@code player} that wishes to automatically join the best server
|
||||
* available for that server type.
|
||||
* @param player - the player hoping to select a server
|
||||
* @param serverType - the name of the type of server to be joined
|
||||
*/
|
||||
public void selectServer(Player player, String serverType)
|
||||
{
|
||||
ServerInfo bestServer = getBestServer(player, serverType);
|
||||
|
||||
if (bestServer != null)
|
||||
{
|
||||
SelectServer(player, bestServer);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param serverType - the type of server that should be fetched
|
||||
* @return the best server that a new player should join according to a {@code serverType} constraint.
|
||||
*/
|
||||
public ServerInfo getBestServer(Player player, String serverType)
|
||||
{
|
||||
List<ServerInfo> servers = new ArrayList<ServerInfo>(GetServerList(serverType));
|
||||
|
||||
Collections.sort(servers, new ServerCountSorter());
|
||||
servers = fetchOpenServers(player, servers, servers.size()); // Removes all full servers from list
|
||||
|
||||
int count = Math.min(servers.size(), TOP_SERVERS);
|
||||
|
||||
if (count > 0)
|
||||
{
|
||||
ServerInfo largestServer = servers.get(0);
|
||||
|
||||
if (largestServer.getAvailableSlots() >= MIN_SLOTS_REQUIRED)
|
||||
{
|
||||
return largestServer;
|
||||
}
|
||||
else
|
||||
{
|
||||
return servers.get(random.nextInt(count));
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<ServerInfo> fetchOpenServers(Player player, List<ServerInfo> servers, int count)
|
||||
{
|
||||
List<ServerInfo> results = new ArrayList<ServerInfo>();
|
||||
int requiredSlots = (servers.size() > 0) ? GetRequiredSlots(player, servers.get(0).ServerType) : 0;
|
||||
|
||||
for (ServerInfo server : servers)
|
||||
{
|
||||
if (results.size() >= count) break;
|
||||
|
||||
if (server.getAvailableSlots() > requiredSlots)
|
||||
{
|
||||
results.add(server);
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
public void ListServerNpcs(Player caller)
|
||||
{
|
||||
UtilPlayer.message(caller, F.main(getName(), "Listing Server Npcs:"));
|
||||
|
@ -0,0 +1,13 @@
|
||||
package mineplex.hub.server.ui;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import mineplex.hub.server.ServerInfo;
|
||||
|
||||
public class ServerCountSorter implements Comparator<ServerInfo>
|
||||
{
|
||||
public int compare(ServerInfo a, ServerInfo b)
|
||||
{
|
||||
return a.CurrentPlayers - b.CurrentPlayers;
|
||||
}
|
||||
}
|
@ -401,7 +401,7 @@ public class ServerNpcPage extends ShopPageBase<ServerManager, ServerNpcShop> im
|
||||
{
|
||||
int slots = getPlugin().GetRequiredSlots(player, serverInfo.ServerType);
|
||||
|
||||
if (serverInfo.MaxPlayers - serverInfo.CurrentPlayers < slots && !(getDonationManager().Get(getPlayer().getName()).OwnsUnknownPackage(serverInfo.ServerType + " ULTRA") || getClient().GetRank().Has(Rank.ULTRA)))
|
||||
if (serverInfo.getAvailableSlots() < slots && !(getDonationManager().Get(getPlayer().getName()).OwnsUnknownPackage(serverInfo.ServerType + " ULTRA") || getClient().GetRank().Has(Rank.ULTRA)))
|
||||
{
|
||||
playDenySound(player);
|
||||
return;
|
||||
|
@ -14,9 +14,13 @@ import mineplex.hub.server.ServerManager;
|
||||
|
||||
public class ServerNpcShop extends ShopBase<ServerManager>
|
||||
{
|
||||
public ServerNpcShop(ServerManager plugin, CoreClientManager clientManager, DonationManager donationManager, String name)
|
||||
private boolean _teamBased; // Whether this server type has a team/solo based component
|
||||
|
||||
public ServerNpcShop(ServerManager plugin, CoreClientManager clientManager, DonationManager donationManager, String name, boolean teamBased)
|
||||
{
|
||||
super(plugin, clientManager, donationManager, name);
|
||||
|
||||
_teamBased = teamBased;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -65,4 +69,19 @@ public class ServerNpcShop extends ShopBase<ServerManager>
|
||||
{
|
||||
getPlugin().getHubManager().GetVisibility().removeHiddenPlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean attemptShopOpen(Player player)
|
||||
{
|
||||
if (!_teamBased) // Check this isn't a team/solo gametype shop
|
||||
{
|
||||
getPlugin().selectServer(player, getName());
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// TODO: Open up team/solo selection menu and then select appropriate server
|
||||
return super.attemptShopOpen(player);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user