summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElgarL <ElgarL@Palmergames.com>2014-06-20 10:56:52 +0100
committerElgarL <ElgarL@Palmergames.com>2014-06-20 10:56:52 +0100
commit9a55d32b7569d520e3b0365df8a08405be1ac6d8 (patch)
tree64b4abfa4e0a21883b216bd7a3922ba50e998b03
parentd86d72eeb75593c3125f876a8cfcf199eba12352 (diff)
downloadEssentials-9a55d32b7569d520e3b0365df8a08405be1ac6d8.tar
Essentials-9a55d32b7569d520e3b0365df8a08405be1ac6d8.tar.gz
Essentials-9a55d32b7569d520e3b0365df8a08405be1ac6d8.tar.lz
Essentials-9a55d32b7569d520e3b0365df8a08405be1ac6d8.tar.xz
Essentials-9a55d32b7569d520e3b0365df8a08405be1ac6d8.zip
Convert all User lookups and commands to use UUIDs where possible.
-rw-r--r--EssentialsGroupManager/src/Changelog.txt3
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java40
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java35
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java2
-rw-r--r--EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java16
5 files changed, 45 insertions, 51 deletions
diff --git a/EssentialsGroupManager/src/Changelog.txt b/EssentialsGroupManager/src/Changelog.txt
index f2b4b5d6f..6d0777411 100644
--- a/EssentialsGroupManager/src/Changelog.txt
+++ b/EssentialsGroupManager/src/Changelog.txt
@@ -233,4 +233,5 @@ v2.1:
- 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).
- - Add internal name to UUID resolution to speed data lookups. \ No newline at end of file
+ - Add internal name to UUID resolution to speed data lookups.
+ - Convert all User lookups and commands to use UUIDs where possible. \ No newline at end of file
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java
index ac8404956..b2059a9bc 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/GroupManager.java
@@ -417,7 +417,7 @@ public class GroupManager extends JavaPlugin {
return true;
}
- senderUser = worldsHolder.getWorldData(senderPlayer).getUser(senderPlayer.getName());
+ senderUser = worldsHolder.getWorldData(senderPlayer).getUser(senderPlayer.getUniqueId().toString());
senderGroup = senderUser.getGroup();
isOpOverride = (isOpOverride && (senderPlayer.isOp() || worldsHolder.getWorldPermissions(senderPlayer).has(senderPlayer, "groupmanager.op")));
@@ -534,7 +534,7 @@ public class GroupManager extends JavaPlugin {
}
// Validating permissions
- if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getLastName(), senderGroup.getName()) : false)) {
+ if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getUUID(), senderGroup.getName()) : false)) {
sender.sendMessage(ChatColor.RED + "Can't modify a player with the same permissions as you, or higher.");
return true;
}
@@ -542,7 +542,7 @@ public class GroupManager extends JavaPlugin {
sender.sendMessage(ChatColor.RED + "The destination group can't be the same as yours, or higher.");
return true;
}
- if (!isConsole && !isOpOverride && (!permissionHandler.inGroup(senderUser.getLastName(), auxUser.getGroupName()) || !permissionHandler.inGroup(senderUser.getLastName(), auxGroup.getName()))) {
+ if (!isConsole && !isOpOverride && (!permissionHandler.inGroup(senderUser.getUUID(), auxUser.getGroupName()) || !permissionHandler.inGroup(senderUser.getUUID(), auxGroup.getName()))) {
sender.sendMessage(ChatColor.RED + "You can't modify a player involving a group that you don't inherit.");
return true;
}
@@ -575,7 +575,7 @@ public class GroupManager extends JavaPlugin {
auxUser = dataHolder.getUser(args[0]);
}
// Validating permission
- if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getLastName(), senderGroup.getName()) : false)) {
+ if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getUUID(), senderGroup.getName()) : false)) {
sender.sendMessage(ChatColor.RED + "You can't modify a player with same permissions as you, or higher.");
return true;
}
@@ -619,7 +619,7 @@ public class GroupManager extends JavaPlugin {
return true;
}
// Validating permission
- if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getLastName(), senderGroup.getName()) : false)) {
+ if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getUUID(), senderGroup.getName()) : false)) {
sender.sendMessage(ChatColor.RED + "You can't modify a player with same permissions as you, or higher.");
return true;
}
@@ -627,7 +627,7 @@ public class GroupManager extends JavaPlugin {
sender.sendMessage(ChatColor.RED + "The sub-group can't be the same as yours, or higher.");
return true;
}
- if (!isConsole && !isOpOverride && (!permissionHandler.inGroup(senderUser.getLastName(), auxUser.getGroupName()) || !permissionHandler.inGroup(senderUser.getLastName(), auxGroup.getName()))) {
+ if (!isConsole && !isOpOverride && (!permissionHandler.inGroup(senderUser.getUUID(), auxUser.getGroupName()) || !permissionHandler.inGroup(senderUser.getUUID(), auxGroup.getName()))) {
sender.sendMessage(ChatColor.RED + "You can't modify a player involving a group that you don't inherit.");
return true;
}
@@ -666,7 +666,7 @@ public class GroupManager extends JavaPlugin {
}
// Validating permission
- if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getLastName(), senderGroup.getName()) : false)) {
+ if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getUUID(), senderGroup.getName()) : false)) {
sender.sendMessage(ChatColor.RED + "You can't modify a player with same permissions as you, or higher.");
return true;
}
@@ -749,7 +749,7 @@ public class GroupManager extends JavaPlugin {
}
// Validating your permissions
- if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getLastName(), senderGroup.getName()) : false)) {
+ if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getUUID(), senderGroup.getName()) : false)) {
sender.sendMessage(ChatColor.RED + "Can't modify player with same group than you, or higher.");
return true;
}
@@ -807,7 +807,7 @@ public class GroupManager extends JavaPlugin {
{
auxString = args[i].replace("'", "");
- if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getLastName(), senderGroup.getName()) : false)) {
+ if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getUUID(), senderGroup.getName()) : false)) {
sender.sendMessage(ChatColor.RED + "You can't modify a player with same group as you, or higher.");
continue;
}
@@ -861,7 +861,7 @@ public class GroupManager extends JavaPlugin {
auxUser = dataHolder.getUser(args[0]);
}
// Validating your permissions
- if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getLastName(), senderGroup.getName()) : false)) {
+ if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getUUID(), senderGroup.getName()) : false)) {
sender.sendMessage(ChatColor.RED + "You can't modify a player with same group as you, or higher.");
return true;
}
@@ -1660,7 +1660,7 @@ public class GroupManager extends JavaPlugin {
auxUser = dataHolder.getUser(args[0]);
}
// Validating permission
- if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getLastName(), senderGroup.getName()) : false)) {
+ if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getUUID(), senderGroup.getName()) : false)) {
sender.sendMessage(ChatColor.RED + "Can't modify player with same permissions than you, or higher.");
return true;
}
@@ -1669,7 +1669,7 @@ public class GroupManager extends JavaPlugin {
overloadedUsers.put(dataHolder.getName().toLowerCase(), new ArrayList<User>());
}
dataHolder.overloadUser(auxUser.getLastName());
- overloadedUsers.get(dataHolder.getName().toLowerCase()).add(dataHolder.getUser(auxUser.getLastName()));
+ overloadedUsers.get(dataHolder.getName().toLowerCase()).add(dataHolder.getUser(auxUser.getUUID()));
sender.sendMessage(ChatColor.YELLOW + "Player set to overload mode!");
return true;
@@ -1694,7 +1694,7 @@ public class GroupManager extends JavaPlugin {
auxUser = dataHolder.getUser(args[0]);
}
// Validating permission
- if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getLastName(), senderGroup.getName()) : false)) {
+ if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getUUID(), senderGroup.getName()) : false)) {
sender.sendMessage(ChatColor.RED + "You can't modify a player with same permissions as you, or higher.");
return true;
}
@@ -1892,7 +1892,7 @@ public class GroupManager extends JavaPlugin {
return true;
}
// Validating permission
- if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getLastName(), senderGroup.getName()) : false)) {
+ if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getUUID(), senderGroup.getName()) : false)) {
sender.sendMessage(ChatColor.RED + "You can't modify a player with same permissions as you, or higher.");
return true;
}
@@ -1900,7 +1900,7 @@ public class GroupManager extends JavaPlugin {
sender.sendMessage(ChatColor.RED + "The destination group can't be the same as yours, or higher.");
return true;
}
- if (!isConsole && !isOpOverride && (!permissionHandler.inGroup(senderUser.getLastName(), auxUser.getGroupName()) || !permissionHandler.inGroup(senderUser.getLastName(), auxGroup.getName()))) {
+ if (!isConsole && !isOpOverride && (!permissionHandler.inGroup(senderUser.getUUID(), auxUser.getGroupName()) || !permissionHandler.inGroup(senderUser.getUUID(), auxGroup.getName()))) {
sender.sendMessage(ChatColor.RED + "You can't modify a player involving a group that you don't inherit.");
return true;
}
@@ -1948,7 +1948,7 @@ public class GroupManager extends JavaPlugin {
return true;
}
// Validating permission
- if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getLastName(), senderGroup.getName()) : false)) {
+ if (!isConsole && !isOpOverride && (senderGroup != null ? permissionHandler.inGroup(auxUser.getUUID(), senderGroup.getName()) : false)) {
sender.sendMessage(ChatColor.RED + "You can't modify a player with same permissions as you, or higher.");
return true;
}
@@ -1956,7 +1956,7 @@ public class GroupManager extends JavaPlugin {
sender.sendMessage(ChatColor.RED + "The destination group can't be the same as yours, or higher.");
return true;
}
- if (!isConsole && !isOpOverride && (!permissionHandler.inGroup(senderUser.getLastName(), auxUser.getGroupName()) || !permissionHandler.inGroup(senderUser.getLastName(), auxGroup.getName()))) {
+ if (!isConsole && !isOpOverride && (!permissionHandler.inGroup(senderUser.getUUID(), auxUser.getGroupName()) || !permissionHandler.inGroup(senderUser.getUUID(), auxGroup.getName()))) {
sender.sendMessage(ChatColor.RED + "You can't modify a player involving a group that you don't inherit.");
return true;
}
@@ -2208,18 +2208,18 @@ public class GroupManager extends JavaPlugin {
if (players.isEmpty()) {
// Check for an offline player (exact match).
if (Arrays.asList(this.getServer().getOfflinePlayers()).contains(Bukkit.getOfflinePlayer(playerName))) {
- match.add(playerName);
+ match.add(Bukkit.getOfflinePlayer(playerName).getUniqueId().toString());
} else {
// look for partial matches
for (OfflinePlayer offline : this.getServer().getOfflinePlayers()) {
if (offline.getName().toLowerCase().startsWith(playerName.toLowerCase()))
- match.add(offline.getName());
+ match.add(offline.getUniqueId().toString());
}
}
} else {
for (Player player : players) {
- match.add(player.getName());
+ match.add(player.getUniqueId().toString());
}
}
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java
index 4a1d6506a..1e1ae96c3 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/dataholder/WorldDataHolder.java
@@ -108,8 +108,10 @@ public class WorldDataHolder {
}
/**
- * Search for a user. If it doesn't exist, create a new one with default
- * group.
+ * Search for a user. If it doesn't exist, create a new one with default group.
+ *
+ * If this is called passing a player name with mantogglevalidate off
+ * it can return the wrong user object (offline/online UUID match).
*
* @param userId the UUID String or name of the user
* @return class that manage that user permission
@@ -162,28 +164,19 @@ public class WorldDataHolder {
}
// Search for a LastName match
+ user = getUsers().get(currentName.toLowerCase());
- if (nameToUUIDLookup.containsKey(currentName)) {
+ if ((user != null) && user.getLastName().equalsIgnoreCase(currentName) && user.getUUID().equalsIgnoreCase(user.getLastName())) {
- for (String uid : getUUIDLookup(currentName)) {
-
- User usr = getUsers().get(uid);
-
- if (usr.getLastName().equalsIgnoreCase(currentName) && usr.getUUID().equalsIgnoreCase(usr.getLastName())) {
-
- // Clone this user so we can set it's uUID
- user = usr.clone(uUID, currentName);
-
- // Delete it and replace with the new clone.
- this.removeUser(usr.getUUID());
- this.addUser(user);
-
- return getUsers().get(uUID.toLowerCase());
- }
-
- }
- }
+ // Clone this user so we can set it's uUID
+ User usr = user.clone(uUID, currentName);
+
+ // Delete it and replace with the new clone.
+ this.removeUser(user.getUUID());
+ this.addUser(usr);
+ return getUsers().get(uUID.toLowerCase());
+ }
// No user account found so create a new one.
User newUser = createUser(uUID);
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java
index d8d12d836..12b6d4e7e 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/AnjoPermissionsHandler.java
@@ -67,7 +67,7 @@ public class AnjoPermissionsHandler extends PermissionsReaderInterface {
@Override
public boolean permission(Player player, String permission) {
- return checkUserPermission(ph.getUser(player.getName()).updatePlayer(player), permission);
+ return checkUserPermission(ph.getUser(player.getUniqueId().toString()).updatePlayer(player), permission);
}
/**
diff --git a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java
index a4f68864f..dc2197c91 100644
--- a/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java
+++ b/EssentialsGroupManager/src/org/anjocaido/groupmanager/permissions/BukkitPermissions.java
@@ -147,21 +147,21 @@ public class BukkitPermissions {
return;
}
- String name = player.getName();
+ String uuid = player.getUniqueId().toString();
// Reset the User objects player reference.
- User user = plugin.getWorldsHolder().getWorldData(player.getWorld().getName()).getUser(name);
+ User user = plugin.getWorldsHolder().getWorldData(player.getWorld().getName()).getUser(uuid);
if (user != null)
user.updatePlayer(player);
PermissionAttachment attachment;
// Find the players current attachment, or add a new one.
- if (this.attachments.containsKey(name)) {
- attachment = this.attachments.get(name);
+ if (this.attachments.containsKey(uuid)) {
+ attachment = this.attachments.get(uuid);
} else {
attachment = player.addAttachment(plugin);
- this.attachments.put(name, attachment);
+ this.attachments.put(uuid, attachment);
}
if (world == null) {
@@ -170,7 +170,7 @@ public class BukkitPermissions {
// Add all permissions for this player (GM only)
// child nodes will be calculated by Bukkit.
- List<String> playerPermArray = new ArrayList<String>(plugin.getWorldsHolder().getWorldData(world).getPermissionsHandler().getAllPlayersPermissions(name, false));
+ List<String> playerPermArray = new ArrayList<String>(plugin.getWorldsHolder().getWorldData(world).getPermissionsHandler().getAllPlayersPermissions(uuid, false));
LinkedHashMap<String, Boolean> newPerms = new LinkedHashMap<String, Boolean>();
// Sort the perm list by parent/child, so it will push to superperms
@@ -190,7 +190,7 @@ public class BukkitPermissions {
*/
if (!Bukkit.getServer().getOnlineMode()
&& (newPerms.containsKey("groupmanager.noofflineperms") && (newPerms.get("groupmanager.noofflineperms") == true))) {
- removeAttachment(name);
+ removeAttachment(uuid);
return;
}
@@ -219,7 +219,7 @@ public class BukkitPermissions {
e.printStackTrace();
}
- GroupManager.logger.finest("Attachment updated for: " + name);
+ GroupManager.logger.finest("Attachment updated for: " + player.getName());
}
/**