Java Code Examples for com.mojang.authlib.minecraft.MinecraftProfileTexture#Type

The following examples show how to use com.mojang.authlib.minecraft.MinecraftProfileTexture#Type . 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
private static void getTexturesMojang(Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> textures, String texturesBase64, GameProfile profile) {
    // Decode textures payload
    JsonObject texturesJSON;
    try {
        byte[] decoded = Base64.getDecoder().decode(texturesBase64);
        texturesJSON = JsonParser.parseString(new String(decoded, IOHelper.UNICODE_CHARSET)).getAsJsonObject().getAsJsonObject("textures");
    } catch (Exception ignored) {
        LogHelper.error("Could not decode textures payload, Username: '%s', UUID: '%s'", profile.getName(), profile.getUUID());
        return;
    }

    // Fetch textures from textures JSON
    for (MinecraftProfileTexture.Type type : MinecraftProfileTexture.PROFILE_TEXTURE_TYPES) {
        if (textures.containsKey(type))
            continue; // Overriden by launcher

        // Get texture from JSON
        JsonElement textureJSON = texturesJSON.get(type.name());
        if (textureJSON != null && textureJSON.isJsonObject()) {
            JsonElement urlValue = textureJSON.getAsJsonObject().get("url");
            if (urlValue.isJsonPrimitive())
                textures.put(type, new MinecraftProfileTexture(urlValue.getAsString()));
        }
    }
}
 
Example 2
Source File: MixinSkinManager.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "loadSkinFromCache", cancellable = true, at = @At("HEAD"))
private void injectSkinProtect(GameProfile gameProfile, CallbackInfoReturnable<Map<MinecraftProfileTexture.Type, MinecraftProfileTexture>> cir) {
    if (gameProfile == null)
        return;
    
    NameProtect nameProtect = (NameProtect) LiquidBounce.moduleManager.getModule(NameProtect.class);

    if (nameProtect.getState() && nameProtect.skinProtectValue.get()) {
        if (nameProtect.allPlayersValue.get() || Objects.equals(gameProfile.getId(), Minecraft.getMinecraft().getSession().getProfile().getId())) {
            cir.setReturnValue(new HashMap<>());
            cir.cancel();
        }
    }
}
 
Example 3
Source File: MixinSkinManager.java    From LiquidBounce with GNU General Public License v3.0 5 votes vote down vote up
@Inject(method = "loadSkinFromCache", cancellable = true, at = @At("HEAD"))
private void injectSkinProtect(GameProfile gameProfile, CallbackInfoReturnable<Map<MinecraftProfileTexture.Type, MinecraftProfileTexture>> cir) {
    if (gameProfile == null)
        return;
    
    NameProtect nameProtect = (NameProtect) LiquidBounce.moduleManager.getModule(NameProtect.class);

    if (nameProtect.getState() && nameProtect.skinProtectValue.get()) {
        if (nameProtect.allPlayersValue.get() || Objects.equals(gameProfile.getId(), Minecraft.getMinecraft().getSession().getProfile().getId())) {
            cir.setReturnValue(new HashMap<>());
            cir.cancel();
        }
    }
}
 
Example 4
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 5
Source File: PlayerSkinProviderMixin.java    From Wurst7 with GNU General Public License v3.0 4 votes vote down vote up
@Inject(at = {@At("HEAD")},
	method = {
		"loadSkin(Lcom/mojang/authlib/GameProfile;Lnet/minecraft/client/texture/PlayerSkinProvider$SkinTextureAvailableCallback;Z)V"},
	cancellable = true)
private void onLoadSkin(GameProfile profile,
	PlayerSkinProvider.SkinTextureAvailableCallback callback,
	boolean requireSecure, CallbackInfo ci)
{
	// Can't @Inject nicely because everything is wrapped in a lambda.
	// Had to replace the whole method.
	
	Runnable runnable = () -> {
		HashMap<MinecraftProfileTexture.Type, MinecraftProfileTexture> map =
			Maps.newHashMap();
		
		try
		{
			map.putAll(sessionService.getTextures(profile, requireSecure));
		}catch(InsecureTextureException var7)
		{
			
		}
		
		if(map.isEmpty())
		{
			profile.getProperties().clear();
			if(profile.getId().equals(MinecraftClient.getInstance()
				.getSession().getProfile().getId()))
			{
				profile.getProperties().putAll(
					MinecraftClient.getInstance().getSessionProperties());
				map.putAll(sessionService.getTextures(profile, false));
			}else
			{
				sessionService.fillProfileProperties(profile,
					requireSecure);
				
				try
				{
					map.putAll(
						sessionService.getTextures(profile, requireSecure));
				}catch(InsecureTextureException var6)
				{
					
				}
			}
		}
		
		addWurstCape(profile, map);
		
		MinecraftClient.getInstance().execute(() -> {
			RenderSystem.recordRenderCall(() -> {
				ImmutableList.of(Type.SKIN, Type.CAPE).forEach((type) -> {
					if(map.containsKey(type))
						loadSkin(map.get(type), type, callback);
				});
			});
		});
	};
	Util.getServerWorkerExecutor().execute(runnable);
	
	ci.cancel();
}
 
Example 6
Source File: PaperMinecraftSessionService.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Map<MinecraftProfileTexture.Type, MinecraftProfileTexture> getTextures(GameProfile profile, boolean requireSecure) {
    return super.getTextures(profile, requireSecure);
}