Java Code Examples for com.mojang.authlib.GameProfile

The following examples show how to use com.mojang.authlib.GameProfile. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: PingAPI   Source File: ServerInfoPacketHandler.java    License: MIT License 6 votes vote down vote up
/**
 * Creates a new PingReply instance from the data found in a PacketStatusOutServerInfo packet
 * @param packet The PacketStatusOutServerInfo instance
 * @param ctx The ChannelHandlerContext instance
 * @return A PingReply instance
 */
public static PingReply constructReply(PacketStatusOutServerInfo packet, ChannelHandlerContext ctx) {
	try {
		ServerPing ping = (ServerPing) SERVER_PING_FIELD.get(packet);
		String motd = ChatSerializer.a(ping.a());
		int max = ping.b().a();
		int online = ping.b().b();
		int protocolVersion = ping.getServerData().getProtocolVersion();
		String protocolName = ping.getServerData().a();
		GameProfile[] profiles = ping.b().c();
		List<String> list = new ArrayList<String>();
		for(int i = 0; i < profiles.length; i++) {
			list.add(profiles[i].getName());
		}
		PingReply reply = new PingReply(ctx, motd, online, max, protocolVersion, protocolName, list);
		return reply;
	} catch(IllegalAccessException e) {
		e.printStackTrace();
	}
	return null;
}
 
Example 2
Source Project: PingAPI   Source File: ServerInfoPacketHandler.java    License: MIT License 6 votes vote down vote up
/**
 * Creates a new PingReply instance from the data found in a PacketStatusOutServerInfo packet
 * @param packet The PacketStatusOutServerInfo instance
 * @param ctx The ChannelHandlerContext instance
 * @return A PingReply instance
 */
public static PingReply constructReply(PacketStatusOutServerInfo packet, ChannelHandlerContext ctx) {
	try {
		ServerPing ping = (ServerPing) SERVER_PING_FIELD.get(packet);
		String motd = ChatSerializer.a(ping.a());
		int max = ping.b().a();
		int online = ping.b().b();
		int protocolVersion = ping.c().b();
		String protocolName = ping.c().a();
		GameProfile[] profiles = ping.b().c();
		List<String> list = new ArrayList<String>();
		for(int i = 0; i < profiles.length; i++) {
			list.add(profiles[i].getName());
		}
		PingReply reply = new PingReply(ctx, motd, online, max, protocolVersion, protocolName, list);
		return reply;
	} catch(IllegalAccessException e) {
		e.printStackTrace();
	}
	return null;
}
 
Example 3
Source Project: PingAPI   Source File: ServerInfoPacketHandler.java    License: MIT License 6 votes vote down vote up
/**
 * Creates a new PacketStatusOutServerInfo packet from the data found in a PingReply instance
 * @param reply The PingReply instance
 * @return A PacketStatusOutServerInfo packet
 */
public static PacketStatusOutServerInfo constructPacket(PingReply reply) {
	GameProfile[] sample = new GameProfile[reply.getPlayerSample().size()];
	List<String> list = reply.getPlayerSample();
	for(int i = 0; i < list.size(); i++) {
		sample[i] = new GameProfile(UUID.randomUUID(), list.get(i));
	}
	ServerPingPlayerSample playerSample = new ServerPingPlayerSample(reply.getMaxPlayers(), reply.getOnlinePlayers());
	playerSample.a(sample);
	ServerPing ping = new ServerPing();
	ping.setMOTD(new ChatComponentText(reply.getMOTD()));
	ping.setPlayerSample(playerSample);
	ping.setServerInfo(new ServerData(reply.getProtocolName(), reply.getProtocolVersion()));
	ping.setFavicon(((CraftIconCache) reply.getIcon()).value);
	return new PacketStatusOutServerInfo(ping);
}
 
Example 4
Source Project: PGM   Source File: NMSHacks.java    License: GNU Affero General Public License v3.0 6 votes vote down vote up
static PacketPlayOutPlayerInfo.PlayerInfoData playerListPacketData(
    PacketPlayOutPlayerInfo packet,
    UUID uuid,
    String name,
    @Nullable BaseComponent displayName,
    GameMode gamemode,
    int ping,
    @Nullable Skin skin) {
  GameProfile profile = new GameProfile(uuid, name);
  if (skin != null) {
    for (Map.Entry<String, Collection<Property>> entry :
        Skins.toProperties(skin).asMap().entrySet()) {
      profile.getProperties().putAll(entry.getKey(), entry.getValue());
    }
  }
  PacketPlayOutPlayerInfo.PlayerInfoData data =
      packet.constructData(
          profile,
          ping,
          gamemode == null ? null : WorldSettings.EnumGamemode.getById(gamemode.getValue()),
          null); // ELECTROID
  data.displayName = displayName == null ? null : new BaseComponent[] {displayName};
  return data;
}
 
Example 5
Source Project: The-5zig-Mod   Source File: ServerPing.java    License: MIT License 6 votes vote down vote up
private int checkPing() {
	long l = System.currentTimeMillis();
	if (l - lastPinged < 1000) {
		return ping;
	}
	lastPinged = l;

	GameProfile gameProfile = The5zigMod.getDataManager().getGameProfile();
	for (NetworkPlayerInfo networkPlayerInfo : The5zigMod.getVars().getServerPlayers()) {
		if (gameProfile.equals(networkPlayerInfo.getGameProfile()) || gameProfile.getName().equals(ChatColor.stripColor(networkPlayerInfo.getDisplayName()))
				|| (networkPlayerInfo.getGameProfile() != null && gameProfile.getName().equals(networkPlayerInfo.getGameProfile().getName()))) {
			if (networkPlayerInfo.getPing() <= 0) {
				ping = 0;
			} else {
				ping = networkPlayerInfo.getPing();
			}
			break;
		}
	}

	return ping;
}
 
Example 6
Source Project: The-5zig-Mod   Source File: ResourceManager.java    License: MIT License 6 votes vote down vote up
public boolean renderInPersonMode(Object instance, Object itemStackObject, Object entityPlayerObject, Object cameraTransformTypeObject, boolean leftHand) {
	if (!MinecraftFactory.getClassProxyCallback().isRenderCustomModels()) {
		return false;
	}
	adz itemStack = (adz) itemStackObject;
	if (!(entityPlayerObject instanceof zs)) {
		return false;
	}
	zs entityPlayer = (zs) entityPlayerObject;
	bpl.b cameraTransformType = (bpl.b) cameraTransformTypeObject;
	GameProfile profile = entityPlayer.cP();
	PlayerResource playerResource = playerProfile.getName().equals(profile.getName()) ? ownPlayerResource : playerResources.getIfPresent(profile.getId());
	if (playerResource == null || playerResource.getItemModelResources() == null) {
		return false;
	}
	for (ItemModelResource itemModelResource : playerResource.getItemModelResources()) {
		if (shouldRender(itemModelResource, entityPlayer, itemStack)) {
			render(instance, itemStack, itemModelResource, cameraTransformType, leftHand);
			return true;
		}
	}

	return false;
}
 
Example 7
Source Project: fabric-carpet   Source File: PlayerCommand.java    License: MIT License 6 votes vote down vote up
private static boolean cantSpawn(CommandContext<ServerCommandSource> context)
{
    String playerName = StringArgumentType.getString(context, "player");
    MinecraftServer server = context.getSource().getMinecraftServer();
    PlayerManager manager = server.getPlayerManager();
    PlayerEntity player = manager.getPlayer(playerName);
    if (player != null)
    {
        Messenger.m(context.getSource(), "r Player ", "rb " + playerName, "r  is already logged on");
        return true;
    }
    GameProfile profile = server.getUserCache().findByName(playerName);
    if (manager.getUserBanList().contains(profile))
    {
        Messenger.m(context.getSource(), "r Player ", "rb " + playerName, "r  is banned");
        return true;
    }
    if (manager.isWhitelistEnabled() && profile != null && manager.isWhitelisted(profile) && !context.getSource().hasPermissionLevel(2))
    {
        Messenger.m(context.getSource(), "r Whitelisted players can only be spawned by operators");
        return true;
    }
    return false;
}
 
Example 8
Source Project: XSeries   Source File: SkullUtils.java    License: MIT License 6 votes vote down vote up
@Nonnull
public static SkullMeta getSkullByValue(@Nonnull SkullMeta head, @Nonnull String value) {
    Validate.notEmpty(value, "Skull value cannot be null or empty");
    GameProfile profile = new GameProfile(UUID.randomUUID(), null);

    profile.getProperties().put("textures", new Property("textures", value));
    try {
        Field profileField = head.getClass().getDeclaredField("profile");
        profileField.setAccessible(true);
        profileField.set(head, profile);
    } catch (SecurityException | NoSuchFieldException | IllegalAccessException ex) {
        ex.printStackTrace();
    }

    return head;
}
 
Example 9
Source Project: QualityArmory   Source File: SkullHandler.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static String getURL(ItemStack is) {
	if (is.getType() !=MultiVersionLookup.getSkull())
		return null;
	ItemMeta headMeta = is.getItemMeta();
	Class<?> headMetaClass = headMeta.getClass();
	GameProfile prof = ReflectionsUtil.getField(headMetaClass, "profile", GameProfile.class).get(headMeta);
	PropertyMap propertyMap = prof.getProperties();
	Collection<Property> textures64 = propertyMap.get("textures");
	String tex64 = null;
	for (Property p : textures64) {
		if (p.getName().equals("textures")) {
			tex64 = p.getValue();
			break;
		}
	}
	if (tex64 != null) {
	    byte[] decode = null;
		decode = Base64.getDecoder().decode(tex64);
		String string = new String(decode);
		String parsed = string.split("SKIN:{url:\"")[1].split("\"}}}")[0];
		return parsed;
	}
	return null;
}
 
Example 10
Source Project: PingAPI   Source File: ServerInfoPacketHandler.java    License: MIT License 6 votes vote down vote up
/**
 * Creates a new PingReply instance from the data found in a PacketStatusOutServerInfo packet
 * @param packet The PacketStatusOutServerInfo instance
 * @param ctx The ChannelHandlerContext instance
 * @return A PingReply instance
 */
public static PingReply constructReply(PacketStatusOutServerInfo packet, ChannelHandlerContext ctx) {
	try {
		ServerPing ping = (ServerPing) SERVER_PING_FIELD.get(packet);
		String motd = ChatSerializer.a(ping.a());
		int max = ping.b().a();
		int online = ping.b().b();
		int protocolVersion = ping.getServerData().getProtocolVersion();
		String protocolName = ping.getServerData().a();
		GameProfile[] profiles = ping.b().c();
		List<String> list = new ArrayList<String>();
		for(int i = 0; i < profiles.length; i++) {
			list.add(profiles[i].getName());
		}
		PingReply reply = new PingReply(ctx, motd, online, max, protocolVersion, protocolName, list);
		return reply;
	} catch(IllegalAccessException e) {
		e.printStackTrace();
	}
	return null;
}
 
Example 11
Source Project: ForgeHax   Source File: ChatIdentifierService.java    License: MIT License 6 votes vote down vote up
private static boolean extract(
    String message, Pattern[] patterns, BiConsumer<GameProfile, String> callback) {
  for (Pattern pattern : patterns) {
    Matcher matcher = pattern.matcher(message);
    if (matcher.find()) {
      final String messageSender = matcher.group(1);
      final String messageOnly = matcher.group(2);
      if (!Strings.isNullOrEmpty(messageSender)) {
        for (NetworkPlayerInfo data : getLocalPlayer().connection.getPlayerInfoMap()) {
          if (
              String.CASE_INSENSITIVE_ORDER
                  .compare(messageSender, data.getGameProfile().getName())
                  == 0) {
            callback.accept(data.getGameProfile(), messageOnly);
            return true;
          }
        }
      }
    }
  }
  return false;
}
 
Example 12
Source Project: Et-Futurum   Source File: ItemSkullRenderer.java    License: The Unlicense 6 votes vote down vote up
@Override
public void renderItem(ItemRenderType type, ItemStack stack, Object... data) {
	GameProfile profile = stack.hasTagCompound() ? profile = getGameProfile(stack) : null;

	switch (type) {
		case ENTITY:
			renderSkull(-0.25F, -0.5F, -0.5F, stack.getItemDamage(), profile);
			break;
		case EQUIPPED:
			renderSkull(0.5F, 0.0F, 0.0F, stack.getItemDamage(), profile);
			break;
		case EQUIPPED_FIRST_PERSON:
			renderSkull(0.5F, 0.35F, 0.25F, stack.getItemDamage(), profile);
			break;
		case INVENTORY:
			OpenGLHelper.scale(1.5, 1.5, 1.5);
			renderSkull(0.75F, 0.30F, 0.5F, stack.getItemDamage(), profile);
			break;
		default:
			break;
	}
}
 
Example 13
Source Project: PingAPI   Source File: ServerInfoPacketHandler.java    License: MIT License 6 votes vote down vote up
/**
 * Creates a new PacketStatusOutServerInfo packet from the data found in a PingReply instance
 * @param reply The PingReply instance
 * @return A PacketStatusOutServerInfo packet
 */
public static PacketStatusOutServerInfo constructPacket(PingReply reply) {
	GameProfile[] sample = new GameProfile[reply.getPlayerSample().size()];
	List<String> list = reply.getPlayerSample();
	for(int i = 0; i < list.size(); i++) {
		sample[i] = new GameProfile(UUID.randomUUID(), list.get(i));
	}
	ServerPingPlayerSample playerSample = new ServerPingPlayerSample(reply.getMaxPlayers(), reply.getOnlinePlayers());
	playerSample.a(sample);
	ServerPing ping = new ServerPing();
	ping.setMOTD(new ChatComponentText(reply.getMOTD()));
	ping.setPlayerSample(playerSample);
	ping.setServerInfo(new ServerData(reply.getProtocolName(), reply.getProtocolVersion()));
	ping.setFavicon(((CraftIconCache) reply.getIcon()).value);
	return new PacketStatusOutServerInfo(ping);
}
 
Example 14
Source Project: OpenPeripheral-Addons   Source File: TileEntityGlassesBridge.java    License: MIT License 6 votes vote down vote up
private void queueEvent(String event, EntityPlayer user, IEventArgsSource source) {
	final GameProfile gameProfile = user.getGameProfile();
	final UUID userId = gameProfile.getId();
	final String idString = userId != null? userId.toString() : null;
	final String userName = gameProfile.getName();

	for (IArchitectureAccess computer : computers) {
		final Object[] extra = source.getArgs(computer);
		final Object[] args = new Object[3 + extra.length];
		System.arraycopy(extra, 0, args, 3, extra.length);
		args[0] = computer.peripheralName();
		args[1] = userName;
		args[2] = idString;

		computer.signal(event, args);
	}
}
 
Example 15
Source Project: ForgeHax   Source File: ScoreboardListenerService.java    License: MIT License 6 votes vote down vote up
private void fireEvents(
    SPacketPlayerListItem.Action action, PlayerInfo info, GameProfile profile) {
  if (ignore || info == null) {
    return;
  }
  switch (action) {
    case ADD_PLAYER: {
      MinecraftForge.EVENT_BUS.post(new PlayerConnectEvent.Join(info, profile));
      break;
    }
    case REMOVE_PLAYER: {
      MinecraftForge.EVENT_BUS.post(new PlayerConnectEvent.Leave(info, profile));
      break;
    }
  }
}
 
Example 16
Source Project: The-5zig-Mod   Source File: ResourceManager.java    License: MIT License 6 votes vote down vote up
public boolean renderInPersonMode(Object instance, Object itemStackObject, Object entityPlayerObject, Object cameraTransformTypeObject, boolean leftHand) {
	if (!MinecraftFactory.getClassProxyCallback().isRenderCustomModels()) {
		return false;
	}
	adq itemStack = (adq) itemStackObject;
	if (!(entityPlayerObject instanceof zj)) {
		return false;
	}
	zj entityPlayer = (zj) entityPlayerObject;
	bos.b cameraTransformType = (bos.b) cameraTransformTypeObject;
	GameProfile profile = entityPlayer.cK();
	PlayerResource playerResource = playerProfile.getName().equals(profile.getName()) ? ownPlayerResource : playerResources.getIfPresent(profile.getId());
	if (playerResource == null || playerResource.getItemModelResources() == null) {
		return false;
	}
	for (ItemModelResource itemModelResource : playerResource.getItemModelResources()) {
		if (shouldRender(itemModelResource, entityPlayer, itemStack)) {
			render(instance, itemStack, itemModelResource, cameraTransformType, leftHand);
			return true;
		}
	}

	return false;
}
 
Example 17
Source Project: PingAPI   Source File: ServerInfoPacketHandler.java    License: MIT License 6 votes vote down vote up
/**
 * Creates a new PingReply instance from the data found in a PacketStatusOutServerInfo packet
 * @param packet The PacketStatusOutServerInfo instance
 * @param ctx The ChannelHandlerContext instance
 * @return A PingReply instance
 */
public static PingReply constructReply(PacketStatusOutServerInfo packet, ChannelHandlerContext ctx) {
	try {
		ServerPing ping = (ServerPing) SERVER_PING_FIELD.get(packet);
		String motd = ChatSerializer.a(ping.a());
		int max = ping.b().a();
		int online = ping.b().b();
		int protocolVersion = ping.c().b();
		String protocolName = ping.c().a();
		GameProfile[] profiles = ping.b().c();
		List<String> list = new ArrayList<String>();
		for(int i = 0; i < profiles.length; i++) {
			list.add(profiles[i].getName());
		}
		PingReply reply = new PingReply(ctx, motd, online, max, protocolVersion, protocolName, list);
		return reply;
	} catch(IllegalAccessException e) {
		e.printStackTrace();
	}
	return null;
}
 
Example 18
Source Project: RuntimeTransformer   Source File: SkullMetaTransformer.java    License: MIT License 6 votes vote down vote up
@Inject(InjectionType.OVERRIDE)
void applyToItem(final NBTTagCompound tag) {
    super_applyToItem(tag);
    if (this.profile != null) {
        NBTTagCompound owner = new NBTTagCompound();
        GameProfileSerializer.serialize(owner, this.profile);
        tag.set("SkullOwner", owner);
        System.out.println("Set owner to " + owner);
        TileEntitySkull.b(this.profile, new Predicate<GameProfile>() {
            @Override
            public boolean apply(@Nullable GameProfile gameProfile) {
                NBTTagCompound newOwner = new NBTTagCompound();
                GameProfileSerializer.serialize(newOwner, gameProfile);
                tag.set("SkullOwner", newOwner);
                System.out.println("Received game profile!");
                return false;
            }
        });
    }

}
 
Example 19
Source Project: PingAPI   Source File: ServerInfoPacketHandler.java    License: MIT License 6 votes vote down vote up
/**
 * Creates a new PingReply instance from the data found in a PacketStatusOutServerInfo packet
 * @param packet The PacketStatusOutServerInfo instance
 * @param ctx The ChannelHandlerContext instance
 * @return A PingReply instance
 */
public static PingReply constructReply(PacketStatusOutServerInfo packet, ChannelHandlerContext ctx) {
	try {
		ServerPing ping = (ServerPing) SERVER_PING_FIELD.get(packet);
		String motd = ChatSerializer.a(ping.a());
		int max = ping.b().a();
		int online = ping.b().b();
		int protocolVersion = ping.getServerData().getProtocolVersion();
		String protocolName = ping.getServerData().a();
		GameProfile[] profiles = ping.b().c();
		List<String> list = new ArrayList<String>();
		for(int i = 0; i < profiles.length; i++) {
			list.add(profiles[i].getName());
		}
		PingReply reply = new PingReply(ctx, motd, online, max, protocolVersion, protocolName, list);
		return reply;
	} catch(IllegalAccessException e) {
		e.printStackTrace();
	}
	return null;
}
 
Example 20
Source Project: MineLittlePony   Source File: PonySkull.java    License: MIT License 6 votes vote down vote up
@Override
public Identifier getSkinResource(@Nullable GameProfile profile) {
    deadMau5.setVisible(profile != null && "deadmau5".equals(profile.getName()));

    if (profile != null) {
        Identifier skin = SkinsProxy.instance.getSkinTexture(profile);

        if (skin != null) {
            return skin;
        }

        return DefaultSkinHelper.getTexture(PlayerEntity.getUuidFromProfile(profile));
    }

    return DefaultSkinHelper.getTexture();
}
 
Example 21
@Override
public void joinServer(GameProfile profile, String accessToken, String serverID) throws AuthenticationException {

    // Join server
    String username = profile.getName();
    if (LogHelper.isDebugEnabled()) {
        LogHelper.debug("joinServer, Username: '%s', Access token: %s, Server ID: %s", username, accessToken, serverID);
    }

    // Make joinServer request
    boolean success;
    try {
        success = new JoinServerRequest(username, accessToken, serverID).request().allow;
    } catch (Exception e) {
        LogHelper.error(e);
        throw new AuthenticationUnavailableException(e);
    }

    // Verify is success
    if (!success)
        throw new AuthenticationException("Bad Login (Clientside)");
}
 
Example 22
Source Project: ForgeHax   Source File: MatrixNotifications.java    License: MIT License 5 votes vote down vote up
private static String getUriUuid() {
  return Optional.of(MC.getSession().getProfile())
      .map(GameProfile::getId)
      .map(UUID::toString)
      .map(id -> id.replaceAll("-", ""))
      .orElse(null);
}
 
Example 23
Source Project: Thermos   Source File: CraftProfileBanList.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void pardon(String target) {
    Validate.notNull(target, "Target cannot be null");

    GameProfile profile = MinecraftServer.getServer().func_152358_ax().func_152655_a(target);
    list.func_152684_c(profile);
}
 
Example 24
Source Project: Kettle   Source File: CraftProfileBanEntry.java    License: GNU General Public License v3.0 5 votes vote down vote up
public CraftProfileBanEntry(GameProfile profile, UserListBansEntry entry, UserListBans list) {
    this.list = list;
    this.profile = profile;
    this.created = entry.getCreated() != null ? new Date(entry.getCreated().getTime()) : null;
    this.source = entry.getSource();
    this.expiration = entry.getBanEndDate() != null ? new Date(entry.getBanEndDate().getTime()) : null;
    this.reason = entry.getBanReason();
}
 
Example 25
Source Project: FastAsyncWorldedit   Source File: FaweForge.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public UUID getUUID(String name) {
    try {
        GameProfile profile = FMLCommonHandler.instance().getMinecraftServerInstance().getPlayerProfileCache().getGameProfileForUsername(name);
        return profile.getId();
    } catch (Throwable e) {
        return null;
    }
}
 
Example 26
Source Project: OpenPeripheral-Addons   Source File: TileEntityGlassesBridge.java    License: MIT License 5 votes vote down vote up
@Asynchronous
@ScriptCallable(returnTypes = ReturnType.TABLE, description = "Get the names of all the users linked up to this bridge")
public List<GameProfile> getUsers() {
	List<GameProfile> result = Lists.newArrayList();
	for (PlayerInfo info : knownPlayersByUUID.values())
		result.add(info.profile);

	return result;
}
 
Example 27
Source Project: Item-NBT-API   Source File: GameprofileTest.java    License: MIT License 5 votes vote down vote up
@Override
public void test() throws Exception {
	UUID uuid = UUID.randomUUID();
	GameProfile profile = new GameProfile(uuid, "random");
	NBTCompound nbt = NBTGameProfile.toNBT(profile);
	profile = null;
	profile = NBTGameProfile.fromNBT(nbt);
	if (profile == null || !profile.getId().equals(uuid)) {
		throw new NbtApiException("Error when converting a GameProfile from/to NBT!");
	}
}
 
Example 28
Source Project: The-5zig-Mod   Source File: ResourceManager.java    License: MIT License 5 votes vote down vote up
@Override
public Object getCapeLocation(Object player) {
	GameProfile profile = ((bpp) player).cS();
	if (playerProfile.getName().equals(profile.getName())) {
		return getCapeLocation(ownPlayerResource);
	} else {
		return getCapeLocation(playerResources.getIfPresent(profile.getId()));
	}
}
 
Example 29
Source Project: Kettle   Source File: CraftProfileBanList.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean isBanned(String target) {
    Validate.notNull(target, "Target cannot be null");

    GameProfile profile = MinecraftServer.getServerCB().getPlayerProfileCache().getGameProfileForUsername(target);
    if (profile == null) {
        return false;
    }

    return list.isBanned(profile);
}
 
Example 30
Source Project: Hyperium   Source File: MixinNBTUtil.java    License: GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @author Sk1er
 * @reason Not proper null checks
 */
@Overwrite
public static GameProfile readGameProfileFromNBT(NBTTagCompound compound) {
    String s = null;
    String s1 = null;

    if (compound.hasKey("Name", 8)) s = compound.getString("Name");
    if (compound.hasKey("Id", 8)) s1 = compound.getString("Id");

    if (StringUtils.isNullOrEmpty(s) && StringUtils.isNullOrEmpty(s1)) {
        return null;
    } else {
        UUID uuid = null;
        if (s1 != null)
            try {
                uuid = UUID.fromString(s1);
            } catch (Throwable ignored) {
            }

        GameProfile gameprofile = new GameProfile(uuid, s);

        if (compound.hasKey("Properties", 10)) {
            NBTTagCompound nbttagcompound = compound.getCompoundTag("Properties");

            for (String s2 : nbttagcompound.getKeySet()) {
                NBTTagList nbttaglist = nbttagcompound.getTagList(s2, 10);

                int bound = nbttaglist.tagCount();
                for (int i = 0; i < bound; i++) {
                    NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
                    String s3 = nbttagcompound1.getString("Value");
                    gameprofile.getProperties().put(s2, nbttagcompound1.hasKey("Signature", 8) ?
                        new Property(s2, s3, nbttagcompound1.getString("Signature")) : new Property(s2, s3));
                }
            }
        }

        return gameprofile;
    }
}