error in my console + plugin not loading

Discussion in 'Plugin Development' started by MaplePlaysMC, Jun 5, 2014.

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

    MaplePlaysMC

    I am making a Dueling plugin but it will not load on my server heres my Stack trace
    Code:
    [13:59:39] [Server thread/ERROR]: Could not load 'plugins/Duel.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.IllegalArgumentException: Plugin already initialized!
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:328) ~[Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) [Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at org.bukkit.craftbukkit.v1_7_R2.CraftServer.loadPlugins(CraftServer.java:350) [Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at org.bukkit.craftbukkit.v1_7_R2.CraftServer.<init>(CraftServer.java:312) [Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at net.minecraft.server.v1_7_R2.PlayerList.<init>(PlayerList.java:63) [Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at net.minecraft.server.v1_7_R2.DedicatedPlayerList.<init>(SourceFile:14) [Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at net.minecraft.server.v1_7_R2.DedicatedServer.init(DedicatedServer.java:126) [Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at net.minecraft.server.v1_7_R2.MinecraftServer.run(MinecraftServer.java:426) [Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at net.minecraft.server.v1_7_R2.ThreadServerApplication.run(SourceFile:618) [Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
    Caused by: java.lang.IllegalArgumentException: Plugin already initialized!
        at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:98) ~[Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:59) ~[Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at me.maple.duel.DuelCore.<init>(DuelCore.java:11) ~[?:?]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.7.0_55]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.7.0_55]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.7.0_55]
        at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.7.0_55]
        at java.lang.Class.newInstance(Unknown Source) ~[?:1.7.0_55]
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:52) ~[Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:127) ~[Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        ... 9 more
    Caused by: java.lang.IllegalStateException: Initial initialization
        at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:101) ~[Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:59) ~[Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at me.maple.duel.DuelCore.<init>(DuelCore.java:11) ~[?:?]
        at me.maple.duel.DuelCore.<clinit>(DuelCore.java:14) ~[?:?]
        at java.lang.Class.forName0(Native Method) ~[?:1.7.0_55]
        at java.lang.Class.forName(Unknown Source) ~[?:1.7.0_55]
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:40) ~[Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:127) ~[Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        ... 9 more
    Can anybody tell me the problem?

    thanks!
     
  2. Offline

    Arkel

    If you read the output:
    Code:
    org.bukkit.plugin.InvalidPluginException: java.lang.IllegalArgumentException: Plugin already initialized
    Do you have two copies of Duel.jar in your plugins folder?
     
  3. Offline

    MaplePlaysMC

    No only that one http://gyazo.com/62b030d864013aa6dda0e26745000d51
     
  4. Offline

    Arkel

    Can you post your plugin.yml and JavaPlugin subclass?
     
  5. Offline

    MaplePlaysMC


    Code:
    name: Duel
    author: Maple
    version: 1.0
    main: me.maple.duel.DuelCore
    description: a plugin created exclusively for supreme 1v1s!
    commands:
      duel:
        usage: /duel
        description: 
    And im guessing this would be my sub class

    Code:java
    1. package me.maple.duel;
    2.  
    3. import java.util.HashMap;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. public class DuelCore extends JavaPlugin{
    12.  
    13. private static DuelCore instance = new DuelCore();
    14. public static DuelCore getInstance() { return instance; }
    15.  
    16. private HashMap<Player, Player> Duel = new HashMap();
    17.  
    18.  
    19.  
    20.  
    21. public void onEnable()
    22. {
    23. Bukkit.getPluginManager().registerEvents(DuelListener.getInstance(), this);
    24. }
    25.  
    26.  
    27. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
    28. {
    29. if (commandLabel.equalsIgnoreCase("duel")) {
    30. Player p1 = (Player)sender;
    31. if (args.length != 2) {
    32. sendCorrection(p1);
    33. } else {
    34. Player p2 = Bukkit.getPlayer(args[1]);
    35. if (args[0].equalsIgnoreCase("accept")) {
    36. if (Requests.getInstance().hasRequested(p2)) {
    37. if (Requests.getInstance().getRequested(p2).equals(p1)) {
    38. getInstance().startDuel(p1, p2);
    39. } else {
    40. p1.sendMessage(p2.getName() + " has not requested to duel with you or the request has expired");
    41. }
    42. } else {
    43. p1.sendMessage(p2.getName() + " has not requested to duel with you or the request has expired");
    44. }
    45. } else if (args[0].equalsIgnoreCase("decline")) {
    46. if (Requests.getInstance().hasRequested(p2)) {
    47. if (Requests.getInstance().getRequested(p2).equals(p1)) {
    48. p2.sendMessage("Succesfully declined " + p1.getName() + "'s request");
    49. } else {
    50. p1.sendMessage(p2.getName() + " has not requested to duel with you or the request has expired");
    51. }
    52. } else {
    53. p1.sendMessage(p2.getName() + " has not requested to duel with you or the request has expired");
    54. }
    55. } else if (args[0].equalsIgnoreCase("request")) {
    56. Requests.getInstance().sendRequest(p1, p2);
    57. Requests.getInstance().addDelayedRequest(p1, p2);
    58. } else {
    59. sendCorrection(p1);
    60. }
    61. }
    62. }
    63. return false;
    64. }
    65.  
    66.  
    67.  
    68.  
    69. private void sendCorrection(Player p)
    70. {
    71. p.sendMessage("The correct syntax is /duel [accept/decline] [playername]");
    72. }
    73.  
    74. public void startDuel(Player p1, Player p2)
    75. {
    76. if (p1.getWorld().getName() != p2.getWorld().getName()) { return;
    77. }
    78.  
    79.  
    80. if (Duel.containsKey(p1)) return;
    81. if (Duel.containsKey(p2)) return;
    82. if (Duel.containsValue(p1)) return;
    83. if (Duel.containsValue(p2)) return;
    84. Duel.put(p1, p2);
    85. Duel.put(p2, p1);
    86. p1.sendMessage("You are now dueling " + p2.getName());
    87. p2.sendMessage("You are now dueling " + p1.getName());
    88. }
    89.  
    90.  
    91.  
    92.  
    93.  
    94.  
    95. public void endDuel(Player p1, Player p2)
    96. {
    97. if (!Duel.containsKey(p1)) return;
    98. if (!Duel.containsKey(p2)) return;
    99. if (!Duel.containsValue(p1)) return;
    100. if (!Duel.containsValue(p2)) return;
    101. Duel.remove(p1);
    102. Duel.remove(p2);
    103. }
    104.  
    105.  
    106.  
    107.  
    108.  
    109. public boolean isInDuel(Player p)
    110. {
    111. if (Duel.containsKey(p)) return true;
    112. if (Duel.containsValue(p)) return true;
    113. return false;
    114. }
    115.  
    116.  
    117.  
    118.  
    119.  
    120.  
    121. public boolean isInDuelWith(Player p1, Player p2)
    122. {
    123. if (!Duel.containsKey(p1)) return false;
    124. if (!Duel.containsKey(p2)) return false;
    125. if (!Duel.containsValue(p1)) return false;
    126. if (!Duel.containsValue(p2)) return false;
    127. if (((Player)Duel.get(p1)).equals(p2)) return true;
    128. return false;
    129. }
    130.  
    131.  
    132.  
    133.  
    134.  
    135. public Player getInDuelWith(Player p)
    136. {
    137. if (!Duel.containsKey(p)) return null;
    138. if (!Duel.containsValue(p)) return null;
    139. return (Player)Duel.get(p);
    140. }
    141. }
     
  6. Offline

    fireblast709

    MaplePlaysMC the class he ment was the one that extends JavaPlugin ;)
     
  7. Offline

    MaplePlaysMC

    updated Thanks :D
     
  8. Offline

    fireblast709

    MaplePlaysMC Don't use static. That aside you are creating your own instance, which is not how it is supposed to be.
     
  9. Offline

    MaplePlaysMC


    Can you show me a Example of how it should be? please
     
  10. Offline

    fireblast709

    MaplePlaysMC
    Code:java
    1. public class DuelCore extends JavaPlugin
    2. {
    3.  
    4. private HashMap<Player, Player> Duel = new HashMap();
    5.  
    6. public void onEnable()
    7. {
    8. Bukkit.getPluginManager().registerEvents(DuelListener.getInstance(), this);
    9. }
     
  11. Offline

    MaplePlaysMC

  12. Offline

    fireblast709

    MaplePlaysMC then you are creating more instances of you main class elsewhere
     
  13. Offline

    Gater12

    MaplePlaysMC
    Any other classes that extends JavaPlugin. There should only be one.

    Also use generics instead of raw type to initialize create HashMap.
     
  14. Offline

    fireblast709

    Not making sense there. You use generics to create classes like HashMaps, not to initialize them.
     
    Gater12 likes this.
  15. Offline

    MaplePlaysMC

    So i changed it to
    Code:java
    1. package me.maple.duel;
    2.  
    3. import java.util.HashMap;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.command.Command;
    7. import org.bukkit.command.CommandSender;
    8. import org.bukkit.entity.Player;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. public class DuelCore extends JavaPlugin{
    12.  
    13. private static DuelCore instance = new DuelCore();
    14. public static DuelCore getInstance() { return instance; }
    15.  
    16. private HashMap<Player, Player> Duel = new HashMap();
    17.  
    18.  
    19.  
    20.  
    21. public void onEnable()
    22. {
    23. Bukkit.getPluginManager().registerEvents(DuelListener.getInstance(), this);
    24. }
    25.  
    26.  
    27. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args)
    28. {
    29. if (commandLabel.equalsIgnoreCase("duel")) {
    30. Player p1 = (Player)sender;
    31. if (args.length != 2) {
    32. sendCorrection(p1);
    33. } else {
    34. Player p2 = Bukkit.getPlayer(args[1]);
    35. if (args[0].equalsIgnoreCase("accept")) {
    36. if (Requests.getinstance().hasRequested(p2)) {
    37. if (Requests.getinstance().getRequested(p2).equals(p1)) {
    38. getInstance().startDuel(p1, p2);
    39. } else {
    40. p1.sendMessage(p2.getName() + " has not requested to duel with you or the request has expired");
    41. }
    42. } else {
    43. p1.sendMessage(p2.getName() + " has not requested to duel with you or the request has expired");
    44. }
    45. } else if (args[0].equalsIgnoreCase("decline")) {
    46. if (Requests.getinstance().hasRequested(p2)) {
    47. if (Requests.getinstance().getRequested(p2).equals(p1)) {
    48. p2.sendMessage("Succesfully declined " + p1.getName() + "'s request");
    49. } else {
    50. p1.sendMessage(p2.getName() + " has not requested to duel with you or the request has expired");
    51. }
    52. } else {
    53. p1.sendMessage(p2.getName() + " has not requested to duel with you or the request has expired");
    54. }
    55. } else if (args[0].equalsIgnoreCase("request")) {
    56. Requests.getinstance().sendRequest(p1, p2);
    57. Requests.getinstance().addDelayedRequest(p1, p2);
    58. } else {
    59. sendCorrection(p1);
    60. }
    61. }
    62. }
    63. return false;
    64. }
    65.  
    66.  
    67.  
    68.  
    69. private void sendCorrection(Player p)
    70. {
    71. p.sendMessage("The correct syntax is /duel [accept/decline] [playername]");
    72. }
    73.  
    74. public void startDuel(Player p1, Player p2)
    75. {
    76. if (p1.getWorld().getName() != p2.getWorld().getName()) { return;
    77. }
    78.  
    79.  
    80. if (Duel.containsKey(p1)) return;
    81. if (Duel.containsKey(p2)) return;
    82. if (Duel.containsValue(p1)) return;
    83. if (Duel.containsValue(p2)) return;
    84. Duel.put(p1, p2);
    85. Duel.put(p2, p1);
    86. p1.sendMessage("You are now dueling " + p2.getName());
    87. p2.sendMessage("You are now dueling " + p1.getName());
    88. }
    89.  
    90.  
    91.  
    92.  
    93.  
    94.  
    95. public void endDuel(Player p1, Player p2)
    96. {
    97. if (!Duel.containsKey(p1)) return;
    98. if (!Duel.containsKey(p2)) return;
    99. if (!Duel.containsValue(p1)) return;
    100. if (!Duel.containsValue(p2)) return;
    101. Duel.remove(p1);
    102. Duel.remove(p2);
    103. }
    104.  
    105.  
    106.  
    107.  
    108.  
    109. public boolean isInDuel(Player p)
    110. {
    111. if (Duel.containsKey(p)) return true;
    112. if (Duel.containsValue(p)) return true;
    113. return false;
    114. }
    115.  
    116.  
    117.  
    118.  
    119.  
    120.  
    121. public boolean isInDuelWith(Player p1, Player p2)
    122. {
    123. if (!Duel.containsKey(p1)) return false;
    124. if (!Duel.containsKey(p2)) return false;
    125. if (!Duel.containsValue(p1)) return false;
    126. if (!Duel.containsValue(p2)) return false;
    127. if (((Player)Duel.get(p1)).equals(p2)) return true;
    128. return false;
    129. }
    130.  
    131.  
    132.  
    133.  
    134.  
    135. public Player getInDuelWith(Player p)
    136. {
    137. if (!Duel.containsKey(p)) return null;
    138. if (!Duel.containsValue(p)) return null;
    139. return (Player)Duel.get(p);
    140. }
    141. }

    but im getting this error now
    Code:
    [13:59:39] [Server thread/ERROR]: Could not load 'plugins/Duel.jar' in folder 'plugins'
    org.bukkit.plugin.InvalidPluginException: java.lang.IllegalArgumentException: Plugin already initialized!
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:131) ~[Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:328) ~[Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:251) [Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at org.bukkit.craftbukkit.v1_7_R2.CraftServer.loadPlugins(CraftServer.java:350) [Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at org.bukkit.craftbukkit.v1_7_R2.CraftServer.<init>(CraftServer.java:312) [Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at net.minecraft.server.v1_7_R2.PlayerList.<init>(PlayerList.java:63) [Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at net.minecraft.server.v1_7_R2.DedicatedPlayerList.<init>(SourceFile:14) [Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at net.minecraft.server.v1_7_R2.DedicatedServer.init(DedicatedServer.java:126) [Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at net.minecraft.server.v1_7_R2.MinecraftServer.run(MinecraftServer.java:426) [Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at net.minecraft.server.v1_7_R2.ThreadServerApplication.run(SourceFile:618) [Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
    Caused by: java.lang.IllegalArgumentException: Plugin already initialized!
        at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:98) ~[Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:59) ~[Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at me.maple.duel.DuelCore.<init>(DuelCore.java:11) ~[?:?]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[?:1.7.0_55]
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.7.0_55]
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source) ~[?:1.7.0_55]
        at java.lang.reflect.Constructor.newInstance(Unknown Source) ~[?:1.7.0_55]
        at java.lang.Class.newInstance(Unknown Source) ~[?:1.7.0_55]
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:52) ~[Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:127) ~[Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        ... 9 more
    Caused by: java.lang.IllegalStateException: Initial initialization
        at org.bukkit.plugin.java.PluginClassLoader.initialize(PluginClassLoader.java:101) ~[Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at org.bukkit.plugin.java.JavaPlugin.<init>(JavaPlugin.java:59) ~[Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at me.maple.duel.DuelCore.<init>(DuelCore.java:11) ~[?:?]
        at me.maple.duel.DuelCore.<clinit>(DuelCore.java:14) ~[?:?]
        at java.lang.Class.forName0(Native Method) ~[?:1.7.0_55]
        at java.lang.Class.forName(Unknown Source) ~[?:1.7.0_55]
        at org.bukkit.plugin.java.PluginClassLoader.<init>(PluginClassLoader.java:40) ~[Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:127) ~[Bukkit_Dev.jar:git-Bukkit-1.7.2-R0.3-14-g8f8716c-b3042jnks]
        ... 9 more
     
  16. Offline

    xTigerRebornx

    MaplePlaysMC You are still trying to create the instance yourself (which Bukkit won't let you do if its made an instance), simply assign the instance that Bukkit makes to your instance variable, or use another solution to getting an instance
    These other solutions include:
    PluginManager#getPlugin() (Bukkit.getPluginManager().getPlugin("YourPlugin"))
    JavaPlugin#getPlugin(Class<T> class) (Pass in the class of your class that extends JavaPlugin)
    Dependency Injection (through a Constructor)

    There are probably more, I just don't feel like listing then all XD
     
  17. Offline

    Kassestral

    MaplePlaysMC
    Also why no onDisable() ? xD
     
  18. Offline

    jimuskin

    Kassestral onDisable isn't needed.
    MaplePlaysMC
    Remove this:
    Code:java
    1. private static DuelCore instance = new DuelCore();
    2. public static DuelCore getInstance() { return instance; }


    and change it to this:

    Code:java
    1. private static DuelCore instance = this;
    2. public static DuealCore getInstance(){ return instance;}
     
  19. Offline

    xTigerRebornx

    jimuskin
    Code:
    private static DuelCore instance = this;
    I don't think this would even compile, can't use 'this' in a static context, he'd want to initialize his instance in onEnable()
     
  20. Offline

    jimuskin

    xTigerRebornx
    Well then it would be something like this:

    Code:java
    1. private static DuelCore instane;


    Code:java
    1. public void onEnable(){
    2. instance = this;
    3. }


    It does work - I do it all the time.
     
  21. Offline

    xTigerRebornx

    jimuskin That would work (though there are other ways of doing it through the Bukkit API), the code I quoted before wouldn't (you got the concept, just not the actual "code")
     
    jimuskin likes this.
Thread Status:
Not open for further replies.

Share This Page