From 74c86901d08d8d75a4bb921a86ea47c27effa870 Mon Sep 17 00:00:00 2001 From: tastybento Date: Fri, 25 May 2018 17:15:56 -0700 Subject: [PATCH] Fixed issue with player name not being set correctly. --- .../tastybento/bskyblock/api/user/User.java | 23 +++++++++++-------- .../bskyblock/database/objects/Players.java | 3 ++- .../managers/IslandWorldManager.java | 18 +++++++++++---- .../bskyblock/managers/PlayersManager.java | 2 +- 4 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/main/java/us/tastybento/bskyblock/api/user/User.java b/src/main/java/us/tastybento/bskyblock/api/user/User.java index e43c88732..9d7ea7644 100644 --- a/src/main/java/us/tastybento/bskyblock/api/user/User.java +++ b/src/main/java/us/tastybento/bskyblock/api/user/User.java @@ -28,14 +28,14 @@ import us.tastybento.bskyblock.api.placeholders.PlaceholderHandler; public class User { private static Map users = new HashMap<>(); - + /** * Clears all users from the user list */ public static void clearUsers() { users.clear(); } - + /** * Get an instance of User from a CommandSender * @param sender @@ -89,7 +89,7 @@ public class User { private static BSkyBlock plugin = BSkyBlock.getInstance(); - private final Player player; + private Player player; private final UUID playerUUID; private final CommandSender sender; @@ -111,7 +111,7 @@ public class User { this.playerUUID = playerUUID; sender = player; } - + /** * Used for testing * @param plugin @@ -133,7 +133,12 @@ public class User { } public String getName() { - return player != null ? player.getName() : playerUUID.toString(); + player = Bukkit.getPlayer(playerUUID); + if (player != null) { + return player.getName(); + } + // Try and get name from database + return plugin.getPlayers().getName(playerUUID); } /** @@ -322,17 +327,17 @@ public class User { player.updateInventory(); } - + /** * Performs a command as the player * @param cmd * @return true if the command was successful, otherwise false */ public boolean performCommand(String cmd) { - return player.performCommand(cmd); - + return player.performCommand(cmd); + } - + /* (non-Javadoc) * @see java.lang.Object#hashCode() */ diff --git a/src/main/java/us/tastybento/bskyblock/database/objects/Players.java b/src/main/java/us/tastybento/bskyblock/database/objects/Players.java index 5b07109c2..ee32b4c74 100755 --- a/src/main/java/us/tastybento/bskyblock/database/objects/Players.java +++ b/src/main/java/us/tastybento/bskyblock/database/objects/Players.java @@ -55,7 +55,8 @@ public class Players implements DataObject { resetsLeft = plugin.getSettings().getResetLimit(); locale = ""; kickedList = new HashMap<>(); - this.playerName = uniqueId.toString(); // To start, until it is set later + // Try to get player's name + this.playerName = Bukkit.getOfflinePlayer(uniqueId).getName(); } /** diff --git a/src/main/java/us/tastybento/bskyblock/managers/IslandWorldManager.java b/src/main/java/us/tastybento/bskyblock/managers/IslandWorldManager.java index 109f9f3ce..cee314c9d 100644 --- a/src/main/java/us/tastybento/bskyblock/managers/IslandWorldManager.java +++ b/src/main/java/us/tastybento/bskyblock/managers/IslandWorldManager.java @@ -1,6 +1,7 @@ package us.tastybento.bskyblock.managers; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.stream.Collectors; @@ -9,9 +10,9 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.World.Environment; -import org.bukkit.entity.EntityType; import org.bukkit.WorldCreator; import org.bukkit.WorldType; +import org.bukkit.entity.EntityType; import us.tastybento.bskyblock.BSkyBlock; import us.tastybento.bskyblock.api.configuration.WorldSettings; @@ -136,10 +137,10 @@ public class IslandWorldManager { } /** - * @return Set of over worlds + * @return List of over worlds */ - public Set getOverWorlds() { - return worlds.keySet().stream().filter(w -> w.getEnvironment().equals(Environment.NORMAL)).collect(Collectors.toSet()); + public List getOverWorlds() { + return worlds.keySet().stream().filter(w -> w.getEnvironment().equals(Environment.NORMAL)).collect(Collectors.toList()); } /** @@ -408,5 +409,14 @@ public class IslandWorldManager { } return r.toString(); } + + /** + * Gets world from friendly name + * @param friendlyWorldName + * @return world, or null if not known + */ + public World getIslandWorld(String friendlyWorldName) { + return worlds.entrySet().stream().filter(e -> e.getValue().equalsIgnoreCase(friendlyWorldName)).findFirst().map(en -> en.getKey()).orElse(null); + } } diff --git a/src/main/java/us/tastybento/bskyblock/managers/PlayersManager.java b/src/main/java/us/tastybento/bskyblock/managers/PlayersManager.java index 43b655007..ea8c0739f 100644 --- a/src/main/java/us/tastybento/bskyblock/managers/PlayersManager.java +++ b/src/main/java/us/tastybento/bskyblock/managers/PlayersManager.java @@ -284,7 +284,7 @@ public class PlayersManager { */ public String getName(UUID playerUUID) { if (playerUUID == null) { - return ""; + return null; } addPlayer(playerUUID); return playerCache.get(playerUUID).getPlayerName();