2015-03-25 23:10:59 +01:00
|
|
|
package mineplex.playerCache;
|
|
|
|
|
|
|
|
import java.util.UUID;
|
|
|
|
|
|
|
|
import mineplex.serverdata.Region;
|
|
|
|
import mineplex.serverdata.redis.RedisDataRepository;
|
|
|
|
import mineplex.serverdata.servers.ServerManager;
|
|
|
|
|
|
|
|
public class PlayerCache
|
|
|
|
{
|
2015-08-29 05:58:58 +02:00
|
|
|
private static PlayerCache _instance = null;
|
|
|
|
|
2015-03-25 23:10:59 +01:00
|
|
|
private RedisDataRepository<PlayerInfo> _repository;
|
|
|
|
|
2015-08-29 05:58:58 +02:00
|
|
|
public static PlayerCache getInstance()
|
|
|
|
{
|
|
|
|
if (_instance == null)
|
|
|
|
_instance = new PlayerCache();
|
|
|
|
|
|
|
|
return _instance;
|
|
|
|
}
|
|
|
|
|
|
|
|
private PlayerCache()
|
2015-03-25 23:10:59 +01:00
|
|
|
{
|
|
|
|
_repository = new RedisDataRepository<PlayerInfo>(
|
|
|
|
ServerManager.getMasterConnection(),
|
|
|
|
ServerManager.getSlaveConnection(),
|
|
|
|
Region.ALL,
|
|
|
|
PlayerInfo.class,
|
|
|
|
"playercache");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void addPlayer(PlayerInfo player)
|
|
|
|
{
|
2015-08-29 05:58:58 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
_repository.addElement(player, 60 * 60 * 6); // 6 Hours
|
|
|
|
}
|
|
|
|
catch (Exception exception)
|
|
|
|
{
|
|
|
|
System.out.println("Error adding player info in PlayerCache : " + exception.getMessage());
|
|
|
|
exception.printStackTrace();
|
|
|
|
}
|
2015-03-25 23:10:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public PlayerInfo getPlayer(UUID uuid)
|
|
|
|
{
|
2015-08-29 05:58:58 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
return _repository.getElement(uuid.toString());
|
|
|
|
}
|
|
|
|
catch (Exception exception)
|
|
|
|
{
|
|
|
|
System.out.println("Error retrieving player info in PlayerCache : " + exception.getMessage());
|
|
|
|
exception.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2015-03-25 23:10:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void clean()
|
|
|
|
{
|
|
|
|
_repository.clean();
|
|
|
|
}
|
|
|
|
}
|