diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java index 1da753018..6a42a4cae 100644 --- a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/ClansManager.java @@ -56,6 +56,7 @@ import mineplex.game.clans.clans.commands.ClanManagementCommand; import mineplex.game.clans.clans.commands.ClansAllyChatCommand; import mineplex.game.clans.clans.commands.ClansChatCommand; import mineplex.game.clans.clans.commands.ClansCommand; +import mineplex.game.clans.clans.commands.ClansLoginManager; import mineplex.game.clans.clans.commands.MapCommand; import mineplex.game.clans.clans.commands.RegionsCommand; import mineplex.game.clans.clans.commands.ServerTimeCommand; @@ -182,6 +183,8 @@ public class ClansManager extends MiniClientPlugin implements IRelat _itemMapManager = new ItemMapManager(this, _worldEvent); _explosion = new Explosion(plugin, blockRestore); + + new ClansLoginManager(getPlugin(), clientManager, _serverName); Energy energy = new Energy(plugin); // TODO: Re-enable customtagfix with NCP update? diff --git a/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansLoginManager.java b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansLoginManager.java new file mode 100644 index 000000000..f8d2f6de7 --- /dev/null +++ b/Plugins/Mineplex.Game.Clans/src/mineplex/game/clans/clans/commands/ClansLoginManager.java @@ -0,0 +1,68 @@ +package mineplex.game.clans.clans.commands; + +import java.sql.ResultSet; +import java.sql.SQLException; + +import org.bukkit.entity.Player; +import org.bukkit.plugin.java.JavaPlugin; + +import mineplex.core.MiniPlugin; +import mineplex.core.account.CoreClientManager; +import mineplex.core.account.ILoginProcessor; +import mineplex.core.common.util.UtilPlayer; +import mineplex.database.Tables; +import org.jooq.impl.DSL; + +public class ClansLoginManager extends MiniPlugin implements ILoginProcessor +{ + private String _serverName; + + public ClansLoginManager(JavaPlugin plugin, CoreClientManager clientManager, String serverName) + { + super("Clans Login Manager", plugin); + + _serverName = serverName; + clientManager.addStoredProcedureLoginProcessor(this); + } + + private void kickPlayer(Player player, String homeServer) + { + player.kickPlayer("This is not your home server. To play clans, connect to " + homeServer); + + } + + @Override + public void processLoginResultSet(final String playerName, int accountId, ResultSet resultSet) throws SQLException + { + while (resultSet.next()) + { + final String serverName = resultSet.getString(1); + + if (serverName != null) + { + System.out.println("Player " + playerName + " is from server: " + serverName); + + + if (!serverName.equals(_serverName)) + { + runSyncLater(new Runnable() + { + @Override + public void run() + { + final Player player = UtilPlayer.searchExact(playerName); + if (player != null) + kickPlayer(player, serverName); + } + }, 20); + } + } + } + } + + @Override + public String getQuery(int accountId, String uuid, String name) + { + return "SELECT `clanServer`.`serverName` FROM `accountClan` JOIN `clans` ON `clans`.`id` = `accountClan`.`clanId` JOIN `clanServer` ON `clanServer`.`id` = `clans`.`serverId` WHERE `accountClan`.`accountId` = " + accountId + ";"; + } +}