Removed AccountCache.

Converted that to PlayerCache and store account id in there.
This commit is contained in:
Jonathan Williams 2015-08-28 20:58:58 -07:00
parent abf1f23087
commit 6f0309622c
15 changed files with 101 additions and 82 deletions

11
.gitignore vendored
View File

@ -39,3 +39,14 @@ zBench
zMyst zMyst
zSotanna zSotanna
zSotanna2 zSotanna2
/.recommenders/index/http___download_eclipse_org_recommenders_models_mars_/_0.fdt
/.recommenders/index/http___download_eclipse_org_recommenders_models_mars_/_0.fdx
/.recommenders/index/http___download_eclipse_org_recommenders_models_mars_/_0.fnm
/.recommenders/index/http___download_eclipse_org_recommenders_models_mars_/_0.frq
/.recommenders/index/http___download_eclipse_org_recommenders_models_mars_/_0.nrm
/.recommenders/index/http___download_eclipse_org_recommenders_models_mars_/_0.prx
/.recommenders/index/http___download_eclipse_org_recommenders_models_mars_/_0.tii
/.recommenders/index/http___download_eclipse_org_recommenders_models_mars_/_0.tis
/.recommenders/index/http___download_eclipse_org_recommenders_models_mars_/segments.gen
/.recommenders/index/http___download_eclipse_org_recommenders_models_mars_/segments_1
/.recommenders/index/http___download_eclipse_org_recommenders_models_mars_/write.lock

View File

@ -86,6 +86,9 @@
<fileset dir="../Mineplex.ServerData/bin"> <fileset dir="../Mineplex.ServerData/bin">
<include name="**/*.class"/> <include name="**/*.class"/>
</fileset> </fileset>
<fileset dir="../Mineplex.PlayerCache/bin">
<include name="**/*.class"/>
</fileset>
<zipfileset src="../Libraries/jooq-3.5.2.jar" /> <zipfileset src="../Libraries/jooq-3.5.2.jar" />
<zipfileset src="../Libraries/httpclient-4.2.jar" /> <zipfileset src="../Libraries/httpclient-4.2.jar" />
@ -152,6 +155,9 @@
<fileset dir="../Mineplex.Database/bin"> <fileset dir="../Mineplex.Database/bin">
<include name="**/*.class"/> <include name="**/*.class"/>
</fileset> </fileset>
<fileset dir="../Mineplex.PlayerCache/bin">
<include name="**/*.class"/>
</fileset>
<fileset dir="../Mineplex.ServerData/bin"> <fileset dir="../Mineplex.ServerData/bin">
<include name="**/*.class"/> <include name="**/*.class"/>
</fileset> </fileset>
@ -198,6 +204,9 @@
<fileset dir="../Mineplex.ServerData/bin"> <fileset dir="../Mineplex.ServerData/bin">
<include name="**/*.class"/> <include name="**/*.class"/>
</fileset> </fileset>
<fileset dir="../Mineplex.PlayerCache/bin">
<include name="**/*.class"/>
</fileset>
<zipfileset src="../Libraries/jooq-3.5.2.jar" /> <zipfileset src="../Libraries/jooq-3.5.2.jar" />
<zipfileset src="../Libraries/httpclient-4.2.jar" /> <zipfileset src="../Libraries/httpclient-4.2.jar" />
@ -234,6 +243,9 @@
<fileset dir="../Mineplex.ServerData/bin"> <fileset dir="../Mineplex.ServerData/bin">
<include name="**/*.class"/> <include name="**/*.class"/>
</fileset> </fileset>
<fileset dir="../Mineplex.PlayerCache/bin">
<include name="**/*.class"/>
</fileset>
<zipfileset src="../Libraries/jooq-3.5.2.jar" /> <zipfileset src="../Libraries/jooq-3.5.2.jar" />
<zipfileset src="../Libraries/httpclient-4.2.jar" /> <zipfileset src="../Libraries/httpclient-4.2.jar" />

View File

@ -1,6 +1,5 @@
package mineplex.bungee.playerStats; package mineplex.bungee.playerStats;
import java.util.HashMap;
import java.util.HashSet; import java.util.HashSet;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -19,7 +18,6 @@ public class PlayerStats implements Listener, Runnable
private Plugin _plugin; private Plugin _plugin;
private PlayerStatsRepository _repository; private PlayerStatsRepository _repository;
private PlayerCache _playerCache = new PlayerCache();
private HashSet<UUID> _retrievingPlayerInfo = new HashSet<UUID>(); private HashSet<UUID> _retrievingPlayerInfo = new HashSet<UUID>();
public PlayerStats(Plugin plugin) public PlayerStats(Plugin plugin)
@ -52,7 +50,7 @@ public class PlayerStats implements Listener, Runnable
boolean addOrUpdatePlayer = false; boolean addOrUpdatePlayer = false;
playerInfo = _playerCache.getPlayer(uuid); playerInfo = PlayerCache.getInstance().getPlayer(uuid);
if (playerInfo == null) if (playerInfo == null)
{ {
@ -81,11 +79,11 @@ public class PlayerStats implements Listener, Runnable
else else
playerInfo = updatedPlayerInfo; playerInfo = updatedPlayerInfo;
_playerCache.addPlayer(playerInfo); PlayerCache.getInstance().addPlayer(playerInfo);
} }
playerInfo.setSessionId(_repository.updatePlayerStats(playerInfo.getId(), ipInfo.id)); playerInfo.setSessionId(_repository.updatePlayerStats(playerInfo.getId(), ipInfo.id));
_playerCache.addPlayer(playerInfo); PlayerCache.getInstance().addPlayer(playerInfo);
} }
finally finally
{ {
@ -106,13 +104,13 @@ public class PlayerStats implements Listener, Runnable
PlayerInfo playerInfo = null; PlayerInfo playerInfo = null;
playerInfo = _playerCache.getPlayer(uuid); playerInfo = PlayerCache.getInstance().getPlayer(uuid);
int timeout = 5; int timeout = 5;
while (playerInfo == null && _retrievingPlayerInfo.contains(uuid) && timeout <= 5) while (playerInfo == null && _retrievingPlayerInfo.contains(uuid) && timeout <= 5)
{ {
playerInfo = _playerCache.getPlayer(uuid); playerInfo = PlayerCache.getInstance().getPlayer(uuid);
if (playerInfo != null) if (playerInfo != null)
break; break;
@ -140,6 +138,6 @@ public class PlayerStats implements Listener, Runnable
@Override @Override
public void run() public void run()
{ {
_playerCache.clean(); PlayerCache.getInstance().clean();
} }
} }

View File

@ -14,5 +14,6 @@
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/craftbukkit.jar"/> <classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/craftbukkit.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Core.Common"/> <classpathentry combineaccessrules="false" kind="src" path="/Mineplex.Core.Common"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/NoCheatPlus.jar"/> <classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/NoCheatPlus.jar"/>
<classpathentry combineaccessrules="false" kind="src" path="/Mineplex.PlayerCache"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View File

@ -1,33 +0,0 @@
package mineplex.core.account;
import java.util.UUID;
import mineplex.serverdata.data.Data;
public class AccountCache implements Data
{
private UUID _uuid;
private Integer _id;
public AccountCache(UUID uuid, int id)
{
_uuid = uuid;
_id = id;
}
public UUID getUUID()
{
return _uuid;
}
public int getId()
{
return _id;
}
@Override
public String getDataId()
{
return _uuid.toString();
}
}

View File

@ -22,10 +22,8 @@ import mineplex.core.common.util.UtilPlayer;
import mineplex.core.timing.TimingManager; import mineplex.core.timing.TimingManager;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.serverdata.Region; import mineplex.playerCache.PlayerCache;
import mineplex.serverdata.data.BungeeServer; import mineplex.playerCache.PlayerInfo;
import mineplex.serverdata.redis.RedisDataRepository;
import mineplex.serverdata.servers.ServerManager;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer; import org.bukkit.OfflinePlayer;
@ -48,7 +46,6 @@ public class CoreClientManager extends MiniPlugin
private AccountRepository _repository; private AccountRepository _repository;
private NautHashMap<String, CoreClient> _clientList; private NautHashMap<String, CoreClient> _clientList;
private HashSet<String> _duplicateLoginGlitchPreventionList; private HashSet<String> _duplicateLoginGlitchPreventionList;
private RedisDataRepository<AccountCache> _accountCacheRepository;
private NautHashMap<String, ILoginProcessor> _loginProcessors = new NautHashMap<String, ILoginProcessor>(); private NautHashMap<String, ILoginProcessor> _loginProcessors = new NautHashMap<String, ILoginProcessor>();
private LinkedList<IQuerylessLoginProcessor> _querylessLoginProcessors = new LinkedList<IQuerylessLoginProcessor>(); private LinkedList<IQuerylessLoginProcessor> _querylessLoginProcessors = new LinkedList<IQuerylessLoginProcessor>();
@ -66,9 +63,6 @@ public class CoreClientManager extends MiniPlugin
_repository = new AccountRepository(plugin, webServer); _repository = new AccountRepository(plugin, webServer);
_clientList = new NautHashMap<String, CoreClient>(); _clientList = new NautHashMap<String, CoreClient>();
_duplicateLoginGlitchPreventionList = new HashSet<String>(); _duplicateLoginGlitchPreventionList = new HashSet<String>();
_accountCacheRepository = new RedisDataRepository<AccountCache>(ServerManager.getMasterConnection(), ServerManager.getSlaveConnection(),
Region.ALL, AccountCache.class, "accountCache");
} }
public AccountRepository getRepository() public AccountRepository getRepository()
@ -251,7 +245,15 @@ public class CoreClientManager extends MiniPlugin
Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response, uuid)); Bukkit.getServer().getPluginManager().callEvent(new ClientWebResponseEvent(response, uuid));
if (client.getAccountId() > 0) if (client.getAccountId() > 0)
_accountCacheRepository.addElement(new AccountCache(uuid, client.getAccountId()), 60 * 60 * 6); {
PlayerInfo playerInfo = PlayerCache.getInstance().getPlayer(uuid);
if (playerInfo != null)
{
playerInfo.setAccountId(client.getAccountId());
PlayerCache.getInstance().addPlayer(playerInfo);
}
}
} }
catch (Exception exception) catch (Exception exception)
{ {
@ -326,13 +328,12 @@ public class CoreClientManager extends MiniPlugin
if (client.getAccountId() > 0) if (client.getAccountId() > 0)
{ {
try PlayerInfo playerInfo = PlayerCache.getInstance().getPlayer(uuid);
if (playerInfo != null)
{ {
_accountCacheRepository.addElement(new AccountCache(uuid, client.getAccountId()), 60 * 60 * 6); playerInfo.setAccountId(client.getAccountId());
} PlayerCache.getInstance().addPlayer(playerInfo);
catch (Exception e)
{
e.printStackTrace();
} }
} }
@ -544,9 +545,4 @@ public class CoreClientManager extends MiniPlugin
return client.GetRank().has(rank); return client.GetRank().has(rank);
} }
public int getCachedClientAccountId(UUID uuid)
{
return _accountCacheRepository.getElement(uuid.toString()).getId();
}
} }

View File

@ -24,6 +24,7 @@ import mineplex.core.donation.repository.token.DonorTokenWrapper;
import mineplex.core.server.util.TransactionResponse; import mineplex.core.server.util.TransactionResponse;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.playerCache.PlayerCache;
public class DonationManager extends MiniDbClientPlugin<Donor> public class DonationManager extends MiniDbClientPlugin<Donor>
{ {
@ -279,7 +280,7 @@ public class DonationManager extends MiniDbClientPlugin<Donor>
{ {
public void run() public void run()
{ {
RewardCoins(null, caller, player.getName(), ClientManager.getCachedClientAccountId(player.getUniqueId()), total, false); RewardCoins(null, caller, player.getName(), PlayerCache.getInstance().getPlayer(player.getUniqueId()).getAccountId(), total, false);
} }
}); });
} }

View File

@ -21,6 +21,7 @@ import mineplex.core.inventory.data.InventoryRepository;
import mineplex.core.inventory.data.Item; import mineplex.core.inventory.data.Item;
import mineplex.core.updater.UpdateType; import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent; import mineplex.core.updater.event.UpdateEvent;
import mineplex.playerCache.PlayerCache;
public class InventoryManager extends MiniDbClientPlugin<ClientInventory> public class InventoryManager extends MiniDbClientPlugin<ClientInventory>
{ {
@ -180,7 +181,7 @@ public class InventoryManager extends MiniDbClientPlugin<ClientInventory>
synchronized (_inventoryLock) synchronized (_inventoryLock)
{ {
final boolean success = _repository.incrementClientInventoryItem(ClientManager.getCachedClientAccountId(uuid), _items.get(item).Id, count); final boolean success = _repository.incrementClientInventoryItem(PlayerCache.getInstance().getPlayer(uuid).getAccountId(), _items.get(item).Id, count);
if (callback != null) if (callback != null)
{ {

View File

@ -23,6 +23,7 @@ import mineplex.core.common.util.UtilServer;
import mineplex.core.stats.command.GiveStatCommand; import mineplex.core.stats.command.GiveStatCommand;
import mineplex.core.stats.command.TimeCommand; import mineplex.core.stats.command.TimeCommand;
import mineplex.core.stats.event.StatChangeEvent; import mineplex.core.stats.event.StatChangeEvent;
import mineplex.playerCache.PlayerCache;
public class StatsManager extends MiniDbClientPlugin<PlayerStats> public class StatsManager extends MiniDbClientPlugin<PlayerStats>
{ {
@ -139,7 +140,7 @@ public class StatsManager extends MiniDbClientPlugin<PlayerStats>
if (player.isOnline()) if (player.isOnline())
continue; continue;
int uploadKey = ClientManager.getCachedClientAccountId(player.getUniqueId()); int uploadKey = PlayerCache.getInstance().getPlayer(player.getUniqueId()).getAccountId();
uploadQueue.put(uploadKey, new NautHashMap<Integer, Long>()); uploadQueue.put(uploadKey, new NautHashMap<Integer, Long>());

View File

@ -14,6 +14,7 @@ import mineplex.core.account.CoreClientManager;
import mineplex.core.common.util.Callback; import mineplex.core.common.util.Callback;
import mineplex.core.common.util.NautHashMap; import mineplex.core.common.util.NautHashMap;
import mineplex.core.task.repository.TaskRepository; import mineplex.core.task.repository.TaskRepository;
import mineplex.playerCache.PlayerCache;
public class TaskManager extends MiniDbClientPlugin<TaskClient> public class TaskManager extends MiniDbClientPlugin<TaskClient>
{ {
@ -68,7 +69,7 @@ public class TaskManager extends MiniDbClientPlugin<TaskClient>
synchronized (_taskLock) synchronized (_taskLock)
{ {
final boolean success = _repository.addAccountTask(ClientManager.getCachedClientAccountId(uuid), _tasks.get(task)); final boolean success = _repository.addAccountTask(PlayerCache.getInstance().getPlayer(uuid).getAccountId(), _tasks.get(task));
if (callback != null) if (callback != null)
{ {

View File

@ -4,6 +4,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import net.minecraft.server.v1_7_R4.MinecraftServer; import net.minecraft.server.v1_7_R4.MinecraftServer;
import mineplex.core.account.CoreClientManager; import mineplex.core.account.CoreClientManager;
import mineplex.core.achievement.AchievementManager;
import mineplex.core.antihack.AntiHack; import mineplex.core.antihack.AntiHack;
import mineplex.core.blockrestore.BlockRestore; import mineplex.core.blockrestore.BlockRestore;
import mineplex.core.chat.Chat; import mineplex.core.chat.Chat;
@ -23,6 +24,7 @@ import mineplex.core.punish.Punish;
import mineplex.core.recharge.Recharge; import mineplex.core.recharge.Recharge;
import mineplex.core.serverConfig.ServerConfiguration; import mineplex.core.serverConfig.ServerConfiguration;
import mineplex.core.spawn.Spawn; import mineplex.core.spawn.Spawn;
import mineplex.core.stats.StatsManager;
import mineplex.core.status.ServerStatusManager; import mineplex.core.status.ServerStatusManager;
import mineplex.core.teleport.Teleport; import mineplex.core.teleport.Teleport;
import mineplex.core.updater.FileUpdater; import mineplex.core.updater.FileUpdater;
@ -79,7 +81,7 @@ public class Clans extends JavaPlugin
BlockRestore blockRestore = new BlockRestore(this); BlockRestore blockRestore = new BlockRestore(this);
IgnoreManager ignoreManager = new IgnoreManager(this, _clientManager, preferenceManager, portal); IgnoreManager ignoreManager = new IgnoreManager(this, _clientManager, preferenceManager, portal);
Chat chat = new Chat(this, _clientManager, preferenceManager, serverStatusManager.getCurrentServerName()); Chat chat = new Chat(this, _clientManager, preferenceManager, new AchievementManager(new StatsManager(this, _clientManager), _clientManager, _donationManager), serverStatusManager.getCurrentServerName());
new MessageManager(this, _clientManager, preferenceManager, ignoreManager, punish, new FriendManager(this, _clientManager, preferenceManager, portal), chat); new MessageManager(this, _clientManager, preferenceManager, ignoreManager, punish, new FriendManager(this, _clientManager, preferenceManager, portal), chat);
new MemoryFix(this); new MemoryFix(this);

View File

@ -8,9 +8,19 @@ import mineplex.serverdata.servers.ServerManager;
public class PlayerCache public class PlayerCache
{ {
private static PlayerCache _instance = null;
private RedisDataRepository<PlayerInfo> _repository; private RedisDataRepository<PlayerInfo> _repository;
public PlayerCache() public static PlayerCache getInstance()
{
if (_instance == null)
_instance = new PlayerCache();
return _instance;
}
private PlayerCache()
{ {
_repository = new RedisDataRepository<PlayerInfo>( _repository = new RedisDataRepository<PlayerInfo>(
ServerManager.getMasterConnection(), ServerManager.getMasterConnection(),
@ -21,14 +31,32 @@ public class PlayerCache
} }
public void addPlayer(PlayerInfo player) public void addPlayer(PlayerInfo player)
{
try
{ {
_repository.addElement(player, 60 * 60 * 6); // 6 Hours _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) public PlayerInfo getPlayer(UUID uuid)
{
try
{ {
return _repository.getElement(uuid.toString()); 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() public void clean()
{ {

View File

@ -7,6 +7,7 @@ import mineplex.serverdata.data.Data;
public class PlayerInfo implements Data public class PlayerInfo implements Data
{ {
private int _id; private int _id;
private int _accountId;
private UUID _uuid; private UUID _uuid;
private String _name; private String _name;
private boolean _online; private boolean _online;
@ -34,6 +35,11 @@ public class PlayerInfo implements Data
return _id; return _id;
} }
public int getAccountId()
{
return _accountId;
}
public UUID getUUID() public UUID getUUID()
{ {
return _uuid; return _uuid;
@ -83,4 +89,9 @@ public class PlayerInfo implements Data
{ {
_version = version; _version = version;
} }
public void setAccountId(int accountId)
{
_accountId = accountId;
}
} }

View File

@ -11,6 +11,6 @@
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/httpclient-4.2.jar"/> <classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/httpclient-4.2.jar"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/commons-codec-1.6.jar"/> <classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/commons-codec-1.6.jar"/>
<classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/gson-2.2.1.jar"/> <classpathentry kind="var" path="REPO_DIR/Plugins/Libraries/gson-2.2.1.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre7"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre1.8.0_60"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View File

@ -1,11 +0,0 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.7