Events from another class not registering no matter what

Discussion in 'Plugin Development' started by kapseljava, Oct 8, 2019.

  1. Offline

    kapseljava

    As in the title I made a new class for events for my plugin. Then I registered it in the onEnable() method, but after testing it is not working. I tried some other ways to register events class - nothing works. Please help me, it stopped me in my Java and Bukkit learning. I'm quite new to it :)
    Main class:
    Code:
    public class Main extends JavaPlugin{
    
        @Override
        public void onEnable() {
            PluginManager pm = Bukkit.getPluginManager();
           
            pm.registerEvents(new EventsClass(), this);
            Bukkit.broadcastMessage(ChatColor.YELLOW + "Pack is on!");
        }
    Events class:
    Code:
    public class EventsClass implements Listener{
      
        public EventsClass() {
        }
      
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event){
            System.out.println("message to console - the player joined!");
        }
     
    }
     
  2. Offline

    timtower Moderator Moderator

    @kapseljava Do you get errors in the console on startup?
     
    kapseljava likes this.
  3. Offline

    kapseljava

    nope, no errors on startup nor reload
    edit:
    Well I got those ambiguous errors relating folders due to my other tests, but I believe it's not related.
     
  4. Offline

    timtower Moderator Moderator

    The pack is on message is being printed? Could you post the classes without removing the imports?

    And that is related. You have 2 plugins with the same main package probably.
     
  5. Offline

    kapseljava

    main
    Code:
    package me.kapselme;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.event.*;
    
    public class Main extends JavaPlugin{
    
        @Override
        public void onEnable() {
            PluginManager pm = Bukkit.getPluginManager();
           
            pm.registerEvents(new EventsClass(), this);
            Bukkit.broadcastMessage(ChatColor.YELLOW + "Pack is on!");
      
        }
    events
    Code:
    package me.kapselme;
    
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    
    public class EventsClass implements Listener{
      
        public EventsClass() {
        }
      
        @EventHandler
        public void onMove(PlayerJoinEvent event){
            System.out.println("message");
        }
     
    }
     
  6. Offline

    timtower Moderator Moderator

    @kapseljava Yeah, based on that package name and main class I assume that you have multiple plugins with the same main class.
    Use a plugin specific package like "me.kapselme.pack"
     
    kapseljava likes this.
  7. Offline

    kapseljava

    okay will test now

    It works now thanks! Had to delete older not used plugins.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Oct 8, 2019

Share This Page