Merged ProfileSaveTask and RemoveProfileFromMemory

This commit is contained in:
bm01 2012-06-10 06:55:27 +02:00
parent 5d0d89e74d
commit c9082083d1
4 changed files with 14 additions and 42 deletions

View File

@ -32,7 +32,6 @@ import com.gmail.nossr50.events.chat.McMMOPartyChatEvent;
import com.gmail.nossr50.locale.LocaleLoader;
import com.gmail.nossr50.party.Party;
import com.gmail.nossr50.runnables.BleedTimer;
import com.gmail.nossr50.runnables.RemoveProfileFromMemoryTask;
import com.gmail.nossr50.skills.combat.Taming;
import com.gmail.nossr50.skills.gathering.BlastMining;
import com.gmail.nossr50.skills.gathering.Fishing;
@ -145,9 +144,6 @@ public class PlayerListener implements Listener {
//Bleed it out
BleedTimer.bleedOut(player);
//Schedule PlayerProfile removal 2 minutes after quitting
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new RemoveProfileFromMemoryTask(player), 2400);
}
/**

View File

@ -1,20 +1,21 @@
package com.gmail.nossr50.runnables;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.util.Users;
public class ProfileSaveTask implements Runnable {
private Player player;
private PlayerProfile playerProfile;
public ProfileSaveTask(Player player) {
this.player = player;
public ProfileSaveTask(PlayerProfile playerProfile) {
this.playerProfile = playerProfile;
}
@Override
public void run() {
if (player != null) {
Users.getProfile(player).save();
playerProfile.save();
if (!playerProfile.getPlayer().isOnline()) {
Users.getProfiles().remove(playerProfile);
}
}
}

View File

@ -1,28 +0,0 @@
package com.gmail.nossr50.runnables;
import org.bukkit.entity.Player;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.util.Users;
public class RemoveProfileFromMemoryTask implements Runnable {
private Player player;
public RemoveProfileFromMemoryTask(Player player) {
this.player = player;
}
@Override
public void run() {
PlayerProfile playerProfile = Users.getProfile(player);
//Check if the profile still exists (stuff like MySQL reconnection removes profiles)
if (playerProfile != null) {
playerProfile.save(); //We save here so players don't quit/reconnect to cause lag
if (!player.isOnline()) {
Users.removeUser(playerProfile);
}
}
}
}

View File

@ -1,9 +1,11 @@
package com.gmail.nossr50.runnables;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitScheduler;
import com.gmail.nossr50.mcMMO;
import com.gmail.nossr50.datatypes.PlayerProfile;
import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.util.Users;
public class SaveTimer implements Runnable {
private final mcMMO plugin;
@ -16,9 +18,10 @@ public class SaveTimer implements Runnable {
public void run() {
//All player data will be saved periodically through this
int count = 1;
BukkitScheduler bukkitScheduler = plugin.getServer().getScheduler();
for (Player player : plugin.getServer().getOnlinePlayers()) {
plugin.getServer().getScheduler().scheduleSyncDelayedTask(plugin, new ProfileSaveTask(player), count);
for (PlayerProfile playerProfile : Users.getProfiles()) {
bukkitScheduler.scheduleSyncDelayedTask(plugin, new ProfileSaveTask(playerProfile), count);
count++;
}