Hello Everyone I've actually got to issues, but the event timing issue is the show stopper, so I'll ask about it first. The plugin I am working on contains several event listeners. Two of the event listeners are PlayerEggThrowEvent and EntityDamageByEntityEvent. For some reason, when I throw an egg at a mob (testing with a horse), the EntityDamageByEntityEvent fires before the PlayerEggThrowEvent. Thus, the plugin is not checking if the egg that damaged the entity is a special egg. Question: Why are the events not firing in chronological order and how can I fix it? Code (Text): @EventHandler public void onPlayerEggThrow(PlayerEggThrowEvent pete) { Egg theEgg = pete.getEgg(); Player player = pete.getPlayer(); ItemStack iih = player.getItemInHand(); if (iih.hasItemMeta()) { ItemMeta iihData = iih.getItemMeta(); if (iihData.hasDisplayName()) { String iihDN = iihData.getDisplayName(); if (iihDN.contains("Mob Trapper")) { theEgg.setCustomNameVisible(false); theEgg.setCustomName("pokemon"); getLogger().info("1. eggs new custom name = " + theEgg.getCustomName()); // testing } } } } @EventHandler public void onEntityDamageByEntity(EntityDamageByEntityEvent edbee) { Entity victom = edbee.getEntity(); getLogger().info("2. victom = " + victom.getType().toString()); // testing Entity damager = edbee.getDamager(); getLogger().info("3. damager = " + damager.getType().toString()); // testing String damagerName = damager.getCustomName(); getLogger().info("4. damagerName = " + damagerName); // testing if (damagerName != null) { if (damagerName.contains("pokemon")) { getLogger().info("5. the name was pokemon"); // testing } } } Server output shows: [13:31:46 INFO]: [EF_Uts] 2. victom = HORSE [13:31:46 INFO]: [EF_Uts] 3. damager = EGG [13:31:46 INFO]: [EF_Uts] 4. damagerName = null [13:31:46 INFO]: [EF_Uts] 1. eggs new custom name = pokemon Question 2: Since getItemInHand() is deprecated, what method(s) are replacing it? Thanks
According to the documents for PlayerEggThrowEvent, the event is called when an egg is thrown and it might hatch. As a substitute to that event, I would use ProjectileLaunchEvent and see how that goes.
p.e.t.e = PlayerEggThrowEvent e.d.b.e.e = EntityDamageByEntityEvent It's all personal preference for naming them, as long as you follow the conventions. He seems to understand it, so it's all good.
Actually, they were both called e, but I thought using the same name might be what is causing the problem; it isn't.
Code (Text): PlayerInventory#getItemInMainHand() PlayerInventory#getItemInOffHand() //i.e. ItemStack handItem = player.getInventory().getItemInMainHand(); Have you tried testing the ProjectileHitEvent to see when it fires in relation to the damage event?
Thank You Changing the event to ProjectileLaunchEvent worked. It did require a few more extra statements to get the itemStack from the player's inventory; but at least I can now continue. Its strange that the playerThrowEggEvent doesn't work since logically it is just a more specific version of the ProjectileLaunchEvent. Now I know not all events are created equally.
Thanks for your reply. I tried your suggestion but it didn't work. The spigot documentation seems to indicate that the event-priorities commands are intended to keep multiple plugins from fighting over the same event. My problem concerns to separate events. GamerzKing's suggestion worked (using projectileLaunchEvent instead of playerEggThrowEvent.