Replaced playerName fields in PlayerProfile and Users by the Player object

This commit is contained in:
bm01
2012-06-06 01:19:39 +02:00
parent b8be1d1866
commit 56aff1d191
13 changed files with 72 additions and 74 deletions

View File

@ -27,7 +27,7 @@ public class GainXp implements Runnable {
@Override
public void run() {
int health = target.getHealth();
int damage = baseHealth - health;
int damage = baseHealth - health;
//May avoid negative xp, we don't know what other plugins do with the entity health
if (damage <= 0) {

View File

@ -5,7 +5,7 @@ import org.bukkit.entity.Player;
import com.gmail.nossr50.util.Users;
public class ProfileSaveTask implements Runnable {
Player player = null;
private Player player;
public ProfileSaveTask(Player player) {
this.player = player;
@ -14,7 +14,7 @@ public class ProfileSaveTask implements Runnable {
@Override
public void run() {
if (player != null) {
Users.getProfileByName(player.getName()).save();
Users.getProfile(player).save();
}
}
}

View File

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

View File

@ -19,11 +19,11 @@ public class SQLReconnect implements Runnable {
if (!Database.isConnected()) {
Database.connect();
if (Database.isConnected()) {
for (PlayerProfile x : Users.players.values()) {
for (PlayerProfile x : Users.getProfiles().values()) {
x.save(); //Save all profiles
}
Users.players.clear(); //Clear the profiles
Users.getProfiles().clear(); //Clear the profiles
for (Player x : plugin.getServer().getOnlinePlayers()) {
Users.addUser(x); //Add in new profiles, forcing them to 'load' again from MySQL
}