Punishment Plugin. Error

Discussion in 'Plugin Development' started by MCBro911, Mar 25, 2016.

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

    MCBro911

    When the plugin starts this occurs

    Show Spoiler
    8:58:00 PM [SEVERE] Error occurred while enabling PunishInventory v4.0.0 (Is it up to date?)
    8:58:00 PM java.lang.Error: Unresolved compilation problems:
    8:58:00 PM The method registerEvents(Listener, Plugin) in the type PluginManager is not applicable for the arguments (InventoryClickEvent, Main)
    8:58:01 PM The constructor InventoryClickEvent() is undefined
    8:58:01 PM The method registerEvents(Listener, Plugin) in the type PluginManager is not applicable for the arguments (PlayerJoinEvent, Main)
    8:58:01 PM The constructor PlayerJoinEvent() is undefined
    8:58:01 PM The method registerEvents(Listener, Plugin) in the type PluginManager is not applicable for the arguments (PlayerChatEvent, Main)
    8:58:01 PM The constructor PlayerChatEvent() is undefined
    8:58:01 PM at jaden.punishments.punisher.Main.onEnable(Main.java:29) ~[?:?]
    8:58:01 PM at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:292) ~[craftbukkit-1.9-R0.1-SNAPSHOT-latest.jar:git-Bukkit-8e5eab2]
    8:58:01 PM at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:332) [craftbukkit-1.9-R0.1-SNAPSHOT-latest.jar:git-Bukkit-8e5eab2]
    8:58:01 PM at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:404) [craftbukkit-1.9-R0.1-SNAPSHOT-latest.jar:git-Bukkit-8e5eab2]
    8:58:01 PM at org.bukkit.craftbukkit.v1_9_R1.CraftServer.loadPlugin(CraftServer.java:346) [craftbukkit-1.9-R0.1-SNAPSHOT-latest.jar:git-Bukkit-8e5eab2]
    8:58:01 PM at org.bukkit.craftbukkit.v1_9_R1.CraftServer.enablePlugins(CraftServer.java:318) [craftbukkit-1.9-R0.1-SNAPSHOT-latest.jar:git-Bukkit-8e5eab2]
    8:58:01 PM at net.minecraft.server.v1_9_R1.MinecraftServer.t(MinecraftServer.java:403) [craftbukkit-1.9-R0.1-SNAPSHOT-latest.jar:git-Bukkit-8e5eab2]
    8:58:01 PM at net.minecraft.server.v1_9_R1.MinecraftServer.l(MinecraftServer.java:368) [craftbukkit-1.9-R0.1-SNAPSHOT-latest.jar:git-Bukkit-8e5eab2]
    8:58:01 PM at net.minecraft.server.v1_9_R1.MinecraftServer.a(MinecraftServer.java:323) [craftbukkit-1.9-R0.1-SNAPSHOT-latest.jar:git-Bukkit-8e5eab2]
    8:58:01 PM at net.minecraft.server.v1_9_R1.DedicatedServer.init(DedicatedServer.java:241) [craftbukkit-1.9-R0.1-SNAPSHOT-latest.jar:git-Bukkit-8e5eab2]
    8:58:01 PM at net.minecraft.server.v1_9_R1.MinecraftServer.run(MinecraftServer.java:506) [craftbukkit-1.9-R0.1-SNAPSHOT-latest.jar:git-Bukkit-8e5eab2]
    8:58:01 PM at java.lang.Thread.run(Unknown Source) [?:1.8.0_66]



    This is the code

    Show Spoiler
    package jaden.punishments.punisher;

    import sys.punisher.commands.Punisher;
    import sys.punisher.commands.listeners.InventoryClick;
    import sys.punisher.commands.listeners.PlayerChat;
    import sys.punisher.commands.listeners.PlayerJoin;
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Server;
    import org.bukkit.command.PluginCommand;
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.player.PlayerChatEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;

    @SuppressWarnings("deprecation")
    public class Main
    extends JavaPlugin
    {
    public String prefix = ChatColor.DARK_RED + "&f&L[&4&lPunishments&F&l] " + ChatColor.RESET;
    private static Main instance;

    public void onEnable()
    {
    instance = this;

    PluginManager pm = Bukkit.getServer().getPluginManager();
    pm.registerEvents(new InventoryClickEvent(), instance);
    pm.registerEvents(new PlayerJoinEvent(), instance);
    pm.registerEvents(new PlayerChatEvent(), instance);

    registerCommands();

    saveConfig();
    }

    public void onDisable() {}

    public static Main getInstance()
    {
    return instance;
    }

    private void registerCommands()
    {
    getCommand("punish").setExecutor(new Punisher());
    }
    }
     
  2. It seems like you have imported the events and not the classes.

    _zircon_.
     
  3. Offline

    mcdorli

    1.: Why is the instance static?
    2.: Why do you have an onDisable, if you don't use it?
    3.: The method registerEvents(Listener, Plugin) in the type PluginManager is not applicable for the arguments (InventoryClickEvent, Main)
    InventoryClickEvent either
    a) Doesn't extend Listener
    b) You imported the wrong class, never name your classes the same as bukkit classes
     
  4. For your point 3: They are not the wrong way round, it is looking for an event and not a listener class.
     
  5. Offline

    mcdorli

    I already changed it before you commented
     
  6. Mmk...
     
  7. Offline

    MCBro911

    What lines are you referring to?
     
  8. Offline

    Zombie_Striker

    1. He is referring to the only static field.
    2. He is referring to the only onDisable
    3. He is referring to when you are registering your "events". The input is a listener, not the event instance. Replace those three lines with registerEvents(Listener class , this);
    A) Refers to number 4. The class you are registering must implement listener
    B) You imported the wrong class. As he said, the names of each of your classes must be unique.
     
  9. Offline

    mine-care

    @MCBro911

    1. private static Main instance;

    2. public void onDisable() {}

    3. public class Main extends JavaPlugin {

    Code:
    pm.registerEvents(new InventoryClickEvent(), instance);
    pm.registerEvents(new PlayerJoinEvent(), instance);
    pm.registerEvents(new PlayerChatEvent(), instance);
    import org.bukkit.event.inventory.InventoryClickEvent;
    import org.bukkit.event.player.PlayerChatEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    
    That is what @mcdorli refers to

    EDIT: Ninja'ed by @Zombie_Striker
     
  10. Offline

    Irantwomiles

    It's not a good idea to name your "main" class Main. Also why don't you create the instance in your listeners class? Like
    Code:
    
    Main plugin;
    
    public listenerclassname (Main plugin) { this.plugin = plugin; }
    
    
    also I think you have to register your classes like this

    Code:
    Bukkit.getPluginManager().registerEvents(new listenerclassname(this), this); 
    
     
  11. Offline

    MCBro911

    All I wanted to do was update my 1.7 plugin to 1.9.

    How would I exactly do that? Those codes used to work back in 1.7
     
  12. Offline

    Zombie_Striker

    Your problem is that you are trying to register the events instead of the class that has those commands. This should never have worked in any update.

    Just register the listener (the class that extends listener) instead of the events themselves and that error should go away.
     
  13. Offline

    MCBro911

    so
    public class Main extends JavaPlugin {

    ?
     
  14. Offline

    Zombie_Striker

    @MCBro911
    I really don't know what you are trying to say.

    The thing is, you need to register the one that has implements Listener and has the events in it. Just register the class with the events in it.
     
  15. Offline

    mcdorli

    When something "works" that doesn't mean it is OK to have it like that. With this code, you can't be considered a java developer.
     
Thread Status:
Not open for further replies.

Share This Page