Solved [1.8.8] Error occurred while enabling Plugin

Discussion in 'Spigot Plugin Development' started by Moose1031, Apr 12, 2019.

Thread Status:
Not open for further replies.
  1. So i'm trying to code a plugin that give a runs a command when i player does something and when i was test i got this error:
    Code (Text):
    [15:54:35 ERROR]: Error occurred while enabling MineKeys v1.0 (Is it up to date?)
    java.lang.ClassCastException: me.moose.MineKeys.main cannot be cast to org.bukkit.event.Listener
            at me.moose.MineKeys.main.onEnable(main.java:26) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:321) ~[1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:340) [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at com.rylinaux.plugman.util.PluginUtil.load(PluginUtil.java:285) [PlugMan%20(1).jar:?]
            at com.rylinaux.plugman.command.LoadCommand.execute(LoadCommand.java:114) [PlugMan%20(1).jar:?]
            at com.rylinaux.plugman.PlugManCommandHandler.onCommand(PlugManCommandHandler.java:104) [PlugMan%20(1).jar:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchCommand(CraftServer.java:641) [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at org.bukkit.craftbukkit.v1_8_R3.CraftServer.dispatchServerCommand(CraftServer.java:627) [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.aO(DedicatedServer.java:412) [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:375) [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [1.8.8.jar:git-Spigot-db6de12-18fbb24]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_202]
     
  2. Can I please see the code? Because it seems like you're casting the main class (Plugin) to Listener which isn't possible.
     
  3. ok here
    Code (Java):
    package me.moose.MineKeys;
    import org.bukkit.plugin.java.*;
    import org.bukkit.configuration.file.*;
    import java.io.*;
    import org.bukkit.plugin.*;
    import org.bukkit.event.block.*;
    import org.bukkit.*;
    import org.bukkit.entity.*;
    import org.bukkit.event.*;
    import java.util.*;
    import org.bukkit.command.*;
    import org.bukkit.event.Listener;
    public class main extends JavaPlugin {
        public static main plugin;
        FileConfiguration config;
        File cfile;
        private Random rand;
        public main() {
            this.rand = new Random();
        }
        public void onEnable() {
            plugin = this;
            System.out.print("MineKeys Loaded. Made by Moose1301");
            this.getConfig();
            this.saveDefaultConfig();
            Bukkit.getServer().getPluginManager().registerEvents((Listener)this, (Plugin)this);
            this.config = this.getConfig();
            this.config.options().copyDefaults(true);
            this.saveConfig();
            this.cfile = new File(this.getDataFolder(), "config.yml");
        }
        public static String color(final String format) {
            return ChatColor.translateAlternateColorCodes('&', format);
        }
        @EventHandler
        public void onBlockBreak(final BlockBreakEvent e) {
            final Player p = e.getPlayer();
            if (p.hasPermission("Minekey.use") && p.getGameMode() == GameMode.SURVIVAL && this.rand.nextInt(101) <= this.getConfig().getInt("KeyChance")) {
                final List<String> list = (List<String>)this.config.getStringList("Commands");
                final int index = this.rand.nextInt(list.size());
                final String cmd = list.get(index);
                Bukkit.dispatchCommand((CommandSender)Bukkit.getConsoleSender(), cmd.replace("{player}", p.getName()));
            }
    }
    }
    that my main.class
     
  4. Replace
    Code (Java):
    Bukkit.getServer().getPluginManager().registerEvents((Listener)this, (Plugin)this);
    with
    Code (Java):
    Bukkit.getServer().getPluginManager().registerEvents(this, this);
    Because the issue as I've stated above you're casting Plugin to Listener which doesn't seem to be possible, if that works please don't forget to leave me a positive rating <3

    EDIT: LOL NO, just implement Listener on your main class.
     
    • Creative Creative x 1
Thread Status:
Not open for further replies.