Question: How do you Identify Items?

Discussion in 'Spigot Plugin Development' started by TheMrJezza, May 5, 2015.

  1. Hello everyone, I have this bit of code here that throws an egg when you right click a blaze rod
    Code (Text):
        public void onClick(PlayerInteractEvent event) {
            Player player = event.getPlayer();
            if ((event.getItem() != null && event.getItem().getType()
                    && (event.getItem().getItemMeta().getLore().equals("FunGun"))) {
                Projectile egg = player.launchProjectile(Egg.class);
    I have a few questions though...
    No.1 : How can I only make certain blaze rods shoot eggs?
    No.2 : How can I launch fireworks where an egg lands? I only mean eggs shot from a blaze rod.
    No.3 : What would be a way to make egg shooting blaze rods with a command?

    Thanks in advance everyone.
  2. 1) ItemMeta display name/lore/ specific enchant and listen for it

    2) ProjectileHitEvent. Check if it was done through the blaze rod (possibly add the eggs to a weakreference)

    3) create an item template (with meta if applicable), check if inventory is full possibly, give player item
  3. The blaze rod isn't enchanted, and I don't quite understand, are you saying to check what lore the blaze rod has?
  4. You need to give the rods which can shoot eggs an unique attribute like a specific enchant, specific name or a specific lore. Otherwise the rods are not to identify.
    • Agree Agree x 1
  5. @Yannici So like setMeta() or something like that? This is the first time I have ever tried this
  6. You can set a MetadataValue for a block with Block#setMetaData(String key, MetadataValue value) for example. Or you can add a itemstack of rods in your inventory with a specific display name or lore and place it somewhere.
  7. @Yannici And for launching fireworks where the egg smashes?
  8. @nikmanG already told you ...
  9. if(player.getItemInHand(().getItemMeta.getLore or getDisplayName().contains("");

    Sorry for the spoon :$
    • Like Like x 1
  10. @Tjerkh987 In this case the spoonfeeding pointed something out to me, I have tried this already, before I came here to the forums, but I couldn't get it to work. This means I have to look elsewhere in the code, thanks
  11. Try using AttributeStorage or HiddenStringUtils .
  12. Everything works, but ProjectileHitEvent it making all projectile types spawn fireworks when they hit something, arrows, eggs that didn't come from an egg shooter blaze rod etc..... Thats a problem.
  13. Once a player fires the rod put the egg in a list. On hit check if set projectile is in the list and only then make it go off (as well as removing the egg from the list)
  14. He don't have to store anything, since you shot the arrow it convert into a entity, he can store info in the entity.
  15. I was thinking of giving the egg a lore as soon as the blaze rod shot it, but I don't understand fully what goes after setLore()..... Its harder then it looks. Also 1 other thing, I don't know if this is the plugin, but any fireworks that get fired, none of them explode when they are in the air, they just disappear...
  16. All lore is, is a List<String>. If you have trouble with getLore then it is because it has none, hence you get null.

    Code (Text):
    List<String> lore = new ArrayList<>();

    ...add to lore...

    item.getItemMeta().setLore(lore); whatever else...
  17. And for actually saying what the lore is? I know this is a stupid question, and I'm sure the answer is really obvious, but atleast I shouldn't have any reason to ask again....