(1.15.2) NPE using isSimilar on base64 textured skulls

Discussion in 'Plugin Development' started by Tango_, Feb 23, 2020.

Thread Status:
Not open for further replies.
  1. Offline

    Tango_

    Hi all, I'm getting a null pointer when comparing two skulls that have been assigned a texture. Any method that uses the equals method returns the same error, including .isSimilar, and .contains ect.

    The following code works perfectly on 1.14.4. But something has changed and now I get an NPE for some reason and its really confusing.

    Code:
           @Override
           public void onEnable() {
              ItemStack head1 = new ItemStack(Material.PLAYER_HEAD);
    
              UUID uuid = UUID.randomUUID();
              GameProfile profile1 = new GameProfile(uuid, null);
              profile1.getProperties().put("textures", new Property("textures", "some random skin value"));
    
              setProfile(head1, profile1);
    
              ItemStack head2 = head1.clone();
    
              if(head1.isSimilar(head2)) { // Fails here
                  System.out.println("Is similar");
              }
    
           }
    
           private void setProfile(ItemStack item, GameProfile profile) {
              ItemMeta meta = item.getItemMeta();
              try {
                 Field field = meta.getClass().getDeclaredField("profile");
                 field.setAccessible(true);
                 field.set(meta, profile);
              } catch (NoSuchFieldException | IllegalAccessException ex) {
                 ex.printStackTrace();
              }
              item.setItemMeta(meta);
           }
        }

    My imports:
    My imports (open)
    Code:
    import java.lang.reflect.Field;
    import java.util.UUID;
    
    import org.bukkit.Material;
    import org.bukkit.craftbukkit.libs.org.apache.commons.codec.binary.Base64;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.inventory.meta.SkullMeta;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import com.mojang.authlib.GameProfile;
    import com.mojang.authlib.properties.Property;


    The error:
    The error (open)
    Code:
    [10:57:25 ERROR]: Error occurred while enabling SkullTest v0.0.1 (Is it up to date?)
    java.lang.NullPointerException: null
            at org.bukkit.craftbukkit.v1_15_R1.inventory.CraftMetaSkull.equalsCommon(CraftMetaSkull.java:220) ~[patched_1.15.2.jar:git-Paper-112]
            at org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemFactory.equals(CraftItemFactory.java:307) ~[patched_1.15.2.jar:git-Paper-112]
            at org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemFactory.equals(CraftItemFactory.java:294) ~[patched_1.15.2.jar:git-Paper-112]
            at org.bukkit.inventory.ItemStack.isSimilar(ItemStack.java:293) ~[patched_1.15.2.jar:git-Paper-112]
            at me.tango.skulltest.Main.onEnable(Main.java:34) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:263) ~[patched_1.15.2.jar:git-Paper-112]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337) ~[patched_1.15.2.jar:git-Paper-112]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:435) ~[patched_1.15.2.jar:git-Paper-112]
            at org.bukkit.craftbukkit.v1_15_R1.CraftServer.enablePlugin(CraftServer.java:470) ~[patched_1.15.2.jar:git-Paper-112]
            at org.bukkit.craftbukkit.v1_15_R1.CraftServer.enablePlugins(CraftServer.java:384) ~[patched_1.15.2.jar:git-Paper-112]
            at net.minecraft.server.v1_15_R1.MinecraftServer.a(MinecraftServer.java:482) ~[patched_1.15.2.jar:git-Paper-112]
            at net.minecraft.server.v1_15_R1.DedicatedServer.init(DedicatedServer.java:298) ~[patched_1.15.2.jar:git-Paper-112]
            at net.minecraft.server.v1_15_R1.MinecraftServer.run(MinecraftServer.java:885) ~[patched_1.15.2.jar:git-Paper-112]
            at java.lang.Thread.run(Thread.java:834) [?:?]
    [10:57:25 INFO]: [SkullTest] Disabling SkullTest v0.0.1


    NOTE: I am able to get the skull ingame with texture, but errors when doing any comparing methods.

    Any help appreciated!
     
Thread Status:
Not open for further replies.

Share This Page