Add support for clans hub connection inside bungees
This commit is contained in:
parent
818ed4c9a9
commit
9fab8366b7
@ -16,9 +16,11 @@ public class Mineplexer extends Plugin
|
||||
{
|
||||
@Override
|
||||
public void onEnable() {
|
||||
getProxy().getScheduler().runAsync(this, new Runnable() {
|
||||
getProxy().getScheduler().runAsync(this, new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run() {
|
||||
public void run()
|
||||
{
|
||||
// Sentry setup
|
||||
Handler sentry = new SentryHandler(new DefaultRavenFactory().createRavenInstance(
|
||||
new Dsn("https://470f12378af3453ba089e0c0a0c9aae6:292516b722594784807aebb06db8ec38@app.getsentry.com/66323"
|
||||
@ -30,10 +32,9 @@ public class Mineplexer extends Plugin
|
||||
|
||||
new MotdManager(this);
|
||||
new LobbyBalancer(this);
|
||||
PlayerCount playerCount = new PlayerCount(this);
|
||||
new PlayerCount(this);
|
||||
new FileUpdater(this);
|
||||
new PlayerStats(this);
|
||||
//new InternetStatus(this);
|
||||
new PlayerTracker(this);
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,6 @@ package mineplex.bungee.lobbyBalancer;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@ -12,21 +11,24 @@ import mineplex.serverdata.Region;
|
||||
import mineplex.serverdata.data.MinecraftServer;
|
||||
import mineplex.serverdata.servers.ServerManager;
|
||||
import mineplex.serverdata.servers.ServerRepository;
|
||||
import net.md_5.bungee.api.config.ServerInfo;
|
||||
import net.md_5.bungee.api.event.ServerConnectEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
import net.md_5.bungee.event.EventHandler;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
public class LobbyBalancer implements Listener, Runnable
|
||||
{
|
||||
private Plugin _plugin;
|
||||
private ServerRepository _repository;
|
||||
|
||||
private List<MinecraftServer> _sortedLobbies = new ArrayList<MinecraftServer>();
|
||||
private List<MinecraftServer> _sortedLobbies = Lists.newArrayList();
|
||||
private List<MinecraftServer> _sortedClans = Lists.newArrayList();
|
||||
private static Object _serverLock = new Object();
|
||||
|
||||
private int _lobbyIndex = 0;
|
||||
private int _clansIndex = 0;
|
||||
|
||||
public LobbyBalancer(Plugin plugin)
|
||||
{
|
||||
@ -35,7 +37,7 @@ public class LobbyBalancer implements Listener, Runnable
|
||||
Region region = !new File("eu.dat").exists() ? Region.US : Region.EU;
|
||||
_repository = ServerManager.getServerRepository(region);
|
||||
|
||||
loadLobbyServers();
|
||||
run();
|
||||
|
||||
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
|
||||
_plugin.getProxy().getScheduler().schedule(_plugin, this, 500L, 500L, TimeUnit.MILLISECONDS);
|
||||
@ -44,27 +46,49 @@ public class LobbyBalancer implements Listener, Runnable
|
||||
@EventHandler
|
||||
public void playerConnect(ServerConnectEvent event)
|
||||
{
|
||||
if (!event.getTarget().getName().equalsIgnoreCase("Lobby"))
|
||||
return;
|
||||
|
||||
synchronized (_serverLock)
|
||||
if (event.getTarget().getName().equalsIgnoreCase("Lobby"))
|
||||
{
|
||||
if (_lobbyIndex >= _sortedLobbies.size() || _sortedLobbies.get(_lobbyIndex).getPlayerCount() >= _sortedLobbies.get(_lobbyIndex).getMaxPlayerCount())
|
||||
_lobbyIndex = 0;
|
||||
|
||||
event.setTarget(_plugin.getProxy().getServerInfo(_sortedLobbies.get(_lobbyIndex).getName()));
|
||||
_sortedLobbies.get(_lobbyIndex).incrementPlayerCount(1);
|
||||
System.out.println("Sending " + event.getPlayer().getName() + " to " + _sortedLobbies.get(_lobbyIndex).getName() + "(" + _sortedLobbies.get(_lobbyIndex).getPublicAddress() + ")");
|
||||
_lobbyIndex++;
|
||||
synchronized (_serverLock)
|
||||
{
|
||||
if (_lobbyIndex >= _sortedLobbies.size() || _sortedLobbies.get(_lobbyIndex).getPlayerCount() >= _sortedLobbies.get(_lobbyIndex).getMaxPlayerCount())
|
||||
_lobbyIndex = 0;
|
||||
|
||||
event.setTarget(_plugin.getProxy().getServerInfo(_sortedLobbies.get(_lobbyIndex).getName()));
|
||||
_sortedLobbies.get(_lobbyIndex).incrementPlayerCount(1);
|
||||
System.out.println("Sending " + event.getPlayer().getName() + " to " + _sortedLobbies.get(_lobbyIndex).getName() + "(" + _sortedLobbies.get(_lobbyIndex).getPublicAddress() + ")");
|
||||
_lobbyIndex++;
|
||||
}
|
||||
}
|
||||
if (event.getTarget().getName().equalsIgnoreCase("ClansHub"))
|
||||
{
|
||||
synchronized (_serverLock)
|
||||
{
|
||||
if (_clansIndex >= _sortedClans.size() || _sortedClans.get(_clansIndex).getPlayerCount() >= _sortedClans.get(_clansIndex).getMaxPlayerCount())
|
||||
_clansIndex = 0;
|
||||
|
||||
event.setTarget(_plugin.getProxy().getServerInfo(_sortedClans.get(_clansIndex).getName()));
|
||||
_sortedClans.get(_clansIndex).incrementPlayerCount(1);
|
||||
System.out.println("Sending " + event.getPlayer().getName() + " to " + _sortedClans.get(_clansIndex).getName() + "(" + _sortedClans.get(_clansIndex).getPublicAddress() + ")");
|
||||
_clansIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void run()
|
||||
{
|
||||
loadLobbyServers();
|
||||
loadServers();
|
||||
|
||||
if (!_plugin.getProxy().getServers().containsKey("ClansHub"))
|
||||
{
|
||||
_plugin.getProxy().getServers().put("ClansHub", _plugin.getProxy().constructServerInfo("ClansHub", new InetSocketAddress("lobby.mineplex.com", 25565), "LobbyBalancer", false));
|
||||
}
|
||||
if (!_plugin.getProxy().getServers().containsKey("Lobby"))
|
||||
{
|
||||
_plugin.getProxy().getServers().put("Lobby", _plugin.getProxy().constructServerInfo("Lobby", new InetSocketAddress("lobby.mineplex.com", 25565), "LobbyBalancer", false));
|
||||
}
|
||||
}
|
||||
|
||||
public void loadLobbyServers()
|
||||
public void loadServers()
|
||||
{
|
||||
Collection<MinecraftServer> servers = _repository.getServerStatuses();
|
||||
|
||||
@ -72,6 +96,7 @@ public class LobbyBalancer implements Listener, Runnable
|
||||
{
|
||||
long startTime = System.currentTimeMillis();
|
||||
_sortedLobbies.clear();
|
||||
_sortedClans.clear();
|
||||
|
||||
for (MinecraftServer server : servers)
|
||||
{
|
||||
@ -88,9 +113,17 @@ public class LobbyBalancer implements Listener, Runnable
|
||||
_sortedLobbies.add(server);
|
||||
}
|
||||
}
|
||||
if (server.getName().toUpperCase().startsWith("CLANSHUB"))
|
||||
{
|
||||
if (server.getMotd() == null || !server.getMotd().contains("Restarting"))
|
||||
{
|
||||
_sortedClans.add(server);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Collections.sort(_sortedLobbies, new LobbySorter());
|
||||
Collections.sort(_sortedClans, new LobbySorter());
|
||||
|
||||
long timeSpentInLock = System.currentTimeMillis() - startTime;
|
||||
|
||||
|
@ -1,20 +1,18 @@
|
||||
package mineplex.bungee.motd;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import mineplex.serverdata.Region;
|
||||
import mineplex.serverdata.data.BungeeServer;
|
||||
import mineplex.serverdata.data.DataRepository;
|
||||
import mineplex.serverdata.redis.RedisDataRepository;
|
||||
import mineplex.serverdata.servers.ConnectionData;
|
||||
import mineplex.serverdata.servers.ServerManager;
|
||||
import mineplex.serverdata.servers.ConnectionData.ConnectionType;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import mineplex.serverdata.servers.ServerManager;
|
||||
import net.md_5.bungee.api.event.ProxyPingEvent;
|
||||
import net.md_5.bungee.api.plugin.Listener;
|
||||
import net.md_5.bungee.api.plugin.Plugin;
|
||||
@ -31,6 +29,8 @@ public class MotdManager implements Listener, Runnable
|
||||
private Random _random = new Random();
|
||||
private String _firstLine = " §b§l§m §8§l§m[ §r §9§lMineplex§r §f§lGames§r §8§l§m ]§b§l§m §r";
|
||||
private List<String> _motdLines;
|
||||
private String _firstCLine = " §b§l§m §8§l§m[ §r §9§lMineplex§r §f§lGames§r §8§l§m ]§b§l§m §r";
|
||||
private List<String> _motdCLines;
|
||||
|
||||
public MotdManager(Plugin plugin)
|
||||
{
|
||||
@ -70,25 +70,50 @@ public class MotdManager implements Listener, Runnable
|
||||
public void serverPing(ProxyPingEvent event)
|
||||
{
|
||||
net.md_5.bungee.api.ServerPing serverPing = event.getResponse();
|
||||
|
||||
String motd = _firstLine;
|
||||
if (_motdLines != null && _motdLines.size() > 0)
|
||||
if (event.getConnection().getListener() != null && event.getConnection().getListener().getDefaultServer().equalsIgnoreCase("ClansHub"))
|
||||
{
|
||||
motd += "\n" + _motdLines.get(_random.nextInt(_motdLines.size()));
|
||||
String motd = _firstCLine;
|
||||
if (_motdCLines != null && _motdCLines.size() > 0)
|
||||
{
|
||||
motd += "\n" + _motdCLines.get(_random.nextInt(_motdCLines.size()));
|
||||
}
|
||||
event.setResponse(new net.md_5.bungee.api.ServerPing(serverPing.getVersion(), serverPing.getPlayers(), motd, serverPing.getFaviconObject()));
|
||||
}
|
||||
else
|
||||
{
|
||||
String motd = _firstLine;
|
||||
if (_motdLines != null && _motdLines.size() > 0)
|
||||
{
|
||||
motd += "\n" + _motdLines.get(_random.nextInt(_motdLines.size()));
|
||||
}
|
||||
event.setResponse(new net.md_5.bungee.api.ServerPing(serverPing.getVersion(), serverPing.getPlayers(), motd, serverPing.getFaviconObject()));
|
||||
}
|
||||
|
||||
event.setResponse(new net.md_5.bungee.api.ServerPing(serverPing.getVersion(), serverPing.getPlayers(), motd, serverPing.getFaviconObject()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
GlobalMotd motd = _repository.getElement("MainMotd");
|
||||
|
||||
if (motd != null)
|
||||
{
|
||||
_motdLines = motd.getMotd();
|
||||
_firstLine = motd.getHeadline();
|
||||
{
|
||||
GlobalMotd motd = _repository.getElement("MainMotd");
|
||||
|
||||
if (motd != null)
|
||||
{
|
||||
_motdLines = motd.getMotd();
|
||||
_firstLine = motd.getHeadline();
|
||||
}
|
||||
}
|
||||
{
|
||||
GlobalMotd motd = _repository.getElement("ClansMotd");
|
||||
|
||||
if (motd != null)
|
||||
{
|
||||
_motdCLines = motd.getMotd();
|
||||
_firstCLine = motd.getHeadline();
|
||||
}
|
||||
else
|
||||
{
|
||||
_repository.addElement(new GlobalMotd("ClansMotd", "§4§lMineplex Clans§r", Arrays.asList("Default MOTD")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user