refactor: clean source code
This commit is contained in:
21
Plugins[Modified]/Mineplex.Cache/pom.xml
Normal file
21
Plugins[Modified]/Mineplex.Cache/pom.xml
Normal file
@ -0,0 +1,21 @@
|
||||
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>com.mineplex</groupId>
|
||||
<artifactId>mineplex-parent</artifactId>
|
||||
<version>dev-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>mineplex-cache</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>${project.groupId}</groupId>
|
||||
<artifactId>mineplex-serverdata</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
111
Plugins[Modified]/Mineplex.Cache/src/mineplex/cache/player/PlayerCache.java
vendored
Normal file
111
Plugins[Modified]/Mineplex.Cache/src/mineplex/cache/player/PlayerCache.java
vendored
Normal file
@ -0,0 +1,111 @@
|
||||
package mineplex.cache.player;
|
||||
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import mineplex.serverdata.Region;
|
||||
import mineplex.serverdata.redis.RedisDataRepository;
|
||||
import mineplex.serverdata.redis.atomic.RedisStringRepository;
|
||||
import mineplex.serverdata.servers.ServerManager;
|
||||
|
||||
public enum PlayerCache
|
||||
{
|
||||
INSTANCE;
|
||||
|
||||
public static PlayerCache getInstance()
|
||||
{
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private final RedisDataRepository<PlayerInfo> _playerInfoRepository;
|
||||
private final RedisStringRepository _accountIdRepository;
|
||||
|
||||
PlayerCache()
|
||||
{
|
||||
_playerInfoRepository = new RedisDataRepository<PlayerInfo>(
|
||||
ServerManager.getMasterConnection(),
|
||||
ServerManager.getSlaveConnection(),
|
||||
Region.ALL,
|
||||
PlayerInfo.class,
|
||||
"playercache");
|
||||
|
||||
_accountIdRepository = new RedisStringRepository(
|
||||
ServerManager.getMasterConnection(),
|
||||
ServerManager.getSlaveConnection(),
|
||||
Region.ALL,
|
||||
"accountid",
|
||||
(int) TimeUnit.HOURS.toSeconds(6)
|
||||
);
|
||||
}
|
||||
|
||||
public void addPlayer(PlayerInfo player)
|
||||
{
|
||||
try
|
||||
{
|
||||
_playerInfoRepository.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
|
||||
{
|
||||
PlayerInfo playerInfo = _playerInfoRepository.getElement(uuid.toString());
|
||||
return playerInfo;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
System.out.println("Error retrieving player info in PlayerCache : " + exception.getMessage());
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempts to grab a player's account ID from the cache
|
||||
*
|
||||
* @param uuid Minecraft Account UUID
|
||||
* @return The account id of the player, or -1 if the player is not in the cache
|
||||
*/
|
||||
public int getAccountId(UUID uuid)
|
||||
{
|
||||
String accountIdStr = _accountIdRepository.get(uuid.toString());
|
||||
|
||||
if (accountIdStr == null)
|
||||
return -1;
|
||||
|
||||
try
|
||||
{
|
||||
int accountId = Integer.parseInt(accountIdStr);
|
||||
if (accountId <= 0)
|
||||
{
|
||||
// remove invalid account id
|
||||
_accountIdRepository.del(uuid.toString());
|
||||
return -1;
|
||||
}
|
||||
return accountId;
|
||||
}
|
||||
catch (NumberFormatException ex)
|
||||
{
|
||||
// remove invalid account id
|
||||
_accountIdRepository.del(uuid.toString());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public void updateAccountId(UUID uuid, int newId)
|
||||
{
|
||||
_accountIdRepository.set(uuid.toString(), String.valueOf(newId));
|
||||
}
|
||||
|
||||
public void clean()
|
||||
{
|
||||
_playerInfoRepository.clean();
|
||||
}
|
||||
}
|
93
Plugins[Modified]/Mineplex.Cache/src/mineplex/cache/player/PlayerInfo.java
vendored
Normal file
93
Plugins[Modified]/Mineplex.Cache/src/mineplex/cache/player/PlayerInfo.java
vendored
Normal file
@ -0,0 +1,93 @@
|
||||
package mineplex.cache.player;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import mineplex.serverdata.Utility;
|
||||
import mineplex.serverdata.data.Data;
|
||||
|
||||
public class PlayerInfo implements Data
|
||||
{
|
||||
private int _id;
|
||||
private int _accountId;
|
||||
private UUID _uuid;
|
||||
private String _name;
|
||||
private boolean _online;
|
||||
private long _lastUniqueLogin;
|
||||
private long _loginTime;
|
||||
private int _sessionId;
|
||||
private int _version;
|
||||
|
||||
public PlayerInfo(int id, UUID uuid, String name, int version)
|
||||
{
|
||||
_id = id;
|
||||
_uuid = uuid;
|
||||
_name = name;
|
||||
_version = version;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDataId()
|
||||
{
|
||||
return _uuid.toString();
|
||||
}
|
||||
|
||||
public int getId()
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
|
||||
public UUID getUUID()
|
||||
{
|
||||
return _uuid;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return _name;
|
||||
}
|
||||
|
||||
public boolean getOnline()
|
||||
{
|
||||
return _online;
|
||||
}
|
||||
|
||||
public long getLastUniqueLogin()
|
||||
{
|
||||
return _lastUniqueLogin;
|
||||
}
|
||||
|
||||
public long getLoginTime()
|
||||
{
|
||||
return _loginTime;
|
||||
}
|
||||
|
||||
public int getSessionId()
|
||||
{
|
||||
return _sessionId;
|
||||
}
|
||||
|
||||
public int getVersion()
|
||||
{
|
||||
return _version;
|
||||
}
|
||||
|
||||
public void setSessionId(int sessionId)
|
||||
{
|
||||
_sessionId = sessionId;
|
||||
}
|
||||
|
||||
public void setName(String name)
|
||||
{
|
||||
_name = name;
|
||||
}
|
||||
|
||||
public void setVersion(int version)
|
||||
{
|
||||
_version = version;
|
||||
}
|
||||
|
||||
public void updateLoginTime()
|
||||
{
|
||||
_loginTime = Utility.currentTimeMillis();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user