Created
February 7, 2015 15:54
-
-
Save GaeaKat/bbea2cc98eb24fe6ff0b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import net.minecraftforge.common.UsernameCache; | |
import java.util.Map; | |
import java.util.UUID; | |
public class PlayerUtil { | |
public static UUID getPlayerUUID(String username) | |
{ | |
/* | |
if(FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) { | |
GameProfile profile = MinecraftServer.getServer().func_152358_ax().func_152655_a(username); | |
UUID uuid = null; | |
if (profile == null) | |
uuid = EntityPlayer.func_146094_a(new GameProfile(null, username)); | |
else | |
uuid = profile.getId(); | |
return uuid; | |
} | |
else | |
return PacketPlayerUUID.playerUUID.get(username); | |
*/ | |
for (Map.Entry<UUID,String> entry : UsernameCache.getMap().entrySet()) | |
{ | |
if (entry.getValue().equalsIgnoreCase(username)) | |
{ | |
return entry.getKey(); | |
} | |
} | |
return null; | |
} | |
public static UUID getPlayerUIDUnstable(String possibleUUID) | |
{ | |
if(possibleUUID==null || possibleUUID.isEmpty()) | |
return null; | |
UUID uuid=null; | |
try | |
{ | |
uuid=UUID.fromString(possibleUUID); | |
} | |
catch(IllegalArgumentException e) | |
{ | |
uuid=getPlayerUUID(possibleUUID); | |
} | |
return uuid; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment