Entity death event not working (No errors)

Discussion in 'Plugin Development' started by DenverXDXDXD, Nov 20, 2017.

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

    DenverXDXDXD

    (I am using craftbukkit for minecraft 1.12.2 and I am programming in eclipse)

    I tried to create a plugin that test if a player kills an entity and the player will receive this message: "you just killed an entity". I have a class called EventHandle and another class called PlayerListener.

    Here is the code for both classes

    EventHandle code:
    Code:
    package com.Denver.plugin;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    public class EventHandle extends JavaPlugin{
       
        @Override
        public void onEnable() {
            new PlayerListener(this);
        }
       
        @Override
        public void onDisable() {
        }
    }
    
    PlayerListener Code:
    Code:
    package com.Denver.plugin;
    
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityDeathEvent;
    import org.bukkit.event.player.PlayerEggThrowEvent;
    
    public class PlayerListener implements Listener {
       
        public PlayerListener(EventHandle plugin) {
            plugin.getServer().getPluginManager().registerEvents(this, plugin);
        }
       
       
        @EventHandler
        public void onKill(EntityDeathEvent event) {
            Player killer = event.getEntity().getKiller();    
            killer.sendMessage("You just killed an entity");
        }
       
       
    }
    
    There are no errors with both code. The plugin loaded successfully in the server console but when I kill an entity like a cow it does not print anything in my text box.

    I have another question. Will the entity kill event also work on players?



    Any help would be appreciated. Thanks!
     
  2. Offline

    RunsWithShovels

    @DenverXDXDXD
    I just copied your code exactly and ran it without any issues. I received the message.
     
  3. Offline

    MightyOne

    If you are having errors in the console show the here
     
  4. Try this:

    In your onEnable replace it with:
    Code:
            Bukkit.getServer().getPluginManager().registerEvents(new PlayerListener(this), this);
    
    Change your constructor in PlayerListener to this:
    Code:
    private EventHandler plugin;
    
    public PlayerListener(EventHandle pl) {
            this.plugin = pl;
        }
    Might work ¯\_(ツ)_/¯
     
    Last edited: Nov 20, 2017
Thread Status:
Not open for further replies.

Share This Page