Reading YMLs - Null Pointer

Discussion in 'Plugin Development' started by Rellac, Dec 9, 2014.

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

    Rellac

    Hi, I am attempting to read the "points" value from a yml section and output it to the player, but I seem to have run into a stop of bother.

    Code:
    [21:46:12] [Server thread/INFO]: Rellac issued server command: /points
    [21:46:12] [Server thread/ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'points' in plugin Ranks v1.0
       at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit-1.7.9-R02.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
       at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:180) ~[craftbukkit-1.7.9-R02.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
       at org.bukkit.craftbukkit.v1_7_R3.CraftServer.dispatchCommand(CraftServer.java:701) ~[craftbukkit-1.7.9-R02.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
       at net.minecraft.server.v1_7_R3.PlayerConnection.handleCommand(PlayerConnection.java:956) [craftbukkit-1.7.9-R02.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
       at net.minecraft.server.v1_7_R3.PlayerConnection.a(PlayerConnection.java:817) [craftbukkit-1.7.9-R02.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
       at net.minecraft.server.v1_7_R3.PacketPlayInChat.a(PacketPlayInChat.java:28) [craftbukkit-1.7.9-R02.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
       at net.minecraft.server.v1_7_R3.PacketPlayInChat.handle(PacketPlayInChat.java:47) [craftbukkit-1.7.9-R02.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
       at net.minecraft.server.v1_7_R3.NetworkManager.a(NetworkManager.java:157) [craftbukkit-1.7.9-R02.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
       at net.minecraft.server.v1_7_R3.ServerConnection.c(SourceFile:134) [craftbukkit-1.7.9-R02.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
       at net.minecraft.server.v1_7_R3.MinecraftServer.v(MinecraftServer.java:667) [craftbukkit-1.7.9-R02.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
       at net.minecraft.server.v1_7_R3.DedicatedServer.v(DedicatedServer.java:260) [craftbukkit-1.7.9-R02.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
       at net.minecraft.server.v1_7_R3.MinecraftServer.u(MinecraftServer.java:558) [craftbukkit-1.7.9-R02.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
       at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:469) [craftbukkit-1.7.9-R02.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
       at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [craftbukkit-1.7.9-R02.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
    Caused by: java.lang.ArrayIndexOutOfBoundsException: 0
       at com.test.Ranks.Ranks.onCommand(Ranks.java:65) ~[?:?]
       at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit-1.7.9-R02.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
       ... 13 more
    
    This is caused whenever I run the command:
    Code:
        if(cmd.getName().equalsIgnoreCase("points"))
         {
           getPlayers();
           if (Players.contains("players."+name+".points"))
           {
             int points = Players.getInt("players."+name+".points");
             sender.sendMessage("You Have: [" + points + "] Points");
           }
           else sender.sendMessage("You Have: [0] Points");
         }
    
    All of my handling of the configs through getPlayers() works fine throughout the rest of the entire plugin, so I doubt that it's an issue anywhere but the command itself, but here are the referenced functions in the command:

    Show Spoiler

    Code:
      public FileConfiguration getPlayers()
      {
      if (Players == null)
      {
      reloadPlayers();
      }
      return Players;
      }
    
    Code:
      public void reloadPlayers()
      {
         Reader defConfigStream = null;
      if (PlayersFile == null)
      {
         PlayersFile = new File(getDataFolder(), "players.yml");
      }
      Players = YamlConfiguration.loadConfiguration(PlayersFile);
     
      // Look for defaults in the jar
     
         try
         {
           defConfigStream = new InputStreamReader(this.getResource("players.yml"), "UTF8");
         }
         catch (UnsupportedEncodingException e)
         {
           e.printStackTrace();
         }
      if (defConfigStream != null)
      {
      YamlConfiguration defConfig = YamlConfiguration.loadConfiguration(defConfigStream);
      Players.setDefaults(defConfig);
      }
      }
    

    What seems to be the problem? I don't understand why I should be getting a null pointer here
     
    Last edited by a moderator: Dec 9, 2014
  2. Offline

    Skionz

    @Rellac What is 'Players?' Is it a class? Post your entire class or tell me what line 65 is.
     
    Rellac likes this.
  3. Offline

    Unica

    Ranks.java:65 --> Your ranks class. Line 65.
     
    Rellac likes this.
  4. Offline

    Rellac

    @Skionz @Unica
    Hm,

    String name = Bukkit.getPlayerExact(args[0]).getUniqueId().toString();

    I'm trying to get the player's UUID as a string. As far as I can tell, it reads and writes this value just fine in the YMLs, but it's apparently having issue with this command for some reason?
     
  5. Offline

    Skionz

    @Rellac args[0] does not exist.
     
    Hawktasard and Rellac like this.
  6. Offline

    Hawktasard

    @Rellac
    There's no args[0]
    Edit: ninja :(
     
    Rellac and Skionz like this.
  7. Offline

    Rellac

    Oh I can see where I've failed miserably like an idiot.. Thanks everyone, likes all round :)
     
    Skionz likes this.
Thread Status:
Not open for further replies.

Share This Page