ProjectileHitEvent not working

Discussion in 'Plugin Development' started by BlazingBlast, Oct 8, 2022.

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


    I have a ProjectileHitEvent, but it doesn't get called (while other events that I've tried in that class do)
    This is all my code
    package eggsplosioneplugin.eggsplosionplugin;
    import org.bukkit.entity.EntityType;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.entity.ProjectileHitEvent;
    import org.bukkit.event.Listener;
    public final class EggSplosionPlugin extends JavaPlugin implements Listener {
        private static EggSplosionPlugin mainInstance;
        public static EggSplosionPlugin getInstance() {return mainInstance;}
        public void onEnable() {
            mainInstance = this;
        public void onDisable() {
        public void onProjectileHit(ProjectileHitEvent e) {
            if (e.getEntity().getType() == EntityType.EGG && e.getHitBlock() != null){
                System.out.println("An egg just hit the ground");
            else System.out.println("We found an " + e.getEntityType().name());
    And I've tried `ignoreCancelled = true` but it did not help
    since I've also tried to set priority higher, but that also did not have any effect
    Last edited by a moderator: Oct 9, 2022
  2. Offline

    timtower Administrator Administrator Moderator

  3. Offline


    Yup. Commands in the main class don't need to be set, but events aren't as convenient. You still need to register this, this. Though best practices are that you really should separate classes and not throw everything into one class.

    Lastly, there is no need to include methods that do nothing. That onDisable is superfluous.
  4. Offline

    timtower Administrator Administrator Moderator

    Not sure if this also counts for something this small ;)
  5. Offline


    While I'd agree, I think it's best to reinforce proper procedures when someone is starting out. It's good to form proper habits rather than let lazy design become one's default mindset :)
Thread Status:
Not open for further replies.

Share This Page