Listener not Working

Discussion in 'Spigot Plugin Development' started by kimijug97, Jul 21, 2018.

  1. Code (Text):
    package plugin;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Entity;
    import org.bukkit.entity.EntityType;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.entity.EntityShootBowEvent;
    import org.bukkit.event.player.PlayerChatEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
    import org.bukkit.plugin.PluginDescriptionFile;

    public class hello  extends JavaPlugin implements Listener{
        private PluginDescriptionFile pluginInfo = this.getDescription();

        public void onEnable()
            Bukkit.getPluginManager().registerEvents(this, this);
            System.out.println(pluginInfo.getName() + pluginInfo.getVersion()+" : Hello Plugin!!!");
        public void onDisable()
           System.out.println(pluginInfo.getName() + pluginInfo.getVersion()+" : Good Bye Plugin~");
        public void onEntityShootBow(EntityShootBowEvent event) {
            if(event.getEntity() instanceof Player) {
                Player player = (Player) event.getEntity();
                Entity entity = player.getWorld().spawnEntity(event.getProjectile().getLocation(), EntityType.PRIMED_TNT);
        public void onPlayerChat(PlayerChatEvent event)
                    event.setMessage(ChatColor.AQUA+"[clean] : "+ChatColor.WHITE+event.getMessage());
                    event.setMessage(ChatColor.RED+"[bad word]");
         private boolean isCleanSentence(String s)
                    return false;
                    return false;
             return true;
    I also regist listener event but not working... help me

  2. This is your event method - but technically it's just a plain method because it's not annotated as an EventHandler.
    Just add @EventHandler above your onEntityShootBow.

    This is where you register your listener.

    Read javadocs/plugin examples carefully.
    #2 SCPKeter, Jul 21, 2018
    Last edited: Jul 21, 2018
    • Agree Agree x 1
  3. Hey, so why aren't you using the AsyncPlayerChatEvent, I don't think you are doing anything you can't do async. Unless it is setting the message.
  4. regardless, they should be using AsyncPlayerChatEvent. PlayerChatEvent is deprecated.
  5. Just cause it's depracted doesn't mean useless XD. Although it does come with some maybe errors, there can be some use to it. But still, i dont recomend it unless ur a java expert
  6. FrostedSnowman

    Resource Staff

    Thats what people said when they preferred to use material IDs over the actual materials. look at them now
    • Agree Agree x 1
    • Funny Funny x 1