I have a plugin, in which, when I throw an egg, the player I have thrown the egg teleports to me, I would like that to only happen if the egg is called exactly, how could I do that? Thank you Code (Text): @EventHandler public void onThrow(EntityDamageByEntityEvent e) { Entity damaged = e.getEntity(); Entity damager = e.getDamager(); if((damager instanceof Egg)){ if((damaged instanceof Player)){ Player pdamaged = (Player) e.getEntity(); pdamaged.sendMessage("Test"); Player p = (Player) ((Projectile) damager).getShooter(); p.sendMessage("Test 2"); pdamaged.teleport(p.getLocation()); } } }
doesnt it have an equal method? basically store the egg globally(from wherever your spawning it),and call if e.getDamager().equals(egg) should solve the problem
When you right-click on the air you cancel the event and spawneas an egg projectile, then the entity of that egg is called "teleportegg", and the other entity is damaged by an egg called "teleportegg" teleportation
Code (Java): private Multimap<UUID|Player,Projectile|Integer> launchers = new HashMultimap.create(); onEggThrow(ProjectileLaunchEvent event) { final Projectile projectile = event.getProjectile(); final ProjectileSource source = projectile.getShooter(); if (source != null && source instanceof Player) { launchers.put((Player) source, projectile); } } and then in your event: Code (Java): // instead of your two other checks if (<instance to your map, pleeeease use getters and don't abuse static>.remove(damager.getSource(), damaged) != null) { Player pdDamaged = ...; }
eggs lose their name when theyre converted into entities. you need to use an event (projectilelaunchevent? playerinteractevent?) and add metadata to the egg when it spawns if the item has the custom name. then when a player gets hit by the egg, you check if the egg has the metadata. if the egg does, then you teleport the player to the shooter. https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/event/entity/ProjectileLaunchEvent.html if the projectile from the event is an egg, get the item in the player's hand. if it has the custom name you want, add some metadata value to the egg. then the rest of what i said above /e basically what the guy above me said but you dont need a map. just add metadata to the egg instead. much easier.