Perf: Player Quit

This commit is contained in:
ryanhamshire 2014-11-16 15:13:25 -08:00
parent 9cf7117ea0
commit 5df24c1302
2 changed files with 21 additions and 34 deletions

View File

@ -676,15 +676,13 @@ public abstract class DataStore
//ensure player data is already read from file before trying to save
playerData.getAccruedClaimBlocks();
playerData.getClaims();
this.asyncSavePlayerData(playerID, playerData);
}
//saves changes to player data to secondary storage. MUST be called after you're done making changes, otherwise a reload will lose them
public void savePlayerData(UUID playerID, PlayerData playerData)
{
//ensure player data is already read from file before trying to save
playerData.getAccruedClaimBlocks();
playerData.getClaims();
new SavePlayerDataThread(playerID, playerData).start();
}
@ -1290,6 +1288,9 @@ public abstract class DataStore
public void run()
{
//ensure player data is already read from file before trying to save
playerData.getAccruedClaimBlocks();
playerData.getClaims();
asyncSavePlayerData(this.playerID, this.playerData);
}
}

View File

@ -627,7 +627,8 @@ class PlayerEventHandler implements Listener
void onPlayerQuit(PlayerQuitEvent event)
{
Player player = event.getPlayer();
PlayerData playerData = this.dataStore.getPlayerData(player.getUniqueId());
UUID playerID = player.getUniqueId();
PlayerData playerData = this.dataStore.getPlayerData(playerID);
boolean isBanned;
if(playerData.wasKicked)
{
@ -663,37 +664,22 @@ class PlayerEventHandler implements Listener
this.dataStore.savePlayerData(player.getUniqueId(), playerData);
}
this.onPlayerDisconnect(event.getPlayer(), event.getQuitMessage());
}
//helper for above
private void onPlayerDisconnect(Player player, String notificationMessage)
{
UUID playerID = player.getUniqueId();
PlayerData playerData = this.dataStore.getPlayerData(playerID);
//FEATURE: claims where players have allowed explosions will revert back to not allowing them when the owner logs out
for(Claim claim : playerData.getClaims())
{
claim.areExplosivesAllowed = false;
}
//FEATURE: players in pvp combat when they log out will die
if(GriefPrevention.instance.config_pvp_punishLogout && playerData.inPvpCombat())
{
player.setHealth(0);
}
if(GriefPrevention.instance.config_pvp_punishLogout && playerData.inPvpCombat())
{
player.setHealth(0);
}
//FEATURE: during a siege, any player who logs out dies and forfeits the siege
//FEATURE: during a siege, any player who logs out dies and forfeits the siege
//if player was involved in a siege, he forfeits
if(playerData.siegeData != null)
{
if(player.getHealth() > 0) player.setHealth(0); //might already be zero from above, this avoids a double death message
}
//if player was involved in a siege, he forfeits
if(playerData.siegeData != null)
{
if(player.getHealth() > 0) player.setHealth(0); //might already be zero from above, this avoids a double death message
}
//drop data about this player
this.dataStore.clearCachedPlayerData(playerID);
//drop data about this player
this.dataStore.clearCachedPlayerData(playerID);
}
//determines whether or not a login or logout notification should be silenced, depending on how many there have been in the last minute