GetType

Discussion in 'Plugin Development' started by pvtr_, Jan 5, 2020.

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

    pvtr_

    Hello, I am creating a plugin for the limit of items in inventory and everything is fine, I only encountered a small problem ... I did the GetType method it works, but it also takes a normal item, and I would like it to take only the item with the given name "Treatment" "and this subject is a blaze rod
    Code:
                        if (pinv.getType() == Material.BLAZE_ROD) { 
                            blazeSize += sinv.getAmount();
                        }
    
    Code:
                if (gheadSize > 1) {
                    limit = true;
                    final int toRemove = gheadSize - 1;
                    u.getStore().setGheads(u.getStore().getGheads() + toRemove);
                    p.getInventory().removeItem(new ItemStack[] { HeadManager.getHeadItemStack(toRemove)});
                }
    
    HeadManager
    Code:
    public class HeadManager
    {
        private static final List<UUID> heads;
       
        public static void removeHead(final UUID uuid) {
            HeadManager.heads.remove(uuid);
        }
       
        public static List<UUID> getHeads() {
            return HeadManager.heads;
        }
       
        public static void throwHead(final Player player) {
            ItemsUtil.removeItemInHand(player);
        }
       
        public static ItemStack getHeadItemStack(final int size) {
            return new ItemBuilder(Material.BLAZE_ROD, size).addEnchant(Enchantment.PROTECTION_ENVIRONMENTAL, 1).setName(ChatUtil.fixColors("&e&
    Treatment
    "));
        }
       
        public static boolean isHead(final ItemStack item) {
            return item != null && item.hasItemMeta() && item.getItemMeta().hasDisplayName() && item.getItemMeta().getDisplayName().equalsIgnoreCase(ChatUtil.fixColors("&e&
    Treatment
    "));
        }
       
        static {
            heads = new ArrayList<UUID>();
        }
    }
     
  2. Offline

    timtower Administrator Administrator Moderator

    @pvtr_ Check if there is itemmeta.
    Get the itemmeta.
    Check if there is a displayname.
    Check the displayname.
     
  3. Offline

    pvtr_

    @timtower I can ask a little more clearly because I don't know how to use it instead of material :/
     
  4. Offline

    timtower Administrator Administrator Moderator

  5. Offline

    pvtr_

    It now downloads the same name with the blaze rod, but also tries to download the unnamed and pops up the message but does not download it anyway
    Code:
                        if (pinv.getType() == Material.BLAZE_ROD) {
                            if (pinv.hasItemMeta() && pinv.getItemMeta().hasDisplayName() && pinv.getItemMeta().getDisplayName().equalsIgnoreCase(ChatUtil.fixColors("&e&lGLOWA"))); {                                     
                                gheadSize += pinv.getAmount();
                            }
                        }
    
     
    Last edited: Jan 5, 2020
  6. Offline

    timtower Administrator Administrator Moderator

    @pvtr_ What do you mean with downloads?
     
Thread Status:
Not open for further replies.

Share This Page