Portal now checks server status and player's rank before sending them to a server to prevent login spam.
Refactored portal method names.
This commit is contained in:
parent
47fc6e3b94
commit
8e04a2a5f2
@ -367,7 +367,7 @@ public class AntiHack extends MiniPlugin
|
||||
UtilPlayer.message(player, "If you were not cheating, you will not be banned.");
|
||||
UtilPlayer.message(player, "");
|
||||
UtilPlayer.message(player, C.cGold + C.Strike + "---------------------------------------------");
|
||||
Portal.SendPlayerToServer(player, "Lobby");
|
||||
Portal.sendPlayerToServer(player, "Lobby");
|
||||
}
|
||||
|
||||
UtilServer.broadcast(F.main("MAC", player.getName() + " was kicked for suspicious movement."));
|
||||
|
@ -66,7 +66,7 @@ public class Idle extends MiniPlugin implements Detector
|
||||
|
||||
UtilPlayer.message(player, C.cRed + C.Bold + "Mineplex Anti-Cheat detected Lagging / Fly (Idle)");
|
||||
UtilPlayer.message(player, C.cRed + C.Bold + "You have been returned to Lobby.");
|
||||
Host.Portal.SendPlayerToServer(player, "Lobby");
|
||||
Host.Portal.sendPlayerToServer(player, "Lobby");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,7 @@ public class SendCommand extends CommandBase<Portal>
|
||||
return;
|
||||
}
|
||||
|
||||
Plugin.DoesServerExist(serverTarget, new Callback<Boolean>()
|
||||
Plugin.doesServerExist(serverTarget, new Callback<Boolean>()
|
||||
{
|
||||
public void run(Boolean serverExists)
|
||||
{
|
||||
|
@ -40,7 +40,7 @@ public class ServerCommand extends CommandBase<Portal>
|
||||
}
|
||||
else
|
||||
{
|
||||
Plugin.DoesServerExist(args[0], new Callback<Boolean>()
|
||||
Plugin.doesServerExist(args[0], new Callback<Boolean>()
|
||||
{
|
||||
public void run(final Boolean serverExists)
|
||||
{
|
||||
@ -59,34 +59,34 @@ public class ServerCommand extends CommandBase<Portal>
|
||||
if (servUp.contains("HERO"))
|
||||
{
|
||||
if (playerRank.Has(Rank.HERO))
|
||||
Plugin.SendPlayerToServerWithMessage(player, args[0]);
|
||||
Plugin.sendPlayerToServer(player, args[0]);
|
||||
else
|
||||
deniedAccess = true;
|
||||
}
|
||||
else if (servUp.contains("ULTRA") || servUp.contains("BETA"))
|
||||
{
|
||||
if (playerRank.Has(Rank.ULTRA))
|
||||
Plugin.SendPlayerToServerWithMessage(player, args[0]);
|
||||
Plugin.sendPlayerToServer(player, args[0]);
|
||||
else
|
||||
deniedAccess = true;
|
||||
}
|
||||
else if (servUp.contains("STAFF"))
|
||||
{
|
||||
if (playerRank.Has(Rank.HELPER))
|
||||
Plugin.SendPlayerToServerWithMessage(player, args[0]);
|
||||
Plugin.sendPlayerToServer(player, args[0]);
|
||||
else
|
||||
deniedAccess = true;
|
||||
}
|
||||
else if (servUp.contains("TEST"))
|
||||
{
|
||||
if (playerRank.Has(Rank.MODERATOR))
|
||||
Plugin.SendPlayerToServerWithMessage(player, args[0]);
|
||||
Plugin.sendPlayerToServer(player, args[0]);
|
||||
else
|
||||
deniedAccess = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Plugin.SendPlayerToServerWithMessage(player, args[0]);
|
||||
Plugin.sendPlayerToServer(player, args[0]);
|
||||
}
|
||||
|
||||
if (deniedAccess)
|
||||
|
@ -6,40 +6,46 @@ import java.io.IOException;
|
||||
import java.util.HashSet;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.Callback;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
import mineplex.core.portal.Commands.*;
|
||||
import mineplex.serverdata.MinecraftServer;
|
||||
import mineplex.serverdata.Region;
|
||||
import mineplex.serverdata.ServerCommandManager;
|
||||
import mineplex.serverdata.ServerManager;
|
||||
import mineplex.serverdata.ServerRepository;
|
||||
import mineplex.serverdata.transfers.ServerTransfer;
|
||||
import mineplex.serverdata.transfers.TransferCommand;
|
||||
|
||||
public class Portal extends MiniPlugin
|
||||
{
|
||||
|
||||
// The singleton instance of Portal
|
||||
private static Portal instance;
|
||||
public static Portal getInstance() { return instance; }
|
||||
|
||||
private ServerRepository _repository;
|
||||
private CoreClientManager _clientManager;
|
||||
private HashSet<String> _connectingPlayers = new HashSet<String>();
|
||||
|
||||
private Region _region;
|
||||
|
||||
public Portal(JavaPlugin plugin, String serverName)
|
||||
public Portal(JavaPlugin plugin, CoreClientManager clientManager, String serverName)
|
||||
{
|
||||
super("Portal", plugin);
|
||||
|
||||
instance = this;
|
||||
_clientManager = clientManager;
|
||||
|
||||
this._region = plugin.getConfig().getBoolean("serverstatus.us") ? Region.US : Region.EU;
|
||||
_region = plugin.getConfig().getBoolean("serverstatus.us") ? Region.US : Region.EU;
|
||||
_repository = ServerManager.getServerRepository(_region);
|
||||
|
||||
Bukkit.getMessenger().registerOutgoingPluginChannel(GetPlugin(), "BungeeCord");
|
||||
|
||||
@ -47,66 +53,83 @@ public class Portal extends MiniPlugin
|
||||
ServerCommandManager.getInstance().registerCommandType("TransferCommand", TransferCommand.class, new TransferHandler());
|
||||
}
|
||||
|
||||
public void SendAllPlayers(String serverName)
|
||||
public void sendAllPlayers(String serverName)
|
||||
{
|
||||
for (Player player : Bukkit.getOnlinePlayers())
|
||||
{
|
||||
SendPlayerToServer(player, serverName);
|
||||
sendPlayerToServer(player, serverName);
|
||||
}
|
||||
}
|
||||
|
||||
public void SendPlayerToServerWithMessage(Player player, String serverName)
|
||||
{
|
||||
SendPlayerToServer(player, serverName);
|
||||
|
||||
player.playSound(player.getLocation(), Sound.PORTAL, 0.5f, 2f);
|
||||
|
||||
UtilPlayer
|
||||
.message(
|
||||
player,
|
||||
F.main(getName(), C.cGray + "You have been sent to server: " + C.cGold + serverName
|
||||
+ C.cGray + "!"));
|
||||
}
|
||||
|
||||
public void SendPlayerToServer(final Player player, String serverName)
|
||||
public void sendPlayerToServer(final Player player, final String serverName)
|
||||
{
|
||||
if (_connectingPlayers.contains(player.getName()))
|
||||
return;
|
||||
|
||||
ByteArrayOutputStream b = new ByteArrayOutputStream();
|
||||
DataOutputStream out = new DataOutputStream(b);
|
||||
|
||||
try
|
||||
{
|
||||
out.writeUTF("Connect");
|
||||
out.writeUTF(serverName);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
// Can never happen
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
out.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
final Rank playerRank = _clientManager.Get(player).GetRank();
|
||||
|
||||
player.sendPluginMessage(GetPlugin(), "BungeeCord", b.toByteArray());
|
||||
_connectingPlayers.add(player.getName());
|
||||
|
||||
GetScheduler().scheduleSyncDelayedTask(GetPlugin(), new Runnable()
|
||||
runAsync(new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
_connectingPlayers.remove(player.getName());
|
||||
final MinecraftServer server = _repository.getServerStatus(serverName);
|
||||
|
||||
if (server == null)
|
||||
return;
|
||||
|
||||
Bukkit.getServer().getScheduler().runTask(_plugin, new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
if (server.getPlayerCount() < server.getMaxPlayerCount() || playerRank.Has(Rank.ULTRA))
|
||||
{
|
||||
ByteArrayOutputStream b = new ByteArrayOutputStream();
|
||||
DataOutputStream out = new DataOutputStream(b);
|
||||
|
||||
try
|
||||
{
|
||||
out.writeUTF("Connect");
|
||||
out.writeUTF(serverName);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
// Can never happen
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
out.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
player.sendPluginMessage(GetPlugin(), "BungeeCord", b.toByteArray());
|
||||
_connectingPlayers.add(player.getName());
|
||||
|
||||
GetScheduler().scheduleSyncDelayedTask(GetPlugin(), new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
_connectingPlayers.remove(player.getName());
|
||||
}
|
||||
}, 20L);
|
||||
|
||||
UtilPlayer.message(
|
||||
player,
|
||||
F.main(getName(), "You have been sent to " + C.cGold + serverName));
|
||||
}
|
||||
else
|
||||
UtilPlayer.message(
|
||||
player,
|
||||
F.main(getName(), C.cGold + serverName + C.cRed + " is full!"));
|
||||
}
|
||||
});
|
||||
}
|
||||
}, 20L);
|
||||
});
|
||||
}
|
||||
|
||||
public static void transferPlayer(String playerName, String serverName)
|
||||
@ -116,7 +139,7 @@ public class Portal extends MiniPlugin
|
||||
transferCommand.publish();
|
||||
}
|
||||
|
||||
public void DoesServerExist(final String serverName, final Callback<Boolean> callback)
|
||||
public void doesServerExist(final String serverName, final Callback<Boolean> callback)
|
||||
{
|
||||
if (callback == null)
|
||||
return;
|
||||
|
@ -21,7 +21,7 @@ public class TransferHandler implements CommandCallback
|
||||
|
||||
if (player != null && player.isOnline())
|
||||
{
|
||||
Portal.getInstance().SendPlayerToServer(player, transfer.getServerName());
|
||||
Portal.getInstance().sendPlayerToServer(player, transfer.getServerName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -64,7 +64,7 @@ public class FileUpdater extends MiniPlugin
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
_portal.SendAllPlayers("Lobby");
|
||||
_portal.sendAllPlayers("Lobby");
|
||||
}
|
||||
}, 60L);
|
||||
|
||||
|
@ -68,7 +68,7 @@ public class Clans extends JavaPlugin
|
||||
ServerStatusManager serverStatusManager = new ServerStatusManager(this, _clientManager, new LagMeter(this, _clientManager));
|
||||
new Spawn(this, serverStatusManager.getCurrentServerName());
|
||||
Teleport teleport = new Teleport(this);
|
||||
Portal portal = new Portal(this, serverStatusManager.getCurrentServerName());
|
||||
Portal portal = new Portal(this, _clientManager, serverStatusManager.getCurrentServerName());
|
||||
new FileUpdater(this, portal);
|
||||
|
||||
|
||||
|
@ -99,7 +99,7 @@ public class Hub extends JavaPlugin implements IRelation
|
||||
//Main Modules
|
||||
ServerStatusManager serverStatusManager = new ServerStatusManager(this, clientManager, new LagMeter(this, clientManager));
|
||||
PartyManager partyManager = new PartyManager(this, clientManager, preferenceManager);
|
||||
Portal portal = new Portal(this, serverStatusManager.getCurrentServerName());
|
||||
Portal portal = new Portal(this, clientManager, serverStatusManager.getCurrentServerName());
|
||||
AntiHack.Initialize(this, punish, portal, preferenceManager, clientManager);
|
||||
StatsManager statsManager = new StatsManager(this, clientManager);
|
||||
AchievementManager achievementManager = new AchievementManager(statsManager, clientManager, donationManager);
|
||||
|
@ -422,7 +422,7 @@ public class HubManager extends MiniClientPlugin<HubClient>
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
_portal.SendAllPlayers("Lobby");
|
||||
_portal.sendAllPlayers("Lobby");
|
||||
|
||||
Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(_plugin, new Runnable()
|
||||
{
|
||||
@ -483,7 +483,7 @@ public class HubManager extends MiniClientPlugin<HubClient>
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
_portal.SendPlayerToServer(event.getPlayer(), "Lobby");
|
||||
_portal.sendPlayerToServer(event.getPlayer(), "Lobby");
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -530,7 +530,7 @@ public class ServerManager extends MiniPlugin
|
||||
partyPlayer.leaveVehicle();
|
||||
partyPlayer.eject();
|
||||
|
||||
_portal.SendPlayerToServer(partyPlayer, serverInfo.Name);
|
||||
_portal.sendPlayerToServer(partyPlayer, serverInfo.Name);
|
||||
}
|
||||
|
||||
for (String name : party.GetPlayers())
|
||||
@ -548,7 +548,7 @@ public class ServerManager extends MiniPlugin
|
||||
partyPlayer.leaveVehicle();
|
||||
partyPlayer.eject();
|
||||
|
||||
_portal.SendPlayerToServer(partyPlayer, serverInfo.Name);
|
||||
_portal.sendPlayerToServer(partyPlayer, serverInfo.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -558,7 +558,7 @@ public class ServerManager extends MiniPlugin
|
||||
player.leaveVehicle();
|
||||
player.eject();
|
||||
|
||||
_portal.SendPlayerToServer(player, serverInfo.Name);
|
||||
_portal.sendPlayerToServer(player, serverInfo.Name);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -56,7 +56,7 @@ public class StaffServer extends JavaPlugin
|
||||
PreferencesManager preferenceManager = new PreferencesManager(this, clientManager, donationManager);
|
||||
preferenceManager.GiveItem = false;
|
||||
|
||||
Portal portal = new Portal(this, serverStatusManager.getCurrentServerName());
|
||||
Portal portal = new Portal(this, clientManager, serverStatusManager.getCurrentServerName());
|
||||
new Chat(this, clientManager, preferenceManager, serverStatusManager.getCurrentServerName());
|
||||
new MemoryFix(this);
|
||||
new FileUpdater(this, portal);
|
||||
|
@ -93,7 +93,7 @@ public class Arcade extends JavaPlugin
|
||||
ServerStatusManager serverStatusManager = new ServerStatusManager(this, _clientManager, new LagMeter(this, _clientManager));
|
||||
new Spawn(this, serverStatusManager.getCurrentServerName());
|
||||
Teleport teleport = new Teleport(this);
|
||||
Portal portal = new Portal(this, serverStatusManager.getCurrentServerName());
|
||||
Portal portal = new Portal(this, _clientManager, serverStatusManager.getCurrentServerName());
|
||||
new FileUpdater(this, portal);
|
||||
PacketHandler packetHandler = new PacketHandler(this);
|
||||
|
||||
|
@ -2750,7 +2750,7 @@ public class MineStrike extends TeamGame
|
||||
UtilPlayer.message(player, " ");
|
||||
|
||||
player.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 10f, 1f);
|
||||
Manager.GetPortal().SendPlayerToServer(player, "Lobby");
|
||||
Manager.GetPortal().sendPlayerToServer(player, "Lobby");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
|
@ -1280,7 +1280,7 @@ public class UHC extends TeamGame
|
||||
UtilPlayer.message(player, " ");
|
||||
|
||||
player.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 10f, 1f);
|
||||
Manager.GetPortal().SendPlayerToServer(player, "Lobby");
|
||||
Manager.GetPortal().sendPlayerToServer(player, "Lobby");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -196,7 +196,7 @@ public class GameHostManager implements Listener
|
||||
{
|
||||
UtilPlayer.message(other, C.cGold + C.Bold + string);
|
||||
other.playSound(other.getLocation(), Sound.ENDERDRAGON_GROWL, 10f, 1f);
|
||||
Manager.GetPortal().SendPlayerToServer(other, "Lobby");
|
||||
Manager.GetPortal().sendPlayerToServer(other, "Lobby");
|
||||
}
|
||||
|
||||
_hostExpired = expired;
|
||||
@ -396,7 +396,7 @@ public class GameHostManager implements Listener
|
||||
UtilPlayer.message(player, C.cGold + C.Bold + "You were kicked from this Mineplex Private Server.");
|
||||
|
||||
player.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 10f, 1f);
|
||||
Manager.GetPortal().SendPlayerToServer(player, "Lobby");
|
||||
Manager.GetPortal().sendPlayerToServer(player, "Lobby");
|
||||
}
|
||||
|
||||
public void giveAdmin(Player player)
|
||||
|
@ -491,7 +491,7 @@ public class GameManager implements Listener
|
||||
if (player.isDead())
|
||||
{
|
||||
player.sendMessage(F.main("Afk Monitor", "You are being sent to the Lobby for being AFK."));
|
||||
Manager.GetPortal().SendPlayerToServer(player, "Lobby");
|
||||
Manager.GetPortal().sendPlayerToServer(player, "Lobby");
|
||||
}
|
||||
else if (Manager.IsObserver(player))
|
||||
{
|
||||
|
@ -94,7 +94,7 @@ public class IdleManager implements Listener
|
||||
if (count == 0)
|
||||
{
|
||||
player.playSound(player.getLocation(), Sound.ENDERDRAGON_GROWL, 10f, 1f);
|
||||
getArcadeManager().GetPortal().SendPlayerToServer(player, "Lobby");
|
||||
getArcadeManager().GetPortal().sendPlayerToServer(player, "Lobby");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -126,7 +126,7 @@ public class MiscManager implements Listener
|
||||
if (!Recharge.Instance.usable(event.getPlayer(), "Return to Hub"))
|
||||
return;
|
||||
|
||||
Manager.GetPortal().SendPlayerToServer(player, "Lobby");
|
||||
Manager.GetPortal().sendPlayerToServer(player, "Lobby");
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -134,7 +134,7 @@ public class MiscManager implements Listener
|
||||
{
|
||||
if (event.getMessage().toLowerCase().startsWith("/lobby") || event.getMessage().toLowerCase().startsWith("/hub") || event.getMessage().toLowerCase().startsWith("/leave"))
|
||||
{
|
||||
Manager.GetPortal().SendPlayerToServer(event.getPlayer(), "Lobby");
|
||||
Manager.GetPortal().sendPlayerToServer(event.getPlayer(), "Lobby");
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user