plugin doesn't work

Discussion in 'Plugin Development' started by Epixel, May 4, 2016.

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

    Epixel

    Hello!
    When I try to make a plugin that has custom join/leave/welcome messages it doesn't work. Nothing happens in-game.

    Main:
    Code:
    package com.epixel.messages;
    
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import com.epixel.messages.commands.join;
    
    public class Main extends JavaPlugin{
    
        public void onEnable() {
            getLogger().info("Custom Messages has been enabled!");
        }
    
        public void onDisable() {
            getLogger().info("Custom Messages has been disabled!");
        }
    
        public void registerCommands() {
        }
    
        public void registerEvents() {
            PluginManager pm = getServer().getPluginManager();
        
            pm.registerEvents(new join(), this);
        }
    
    }
    "join" - the actual message coding
    Code:
    package com.epixel.messages.commands;
    
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
    
    public class join implements Listener{
    
        @EventHandler
        public void onPlayerJoin(PlayerJoinEvent event) {
            Player player = event.getPlayer();
               event.setJoinMessage(ChatColor.AQUA + event.getPlayer().getName() + "has joined.");
              player.sendMessage(ChatColor.BLUE + "-------------------------------------------------");
              player.sendMessage(ChatColor.RED + "Welcome," + ChatColor.RED + " " + player + ChatColor.GREEN + " to the server!");
              player.sendMessage(ChatColor.AQUA + "Use the command " + ChatColor.RED + "/server " + ChatColor.AQUA + "in order to see the available servers to connect to.");
              player.sendMessage(ChatColor.LIGHT_PURPLE + "Enjoy your stay!");
    
        }
    
        public void onPlayerLeave(PlayerQuitEvent event) {
               event.setQuitMessage(ChatColor.AQUA + event.getPlayer().getName() + "has left.");
            
        }
    
    }
    @timtower What do you mean by "calling" ?
     
    Last edited: May 4, 2016
  2. Offline

    timtower Administrator Administrator Moderator

    @Epixel Try calling your registerEvents method.
     
  3. Offline

    Irantwomiles

    You're not even registering your events in your onenable
     
  4. Offline

    Esophose

    @Epixel
    What @timtower means by "calling" the registerEvents method is to add registerEvents(); to your onEnable method. Otherwise, your events will never get registered.
    You also don't need to log that your plugin started in the onEnable and onDisable, Bukkit prints that in the console automatically when it loads/stops.
     
  5. Offline

    dbaum102

    type in the onEnable()
    Code:
    registerEvents();
     
  6. Offline

    mcdorli

    Can you please not spoonfeed, especially if 2 others posted the solution hours before you.
     
  7. Offline

    redtsch

    Also, you should follow Java conventions and name your classes with uppercase such as: 'Join' instead of 'join'.
     
    ChipDev likes this.
  8. Offline

    dbaum102

    oops wrong section :O
     
  9. Offline

    ChipDev

    Did you follow the Java oracle tutorial? You should know what "call" means, as in executing a method....
     
    redtsch likes this.
Thread Status:
Not open for further replies.

Share This Page