Solved Already initialized plugin?

Discussion in 'Spigot Plugin Development' started by Gorobetz, Jun 8, 2017.

  1. So yeah I do not understand errors.

    My plugin (Literally only one class)
    Code (Text):

    public class CustomMobCommand extends JavaPlugin implements CommandExecutor{
    public void onEnable(){
        this.getCommand("custommob").setExecutor(new CustomMobCommand());
    }

    @Override
    public boolean onCommand(CommandSender s, Command cmd, String label, String[] args){
        if(s instanceof BlockCommandSender){
            Bukkit.getLogger().info("I DONT KNOW");
            Location hmm = ((BlockCommandSender) s).getBlock().getLocation();
            Entity myEntity =  hmm.getWorld().spawnEntity(hmm, EntityType.valueOf(args[0].toUpperCase()));
     
        }
        return false;
    }
    }
     
    Error message:
    Code (Text):

    [17:08:53 INFO]: [CustomMobsEngine] Enabling CustomMobsEngine v1.0
    [17:08:53 ERROR]: Error occurred while enabling CustomMobsEngine v1.0 (Is it up to date?)
    java.lang.IllegalArgumentException: Plugin already initialized!
            at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:122) ~[spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:67) ~[spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at com.LobsterTrap.customizedmobs.CustomMobCommand.<init>(CustomMobCommand.java:21) ~[?:?]
            at com.LobsterTrap.customizedmobs.CustomMobCommand.onEnable(CustomMobCommand.java:23) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:271) ~[spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:337) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:405) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.craftbukkit.v1_11_R1.CraftServer.enablePlugin(CraftServer.java:376) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.craftbukkit.v1_11_R1.CraftServer.enablePlugins(CraftServer.java:326) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.craftbukkit.v1_11_R1.CraftServer.reload(CraftServer.java:750) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.Bukkit.reload(Bukkit.java:540) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:25) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:141) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.craftbukkit.v1_11_R1.CraftServer.dispatchCommand(CraftServer.java:650) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.craftbukkit.v1_11_R1.CraftServer.dispatchServerCommand(CraftServer.java:636) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.DedicatedServer.aM(DedicatedServer.java:437) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.DedicatedServer.D(DedicatedServer.java:400) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.MinecraftServer.C(MinecraftServer.java:678) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at net.minecraft.server.v1_11_R1.MinecraftServer.run(MinecraftServer.java:576) [spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_131]
    Caused by: java.lang.IllegalStateException: Initial initialization
            at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:125) ~[spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:67) ~[spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at com.LobsterTrap.customizedmobs.CustomMobCommand.<init>(CustomMobCommand.java:21) ~[?:?]
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.8.0_131]
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_131]
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.8.0_131]
            at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.8.0_131]
            at java.lang.Class.newInstance(Unknown Source) ~[?:1.8.0_131]
            at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:76) ~[spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:129) ~[spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:329) ~[spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) ~[spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.craftbukkit.v1_11_R1.CraftServer.loadPlugins(CraftServer.java:301) ~[spigot.jar:git-Spigot-3fb9445-6e3cec8]
            at org.bukkit.craftbukkit.v1_11_R1.CraftServer.reload(CraftServer.java:748) ~[spigot.jar:git-Spigot-3fb9445-6e3cec8]
            ... 10 more
     
    Line 21:
    Code (Text):

    public class CustomMobCommand extends JavaPlugin implements CommandExecutor{
     
    What does one like me do? Am I not suppose to say its a java plugin or.... ?
     
  2. You don't need to implement CommandExecutor or register the command if your onCommand method is in your main class.
     
  3. Did you by chance use the /reload command on your server? Also, is this just a snippet of the code because I don't see an #onDisable() method?
     
  4. You can create only one single instance of your main plugin class.
    Here you try to create a second (bukkit itself creates the first).

    Just use "this" instead of "new CustomMobCommand()".
    But don't do this either.

    Just don't set the executor. If your #onCommand is inside of your main class you don't need to set the executor.
     
    • Agree Agree x 1
  5. There could be 2 problems with this with the first being that more than one of your classes is extending JavaPlugin or you have 2 plugins with the exact same internal package names.
     
  6. The hell does this have to do with java and not spigot? Also, this plugin is for me only.
    neither
    Thanks! Something no one ever explained to me but people will still tell me to learn java
    thanks homie
    Snippets, but I dont have an onDisable() mainly because it isnt required. Also, I did do a /reload to update something but I got the same error when I didnt reload
     
  7. By any chance did you install the plugin into the server with a different name but accidentally changed it to something else so the plugin already exists under a different name?
     
  8. Nah, its all fixed now. Thanks though
     
  9. No problem :).
     
  10. Spigot is literally made with Java. You wouldn't build a house without knowing carpentry, you shouldn't make plugins for a java project without knowing Java. The random castings was my giveaway there.

    And as stated, I pointed out the two primary issues in your code: The BlockCommandSender cast (thus only command blocks can use your command there), and initializing your main class yourself. The JavaPlugin constructor will throw an exception when instantiated from a plugin
     
  11. There is such a thing as learning both at the same time, like I did. It's honestly the best thing to do IMO.
     
    • Like Like x 1
  12. Excuse me... idk if you've been paying attention to the US Presidency, but learning both clearly isn't working.... And it definitely is not the best thing to do.
     
  13. I don't even support Trump, but why are you bringing that up when we're discussing Java and Spigot o_O
     
  14. [​IMG]
     
  15. No, excuse me.
    1. You're just slinging around your political opinion like it matters.
    2. You fail to realize that by learning Java while also learning the Bukkit API, most new developers will gain experience much quicker and will be able to somewhat quickly (if they're smart/dedicated) learn from any mistakes or bad practices.
    3. Trumps failures as a president isn't because he lacks experience or is trying to learn two things at once, it's because he is a morally corrupt human being.

    I'll stop here, bye
     
  16. 1. This had literally nothing to do with my personal political opinion
    2. While that may be true, it is not a great way to do it, this is why we have threads like this. Instead of people actually learning the language itself, they "learn" the bukkit API and have absolutely no idea what they are actually doing.
    3. They are LITERALLY because he is inexperienced.

    Please do stop here and quit your assumptions.
     
    • Creative Creative x 1
  17. There is but it's much less learning Java (the language and structure of everything) and much more learning bukkit paradigms (without understanding why they are that way) and copy/pasting code without understanding it.

    Continuing with the house example, which would you make/decide on first: The foundation/frame, or the bedroom drapes?

    2 isn't sourced in any way and I think you would find it's exactly the opposite. Developers are bogged down trying to learn bukkit (whilst having to google between words to understand it), and determining basic java problems to be bukkit problems. Additionally they don't learn of other available resources for development issues (especially non-bukkit ones, such as stackoverflow).
     
  18. You're right, my bad. Was mainly referencing how I learned Java and the Spigot API which I realize isn't how it typically goes.
     
  19. I know, but implementing a command executor... how am I supposed to know that I dont need to do that with a main class?

    And I want it to be from command blocks only, this plugin is for myself, no one else.