Merge branch 'master' of ssh://184.154.0.242:7999/min/mineplex
This commit is contained in:
commit
519e668d62
@ -0,0 +1,27 @@
|
|||||||
|
package mineplex.bungee.playerTracker;
|
||||||
|
|
||||||
|
import mineplex.serverdata.commands.CommandCallback;
|
||||||
|
import mineplex.serverdata.commands.PlayerJoinCommand;
|
||||||
|
import mineplex.serverdata.commands.ServerCommand;
|
||||||
|
|
||||||
|
public class PlayerJoinHandler implements CommandCallback
|
||||||
|
{
|
||||||
|
private PlayerTracker _playerTracker;
|
||||||
|
|
||||||
|
public PlayerJoinHandler(PlayerTracker playerTracker)
|
||||||
|
{
|
||||||
|
_playerTracker = playerTracker;
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
@Override
|
||||||
|
public void run(ServerCommand command)
|
||||||
|
{
|
||||||
|
if (command instanceof PlayerJoinCommand)
|
||||||
|
{
|
||||||
|
PlayerJoinCommand joinCommand = (PlayerJoinCommand)command;
|
||||||
|
|
||||||
|
_playerTracker.kickPlayerIfOnline(joinCommand.getUuid());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,19 +1,25 @@
|
|||||||
package mineplex.bungee.playerTracker;
|
package mineplex.bungee.playerTracker;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import mineplex.serverdata.Region;
|
import mineplex.serverdata.Region;
|
||||||
|
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.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.ServerConnectedEvent;
|
import net.md_5.bungee.api.event.ServerConnectedEvent;
|
||||||
import net.md_5.bungee.api.plugin.Listener;
|
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
|
public class PlayerTracker implements Listener, Runnable
|
||||||
{
|
{
|
||||||
// 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;
|
||||||
@ -21,6 +27,8 @@ public class PlayerTracker implements Listener
|
|||||||
// Repository storing player status' across network.
|
// Repository storing player status' across network.
|
||||||
private DataRepository<PlayerStatus> _repository;
|
private DataRepository<PlayerStatus> _repository;
|
||||||
|
|
||||||
|
private HashSet<String> _onlineUUIDs = new HashSet<String>();
|
||||||
|
|
||||||
private Plugin _plugin;
|
private Plugin _plugin;
|
||||||
|
|
||||||
public PlayerTracker(Plugin plugin)
|
public PlayerTracker(Plugin plugin)
|
||||||
@ -28,11 +36,14 @@ public class PlayerTracker implements Listener
|
|||||||
_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);
|
||||||
|
|
||||||
Region region = !new File("eu.dat").exists() ? Region.US : Region.EU;
|
Region region = !new File("eu.dat").exists() ? Region.US : Region.EU;
|
||||||
_repository = new RedisDataRepository<PlayerStatus>(ServerManager.getMasterConnection(), ServerManager.getSlaveConnection(),
|
_repository = new RedisDataRepository<PlayerStatus>(ServerManager.getMasterConnection(), ServerManager.getSlaveConnection(),
|
||||||
region, PlayerStatus.class, "playerStatus");
|
region, PlayerStatus.class, "playerStatus");
|
||||||
|
|
||||||
|
ServerCommandManager.getInstance().registerCommandType("PlayerJoinCommand", mineplex.serverdata.commands.PlayerJoinCommand.class, new PlayerJoinHandler(this));
|
||||||
|
|
||||||
System.out.println("Initialized PlayerTracker.");
|
System.out.println("Initialized PlayerTracker.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,5 +70,42 @@ public class PlayerTracker implements Listener
|
|||||||
_repository.removeElement(event.getPlayer().getName().toLowerCase());
|
_repository.removeElement(event.getPlayer().getName().toLowerCase());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
_onlineUUIDs.remove(event.getPlayer().getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void playerConnect(final PostLoginEvent event)
|
||||||
|
{
|
||||||
|
_onlineUUIDs.add(event.getPlayer().getUniqueId().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
HashSet<String> onlineUUIDs = new HashSet<String>();
|
||||||
|
|
||||||
|
for (ProxiedPlayer player : _plugin.getProxy().getPlayers())
|
||||||
|
{
|
||||||
|
onlineUUIDs.add(player.getUniqueId().toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
_onlineUUIDs = onlineUUIDs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPlayerOnline(String uuid)
|
||||||
|
{
|
||||||
|
return _onlineUUIDs.contains(uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void kickPlayerIfOnline(String uuid)
|
||||||
|
{
|
||||||
|
if (_onlineUUIDs.contains(uuid))
|
||||||
|
{
|
||||||
|
ProxiedPlayer player = _plugin.getProxy().getPlayer(UUID.fromString(uuid));
|
||||||
|
|
||||||
|
if (player != null)
|
||||||
|
player.disconnect("You have logged in from another location.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,24 @@
|
|||||||
|
package mineplex.serverdata.commands;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
public class PlayerJoinCommand extends ServerCommand
|
||||||
|
{
|
||||||
|
private String _uuid;
|
||||||
|
|
||||||
|
public PlayerJoinCommand(UUID uuid)
|
||||||
|
{
|
||||||
|
_uuid = uuid.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run()
|
||||||
|
{
|
||||||
|
// Utilitizes a callback functionality to seperate dependencies
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUuid()
|
||||||
|
{
|
||||||
|
return _uuid;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user