mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 21:26:46 +01:00
Return to HashMap!
This commit is contained in:
parent
0b0390620e
commit
dc48d467f5
@ -285,7 +285,7 @@ public class mcMMO extends JavaPlugin {
|
||||
@Override
|
||||
public void onDisable() {
|
||||
//Make sure to save player information if the server shuts down
|
||||
for (PlayerProfile playerProfile : Users.getProfiles()) {
|
||||
for (PlayerProfile playerProfile : Users.getProfiles().values()) {
|
||||
playerProfile.save();
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,7 @@ public class SQLReconnect implements Runnable {
|
||||
if (!Database.isConnected()) {
|
||||
Database.connect();
|
||||
if (Database.isConnected()) {
|
||||
for (PlayerProfile playerProfile : Users.getProfiles()) {
|
||||
for (PlayerProfile playerProfile : Users.getProfiles().values()) {
|
||||
playerProfile.save(); //Save all profiles
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@ public class SaveTimer implements Runnable {
|
||||
int count = 1;
|
||||
BukkitScheduler bukkitScheduler = plugin.getServer().getScheduler();
|
||||
|
||||
for (PlayerProfile playerProfile : Users.getProfiles()) {
|
||||
for (PlayerProfile playerProfile : Users.getProfiles().values()) {
|
||||
bukkitScheduler.scheduleSyncDelayedTask(plugin, new ProfileSaveTask(playerProfile), count);
|
||||
count++;
|
||||
}
|
||||
|
@ -3,9 +3,8 @@ package com.gmail.nossr50.util;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -14,7 +13,7 @@ import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.datatypes.PlayerProfile;
|
||||
|
||||
public class Users {
|
||||
private static List<PlayerProfile> profiles = new ArrayList<PlayerProfile>();
|
||||
private static Map<String, PlayerProfile> profiles = new HashMap<String, PlayerProfile>();
|
||||
|
||||
/**
|
||||
* Load users.
|
||||
@ -44,21 +43,18 @@ public class Users {
|
||||
*/
|
||||
public static PlayerProfile addUser(Player player) {
|
||||
String playerName = player.getName();
|
||||
PlayerProfile playerProfile = profiles.get(playerName);
|
||||
|
||||
for (Iterator<PlayerProfile> it = profiles.iterator() ; it.hasNext() ; ) {
|
||||
PlayerProfile playerProfile = it.next();
|
||||
if (playerProfile != null) {
|
||||
//The player object is different on each reconnection and must be updated
|
||||
playerProfile.setPlayer(player);
|
||||
}
|
||||
else {
|
||||
playerProfile = new PlayerProfile(player, playerName, true);
|
||||
|
||||
if (playerProfile.getPlayerName().equals(playerName)) {
|
||||
//The player object is different on each reconnection and must be updated
|
||||
playerProfile.setPlayer(player);
|
||||
return playerProfile;
|
||||
}
|
||||
profiles.put(playerName, playerProfile);
|
||||
}
|
||||
|
||||
//New player, or already removed from the list
|
||||
PlayerProfile playerProfile = new PlayerProfile(player, playerName, true);
|
||||
|
||||
profiles.add(playerProfile);
|
||||
return playerProfile;
|
||||
}
|
||||
|
||||
@ -74,7 +70,7 @@ public class Users {
|
||||
*
|
||||
* @return a HashMap containing the PlayerProfile of everyone in the database
|
||||
*/
|
||||
public static List<PlayerProfile> getProfiles() {
|
||||
public static Map<String, PlayerProfile> getProfiles() {
|
||||
return profiles;
|
||||
}
|
||||
|
||||
@ -95,14 +91,6 @@ public class Users {
|
||||
* @return the player's profile
|
||||
*/
|
||||
public static PlayerProfile getProfile(String playerName) {
|
||||
for (Iterator<PlayerProfile> it = profiles.iterator() ; it.hasNext() ; ) {
|
||||
PlayerProfile playerProfile = it.next();
|
||||
|
||||
if (playerProfile.getPlayerName().equals(playerName)) {
|
||||
return playerProfile;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
return profiles.get(playerName);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user