ProjectileHitEvent help

Discussion in 'Plugin Development' started by EssentialsPissesMeOff, Nov 29, 2019.

  1. im trying to do 2 things here, with an egg i want to:
    - get the egg's name and if that eggs name matches to the one it is supposed to be it does something that no other random egg but this one with a specific name can do.
    - get the block that the this specific egg has landed on and make uhh, idk, a mob spawn on it (for now)

    I have been trying, i tried the onEggThrowEvent as well but that did not work too well.

    Main Class:
    Code:
        @EventHandler
        public void onJoin(PlayerJoinEvent event) {
            Player player = event.getPlayer();
            ItemStack batBombItem = new ItemStack(Material.EGG, 1);
            ItemMeta batBombItemMeta = batBombItem.getItemMeta();
            batBombItemMeta.setDisplayName("§0§lHi");
            batBombItem.setItemMeta(batBombItemMeta);
            player.getInventory().addItem(batBombItem);
        }
    In my other class:
    Code:
        @EventHandler
        public void onProjectileHit(ProjectileHitEvent event) {
            Entity entity = event.getEntity();
            if (entity instanceof Egg) {
                if (entity.getName().equals("§0§lHi"))
                System.out.println(event.getHitBlock());
            }
        }
    it does not do anything.
    by the way these 2 classes are not connected to each other but that should not be a problem since its getting a specific name anyways.
     
  2. Offline

    KarimAKL

    @EssentialsPissesMeOff I’d probably just listen to the ProjectileLaunchEvent, then check for the required item, if it’s the item, add the entity’s UUID to a list and then check (in the ProjectileHitEvent) if the list contains that UUID.
     
  3. ok so listen to the projectilelaunchevent (from from the projectilehitevent right?), check if it has the name of the item in which was given to you from the onJoin event, if the name of the item matches, add them (the player's uuid?) to an arraylist or list (honestly i dont know the difference, also where do i add them to the list, in the launch evetnt?), once they are added, then check if they are in the list in the hit event. and if they are in that list, "do something", is what your saying?
     
  4. Offline

    KarimAKL

    @EssentialsPissesMeOff I answered a question similar to this one in another thread, you can see what i mean there.
    Link: https://bukkit.org/posts/3612185
    Btw, i'd recommend learning Java before any API, or at least ask (Using a search engine first) things before you use them.
     

Share This Page