Fixed issue with player name not being set correctly.

This commit is contained in:
tastybento 2018-05-25 17:15:56 -07:00
parent 682d34849a
commit 74c86901d0
4 changed files with 31 additions and 15 deletions

View File

@ -28,14 +28,14 @@ import us.tastybento.bskyblock.api.placeholders.PlaceholderHandler;
public class User {
private static Map<UUID, User> 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()
*/

View File

@ -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();
}
/**

View File

@ -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<World> getOverWorlds() {
return worlds.keySet().stream().filter(w -> w.getEnvironment().equals(Environment.NORMAL)).collect(Collectors.toSet());
public List<World> 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);
}
}

View File

@ -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();