Fix players being able to log in multiple times via different bungees
This commit is contained in:
parent
8e7ae7f55f
commit
55b37e0261
@ -14,14 +14,12 @@ public class PlayerJoinHandler implements CommandCallback
|
|||||||
_playerTracker = playerTracker;
|
_playerTracker = playerTracker;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
@Override
|
@Override
|
||||||
public void run(ServerCommand command)
|
public void run(ServerCommand command)
|
||||||
{
|
{
|
||||||
if (command instanceof PlayerJoinCommand)
|
if (command instanceof PlayerJoinCommand)
|
||||||
{
|
{
|
||||||
PlayerJoinCommand joinCommand = (PlayerJoinCommand)command;
|
PlayerJoinCommand joinCommand = (PlayerJoinCommand)command;
|
||||||
|
|
||||||
_playerTracker.kickPlayerIfOnline(UUID.fromString(joinCommand.getUuid()));
|
_playerTracker.kickPlayerIfOnline(UUID.fromString(joinCommand.getUuid()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
package mineplex.bungee.playerTracker;
|
package mineplex.bungee.playerTracker;
|
||||||
|
|
||||||
import java.io.File;
|
import java.util.List;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
import com.google.common.collect.Lists;
|
||||||
|
|
||||||
import mineplex.serverdata.Region;
|
import mineplex.serverdata.Region;
|
||||||
|
import mineplex.serverdata.commands.PlayerJoinCommand;
|
||||||
import mineplex.serverdata.commands.ServerCommandManager;
|
import mineplex.serverdata.commands.ServerCommandManager;
|
||||||
import mineplex.serverdata.data.DataRepository;
|
import mineplex.serverdata.data.DataRepository;
|
||||||
import mineplex.serverdata.data.PlayerStatus;
|
import mineplex.serverdata.data.PlayerStatus;
|
||||||
import mineplex.serverdata.redis.RedisDataRepository;
|
import mineplex.serverdata.redis.RedisDataRepository;
|
||||||
import mineplex.serverdata.servers.ServerManager;
|
import mineplex.serverdata.servers.ServerManager;
|
||||||
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
import net.md_5.bungee.api.connection.ProxiedPlayer;
|
||||||
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
import net.md_5.bungee.api.event.PlayerDisconnectEvent;
|
||||||
import net.md_5.bungee.api.event.PostLoginEvent;
|
import net.md_5.bungee.api.event.PostLoginEvent;
|
||||||
@ -20,7 +21,7 @@ import net.md_5.bungee.api.plugin.Listener;
|
|||||||
import net.md_5.bungee.api.plugin.Plugin;
|
import net.md_5.bungee.api.plugin.Plugin;
|
||||||
import net.md_5.bungee.event.EventHandler;
|
import net.md_5.bungee.event.EventHandler;
|
||||||
|
|
||||||
public class PlayerTracker implements Listener, Runnable
|
public class PlayerTracker implements Listener
|
||||||
{
|
{
|
||||||
// Default period before status expiry (8 hours)
|
// Default period before status expiry (8 hours)
|
||||||
private static final int DEFAULT_STATUS_TIMEOUT = 60 * 60 * 8;
|
private static final int DEFAULT_STATUS_TIMEOUT = 60 * 60 * 8;
|
||||||
@ -28,25 +29,30 @@ public class PlayerTracker implements Listener, Runnable
|
|||||||
// Repository storing player status' across network.
|
// Repository storing player status' across network.
|
||||||
private DataRepository<PlayerStatus> _repository;
|
private DataRepository<PlayerStatus> _repository;
|
||||||
|
|
||||||
private Set<UUID> _onlineUUIDs = new HashSet<>();
|
|
||||||
|
|
||||||
private Plugin _plugin;
|
private Plugin _plugin;
|
||||||
|
|
||||||
|
private final List<UUID> _ignoreKick = Lists.newArrayList();
|
||||||
|
|
||||||
public PlayerTracker(Plugin plugin)
|
public PlayerTracker(Plugin plugin)
|
||||||
{
|
{
|
||||||
_plugin = plugin;
|
_plugin = plugin;
|
||||||
|
|
||||||
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
|
_plugin.getProxy().getPluginManager().registerListener(_plugin, this);
|
||||||
_plugin.getProxy().getScheduler().schedule(_plugin, this, 1L, 1L, TimeUnit.MINUTES);
|
|
||||||
|
|
||||||
_repository = new RedisDataRepository<PlayerStatus>(ServerManager.getMasterConnection(), ServerManager.getSlaveConnection(),
|
_repository = new RedisDataRepository<PlayerStatus>(ServerManager.getMasterConnection(), ServerManager.getSlaveConnection(),
|
||||||
Region.currentRegion(), PlayerStatus.class, "playerStatus");
|
Region.currentRegion(), PlayerStatus.class, "playerStatus");
|
||||||
|
|
||||||
ServerCommandManager.getInstance().registerCommandType("PlayerJoinCommand", mineplex.serverdata.commands.PlayerJoinCommand.class, new PlayerJoinHandler(this));
|
ServerCommandManager.getInstance().initializeServer("BUNGEE ENABLE - " + System.currentTimeMillis());
|
||||||
|
ServerCommandManager.getInstance().registerCommandType(mineplex.serverdata.commands.PlayerJoinCommand.class, new PlayerJoinHandler(this));
|
||||||
|
|
||||||
System.out.println("Initialized PlayerTracker.");
|
System.out.println("Initialized PlayerTracker.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Plugin getPlugin()
|
||||||
|
{
|
||||||
|
return _plugin;
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void playerConnect(final ServerConnectedEvent event)
|
public void playerConnect(final ServerConnectedEvent event)
|
||||||
{
|
{
|
||||||
@ -70,42 +76,32 @@ public class PlayerTracker implements Listener, Runnable
|
|||||||
_repository.removeElement(event.getPlayer().getName().toLowerCase());
|
_repository.removeElement(event.getPlayer().getName().toLowerCase());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
_onlineUUIDs.remove(event.getPlayer().getUniqueId());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void playerConnect(final PostLoginEvent event)
|
public void playerConnect(final PostLoginEvent event)
|
||||||
{
|
{
|
||||||
_onlineUUIDs.add(event.getPlayer().getUniqueId());
|
_ignoreKick.add(event.getPlayer().getUniqueId());
|
||||||
}
|
PlayerJoinCommand command = new PlayerJoinCommand(event.getPlayer().getUniqueId());
|
||||||
|
command.publish();
|
||||||
@Override
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
Set<UUID> onlineUUIDs = new HashSet<>();
|
|
||||||
|
|
||||||
for (ProxiedPlayer player : _plugin.getProxy().getPlayers())
|
|
||||||
{
|
|
||||||
onlineUUIDs.add(player.getUniqueId());
|
|
||||||
}
|
|
||||||
|
|
||||||
_onlineUUIDs = onlineUUIDs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isPlayerOnline(UUID uuid)
|
public boolean isPlayerOnline(UUID uuid)
|
||||||
{
|
{
|
||||||
return _onlineUUIDs.contains(uuid);
|
return _plugin.getProxy().getPlayer(uuid) != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void kickPlayerIfOnline(UUID uuid)
|
public void kickPlayerIfOnline(UUID uuid)
|
||||||
{
|
{
|
||||||
if (_onlineUUIDs.contains(uuid))
|
if (_ignoreKick.remove(uuid))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (isPlayerOnline(uuid))
|
||||||
{
|
{
|
||||||
ProxiedPlayer player = _plugin.getProxy().getPlayer(uuid);
|
ProxiedPlayer player = _plugin.getProxy().getPlayer(uuid);
|
||||||
|
|
||||||
if (player != null)
|
player.disconnect(new TextComponent("You have logged in from another location."));
|
||||||
player.disconnect("You have logged in from another location.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user