onEnable problem...

Discussion in 'Spigot Plugin Development' started by EndureBlackouT, Sep 1, 2016.

  1. So I have two classes. My main "VoteKickMain" and my command listener class "CommandListener" here is the code
    Main:
    Code (Text):
    package me.endureblackout;

    import java.io.File;
    import java.io.IOException;

    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.plugin.java.JavaPlugin;

    public class VoteKickMain extends JavaPlugin {
        public void onEnable() {

            getCommand("vkick").setExecutor(new CommandListener(this));
            File dataFolder = getDataFolder();
            if(!dataFolder.exists()) {
                dataFolder.mkdir();
            }
           
            File file = new File(getDataFolder(), "config.yml");
            if(!(file.exists())) {
                try {
                    saveConfig();
                    setupConfig(getConfig());
                    getConfig().options().copyDefaults(true);
                    saveConfig();
                } catch (Exception e){
                    e.printStackTrace();
                }
            }
        }
       
        private void setupConfig(FileConfiguration config) throws IOException {
            if (!new File(getDataFolder(), "RESET.FILE").exists()) {
                new File(getDataFolder(), "RESET.FILE").createNewFile();
                getConfig().set("Percent to kick", 0.5);
            }
        }
    }
     
    Command Listener:
    Code (Text):
    package me.endureblackout;

    import java.io.File;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.Map;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.configuration.InvalidConfigurationException;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.entity.Player;

    public class CommandListener implements CommandExecutor {
        VoteKickMain plugin;
        public CommandListener(VoteKickMain instance) {
            this.plugin = instance;
        }
       
        public Map<Player, List<String>> kickList = new HashMap<Player, List<String>>();
       
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if(sender instanceof Player) {
                Player p = (Player) sender;
               
                File cfg = new File(plugin.getDataFolder(), "config.yml");
                YamlConfiguration y = new YamlConfiguration();
               
                try {
                    y.load(cfg);
                } catch (IOException | InvalidConfigurationException e) {
                    e.printStackTrace();
                }
               
                    if(cmd.getName().equalsIgnoreCase("vkick")) {
                        if(args.length == 1) {
                            List<String> kicker = new ArrayList<>();
                            if(!(kickList.containsKey(args[0].toLowerCase()))) {
                                kicker.add(p.getName().toLowerCase());
                               
                                for(Player p1 : Bukkit.getServer().getOnlinePlayers()) {
                                    if(p1.getName().equalsIgnoreCase(args[0])) {
                                        kickList.put(p1, kicker);
                                    }
                                }
                                Bukkit.getServer().broadcastMessage(ChatColor.GOLD + args[0] + " has been voted to be kicked!");
                            } else {
                               
                                for(Player p1 : Bukkit.getServer().getOnlinePlayers()) {
                                    if(kickList.containsKey(p1)) {
                                        kickList.get(p1).addAll(kicker);
                                        if(kickList.get(p1).size() / Bukkit.getOnlinePlayers().size() >= y.getInt("Percent to kick")) {
                                            p1.kickPlayer(ChatColor.RED + "You have been voted to be kicked by the online players!");
                                        }
                                    }
                                }
                            }
                    }
                }
            }
           
            return false;
        }
    }
     
    Error in console when enabling:
    Code (Text):
    [11:17:50 ERROR]: Error occurred while enabling VoteKick v1.0 (Is it up to date?)
    java.lang.NoSuchMethodError: me.endureblackout.CommandListener.<init>(Lme/endureblackout/VoteKickMain;)V
            at me.endureblackout.VoteKickMain.onEnable(VoteKickMain.java:12) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[spigot.jar:git-Spigot-fdc1440-53fac9f]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [spigot.jar:git-Spigot-fdc1440-53fac9f]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot.jar:git-Spigot-fdc1440-53fac9f]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.loadPlugin(CraftServer.java:357) [spigot.jar:git-Spigot-fdc1440-53fac9f]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.enablePlugins(CraftServer.java:317) [spigot.jar:git-Spigot-fdc1440-53fac9f]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.reload(CraftServer.java:741) [spigot.jar:git-Spigot-fdc1440-53fac9f]
            at org.bukkit.Bukkit.reload(Bukkit.java:535) [spigot.jar:git-Spigot-fdc1440-53fac9f]
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) [spigot.jar:git-Spigot-fdc1440-53fac9f]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [spigot.jar:git-Spigot-fdc1440-53fac9f]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) [spigot.jar:git-Spigot-fdc1440-53fac9f]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchServerCommand(CraftServer.java:627) [spigot.jar:git-Spigot-fdc1440-53fac9f]
            at net.minecraft.server.v1_8_R3.DedicatedServer.aO(DedicatedServer.java:412) [spigot.jar:git-Spigot-fdc1440-53fac9f]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:375) [spigot.jar:git-Spigot-fdc1440-53fac9f]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:653) [spigot.jar:git-Spigot-fdc1440-53fac9f]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:556) [spigot.jar:git-Spigot-fdc1440-53fac9f]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_60]
    Any help would be appreciated!
     
  2. Choco

    Moderator

    Welp... unless I'm missing something blatantly obvious,
    According to Spigot there's a method in this constructor that doesn't exist :D
    I would say update your Spigot.jar and see if the issue persists

    EDIT: Attempt the rebuild of your plugin mentioned by @stoneminer02, and if it still doesn't work, rebuild Spigot
     
  3. Try to re-build it. It says that there's no constructor matching the code, which there is.
     
    • Agree Agree x 1
  4. Choco

    Moderator

     
  5. Decompile your plugin, and verify that the built jar contains the constructor. If it does, then restart your server instead of reloading.

    If it doesn't, clear your IDE's cache and run the clean task (which should delete cached built classes)

    Oh, also use unique packages. If there's another plugin with the class 'me.endureblackout.CommandListener', it will only load one of them. I'd like to suggest the format tld.website.project[.subpackage] (so in your case, me.endureblackout.votekick)
     
    • Agree Agree x 1
  6. @DarkSeraphim thanks that worked!!


    Sent from my iPhone using Tapatalk