How to make PlayerEggThrowEvent register when egg is thrown

Discussion in 'Plugin Development' started by jstN0body, Mar 27, 2020.

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

    jstN0body

    So basically what is happening and I don't know if this is supposed to happen, minecraft is only triggering the event of a player throwing an egg when it hits something, but I want it to trigger when the egg is thrown does anyone know of a way to do that? (Yes this is a super random plugin but I don't care)
    Code:
    package me.jstN0body.rideableEggs.eggEvent;
    
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Egg;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerEggThrowEvent;
    
    import me.jstN0body.rideableEggs.Main;
    
    public class OnThrowEgg implements Listener {
       
        @SuppressWarnings("unused")
        private Main plugin;
       
        public OnThrowEgg(Main plugin) {
            this.plugin = plugin;
           
            Bukkit.getPluginManager().registerEvents(this, plugin);
        }
       
        @EventHandler
        public void onEggThrown(PlayerEggThrowEvent event) {
            System.out.println("Egg was thrown");
            Player player = event.getPlayer();
            Egg egg = event.getEgg();
            egg.setPassenger(player);
            if (egg.isDead() == true) {
                egg.eject();
            }
        }
               
    }
     
  2. Offline

    wand555

    Maybe listen to PlayerInteractEvent and check if the item equals an egg
     
  3. Offline

    KarimAKL

    @jstN0body I think the correct event for this is "ProjectileLaunchEvent", just check if the projectile is an instanceof Egg.
     
  4. Offline

    jstN0body

  5. Offline

    Strahan

    I'd also add that you shouldn't suppress things the compiler bitches about. You're better off resolving the issues.
     
Thread Status:
Not open for further replies.

Share This Page