6f0309622c
Converted that to PlayerCache and store account id in there.
66 lines
1.3 KiB
Java
66 lines
1.3 KiB
Java
package mineplex.playerCache;
|
|
|
|
import java.util.UUID;
|
|
|
|
import mineplex.serverdata.Region;
|
|
import mineplex.serverdata.redis.RedisDataRepository;
|
|
import mineplex.serverdata.servers.ServerManager;
|
|
|
|
public class PlayerCache
|
|
{
|
|
private static PlayerCache _instance = null;
|
|
|
|
private RedisDataRepository<PlayerInfo> _repository;
|
|
|
|
public static PlayerCache getInstance()
|
|
{
|
|
if (_instance == null)
|
|
_instance = new PlayerCache();
|
|
|
|
return _instance;
|
|
}
|
|
|
|
private PlayerCache()
|
|
{
|
|
_repository = new RedisDataRepository<PlayerInfo>(
|
|
ServerManager.getMasterConnection(),
|
|
ServerManager.getSlaveConnection(),
|
|
Region.ALL,
|
|
PlayerInfo.class,
|
|
"playercache");
|
|
}
|
|
|
|
public void addPlayer(PlayerInfo player)
|
|
{
|
|
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();
|
|
}
|
|
}
|
|
|
|
public PlayerInfo getPlayer(UUID uuid)
|
|
{
|
|
try
|
|
{
|
|
return _repository.getElement(uuid.toString());
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
System.out.println("Error retrieving player info in PlayerCache : " + exception.getMessage());
|
|
exception.printStackTrace();
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public void clean()
|
|
{
|
|
_repository.clean();
|
|
}
|
|
}
|