Java Code Examples for com.mojang.authlib.GameProfile#getProperties()

The following examples show how to use com.mojang.authlib.GameProfile#getProperties() . 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 File: YggdrasilMinecraftSessionService.java    From Launcher with GNU General Public License v3.0 6 votes vote down vote up
public static void fillTextureProperties(GameProfile profile, PlayerProfile pp) {
    boolean debug = LogHelper.isDebugEnabled();
    if (debug) {
        LogHelper.debug("fillTextureProperties, Username: '%s'", profile.getName());
    }
    if (NO_TEXTURES)
        return;

    // Fill textures map
    PropertyMap properties = profile.getProperties();
    if (pp.skin != null) {
        properties.put(Launcher.SKIN_URL_PROPERTY, new Property(Launcher.SKIN_URL_PROPERTY, pp.skin.url, ""));
        properties.put(Launcher.SKIN_DIGEST_PROPERTY, new Property(Launcher.SKIN_DIGEST_PROPERTY, SecurityHelper.toHex(pp.skin.digest), ""));
        if (debug) {
            LogHelper.debug("fillTextureProperties, Has skin texture for username '%s'", profile.getName());
        }
    }
    if (pp.cloak != null) {
        properties.put(Launcher.CLOAK_URL_PROPERTY, new Property(Launcher.CLOAK_URL_PROPERTY, pp.cloak.url, ""));
        properties.put(Launcher.CLOAK_DIGEST_PROPERTY, new Property(Launcher.CLOAK_DIGEST_PROPERTY, SecurityHelper.toHex(pp.cloak.digest), ""));
        if (debug) {
            LogHelper.debug("fillTextureProperties, Has cloak texture for username '%s'", profile.getName());
        }
    }
}
 
Example 2
Source File: SkinsGUI.java    From SkinsRestorerX with GNU General Public License v3.0 6 votes vote down vote up
private void setSkin(ItemStack head, String b64stringtexture) {
    GameProfile profile = new GameProfile(UUID.randomUUID(), null);
    PropertyMap propertyMap = profile.getProperties();
    if (propertyMap == null) {
        throw new IllegalStateException("Profile doesn't contain a property map");
    }
    propertyMap.put("textures", new Property("textures", b64stringtexture));
    ItemMeta headMeta = head.getItemMeta();
    Class<?> headMetaClass = headMeta.getClass();
    try {
        ReflectionUtil.getField(headMetaClass, "profile", GameProfile.class, 0).set(headMeta, profile);
    } catch (IllegalArgumentException | IllegalAccessException e) {
        e.printStackTrace();
    }
    head.setItemMeta(headMeta);
}
 
Example 3
Source File: SkullHandler.java    From QualityArmory with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Return a skull that has a custom texture specified by url.
 *
 * @param url
 *            skin url
 * @return itemstack
 */
@SuppressWarnings("deprecation")
public static ItemStack getCustomSkull64(byte[] url64) {

	GameProfile profile = new GameProfile(UUID.randomUUID(), null);
	PropertyMap propertyMap = profile.getProperties();
	if (propertyMap == null) {
		throw new IllegalStateException("Profile doesn't contain a property map");
	}
	String encodedData = new String(url64);
	propertyMap.put("textures", new Property("textures", encodedData));
	ItemStack head = new ItemStack(MultiVersionLookup.getSkull(), 1, (short) 3);
	ItemMeta headMeta = head.getItemMeta();
	Class<?> headMetaClass = headMeta.getClass();
	ReflectionsUtil.getField(headMetaClass, "profile", GameProfile.class).set(headMeta, profile);
	head.setItemMeta(headMeta);
	return head;
}
 
Example 4
Source File: SkullHandler.java    From QualityArmory with 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 5
Source File: SkullHandler.java    From QualityArmory with GNU General Public License v3.0 6 votes vote down vote up
public static String getURL64(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) {
		return tex64;
	}
	return null;
}
 
Example 6
Source File: GameProfileSerializer.java    From OpenModsLib with MIT License 6 votes vote down vote up
public static void write(GameProfile o, PacketBuffer output) {
	final UUID uuid = o.getId();
	output.writeString(uuid == null? "" : uuid.toString());
	output.writeString(Strings.nullToEmpty(o.getName()));
	final PropertyMap properties = o.getProperties();
	output.writeVarInt(properties.size());
	for (Property p : properties.values()) {
		output.writeString(p.getName());
		output.writeString(p.getValue());

		final String signature = p.getSignature();
		if (signature != null) {
			output.writeBoolean(true);
			output.writeString(signature);
		} else {
			output.writeBoolean(false);
		}
	}
}
 
Example 7
Source File: GameProfileSerializer.java    From OpenModsLib with MIT License 6 votes vote down vote up
public static GameProfile read(PacketBuffer input) {
	final String uuidStr = input.readString(Short.MAX_VALUE);
	UUID uuid = Strings.isNullOrEmpty(uuidStr)? null : UUID.fromString(uuidStr);
	final String name = input.readString(Short.MAX_VALUE);
	GameProfile result = new GameProfile(uuid, name);
	int propertyCount = input.readVarInt();

	final PropertyMap properties = result.getProperties();
	for (int i = 0; i < propertyCount; ++i) {
		String key = input.readString(Short.MAX_VALUE);
		String value = input.readString(Short.MAX_VALUE);
		if (input.readBoolean()) {
			String signature = input.readString(Short.MAX_VALUE);
			properties.put(key, new Property(key, value, signature));
		} else {
			properties.put(key, new Property(key, value));
		}

	}

	return result;
}
 
Example 8
Source File: PacketPlayOutPlayerInfo.java    From TAB with Apache License 2.0 5 votes vote down vote up
public static PlayerInfoData fromNMS(Object nmsData) throws Exception{
	int ping = PING.getInt(nmsData);
	EnumGamemode gamemode = EnumGamemode.fromNMS(GAMEMODE.get(nmsData));
	GameProfile profile = (GameProfile) PROFILE.get(nmsData);
	Object nmsComponent = LISTNAME.get(nmsData);
	IChatBaseComponent listName = IChatBaseComponent.fromString(MethodAPI.getInstance().componentToString(nmsComponent));
	return new PlayerInfoData(profile.getName(), profile.getId(), profile.getProperties(), ping, gamemode, listName);
}
 
Example 9
Source File: CraftPlayerProfile.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
private static void copyProfileProperties(GameProfile source, GameProfile target) {
    PropertyMap sourceProperties = source.getProperties();
    if (sourceProperties.isEmpty()) {
        return;
    }
    PropertyMap properties = target.getProperties();
    properties.clear();

    for (Property property : sourceProperties.values()) {
        properties.put(property.getName(), property);
    }
}
 
Example 10
Source File: GuildSkull.java    From Guilds with MIT License 5 votes vote down vote up
/**
 * Get the texture of a player's skin
 * @param player the player to get the skin from
 * @return skin texture url
 */
private String getTextureUrl(Player player) {
    GameProfile profile = getProfile(player);
    if (profile == null) {
        return "";
    }
    PropertyMap propertyMap = profile.getProperties();
    for (Property property : propertyMap.get("textures")) {
        byte[] decoded = Base64.getDecoder().decode(property.getValue());
        JsonObject texture = new JsonParser().parse(new String(decoded)).getAsJsonObject().get("textures").getAsJsonObject().get("SKIN").getAsJsonObject();
        return texture.get("url").getAsString();
    }
    return "";
}
 
Example 11
Source File: ItemUtils.java    From ProRecipes with GNU General Public License v2.0 5 votes vote down vote up
public static GameProfile createGameProfile(String texture, UUID id)
{
  GameProfile profile = new GameProfile(id, null);
  PropertyMap propertyMap = profile.getProperties();
  if (propertyMap == null)
  {
    Bukkit.getLogger().log(Level.INFO, "No property map found in GameProfile, can't continue.");
    return null;
  }
  propertyMap.put("textures", new Property("textures", texture));
  propertyMap.put("Signature", new Property("Signature", "1234"));
  return profile;
}
 
Example 12
Source File: SpigotMiscUtils.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
public static GameProfile toMojangGameProfile(LoginProfile profile) {
	GameProfile mojangGameProfile = new GameProfile(profile.getUUID(), profile.getName());
	PropertyMap mojangProperties = mojangGameProfile.getProperties();
	profile.getProperties().entrySet().forEach(entry -> mojangProperties.putAll(
		entry.getKey(),
		entry.getValue().stream()
		.map(p -> new Property(p.getName(), p.getValue(), p.getSignature()))
		.collect(Collectors.toList()))
	);
	return mojangGameProfile;
}