com.mojang.authlib.properties.Property Java Examples

The following examples show how to use com.mojang.authlib.properties.Property. 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: NMSHacks.java    From PGM with 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 #2
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 #3
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 #4
Source File: SpigotStuff.java    From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void setSkinProperties(Player player, SkinDataWrapper skindata) {
	CraftPlayer craftPlayer = ((CraftPlayer) player);
	EntityHuman entityHuman = craftPlayer.getHandle();
	try {
		Field gp2 = EntityHuman.class.getDeclaredField("h");
		gp2.setAccessible(true);
		GameProfile profile = (GameProfile) gp2.get(entityHuman);
		profile.getProperties().removeAll("textures");
		profile.getProperties().put("textures", new Property("textures", skindata.getValue(), skindata.getSignature()));
		gp2.set(entityHuman, profile);
	} catch (Exception e) {
		e.printStackTrace();
		return;
	}
}
 
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: 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 #7
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 #8
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 #9
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 #10
Source File: SkullUtils.java    From XSeries with 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 #11
Source File: PacketPlayOutPlayerInfo.java    From TAB with Apache License 2.0 5 votes vote down vote up
public Object toVelocity(ProtocolVersion clientVersion) {
	com.velocitypowered.proxy.protocol.packet.PlayerListItem.Item item = new com.velocitypowered.proxy.protocol.packet.PlayerListItem.Item(uniqueId);
	item.setDisplayName((Component) me.neznamy.tab.platforms.velocity.Main.componentFromString(displayName == null ? null : displayName.toString(clientVersion)));
	if (gameMode != null) item.setGameMode(gameMode.getNetworkId());
	item.setLatency(latency);
	item.setProperties((List<com.velocitypowered.api.util.GameProfile.Property>) skin);
	item.setName(name);
	return item;
}
 
Example #12
Source File: VelocityUtil.java    From Sandbox with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static void readProperties(final PacketByteBuf buf, final GameProfile profile) {
    if (buf.readableBytes() < 4)
        return;
    final int properties = buf.readInt();
    for (int i1 = 0; i1 < properties; i1++) {
        final String name = buf.readString(32767);
        final String value = buf.readString(32767);
        final String signature = buf.readBoolean() ? buf.readString(32767) : null;
        profile.getProperties().put(name, new Property(name, value, signature));
    }
}
 
Example #13
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;
}
 
Example #14
Source File: SpigotNetworkManagerWrapper.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void setSpoofedProfile(UUID uuid, Collection<ProfileProperty> properties) {
	internal.spoofedUUID = uuid;
	if (properties != null) {
		internal.spoofedProfile = properties.stream()
		.map(prop -> new Property(prop.getName(), prop.getValue(), prop.getSignature()))
		.collect(Collectors.toList())
		.toArray(new Property[0]);
	}
}
 
Example #15
Source File: SkullBlock.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
public static GameProfile getPlayerProfile(String textureValue, String textureSignature, String ownerUUID, String ownerName) {
    // Create a new GameProfile with .schematic informations or with fake informations
    GameProfile newSkinProfile = new GameProfile( ownerUUID == null ? UUID.randomUUID() : UUID.fromString(ownerUUID),
            ownerName == null ? getRandomString(16) : null);

    // Insert textures properties
    newSkinProfile.getProperties().put("textures", new Property("textures", textureValue, textureSignature));
    return newSkinProfile;
}
 
Example #16
Source File: SkullBlock.java    From askyblock with GNU General Public License v2.0 5 votes vote down vote up
public static GameProfile getNonPlayerProfile(String textureValue, String ownerUUID, String ownerName) {
    // Create a new GameProfile with .schematic informations or with fake informations
    GameProfile newSkinProfile = new GameProfile(ownerUUID == null ? UUID.randomUUID() : UUID.fromString(ownerUUID),
            ownerName == null ? getRandomString(16) : null);

    // Insert textures properties
    newSkinProfile.getProperties().put("textures", new Property("textures", textureValue));
    return newSkinProfile;
}
 
Example #17
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 #18
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 #19
Source File: MixinNBTUtil.java    From Hyperium with 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;
    }
}
 
Example #20
Source File: CraftPlayerProfile.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setProperty(ProfileProperty property) {
    String name = property.getName();
    PropertyMap properties = profile.getProperties();
    properties.removeAll(name);
    properties.put(name, new Property(name, property.getValue(), property.getSignature()));
}
 
Example #21
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 #22
Source File: SkinsGUI.java    From SkinsRestorerX with GNU General Public License v3.0 5 votes vote down vote up
private ItemStack createSkull(String name, Object property) {
    ItemStack is = XMaterial.PLAYER_HEAD.parseItem();
    SkullMeta sm = (SkullMeta) is.getItemMeta();
    List<String> lore = new ArrayList<>();
    lore.add(Locale.SKINSMENU_SELECT_SKIN.replace("&", "ยง"));
    sm.setDisplayName(name);
    sm.setLore(lore);
    is.setItemMeta(sm);
    setSkin(is, ((Property) property).getValue());
    return is;
}
 
Example #23
Source File: SkullUtil.java    From IF with The Unlicense 5 votes vote down vote up
/**
 * Sets the skull of an existing {@link ItemMeta} from the specified id.
 * The id is the value from the textures.minecraft.net website after the last '/' character.
 *
 * @param meta the meta to change
 * @param id the skull id
 */
public static void setSkull(@NotNull ItemMeta meta, @NotNull String id) {
    GameProfile profile = new GameProfile(UUID.randomUUID(), null);
    byte[] encodedData = Base64.getEncoder().encode(String.format("{textures:{SKIN:{url:\"%s\"}}}",
        "http://textures.minecraft.net/texture/" + id).getBytes());
    profile.getProperties().put("textures", new Property("textures", new String(encodedData)));

    try {
        Field profileField = meta.getClass().getDeclaredField("profile");
        profileField.setAccessible(true);
        profileField.set(meta, profile);
    } catch (NoSuchFieldException | SecurityException | IllegalAccessException e) {
        throw new RuntimeException(e);
    }
}
 
Example #24
Source File: PreLookupProfileEvent.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Get the properties for this profile
 *
 * @return the property map to attach to the new {@link PlayerProfile}
 * @deprecated will be removed with 1.13  Use {@link #getProfileProperties()}
 */
@Deprecated
@Nonnull
public Multimap<String, Property> getProperties() {
    Multimap<String, Property> props = ArrayListMultimap.create();

    for (ProfileProperty property : properties) {
        props.put(property.getName(), new Property(property.getName(), property.getValue(), property.getSignature()));
    }
    return props;
}
 
Example #25
Source File: PreLookupProfileEvent.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Completely replaces all Properties with the new provided properties
 *
 * @param properties the properties to set on the new profile
 * @deprecated will be removed with 1.13 Use {@link #setProfileProperties(Set)}
 */
@Deprecated
public void setProperties(Multimap<String, Property> properties) {
    this.properties = new HashSet<>();
    properties.values().forEach(property -> {
        this.properties.add(new ProfileProperty(property.getName(), property.getValue(), property.getSignature()));
    });
}
 
Example #26
Source File: PreLookupProfileEvent.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Adds additional properties, without removing the original properties
 *
 * @param properties the properties to add to the existing properties
 * @deprecated will be removed with 1.13 use {@link #addProfileProperties(Set)}
 */
@Deprecated
public void addProperties(Multimap<String, Property> properties) {
    properties.values().forEach(property -> {
        this.properties.add(new ProfileProperty(property.getName(), property.getValue(), property.getSignature()));
    });
}
 
Example #27
Source File: YggdrasilMinecraftSessionService.java    From Launcher with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> getTextures(GameProfile profile, boolean requireSecure) {
    if (LogHelper.isDebugEnabled()) {
        LogHelper.debug("getTextures, Username: '%s', UUID: '%s'", profile.getName(), profile.getUUID());
    }
    Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> textures = new EnumMap<>(MinecraftProfileTexture.Type.class);

    // Add textures
    if (!NO_TEXTURES) {
        // Add skin URL to textures map
        Property skinURL = Iterables.getFirst(profile.getProperties().get(Launcher.SKIN_URL_PROPERTY), null);
        Property skinDigest = Iterables.getFirst(profile.getProperties().get(Launcher.SKIN_DIGEST_PROPERTY), null);
        if (skinURL != null && skinDigest != null)
            textures.put(MinecraftProfileTexture.Type.SKIN, new MinecraftProfileTexture(skinURL.getValue(), skinDigest.getValue()));

        // Add cloak URL to textures map
        Property cloakURL = Iterables.getFirst(profile.getProperties().get(Launcher.CLOAK_URL_PROPERTY), null);
        Property cloakDigest = Iterables.getFirst(profile.getProperties().get(Launcher.CLOAK_DIGEST_PROPERTY), null);
        if (cloakURL != null && cloakDigest != null)
            textures.put(MinecraftProfileTexture.Type.CAPE, new MinecraftProfileTexture(cloakURL.getValue(), cloakDigest.getValue()));

        // Try to find missing textures in textures payload (now always true because launcher is not passing elytra skins)
        if (textures.size() != MinecraftProfileTexture.PROFILE_TEXTURE_COUNT) {
            Property texturesMojang = Iterables.getFirst(profile.getProperties().get("textures"), null);
            if (texturesMojang != null)
                getTexturesMojang(textures, texturesMojang.getValue(), profile);
        }
    }

    // Return filled textures
    return textures;
}
 
Example #28
Source File: GameProfileWrapper.java    From NameTagChanger with MIT License 5 votes vote down vote up
public static GameProfileWrapper fromHandle(Object object) {
    Validate.isTrue(object instanceof GameProfile, "object is not a GameProfile");
    GameProfile gameProfile = (GameProfile) object;
    GameProfileWrapper wrapper = new GameProfileWrapper(gameProfile.getId(), gameProfile.getName());
    for (Map.Entry<String, Collection<Property>> entry : gameProfile.getProperties().asMap().entrySet()) {
        for (Property property : entry.getValue()) {
            wrapper.getProperties().put(entry.getKey(), PropertyWrapper.fromHandle(property));
        }
    }
    return wrapper;
}
 
Example #29
Source File: GameProfileWrapper.java    From NameTagChanger with MIT License 5 votes vote down vote up
public Object getHandle() {
    GameProfile gameProfile = new GameProfile(this.uuid, this.name);
    for (Map.Entry<String, Collection<PropertyWrapper>> entry : properties.asMap().entrySet()) {
        for (PropertyWrapper wrapper : entry.getValue()) {
            gameProfile.getProperties().put(entry.getKey(), (Property) wrapper.getHandle());
        }
    }
    return gameProfile;
}
 
Example #30
Source File: NMSHacks.java    From ProjectAres with GNU Affero General Public License v3.0 5 votes vote down vote up
public 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.new PlayerInfoData(profile, ping, gamemode == null ? null : EnumGamemode.getById(gamemode.getValue()), null);
    data.displayName = displayName == null ? null : new BaseComponent[]{ displayName };
    return data;
}