Solved "Plugin is already initialized"

Discussion in 'Plugin Development' started by Nickolous14, Aug 8, 2014.

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

    Nickolous14

    Hi I'm developing a plugin called Trouble in Terrorist Town(You may now the game that it is based off of). But for some reason every time it says "Plugin is already initialized".

    error message:

    Code:
    C:\Users\Nickc_000\Desktop\Minecraft server>java -Xmx3024M -jar craftbukkit.jar
    -o true
    Loading libraries, please wait...
    [10:05:42 INFO]: Starting minecraft server version 1.7.9
    [10:05:42 INFO]: Loading properties
    [10:05:42 INFO]: Default game type: CREATIVE
    [10:05:42 INFO]: Generating keypair
    [10:05:42 INFO]: Starting Minecraft server on *:25565
    [10:05:42 INFO]: This server is running CraftBukkit version git-Bukkit-1.7.9-R0.
    1-b3084jnks (MC: 1.7.9) (Implementing API version 1.7.9-R0.1)
    [10:05:42 INFO]: [Trouble_in_Terrorist_Town] Loading Trouble_in_Terrorist_Town v
    1.0
    [10:05:42 INFO]: Preparing level "world"
    [10:05:42 INFO]: Preparing start region for level 0 (Seed: 5100641857653681035)
    [10:05:43 INFO]: ----- Bukkit Auto Updater -----
    [10:05:43 INFO]: It appears that you're running a Beta Build, when you've specif
    ied in bukkit.yml that you prefer to run Recommended Builds.
    [10:05:43 INFO]: If you would like to be kept informed about new Beta Build rele
    ases, it is recommended that you change 'preferred-channel' in your bukkit.yml t
    o 'beta'.
    [10:05:43 INFO]: With that set, you will be told whenever a new version is avail
    able for download, so that you can always keep up to date and secure with the la
    test fixes.
    [10:05:43 INFO]: If you would like to disable this warning, simply set 'suggest-
    channels' to false in bukkit.yml.
    [10:05:43 INFO]: ----- ------------------- -----
    [10:05:43 INFO]: Preparing start region for level 1 (Seed: -7701118772944643723)
     
    [10:05:44 INFO]: Preparing start region for level 2 (Seed: -7701118772944643723)
     
    [10:05:44 INFO]: [Trouble_in_Terrorist_Town] Enabling Trouble_in_Terrorist_Town
    v1.0
    [10:05:44 ERROR]: Error occurred while enabling Trouble_in_Terrorist_Town v1.0 (
    Is it up to date?)
    java.lang.IllegalArgumentException: Plugin already initialized!
            at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader
    .java:98) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
            at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[craftb
    ukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
            at com.Nickolous14.main.Main.<init>(Main.java:17) ~[?:?]
            at com.Nickolous14.TTT.TTT.start(TTT.java:16) ~[?:?]
            at com.Nickolous14.main.Main.onEnable(Main.java:24) ~[?:?]
            at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:316) ~[c
    raftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
            at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader
    .java:324) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
            at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManage
    r.java:404) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
            at org.bukkit.craftbukkit.v1_7_R3.CraftServer.loadPlugin(CraftServer.jav
    a:446) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
            at org.bukkit.craftbukkit.v1_7_R3.CraftServer.enablePlugins(CraftServer.
    java:380) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
            at net.minecraft.server.v1_7_R3.MinecraftServer.n(MinecraftServer.java:3
    52) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
            at net.minecraft.server.v1_7_R3.MinecraftServer.g(MinecraftServer.java:3
    26) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
            at net.minecraft.server.v1_7_R3.MinecraftServer.a(MinecraftServer.java:2
    82) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
            at net.minecraft.server.v1_7_R3.DedicatedServer.init(DedicatedServer.jav
    a:182) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
            at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java
    :436) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
            at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:6
    28) [craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
    Caused by: java.lang.IllegalStateException: Initial initialization
            at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader
    .java:101) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
            at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:66) ~[craftb
    ukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
            at com.Nickolous14.main.Main.<init>(Main.java:17) ~[?:?]
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    ~[?:1.7.0_51]
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    ~[?:1.7.0_51]
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Sou
    rce) ~[?:1.7.0_51]
            at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.7.0_5
    1]
            at java.lang.Class.newInstance(Unknown Source) ~[?:1.7.0_51]
            at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.jav
    a:52) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
            at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.j
    ava:127) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
            at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.
    java:328) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
            at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager
    .java:251) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
            at org.bukkit.craftbukkit.v1_7_R3.CraftServer.loadPlugins(CraftServer.ja
    va:355) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
            at org.bukkit.craftbukkit.v1_7_R3.CraftServer.<init>(CraftServer.java:31
    7) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
            at net.minecraft.server.v1_7_R3.PlayerList.<init>(PlayerList.java:68) ~[
    craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
            at net.minecraft.server.v1_7_R3.DedicatedPlayerList.<init>(SourceFile:14
    ) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
            at net.minecraft.server.v1_7_R3.DedicatedServer.init(DedicatedServer.jav
    a:126) ~[craftbukkit.jar:git-Bukkit-1.7.9-R0.1-b3084jnks]
            ... 2 more
    [10:05:44 INFO]: Server permissions file permissions.yml is empty, ignoring it
    [10:05:44 INFO]: Done (1.621s)! For help, type "help" or "?"
    >




    Code of Main(that extends JavaPlugin):

    Code:
        @Override
        public void onEnable() {
            getServer().getPluginManager().registerEvents(new PlayerDeathListener(this), this);
            getServer().getPluginManager().registerEvents(new PlayerInteractListener(this), this);
            TTT.start();
        }
     
        @Override
        public void onDisable() {
            TTT.stop();
        }
     
        @Override
        public boolean onCommand(CommandSender sender, Command command,
                String commandLabel, String[] args) {
            Player player = (Player) sender;
            if(commandLabel.equalsIgnoreCase("TTThelp")||commandLabel.equalsIgnoreCase("troubleinterroristtownhelp")||
                    commandLabel.equalsIgnoreCase("TTT")){
                if(args.length == 0 || (args.length == 1 && args[0].equalsIgnoreCase("help"))){
                    Chatutils.sendMessage(player, ChatColor.DARK_PURPLE+"Help for Trouble in Terrorist Town:");
                    Chatutils.sendMessage(player, ChatColor.WHITE+"Trouble in Terrorist Town(a.k.a: TTT) is a plugin for minecraf that when the game starts,"
                            + " there is one terrorist with any weapon it want that has a goal to kill everyone else."
                            + " However no one know who is the terrorist except for the terrorist himself!");
                    //TODO finish commands, help message etc.
                }
            }else if(commandLabel.equalsIgnoreCase("C4")){
                if(args[0].equalsIgnoreCase("d")){
                    if(PlayerInteractListener.isAbleToStartc4()){
                        Chatutils.sendMessage(player, ChatColor.GREEN+"");
                    }else if(!PlayerInteractListener.isAbleToStartc4()){
                        Chatutils.sendMessage(player, ChatColor.RED+"YOU HAVE NOT SET A LOCATION FOR YOUR C4 YET!");
                    }
                }
            }
            return false;
        }
     
        public void schedualLobby(){
            getServer().getScheduler().cancelAllTasks();
            getServer().getScheduler().scheduleSyncRepeatingTask(this, new LobbyCountDown(), 20l, 20l);
        }
     
        public void schedualGame(){
            getServer().getScheduler().cancelAllTasks();
            getServer().getScheduler().scheduleSyncRepeatingTask(this, new GameCountDown(), 20l, 20l);
        }
     
        public void schedualPostGame() {
            getServer().getScheduler().cancelAllTasks();
            getServer().getScheduler().scheduleSyncRepeatingTask(this, new PostCountDown(), 20l, 20l);
        }
     
        

    The BukkitRunnable:


    Code:
    public class LobbyCountDown extends BukkitRunnable{
     
     
        private static int timeUntilGameStart = 30;
     
        public void run() {
            if(timeUntilGameStart == 20){
                Chatutils.broadCast(ChatColor.WHITE+"20 seconds until start!");
            }else if(timeUntilGameStart == 10){
                Chatutils.broadCast(ChatColor.WHITE+"10 seconds until starting!");
            }else if(timeUntilGameStart == 0){
                Chatutils.broadCast(ChatColor.WHITE+"Game Starting!");
                TTT.gameStart();
            }
     
            timeUntilGameStart--;
     
        }
     
     
     
     
    }
    I wasn't going to post it because I didn't think anyone needed it but here is the TTT class:

    Code:
        private static Innocent inn;
        private static Terrorist terr;
     
        public static void start(){
            Main main = new Main();
            TTTState.setCurrentState(TTTState.IN_LOBBY);
            main.schedualLobby();
        }
     
        public static void gameStart(){
            Main main = new Main();
            main.schedualGame();
            TTTState.setCurrentState(TTTState.IN_GAME);
            Player[] player = Bukkit.getOnlinePlayers();
            Random r = new Random(); 
            int i = r.nextInt(Bukkit.getOnlinePlayers().length);
            for(Player players :Bukkit.getOnlinePlayers()){ 
                if(!(player[1] == players)){
                    setInn(new Innocent(players));
                }else if(player[i] == players){
                    terr = new Terrorist(null);
                    setTerrorist(terr);
                    //TODO finnish this stuff
                }
            }
            Innocent.getPlayers().remove(player[i]); 
        }
     
        public static void postGame(){
            Main main = new Main();
            main.schedualPostGame();
        }
     
        public static void reset(){
         
        }
     
        public static void stop() {
         
        }
        public static Terrorist getTerrorist() {
            return terr;
        }
        public static void setTerrorist(Terrorist terr) {
            TTT.terr = terr;
        }
        public static Innocent getInn() {
            return inn;
        }
        public static void setInn(Innocent inn) {
            TTT.inn = inn;
        }
     
        
    Thank you for any advice that you leave.
     
  2. Offline

    Necrodoom

    What is TTT? Paste full main class please.
     
  3. Offline

    1Rogue Retired Staff

    Check your plugins for duplicate jarfiles, and make sure that only one class extends JavaPlugin.
     
  4. Offline

    Nickolous14

    Necrodoom I just edited it with the TTT class in it

    1Rogue Nope just the "Main" class any other advice?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 9, 2016
  5. Offline

    1Rogue Retired Staff

    Do you have your code on a repository somewhere?
     
  6. Offline

    Nickolous14


    Sorry is a repository a github or Source code folder? I think the problem is in the BukkitRunnable.
     
  7. Offline

    SpaceManiac

    "Main main = new Main();" all over the place in the TTT class, as pointed out by the stack trace, is the problem. You can't create new instances of your main JavaPlugin class, only use the one Bukkit gives you.
     
  8. Offline

    rbrick

    In response to SpaceManiac 's post. Have something like this in your main class

    Code:java
    1. private static Main instance;
    2.  
    3. public void onEnable() {
    4. instance = this;
    5. }
    6.  
    7. public static Main getInstance() {
    8. return instance;
    9. }
    10.  
    11. // Then to get the main class
    12. Main.getInstance();


    In case you needed help :)
     
  9. Offline

    1Rogue Retired Staff

    rbrick likes this.
  10. Offline

    Nickolous14



    Thanks, I forgot that using "new " also uses it's super-class, that fixed it.
     
  11. Offline

    rbrick

Thread Status:
Not open for further replies.

Share This Page