Solved Plugin Already Initialized

Discussion in 'Plugin Development' started by ShowbizLocket61, Jan 17, 2016.

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

    ShowbizLocket61

    Alright, so I'm trying to make an API. I have my public static methods, everything's good there. I have a simple API reader to test it, and it works. However, every time I try to reload my KingdomLifeAPI with Plugman while APIReader is still enabled, it gives me an IllegalStateException, saying that my plugin's already initialized.
    Problem is, I tried taking out any instances. I tried using the instance provided by the getPlugin method.

    I tried using
    Code:
    ((Player)sender).sendMessage(KingdomLifeAPI.test("Hip hip hooray!"));
    instead.

    Doesn't work. It has something to do with my APIReader, because it only does that after I use /readAPI.
    Please help, this is an extremely frustrating bug that I've been trying to fix for days, but it's not giving up.

    APIReader code:
    Code:
    package com.patrickzhong.APIReader;
    
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;
    
    import com.patrickzhong.kingdomlifeapi.KingdomLifeAPI;
    
    public class APIReader extends JavaPlugin{
        public void onEnable(){
            getLogger().info("APIReader enabled!");
        }
      
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
            if(cmd.getName().equalsIgnoreCase("readAPI")){
                ((Player)sender).sendMessage(((KingdomLifeAPI)getServer().getPluginManager().getPlugin("KingdomLifeAPI")).test("Hip hip hooray!"));
                return true;
            }
          
            return false;
        }
    }
    
    API test method:
    Code:
    public static String test(String testString){
            return ChatColor.AQUA+"The API works! "+testString;
        }
    
     
  2. Offline

    Lightspeed

    Bump I'm stupid
     
  3. Offline

    Zombie_Striker

    @ShowbizLocket61
    1. DON'T BLIND CAST! Check if the sender is actaully a player before casting
    2. Why don't you just add "KingdomLifeAPI" as a dependency, and simply use "KingdomLifeAPI.test()"
     
    Last edited by a moderator: Jan 18, 2016
  4. Offline

    timtower Administrator Administrator Moderator

    @Zombie_Striker No need for the caps and bold.
    @Lightspeed Do you also get the error when you just restart the entire server?
     
  5. Offline

    ShowbizLocket61

    @Zombie_Striker
    The users of my plugin know to not use it from console. As I specified above, I've tried
    Code:
    ((Player)sender).sendMessage(KingdomLifeAPI.test("Hip hip hooray!"));
    to no avail

    @timtower
    No, I don't get the error when I restart the server. I also don't get the error when I disable APIReader, then reload the API.
    Also, if I use /readAPI and then disable the API, /readAPI still works. So there's an instance of the API somewhere, I just can't find it.
     
  6. Offline

    timtower Administrator Administrator Moderator

    @ShowbizLocket61 Then it is probably best to don't use plugins like Plugman to reload plugins.
     
  7. Offline

    ShowbizLocket61

    @timtower
    Plugman's being doing great on every other plugin, it's just this API-APIReader pair that's been tripping it up, because it doesn't disable both of them. I want to edit my code so that the API can independently reload without having to disable APIReader.
     
  8. Offline

    timtower Administrator Administrator Moderator

    @ShowbizLocket61 And why would you want that? No other plugin is able to do that as far as I know.
    It is a library, it shouldn't need to be reloaded.
     
  9. Offline

    ShowbizLocket61

    @timtower
    I'm still testing, debugging, and fixing my API and it's a pain to restart every time. As far as I know, plugman was created to alleviate that pain.
     
  10. Offline

    timtower Administrator Administrator Moderator

    @ShowbizLocket61 Could be, but that doesn't take away that a restart is better.
    Disable the api reader, disable the api, start the api, start the api reader, problem should be solved.
     
  11. Offline

    ShowbizLocket61

    @timtower
    Yes, but I'm going to hook two plugins on to the api.
    Disable, disable, disable, start, start, start.
    Kind of annoying, isn't it?
     
  12. Offline

    timtower Administrator Administrator Moderator

  13. Offline

    Flaps

    In your on disable for both plugins, disable the other plugin?
     
    ShowbizLocket61 likes this.
  14. Offline

    ShowbizLocket61

    @Flaps
    Thank you so much! That was an awesome suggestion! Works perfectly, thank you so much!!! :D
     
  15. Offline

    Flaps

    Make sure to mark the thread as solved. :)
     
Thread Status:
Not open for further replies.

Share This Page