Merge branch 'master' of ssh://184.154.0.242:7999/min/mineplex

This commit is contained in:
Mini-Chiss 2015-08-30 11:01:23 -07:00
commit 519e668d62
3 changed files with 100 additions and 1 deletions

View File

@ -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());
}
}
}

View File

@ -1,19 +1,25 @@
package mineplex.bungee.playerTracker;
import java.io.File;
import java.util.HashSet;
import java.util.UUID;
import java.util.concurrent.TimeUnit;
import mineplex.serverdata.Region;
import mineplex.serverdata.commands.ServerCommandManager;
import mineplex.serverdata.data.DataRepository;
import mineplex.serverdata.data.PlayerStatus;
import mineplex.serverdata.redis.RedisDataRepository;
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.PostLoginEvent;
import net.md_5.bungee.api.event.ServerConnectedEvent;
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.api.plugin.Plugin;
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)
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.
private DataRepository<PlayerStatus> _repository;
private HashSet<String> _onlineUUIDs = new HashSet<String>();
private Plugin _plugin;
public PlayerTracker(Plugin plugin)
@ -28,11 +36,14 @@ public class PlayerTracker implements Listener
_plugin = plugin;
_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;
_repository = new RedisDataRepository<PlayerStatus>(ServerManager.getMasterConnection(), ServerManager.getSlaveConnection(),
region, PlayerStatus.class, "playerStatus");
ServerCommandManager.getInstance().registerCommandType("PlayerJoinCommand", mineplex.serverdata.commands.PlayerJoinCommand.class, new PlayerJoinHandler(this));
System.out.println("Initialized PlayerTracker.");
}
@ -59,5 +70,42 @@ public class PlayerTracker implements Listener
_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.");
}
}
}

View File

@ -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;
}
}