Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-5426

isSimilar for player heads fails

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • None
    • git-Spigot-f39a89e-f777640 (MC: 1.15) (Implementing API version 1.15-R0.1-SNAPSHOT)
    • Yes

      The isSimilar returns false for equal skulls. This is due to a bug in the equals method of googles ForwardingMultimap.

      The issue should be pretty obvious:

      public boolean equals(@Nullable Object object) { return (object == this || delegate().equals(object)); }
      

      As usual some test code:

      public class TestPlugin extends JavaPlugin implements Listener {
      
         @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 = CraftItemStack.asBukkitCopy(CraftItemStack.asNMSCopy(head1));  //Creating a second, equal ItemStack would work as well.
      
            System.out.println(head1);
            System.out.println(head2);
            System.out.println("This should be true: " + head1.isSimilar(head2));
         }
      
         private static 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);
         }
      }

            Unassigned Unassigned
            Gerrygames Gero Cammans
            Votes:
            3 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved: