Solved Error?

Discussion in 'Plugin Development' started by kxpeep93, Jul 12, 2014.

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

    kxpeep93

    Code:
    org.bukkit.command.CommandException: Unhandled exception executing command 'powe
    r' in plugin HarlemWar v1.0
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[cra
    ftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:17
    5) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(CraftServe
    r.java:683) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            at net.minecraft.server.v1_7_R1.PlayerConnection.handleCommand(PlayerCon
    nection.java:952) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java
    :814) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            at net.minecraft.server.v1_7_R1.PacketPlayInChat.a(PacketPlayInChat.java
    :28) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            at net.minecraft.server.v1_7_R1.PacketPlayInChat.handle(PacketPlayInChat
    .java:47) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146
    ) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [craf
    tbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:6
    55) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:2
    50) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:5
    45) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java
    :457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:6
    17) [craftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
    Caused by: java.lang.NullPointerException
            at me.kxpeep93.HarlemWar.SettingsManager.saveData(SettingsManager.java:5
    7) ~[?:?]
            at me.kxpeep93.HarlemWar.HarlemWar.onCommand(HarlemWar.java:133) ~[?:?]
            at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[cra
    ftbukkit.jar:git-Bukkit-1.7.2-R0.3-2-g85f5776-b3024jnks]
            ... 13 more
    current code:

    Code:java
    1.  
    2.  
    3. public final Logger logger = Logger.getLogger("Minecraft");
    4. public static HarlemWar plugin;
    5. public final EventListener pl = new EventListener();
    6. SettingsManager settings = SettingsManager.getInstance();
    7.  
    8. public void onEnable()
    9. {
    10. Bukkit.getServer().getConsoleSender().sendMessage(Prefix + "Has Been Enabled");
    11. PluginManager pm = getServer().getPluginManager();
    12. pm.registerEvents(this.pl, this);
    13. }
    14.  
    15. public void onDisable()
    16. {
    17. Bukkit.getServer().getConsoleSender().sendMessage(Prefix + "Has Been Disabled");
    18. }
    19.  
    20. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    21. if (!(sender instanceof Player)) {
    22. sender.sendMessage(ChatColor.RED + "This plugin is for players only!");
    23. return true;
    24. }
    25.  
    26. Player player = (Player)sender;
    27.  
    28. if (commandLabel.equalsIgnoreCase("power") || (commandLabel.equalsIgnoreCase("p"))) {
    29. if (args.length == 0) {
    30. player.sendMessage(ChatColor.GRAY + "/power join [Team] : Join The Specified Team!");
    31. if (player.hasPermission("harlemwar.setspawn"))
    32. player.sendMessage(ChatColor.GRAY + "/power setspawn [Team] : Sets The Spawn For The Specified Team!");
    33. }
    34. else
    35. player.sendMessage(Prefix + red + "You Don't Have Permission To Perform This Command");
    36. }
    37. else if (args.length == 2) {
    38. if ((args[0].equalsIgnoreCase("join")) || (args[0].equalsIgnoreCase("j"))) {
    39. String currentGroup = this.settings.getData().getString(player.getName() + ".group");
    40. if ((currentGroup == null) || (player.hasPermission("harlemwar.overrideteam"))) {
    41. if ((args[1].equalsIgnoreCase("greek")) || (args[1].equalsIgnoreCase("greeks")) || (args[1].equalsIgnoreCase("g"))) {
    42. World w = Bukkit.getServer().getWorld(this.settings.getData().getString("Greeks.spawn.world"));
    43. double x = this.settings.getData().getDouble("Greeks.spawn.x");
    44. double y = this.settings.getData().getDouble("Greeks.spawn.y");
    45. double z = this.settings.getData().getDouble("Greeks.spawn.z");
    46. player.teleport(new Location(w, x, y, z));
    47. player.sendMessage(Prefix + green + "Your Were Teleported To Greeks Spawn");
    48. this.settings.getData().set(player.getName() + ".group", "Greeks");
    49. player.sendMessage(Prefix + red +"You have successfully the Greeks!");
    50. } else if ((args[1].equalsIgnoreCase("roman")) || (args[1].equalsIgnoreCase("romans")) || (args[1].equalsIgnoreCase("r"))) {
    51. World w = Bukkit.getServer().getWorld(this.settings.getData().getString("Romans.spawn.world"));
    52. double x = this.settings.getData().getDouble("Romans.spawn.x");
    53. double y = this.settings.getData().getDouble("Romans.spawn.y");
    54. double z = this.settings.getData().getDouble("Romans.spawn.z");
    55. player.teleport(new Location(w, x, y, z));
    56. player.sendMessage(Prefix + green + "Your Were Teleported To Romans Spawn");
    57. this.settings.getData().set(player.getName() + ".group", "Romans");
    58. player.sendMessage(Prefix + "You have successfully joined the Romans!");
    59. }
    60. }
    61. else player.sendMessage(Prefix + "You are already a member of the " + currentGroup + "!");
    62. } else if ((args[0].equalsIgnoreCase("setspawn")) || (args[0].equalsIgnoreCase("ss"))) {
    63. if (player.hasPermission("harlemwar.setspawn")) {
    64. if ((args[1].equalsIgnoreCase("roman")) || (args[1].equalsIgnoreCase("romans")) || (args[1].equalsIgnoreCase("r"))) {
    65. this.settings.getData().set("Romans.spawn.world", player.getLocation().getWorld().getName());
    66. this.settings.getData().set("Romans.spawn.x", Double.valueOf(player.getLocation().getX()));
    67. this.settings.getData().set("Romans.spawn.y", Double.valueOf(player.getLocation().getY()));
    68. this.settings.getData().set("Romans.spawn.z", Double.valueOf(player.getLocation().getZ()));
    69. this.settings.getData().set("Romans.spawn.pitch", Float.valueOf(player.getLocation().getPitch()));
    70. this.settings.getData().set("Romans.spawn.yaw", Float.valueOf(player.getLocation().getYaw()));
    71. this.settings.saveData();
    72. player.sendMessage(Prefix + "Roman Spawn Set");
    73. } else if ((args[1].equalsIgnoreCase("greek")) || (args[1].equalsIgnoreCase("greeks")) || (args[1].equalsIgnoreCase("g"))) {
    74. this.settings.getData().set("Greeks.spawn.world", player.getLocation().getWorld().getName());
    75. this.settings.getData().set("Greeks.spawn.x", Double.valueOf(player.getLocation().getX()));
    76. this.settings.getData().set("Greeks.spawn.y", Double.valueOf(player.getLocation().getY()));
    77. this.settings.getData().set("Greeks.spawn.z", Double.valueOf(player.getLocation().getZ()));
    78. this.settings.getData().set("Greeks.spawn.pitch", Float.valueOf(player.getLocation().getPitch()));
    79. this.settings.getData().set("Greeks.spawn.yaw", Float.valueOf(player.getLocation().getYaw()));
    80. this.settings.saveData();
    81. player.sendMessage(Prefix + "Greek Spawn Set");
    82. } else {
    83. player.sendMessage(ChatColor.GRAY + "/power join [Team] : Join The Specified Team!");
    84. if (player.hasPermission("harlemwar.setspawn"))
    85. player.sendMessage(ChatColor.GRAY + "/power setspawn [Team] : Sets The Spawn For The Specified Team!");
    86. }
    87. }
    88. }
    89. else {
    90. player.sendMessage(ChatColor.GRAY + "/power join [Team] : Join The Specified Team! ");
    91. if (player.hasPermission("harlemwar.setspawn"))
    92. player.sendMessage(ChatColor.GRAY + "/power setspawn [Team] : Sets The Spawn For The Specified Team!");
    93. }
    94. }
    95. else {
    96. player.sendMessage(ChatColor.GRAY + "/power join [Team] : Join The Specified Team!");
    97. if (player.hasPermission("harlemwar.setspawn"))
    98. player.sendMessage(ChatColor.GRAY + "/power setspawn [Team] : Sets The Spawn For The Specified Team!");
    99. }
    100. this.settings.saveData();
    101. return false;
    102. }
    103. }
     
  2. Offline

    iTornado1234

    Code:
    Caused by: java.lang.NullPointerException
            at me.kxpeep93.HarlemWar.SettingsManager.saveData(SettingsManager.java:5
    Thats your error. Something is null at the SettingsManager Class line 5.
     
  3. Offline

    kxpeep93

    iTornado1234 its not showing any errors but here is my settings manager
    Code:java
    1. public class SettingsManager
    2. {
    3. static SettingsManager instance = new SettingsManager();
    4. Plugin p;
    5. FileConfiguration config;
    6. File cfile;
    7. FileConfiguration data;
    8. File dfile;
    9.  
    10. public static SettingsManager getInstance()
    11. {
    12. return instance;
    13. }
    14.  
    15. public void setup(Plugin p)
    16. {
    17. this.cfile = new File(p.getDataFolder(), "config.yml");
    18. this.config = p.getConfig();
    19.  
    20. if (!p.getDataFolder().exists()) {
    21. p.getDataFolder().mkdir();
    22. }
    23.  
    24. this.dfile = new File(p.getDataFolder(), "data.yml");
    25.  
    26. if (!this.dfile.exists()) {
    27. try {
    28. this.dfile.createNewFile();
    29. }
    30. catch (IOException e) {
    31. Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not create data.yml!");
    32. }
    33. }
    34.  
    35. this.data = YamlConfiguration.loadConfiguration(this.dfile);
    36. }
    37.  
    38. public FileConfiguration getData() {
    39. return this.data;
    40. }
    41.  
    42. public void saveData() {
    43. try {
    44. this.data.save(this.dfile);
    45. }
    46. catch (IOException e) {
    47. Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not save data.yml!");
    48. }
    49. }
    50.  
    51. public void reloadData() {
    52. this.data = YamlConfiguration.loadConfiguration(this.dfile);
    53. }
    54.  
    55. public FileConfiguration getConfig() {
    56. return this.config;
    57. }
    58.  
    59. public void saveConfig() {
    60. try {
    61. this.config.save(this.cfile);
    62. }
    63. catch (IOException e) {
    64. Bukkit.getServer().getLogger().severe(ChatColor.RED + "Could not save config.yml!");
    65. }
    66. }
    67.  
    68. public void reloadConfig() {
    69. this.config = YamlConfiguration.loadConfiguration(this.cfile);
    70. }
    71.  
    72. public PluginDescriptionFile getDesc() {
    73. return this.p.getDescription();
    74. }
     
  4. Offline

    iTornado1234

  5. Offline

    izarooni

    Why did you create a new class for the plugin config? :confused:
     
    iTornado1234 likes this.
  6. Offline

    kxpeep93

    izarooni its a settings manger its easier in the long run
     
  7. Offline

    xTigerRebornx

    kxpeep93 Post the full class (don't cut out imports, don't cut out anything you think may not be needed to be posted).

    Edit: Error is fairly obvious. You clearly didn't write this "settings manager", if you did, you would be able to spot the error instantly. There is a certain method that will prepare the settings manager that you never call.
     
  8. Offline

    kxpeep93

    xTigerRebornx incorrect this is my first time using settings manager i don't usually use it so please don't assume stuff !
     
Thread Status:
Not open for further replies.

Share This Page