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