Plugin error?

Discussion in 'Plugin Development' started by Olivewhelmed, May 4, 2021.

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

    Olivewhelmed

    My plugins show up in the server if I do /plugins, if I try using them they won't work. I tried using other plugins too but only one of them worked.

    Logs: https://pastebin.com/jfExdFY0

    Main:
    Code:
    package me.olive.Listeners;
    
    import org.bukkit.plugin.java.JavaPlugin;
    
    import me.olive.Listeners.join.JoinListener;
    
    public class Main extends JavaPlugin {
       
        @Override
        public void onEnable() {
            getConfig().options().copyDefaults(true);
            saveConfig();
           
            new JoinListener(this);
        }
       
    
    }
    
    Commands:
    Code:
    package me.olive.Listeners.join;
    
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import me.olive.Listeners.Main;
    import me.olive.Listeners.utils.Utils;
    
    public class JoinListener implements Listener {
    
        private Main plugin;
        public JoinListener(Main plug) {
            this.plugin = plugin;
           
            Bukkit.getPluginManager().registerEvents(this, plugin);
           
        }
       
        @EventHandler
        public void onJoin(PlayerJoinEvent e) {
            Player p = e.getPlayer();
           
            if (!p.hasPlayedBefore()) {
                Bukkit.broadcastMessage(
                        Utils.chat(plugin.getConfig().getString("firstjoin_message").replace("<player>", p.getName())));
               
            }  else {
                Bukkit.broadcastMessage(Utils.chat(plugin.getConfig().getString("firstjoin_message").replace("<player>", p.getName())));
       
            }
        }
       
    }
    
    Utils:
    Code:
    package me.olive.Listeners.utils;
    
    import org.bukkit.ChatColor;
    
    public class Utils {
       
        public static String chat (String s) {
            return ChatColor.translateAlternateColorCodes('&', s);
        }
    
    }
    
    config.yml:
    Code:
    firstJoin_message: '&a<player> &7has joined the server for the first time!'
    
    join_message: '&e<player> &7has joined the server!' 
    plugin.yml:
    Code:
    name: Listeners
    version: 1.0
    author: Olive
    main: me.olive.Listeners.Main
    description: sends message when joining
    
    Does anyone know how to fix this?
     
  2. Online

    timtower Administrator Administrator Moderator

    @Olivewhelmed
    public JoinListener(Main plug) {
    this.plugin = plugin;
    Look at the names.
     
    Kars likes this.
  3. Offline

    Newdel

    An IDE should tell you this before you even try to build the jar and should even stop (at least in IntelliJ) before you are able to completely finish the build. What are you using to write code in?...

    Edit: Ahh nvd, the compiler thinks that you are using the same plugin variable...but still. The IDE shows that to you. You should definitly read the errors before trying to use the plugin (not all errors are important tho but that should have been obvious)
     
  4. Offline

    Olivewhelmed

    Sorry, I'm new to making plugins, could you tell me what kind of errors are in the code? This is actually my first project:D
     
  5. Offline

    Newdel

    You are declaring a object variable of type Main with name plugin
    You declare a local variable of type Main with name plug
    You do not call plug here but plugin twice so the not initialised object variable gets assigned to itself
    For the IDE part: It should notably change the color of an unused variable so you can see when a variable doesn't get used. Smarter IDEs (like IntelliJ) would also show you that your are assigning a variable to itself
     
Thread Status:
Not open for further replies.

Share This Page