void checkServers() { servers .values() .stream() .filter(server -> !server.isOnline()) .forEach( server -> { ProxyServer.getInstance() .getLogger() .severe( "[Servers] Server " + server.getName() + " detected as offline, removing."); remove(server.getName()); BungeeBridge.getInstance() .getExecutor() .addTask( () -> { Jedis jedis = BungeeBridge.getInstance().getConnector().getBungeeResource(); jedis.hdel("servers", server.getName()); jedis.sadd("offlineservers", server.getName()); jedis.del("connectedonserv:" + server.getName()); jedis.publish("servers", "stop " + server.getName()); jedis.close(); }); }); }
public ServersManager(BungeeBridge plugin) { this.plugin = plugin; // Recover servers // Jedis jedis = plugin.getConnector().getBungeeResource(); Map<String, String> servers = jedis.hgetAll("servers"); jedis.close(); for (String server : servers.keySet()) { String[] ip = servers.get(server).split(":"); if (ip.length == 2) createServer(server, ip[0], ip[1]); } // Init task ProxyServer.getInstance() .getScheduler() .schedule(plugin, this::checkServers, 30, 30, TimeUnit.SECONDS); thread = new SubscribingThread( SubscribingThread.Type.SUBSCRIBE, plugin.getConnector(), new Subscriber(this), "servers"); new Thread(thread).start(); }
public Set<UUID> getPlayers() { Jedis jedis = BungeeBridge.getInstance().getConnector().getBungeeResource(); Set<String> list = jedis.smembers("connectedonserv:" + name); jedis.close(); return list.stream().map(UUID::fromString).collect(Collectors.toSet()); }
public void createServer(String server, String ip, String port) { InetSocketAddress address = new InetSocketAddress(ip, Integer.parseInt(port)); ServerInfo info = ProxyServer.getInstance() .constructServerInfo(server, address, "Automatically added server", false); ProxyServer.getInstance().getServers().put(server, info); RemoteServer remoteServer = new RemoteServer(new Date(), server, info); this.servers.put(server, remoteServer); ProxyServer.getInstance() .getLogger() .info("[Servers] Created server " + server + ", " + ip + ":" + port); BungeeBridge.getInstance() .getExecutor() .addTask( () -> { Jedis jedis = BungeeBridge.getInstance().getConnector().getBungeeResource(); jedis.srem("offlineservers", server); jedis.close(); }); }
@EventHandler public void onJoin(final PostLoginEvent e) { final ProxiedPlayer p = e.getPlayer(); ProxyServer.getInstance() .getScheduler() .runAsync( plugin, () -> { TextComponent welcome = new TextComponent("Bienvenue, " + p.getName() + " !"); welcome.setColor(ChatColor.GOLD); String key = "rejoinlist:" + e.getPlayer().getUniqueId().toString(); Jedis cache = plugin.getConnector().getBungeeResource(); String srv = cache.get(key); cache.close(); if (srv != null) { final ServerInfo server = ProxyServer.getInstance().getServerInfo(srv); if (server != null) ProxyServer.getInstance() .getScheduler() .schedule( plugin, () -> e.getPlayer() .connect( server, (aBoolean, throwable) -> { if (aBoolean) { p.sendMessage( new ComponentBuilder("") .color(ChatColor.GREEN) .append("Vous avez été remis en jeu.") .create()); } }), 200L, TimeUnit.MILLISECONDS); } }); }
public ServerInfo getServer(UUID player) { PlayerData data = plugin.getPlayerDataManager().getPlayerData(player); String server = data.get("currentserver"); if (server == null) return null; return ProxyServer.getInstance().getServerInfo(server); }
public void disable() { plugin.getLogger().info("[Disabling Servers Manager] Killing subscribtions..."); thread.disable(); }