summaryrefslogtreecommitdiffstats
path: root/EssentialsGroupManager
diff options
context:
space:
mode:
authorElgarL <ElgarL@Palmergames.com>2014-06-19 07:59:20 +0100
committerElgarL <ElgarL@Palmergames.com>2014-06-19 07:59:20 +0100
commite862e3c87b4cc98b880894877db17845370c22d9 (patch)
tree42543853c6f47a47ce883b1550a9a84fe6e87939 /EssentialsGroupManager
parentd9fdf3bdf6b735103ce9010f1fa59bab6fe9bd1e (diff)
downloadEssentials-e862e3c87b4cc98b880894877db17845370c22d9.tar
Essentials-e862e3c87b4cc98b880894877db17845370c22d9.tar.gz
Essentials-e862e3c87b4cc98b880894877db17845370c22d9.tar.lz
Essentials-e862e3c87b4cc98b880894877db17845370c22d9.tar.xz
Essentials-e862e3c87b4cc98b880894877db17845370c22d9.zip
Add internal name to UUID resolution to speed data lookups.
Diffstat (limited to 'EssentialsGroupManager')
-rw-r--r--EssentialsGroupManager/src/Changelog.txt3
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java95
2 files changed, 94 insertions, 4 deletions
diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt
index bc050c97b..f2b4b5d6f 100644
--- a/EssentialsGroupManager/src/Changelog.txt
+++ b/EssentialsGroupManager/src/Changelog.txt
@@ -232,4 +232,5 @@ v2.1:
- Fix clones forgetting sub groups.
- Prevent players who have never logged in before from taking over existing accounts.
- Added metrics.
- - Prevent GM's own permission tests from allowing inherited permissions to override inherited negations (caused when we added the exception override for sub groups). \ No newline at end of file
+ - Prevent GM's own permission tests from allowing inherited permissions to override inherited negations (caused when we added the exception override for sub groups).
+ - Add internal name to UUID resolution to speed data lookups. \ No newline at end of file
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java
index f2a43d11e..9c5a9959f 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java
@@ -18,6 +18,8 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
import java.util.TreeSet;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -58,6 +60,11 @@ public class WorldDataHolder {
* The actual users holder
*/
protected UsersDataHolder users = new UsersDataHolder();
+
+ /**
+ * List of UUID's associated with this user name.
+ */
+ protected static Map<String, Set<String>> nameToUUIDLookup = new TreeMap<String, Set<String>>();
/**
*
*/
@@ -116,8 +123,10 @@ public class WorldDataHolder {
// Legacy name matching
if (userId.length() < 36) {
- // Search for a LastName match
- for (User user : getUserList()) {
+ // Search for a name to UUID match
+ for (String uid : getUUIDLookup(userId)) {
+
+ User user = getUsers().get(uid);
if (user.getLastName().equalsIgnoreCase(userId)) {
return user;
@@ -153,7 +162,9 @@ public class WorldDataHolder {
}
// Search for a LastName match
- for (User usr : getUserList()) {
+ for (String uid : getUUIDLookup(currentName)) {
+
+ User usr = getUsers().get(uid);
if (usr.getLastName().equalsIgnoreCase(currentName) && usr.getUUID().equalsIgnoreCase(usr.getLastName())) {
@@ -195,6 +206,10 @@ public class WorldDataHolder {
}
removeUser(theUser.getUUID());
getUsers().put(theUser.getUUID().toLowerCase(), theUser);
+
+ // Store for name to UUID lookups.
+ putUUIDLookup(theUser.getLastName(), theUser.getUUID().toLowerCase());
+
setUsersChanged(true);
if (GroupManager.isLoaded())
GroupManager.getGMEventHandler().callEvent(theUser, Action.USER_ADDED);
@@ -209,10 +224,19 @@ public class WorldDataHolder {
public boolean removeUser(String userId) {
if (getUsers().containsKey(userId.toLowerCase())) {
+
+ User user = getUser(userId.toLowerCase());
+
+ // Remove the name to UUID lookup for this user object.
+ removeUUIDLookup(user.getLastName(), user.getUUID());
+
getUsers().remove(userId.toLowerCase());
+
setUsersChanged(true);
+
if (GroupManager.isLoaded())
GroupManager.getGMEventHandler().callEvent(userId, GMUserEvent.Action.USER_REMOVED);
+
return true;
}
return false;
@@ -1351,6 +1375,7 @@ public class WorldDataHolder {
public void resetUsers() {
users.resetUsers();
+ this.clearUUIDLookup();
}
/**
@@ -1444,5 +1469,69 @@ public class WorldDataHolder {
if (getUsersFile() != null)
setTimeStampUsers(getUsersFile().lastModified());
}
+
+ /** Name to UUID lookups **/
+
+ /**
+ * Add a new name to UUID lookup.
+ *
+ * @param name the User name key to index on.
+ * @param UUID the User object UUID (same as name if there is no UUID).
+ */
+ public void putUUIDLookup(String name, String UUID) {
+
+ Set<String> lookup = getUUIDLookup(name);
+
+ if (lookup == null)
+ lookup = new TreeSet<String>();
+
+ lookup.add(UUID);
+
+ nameToUUIDLookup.put(name, lookup);
+ }
+
+ /**
+ * Delete a name lookup.
+ * Allows for multiple UUID's assigned to a single name (offline/online)
+ *
+ * @param name
+ * @param UUID
+ */
+ public void removeUUIDLookup(String name, String UUID) {
+
+ if (nameToUUIDLookup.containsKey(name)) {
+
+ Set<String> lookup = getUUIDLookup(name);
+
+ lookup.remove(UUID);
+
+ if (lookup.isEmpty()) {
+ nameToUUIDLookup.remove(name);
+ return;
+ }
+
+ nameToUUIDLookup.put(name, lookup);
+
+ }
+
+ }
+
+ /**
+ *
+ * @param name
+ * @return a Set of strings containing the User objects UUID (or name if they don't have a UUID)
+ */
+ public Set<String> getUUIDLookup(String name) {
+
+ return nameToUUIDLookup.get(name);
+ }
+
+ /**
+ * Reset the UUID Lookup cache
+ */
+ protected void clearUUIDLookup() {
+
+ nameToUUIDLookup.clear();
+ }
}