1.15.2 Base64 Encode/Decode??

Discussion in 'Spigot Plugin Development' started by Snowmite, Jan 11, 2020.

  1. What I am trying to do is get a "net.minecraft" custom head skull, and encode it using Base64.

    For example, I am using this burger skull:
    http://textures.minecraft.net/texture/a6ef1c25f516f2e7d6f7667420e33adcf3cdf938cb37f9a41a8b35869f569b

    If I go to base64encode.org, and I input that link to the encoder, I get this:
    aHR0cDovL3RleHR1cmVzLm1pbmVjcmFmdC5uZXQvdGV4dHVyZS9hNmVmMWMyNWY1MTZmMmU3ZDZmNzY2NzQyMGUzM2FkY2YzY2RmOTM4Y2IzN2Y5YTQxYThiMzU4NjlmNTY5Yg==

    So, back to the main coding part, I have this method:
    Code (Text):
        public static ItemStack createHeadClone(Food food) {
            ItemStack skull = XMaterial.PLAYER_HEAD.parseItem();
            byte[] array = Base64.getEncoder().encode(food.getLink().getBytes());
            Bukkit.broadcastMessage("to string: " + food.getLink());
            UUID hashAsId = new UUID(array.hashCode(), array.hashCode());

            return Bukkit.getUnsafe().modifyItemStack(skull,
                    "{SkullOwner:{Id:\"" + hashAsId + "\",Properties:{textures:[{Value:\"" + array.toString() + "\"}]}}}");
        }
    And ingame, this is what is broadcasted:
    Code (Text):
    [[email protected] some weird stuff like this
    So, how would I encode a string like this? Doing it online works, but I want to do it automatically, that way it saves hours of editing the config,

    Am I using the Base64 Encoder incorrectly in my code? Anything he
     
  2. if you wanna convert the byte array to a String, you can just using the String constructor: new String(array)
     
    • Agree Agree x 1
  3. md_5

    Administrator Developer

    That will produce garbage.

    Op wants to replace byte[] array = Base64.getEncoder().encode(food.getLink().getBytes()); with
    String array = Base64.getEncoder().encodeToString(food.getLink().getBytes());