java.lang.IllegalArgumentException: File cannot be null error

Discussion in 'Plugin Development' started by adampoconnor, Aug 2, 2013.

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

    adampoconnor

    Hey guys,

    After about 2 days of research on this error, and with no luck, I've resorted to coming here for help.

    Basically, I get this error when trying to make a new integer variable, at least that's what the stacktrace tells me.

    Here is the class file:

    Code:java
    1. package com.argonathrpg.minecraft.forcespawn;
    2.  
    3.  
    4. // import java.io.File;
    5. // import java.util.logging.Logger;
    6. // import org.bukkit.Bukkit;
    7. import org.bukkit.Location;
    8. // import org.bukkit.configuration.file.FileConfiguration;
    9. // import org.bukkit.ChatColor;
    10. // import org.bukkit.World;
    11. // import org.bukkit.command.Command;
    12. // import org.bukkit.command.CommandSender;
    13. import org.bukkit.entity.Player;
    14. import org.bukkit.event.EventHandler;
    15. import org.bukkit.event.Listener;
    16. import org.bukkit.event.player.PlayerJoinEvent;
    17. import org.bukkit.plugin.java.JavaPlugin;
    18.  
    19.  
    20. public final class ForceSpawn extends JavaPlugin implements Listener {
    21. public void loadConfiguration(){
    22. //See "Creating you're defaults"
    23. getConfig().options().copyDefaults(true); // NOTE: You do not have to use "plugin." if the class extends the java plugin
    24. //Save the config whenever you manipulate it
    25. saveConfig();
    26. String path = "spawnlocation.x";
    27. getConfig().addDefault(path, "1337");
    28. path = "spawnlocation.y";
    29. getConfig().addDefault(path, "1337");
    30. path = "spawnlocation.z";
    31. getConfig().addDefault(path, "1337");
    32. getConfig().options().copyDefaults(true);
    33. saveConfig();
    34. }
    35. public void onEnable() {
    36. loadConfiguration();
    37. getLogger().info("Argonath RPG Spawn Plugin Enabled!");
    38. this.getServer().getPluginManager().registerEvents(new ForceSpawn(), this);
    39. }
    40. public void onDisable() {
    41. getLogger().info("Argonath RPG Spawn Plugin Disabled!");
    42. }
    43. @EventHandler
    44. public void onPlayerJoin(PlayerJoinEvent event) {
    45. Player player = event.getPlayer();
    46. Integer xx;
    47. Integer yy;
    48. Integer zz;
    49. xx = getConfig().getInt("spawnlocation.x");
    50. yy = getConfig().getInt("spawnlocation.y");
    51. zz = getConfig().getInt("spawnlocation.z");
    52. double x;
    53. double y;
    54. double z;
    55. x = (double)xx;
    56. y = (double)yy;
    57. z = (double)zz;
    58. Location playerLocation = player.getLocation();
    59. playerLocation.setX(x);
    60. playerLocation.setY(y);
    61. playerLocation.setZ(z);
    62. player.teleport(playerLocation);
    63. }
    64.  
    65. }
    66.  


    The error is under the PlayerJoinEvent handler. I just can't pinpoint where. The error line is
    Code:text
    1.  
    2. Integer xx;
    3.  


    Here is the stacktrace:
    Code:text
    1.  
    2. 15:40:50 [SEVERE] Could not pass event PlayerJoinEvent to Argonath RPG Spawn Plugin v1
    3. org.bukkit.event.EventException
    4. at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
    5. at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    6. at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
    7. at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
    8. at net.minecraft.server.v1_6_R2.PlayerList.c(PlayerList.java:206)
    9. at net.minecraft.server.v1_6_R2.PlayerList.a(PlayerList.java:102)
    10. at net.minecraft.server.v1_6_R2.PendingConnection.e(PendingConnection.java:130)
    11. at net.minecraft.server.v1_6_R2.PendingConnection.d(PendingConnection.java:43)
    12. at net.minecraft.server.v1_6_R2.DedicatedServerConnectionThread.a(DedicatedServerConnectionThread.java:41)
    13. at net.minecraft.server.v1_6_R2.DedicatedServerConnection.b(SourceFile:29)
    14. at net.minecraft.server.v1_6_R2.MinecraftServer.t(MinecraftServer.java:590)
    15. at net.minecraft.server.v1_6_R2.DedicatedServer.t(DedicatedServer.java:226)
    16. at net.minecraft.server.v1_6_R2.MinecraftServer.s(MinecraftServer.java:486)
    17. at net.minecraft.server.v1_6_R2.MinecraftServer.run(MinecraftServer.java:419)
    18. at net.minecraft.server.v1_6_R2.ThreadServerApplication.run(SourceFile:582)
    19. Caused by: java.lang.IllegalArgumentException: File cannot be null
    20. at org.apache.commons.lang.Validate.notNull(Validate.java:203)
    21. at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:170)
    22. at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:117)
    23. at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:111)
    24. at com.argonathrpg.minecraft.forcespawn.ForceSpawn.onPlayerJoin(ForceSpawn.java:46)
    25. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    26. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    27. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    28. at java.lang.reflect.Method.invoke(Method.java:597)
    29. at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
    30. ... 14 more
    31.  


    Any help would be greatly appreciated.

    NOTE: I do realize that everything is on the same class file, and I'm not supposed to, however it is just to see if I can actually make it work. Also, that method of teleportation works if I have the co-ordinates compiled in. After adding the config part it screwed me over.


    Thanks,

    Adam
     
  2. Offline

    foodyling

    adampoconnor Do you have a config.yml in your jar at all?
     
  3. Offline

    xTrollxDudex

    adampoconnor
    You can't register like that and try this.saveDefaultConfig(); is there anything inside the config at all?
     
  4. Offline

    adampoconnor

    foodyling There is.
    Code:yaml
    1.  
    2. position:
    3. x: 1337
    4. y: 1337
    5. z: 1337
    6.  


    Also, I am not using tabs in YAML

    xTrollxDudex

    Read above on config. Changed everything to this.saveDefaultConfig() to no avail
     
  5. Offline

    xTrollxDudex

    adampoconnor
    Replace line 38:
    PHP:
    this.getServer().getPluginManager().registerEvents(thisthis);
     
  6. Offline

    adampoconnor

    That appears to have worked. I need to reset my co-ordinates and I'll let you know what happens

    Alright. New issue. Although I don't get any exceptions, I now get an issue with the fact that I spawn at 0,0,0 every time....

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

    xTrollxDudex

    adampoconnor
    Just create a new location
    PHP:
    Location loc = new Location(player.getWorld(), xyz);
    player.teleport(loc);
     
  8. Offline

    adampoconnor

    No dice. My guess is, it's not reading the YAML correctly.

    EDIT: Got it working. I got the permissions nodes wrong. Thanks for the help. Solved.
     
Thread Status:
Not open for further replies.

Share This Page