Solved Can't read/write the config.yml

Discussion in 'Plugin Development' started by Heracles421, Dec 20, 2013.

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

    Heracles421

    I'm trying to make a mini-game plugin that is similar to the movie Tron, where you leave a trail of blocks behind you and if another player touches it, he dies. The problem here is that whenever I try to read or write from/to the config, it gives me a NullPointerException, but the config's value is not null.

    Here's the error:
    Show Spoiler

    Code:
    [15:03:05 ERROR]: null
    org.bukkit.command.CommandException: Unhandled exception executing command 'tron' in plugin Tron v1.0
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[minecraft_server.jar:git-Bukkit-1.7.2-R0.1-b2969jnks]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:196) ~[minecraft_server.jar:git-Bukkit-1.7.2-R0.1-b2969jnks]
        at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(CraftServer.java:542) ~[minecraft_server.jar:git-Bukkit-1.7.2-R0.1-b2969jnks]
        at net.minecraft.server.v1_7_R1.PlayerConnection.handleCommand(PlayerConnection.java:929) [minecraft_server.jar:git-Bukkit-1.7.2-R0.1-b2969jnks]
        at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:811) [minecraft_server.jar:git-Bukkit-1.7.2-R0.1-b2969jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInChat.a(PacketPlayInChat.java:28) [minecraft_server.jar:git-Bukkit-1.7.2-R0.1-b2969jnks]
        at net.minecraft.server.v1_7_R1.PacketPlayInChat.handle(PacketPlayInChat.java:47) [minecraft_server.jar:git-Bukkit-1.7.2-R0.1-b2969jnks]
        at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146) [minecraft_server.jar:git-Bukkit-1.7.2-R0.1-b2969jnks]
        at net.minecraft.server.v1_7_R1.ServerConnection.c(SourceFile:134) [minecraft_server.jar:git-Bukkit-1.7.2-R0.1-b2969jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [minecraft_server.jar:git-Bukkit-1.7.2-R0.1-b2969jnks]
        at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [minecraft_server.jar:git-Bukkit-1.7.2-R0.1-b2969jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [minecraft_server.jar:git-Bukkit-1.7.2-R0.1-b2969jnks]
        at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [minecraft_server.jar:git-Bukkit-1.7.2-R0.1-b2969jnks]
        at net.minecraft.server.v1_7_R1.ThreadServerApplication.run(SourceFile:617) [minecraft_server.jar:git-Bukkit-1.7.2-R0.1-b2969jnks]
    Caused by: java.lang.NullPointerException
        at me.ianespana.Tron.GameManager.join(GameManager.java:47) ~[?:?]
        at me.ianespana.Tron.TronCommands.commands(TronCommands.java:36) ~[?:?]
        at me.ianespana.Tron.Tron.onCommand(Tron.java:40) ~[?:?]
        at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[minecraft_server.jar:git-Bukkit-1.7.2-R0.1-b2969jnks]
        ... 13 more

    This error happens with every command that attempts to do something with the config, although the lines where the error occurs change depending on the command you issued.

    And here is the code of my plugin (It's a bit messy since it's my first time making a plugin):
    Show Spoiler

    Main Class (Tron):
    Show Spoiler

    Code:java
    1. package me.ianespana.Tron;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.command.Command;
    5. import org.bukkit.command.CommandSender;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.plugin.PluginDescriptionFile;
    8. import org.bukkit.plugin.java.JavaPlugin;
    9.  
    10. public class Tron extends JavaPlugin {
    11.  
    12. String tronHeader = ChatColor.WHITE + "[" + ChatColor.BLUE + "TRON" + ChatColor.WHITE + "]";
    13.  
    14. private TronCommands tronCommands = new TronCommands();
    15. private GameManager gameManager = new GameManager(this);
    16. @Override
    17. public void onEnable(){
    18. saveDefaultConfig();
    19. getConfig().options().copyDefaults(true);
    20. getServer().getPluginManager().registerEvents(new GameManager(this), this);
    21. PluginDescriptionFile pdfFile = this.getDescription();
    22. getLogger().info(pdfFile.getName() + " version " + pdfFile.getVersion() + " has been enabled.");
    23. this.gameManager.gameTimer();
    24. }
    25.  
    26. @Override
    27. public void onDisable(){
    28. PluginDescriptionFile pdfFile = this.getDescription();
    29. getLogger().info(pdfFile.getName() + " version " + pdfFile.getVersion() + " has been disabled.");
    30. }
    31.  
    32. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    33. if ((sender instanceof Player) && (cmd.getName().equalsIgnoreCase("tron"))) {
    34. Player player = (Player) sender;
    35. if (args.length == 0) {
    36. player.sendMessage(this.tronHeader + ChatColor.BLUE + " Not enough arguements! Do /tron help for help!");
    37. }
    38. this.tronCommands.commands(sender, cmd, args);
    39. return true;
    40. }
    41. return true;
    42. }
    43. }
    44.  



    Command Manager Class (TronCommands):
    Show Spoiler

    Code:java
    1. package me.ianespana.Tron;
    2.  
    3. import org.bukkit.ChatColor;
    4. import org.bukkit.command.Command;
    5. import org.bukkit.command.CommandSender;
    6. import org.bukkit.entity.Player;
    7.  
    8. public class TronCommands {
    9.  
    10. String tronHeader = ChatColor.WHITE + "[" + ChatColor.BLUE + "TRON" + ChatColor.WHITE + "]";
    11.  
    12. private GameManager gameManager = new GameManager(null);
    13.  
    14. public void commands(CommandSender sender, Command cmd, String[] args){
    15. Player player = (Player) sender;
    16. if ((args.length >= 1) && (args.length <= 2)){
    17. //Help command, displays the text below
    18. if (args[0].equalsIgnoreCase("help")){
    19. player.sendMessage(ChatColor.GRAY + "==" + tronHeader + ChatColor.GRAY + "==");
    20. player.sendMessage(ChatColor.GRAY + "Welcome to the offical Tron help guide!");
    21. player.sendMessage(ChatColor.GRAY + "==" + ChatColor.BLUE + "Commands" + ChatColor.GRAY + "==");
    22. player.sendMessage(ChatColor.GRAY + "/tron join - Joins a game.");
    23. player.sendMessage(ChatColor.GRAY + "/tron leave - Leaves the game.");
    24. player.sendMessage(ChatColor.GRAY + "/tron howtoplay - Shows you how to play.");
    25. if (player.hasPermission("tron.admin")){
    26. player.sendMessage(ChatColor.GRAY + "==" + ChatColor.BLUE + "Admin Commands" + ChatColor.GRAY + "==");
    27. player.sendMessage(ChatColor.GRAY + "/tron setspawn blue - Sets the spawnpoint for the blue team.");
    28. player.sendMessage(ChatColor.GRAY + "/tron setspawn red - Sets the spawnpoint for the red team.");
    29. player.sendMessage(ChatColor.GRAY + "/tron setspawn lobby - Sets the spawnpoint for the lobby.");
    30. }
    31. }
    32. //Join command, jumps to GameManager.java
    33. else if (args[0].equalsIgnoreCase("join")){
    34. this.gameManager.join(sender, cmd, args);
    35. }
    36. //Leave command, jumps to GameManager.java
    37. else if (args[0].equalsIgnoreCase("leave")){
    38. this.gameManager.leave(sender, cmd, args);
    39. }
    40. //HowToPlay command, displays the text below
    41. else if (args[0].equalsIgnoreCase("howtoplay")){
    42. player.sendMessage(ChatColor.GRAY + "==" + ChatColor.BLUE + "How to Play" + ChatColor.GRAY + "==");
    43. player.sendMessage(ChatColor.GRAY + "The goal of the game is to kill the enemy team by making them run into your path of light (or blocks). When the enemy team runs into your path of light, they will die. But beware! If you run into your own path or a friend's path of light, you'll die!");
    44. }
    45. //SetSpawn command, jumps to GameManager.java
    46. else if (args[0].equalsIgnoreCase("setspawn")){
    47. if (player.hasPermission("tron.admin")){
    48. this.gameManager.setSpawn(sender, cmd, args);
    49. }
    50. else if (!player.hasPermission("tron.admin")) {
    51. player.sendMessage("You do not have permission to set spawn points.");
    52. }
    53. }
    54. //When the command is unknown, it displays this
    55. else {
    56. player.sendMessage("Unkown command, please say /tron help.");
    57. }
    58. }
    59. //When too many arguments are given, it displays this
    60. else if (args.length > 2){
    61. player.sendMessage("Too many arguments!");
    62. }
    63. }
    64. }
    65.  



    Game Manager class (GameManager):
    Show Spoiler

    Code:java
    1. package me.ianespana.Tron;
    2.  
    3. import java.util.ArrayList;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Location;
    8. import org.bukkit.Material;
    9. import org.bukkit.World;
    10. import org.bukkit.block.Block;
    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.entity.PlayerDeathEvent;
    17. import org.bukkit.event.player.PlayerMoveEvent;
    18.  
    19. public class GameManager implements Listener {
    20.  
    21. public Tron plugin;
    22. public GameManager(Tron tron) {
    23. plugin = tron;
    24. }
    25.  
    26. String tronHeader = ChatColor.WHITE + "[" + ChatColor.BLUE + "TRON" + ChatColor.WHITE + "]";
    27.  
    28. public boolean allowJoin = true;
    29.  
    30. public ArrayList<Location> blocksChanged = new ArrayList<Location>();
    31. public ArrayList<String> gamePlayerList = new ArrayList<String>();
    32. public ArrayList<String> red = new ArrayList<String>();
    33. public ArrayList<String> blue = new ArrayList<String>();
    34.  
    35. //Happens when the player issues the /tron join command
    36. public void join(CommandSender sender, Command cmd, String[] args) {
    37. Player player = (Player) sender;
    38. if (!this.allowJoin) {
    39. player.sendMessage(ChatColor.RED + "The game has already started!");
    40. } else {
    41. if (!this.gamePlayerList.contains(player.getName())) {
    42. this.gamePlayerList.add(player.getName());
    43. player.sendMessage(ChatColor.BLUE + "You have been added to the game!");
    44.  
    45. World lobbyWorld = plugin.getServer().getWorld(plugin.getConfig().getString("lobbySpawn.World"));
    46. double xLobby = plugin.getConfig().getDouble("lobbySpawn.X");
    47. double yLobby = plugin.getConfig().getDouble("lobbySpawn.Y");
    48. double zLobby = plugin.getConfig().getDouble("lobbySpawn.Z");
    49. float lobbyPitch = plugin.getConfig().getInt("lobbySpawn.Pitch");
    50. float lobbyYaw = plugin.getConfig().getInt("lobbySpawn.Yaw");
    51.  
    52. Location lobby = new Location(lobbyWorld, xLobby, yLobby, zLobby, lobbyPitch, lobbyYaw);
    53.  
    54. player.teleport(lobby);
    55. int average = (int) Math.ceil(1.0D * gamePlayerList.size() / 2.0D);
    56.  
    57. if (this.blue.size() < average) {
    58. if (!this.blue.contains(player.getName()) && !this.red.contains(player.getName())) {
    59. this.blue.add(player.getName());
    60. player.sendMessage("You have been added to the " + ChatColor.BLUE + "blue" + ChatColor.WHITE + " team!");
    61. }
    62. } else if (this.red.size() < average) {
    63. if (!this.blue.contains(player.getName()) && !this.red.contains(player.getName())) {
    64. this.red.add(player.getName());
    65. player.sendMessage("You have been added to the " + ChatColor.RED + "red" + ChatColor.WHITE + " team!");
    66. }
    67. }
    68. } else {
    69. player.sendMessage("You are already a part of Tron!");
    70. }
    71. }
    72. }
    73.  
    74. //Happens when the player issues the /tron leave command
    75. public void leave(CommandSender sender, Command cmd, String[] args) {
    76. Player player = (Player) sender;
    77. if (this.gamePlayerList.contains(player.getName())) {
    78. player.sendMessage(ChatColor.RED + "You have left the game!");
    79. this.gamePlayerList.remove(player.getName());
    80. this.blue.remove(player.getName());
    81. this.red.remove(player.getName());
    82. } else {
    83. player.sendMessage(ChatColor.RED + "You are not in a game of Tron!");
    84. }
    85. }
    86.  
    87. //Runs the pre-game timer, which teleports players inside the arena
    88. public void gameTimer() {
    89. this.allowJoin = true;
    90. Bukkit.broadcastMessage(this.tronHeader + ChatColor.BLUE + " is now starting! Do /tron join to join the game!");
    91.  
    92. if (gamePlayerList.size() >= 2) {
    93. this.plugin.getServer().getScheduler().scheduleSyncDelayedTask(this.plugin, new Runnable() {
    94. public void run() {
    95. World worldBlue = GameManager.this.plugin.getServer().getWorld(GameManager.this.plugin.getConfig().getString("blueSpawn.World"));
    96. double xBlue = GameManager.this.plugin.getConfig().getDouble("blueSpawn.X");
    97. double yBlue = GameManager.this.plugin.getConfig().getDouble("blueSpawn.Y");
    98. double zBlue = GameManager.this.plugin.getConfig().getDouble("blueSpawn.Z");
    99. float bluePitch = GameManager.this.plugin.getConfig().getInt("blueSpawn.Pitch");
    100. float blueYaw = GameManager.this.plugin.getConfig().getInt("blueSpawn.Yaw");
    101.  
    102. World worldRed = GameManager.this.plugin.getServer().getWorld(GameManager.this.plugin.getConfig().getString("redSpawn.World"));
    103. double xRed = GameManager.this.plugin.getConfig().getDouble("redSpawn.X");
    104. double yRed = GameManager.this.plugin.getConfig().getDouble("redSpawn.Y");
    105. double zRed = GameManager.this.plugin.getConfig().getDouble("redSpawn.Z");
    106. float redPitch = GameManager.this.plugin.getConfig().getInt("redSpawn.Pitch");
    107. float redYaw = GameManager.this.plugin.getConfig().getInt("redSpawn.Yaw");
    108.  
    109. Location blueSpawn = new Location(worldBlue, xBlue, yBlue, zBlue, blueYaw, bluePitch);
    110. Location redSpawn = new Location(worldRed, xRed, yRed, zRed, redYaw, redPitch);
    111.  
    112. for (String player : GameManager.this.blue) {
    113. Bukkit.getPlayer(player).teleport(blueSpawn);
    114. }
    115. for (String player : GameManager.this.red) {
    116. Bukkit.getPlayer(player).teleport(redSpawn);
    117. }
    118. GameManager.this.allowJoin = false;
    119. }
    120. }, this.plugin.getConfig().getLong("Game_Begin_Time") * 20L);
    121. }
    122. }
    123.  
    124. //Happens when the player issues the /tron setspawn command
    125. public void setSpawn(CommandSender sender, Command cmd, String[] args) {
    126. Player player = (Player) sender;
    127. Location loc = player.getLocation();
    128. if (args[1].equalsIgnoreCase("blue")) {
    129. plugin.getConfig().set("blueSpawn.World", loc.getWorld().getName());
    130. plugin.getConfig().set("blueSpawn.X", Double.valueOf(loc.getX()));
    131. plugin.getConfig().set("blueSpawn.Y", Double.valueOf(loc.getY()));
    132. plugin.getConfig().set("blueSpawn.Z", Double.valueOf(loc.getZ()));
    133. plugin.getConfig().set("blueSpawn.Yaw", Float.valueOf(loc.getYaw()));
    134. plugin.getConfig().set("blueSpawn.Pitch", Float.valueOf(loc.getPitch()));
    135. plugin.saveConfig();
    136. player.sendMessage("You have set the blue spawn!");
    137. } else if (args[1].equalsIgnoreCase("red")) {
    138. plugin.getConfig().set("redSpawn.World", loc.getWorld().getName());
    139. plugin.getConfig().set("redSpawn.X", Double.valueOf(loc.getX()));
    140. plugin.getConfig().set("redSpawn.Y", Double.valueOf(loc.getY()));
    141. plugin.getConfig().set("redSpawn.Z", Double.valueOf(loc.getZ()));
    142. plugin.getConfig().set("redSpawn.Yaw", Float.valueOf(loc.getYaw()));
    143. plugin.getConfig().set("redSpawn.Pitch", Float.valueOf(loc.getPitch()));
    144. plugin.saveConfig();
    145. player.sendMessage("You have set the red spawn!");
    146. } else if (args[1].equalsIgnoreCase("lobby")) {
    147. plugin.getConfig().set("lobbySpawn.World", loc.getWorld().getName());
    148. plugin.getConfig().set("lobbySpawn.X", Double.valueOf(loc.getX()));
    149. plugin.getConfig().set("lobbySpawn.Y", Double.valueOf(loc.getY()));
    150. plugin.getConfig().set("lobbySpawn.Z", Double.valueOf(loc.getZ()));
    151. plugin.getConfig().set("lobbySpawn.Yaw", Float.valueOf(loc.getYaw()));
    152. plugin.getConfig().set("lobbySpawn.Pitch", Float.valueOf(loc.getPitch()));
    153. plugin.saveConfig();
    154. player.sendMessage("You have set the lobby spawn!");
    155. } else if (!args[1].equalsIgnoreCase("blue") || !args[1].equalsIgnoreCase("red") || !args[1].equalsIgnoreCase("lobby")) {
    156. player.sendMessage("Unknown argument, please say /tron help");
    157. } else {
    158. player.sendMessage("Unkown command, please say /tron help.");
    159. }
    160. }
    161.  
    162. //Leaves the blue block trail behind the player
    163. @EventHandler
    164. public void setWoolEffectBlue(PlayerMoveEvent event) {
    165. Player player = event.getPlayer();
    166. Location loc = player.getLocation();
    167. if (this.blue.contains(player.getName())) {
    168. loc.setY(loc.getY() - 1.0D);
    169. loc.setX(loc.getX() - 1.0D);
    170. Block block = loc.getBlock();
    171. if (block.getType() == Material.OBSIDIAN) {
    172. block.setType(Material.DIAMOND_BLOCK);
    173. Location location = block.getLocation();
    174. if (!this.blocksChanged.contains(location)) {
    175. this.blocksChanged.add(location);
    176. }
    177. }
    178. }
    179. }
    180.  
    181. //Leaves the red block trail behind the player
    182. @EventHandler
    183. public void setWoolEffectRed(PlayerMoveEvent event) {
    184. Player player = event.getPlayer();
    185. Location loc = player.getLocation();
    186. if (this.red.contains(player.getName())) {
    187. loc.setY(loc.getY() - 1.0D);
    188. loc.setX(loc.getX() - 1.0D);
    189. Block block = loc.getBlock();
    190. if (block.getType() == Material.OBSIDIAN) {
    191. block.setType(Material.REDSTONE_BLOCK);
    192. Location location = block.getLocation();
    193. if (!this.blocksChanged.contains(location)) {
    194. this.blocksChanged.add(location);
    195. }
    196. }
    197. }
    198. }
    199.  
    200. //Checks if the player should die, and if so, it kills him
    201. @EventHandler
    202. public void setDeathEvent(PlayerMoveEvent event) {
    203. World lobbyWorld = plugin.getServer().getWorld(plugin.getConfig().getString("lobbySpawn.World"));
    204. double xLobby = plugin.getConfig().getDouble("lobbySpawn.X");
    205. double yLobby = plugin.getConfig().getDouble("lobbySpawn.Y");
    206. double zLobby = plugin.getConfig().getDouble("lobbySpawn.Z");
    207. float lobbyPitch = plugin.getConfig().getInt("lobbySpawn.Pitch");
    208. float lobbyYaw = plugin.getConfig().getInt("lobbySpawn.Yaw");
    209.  
    210. Location lobby = new Location(lobbyWorld, xLobby, yLobby, zLobby, lobbyPitch, lobbyYaw);
    211.  
    212. Player player = event.getPlayer();
    213. Location loc = player.getLocation();
    214. if (this.blue.contains(player.getName()) || this.red.contains(player.getName())) {
    215. loc.setY(loc.getY() - 1.0D);
    216. Block block = loc.getBlock();
    217. if (block.getType() == Material.DIAMOND_BLOCK || block.getType() == Material.REDSTONE_BLOCK) {
    218. player.teleport(lobby);
    219. player.setHealth(0.0D);
    220. loc.getWorld().createExplosion(loc, 0.0F);
    221. }
    222. }
    223. }
    224.  
    225. //Runs when the player dies
    226. @EventHandler
    227. public void onDeathEvent(PlayerDeathEvent event) {
    228. String player = event.getEntity().getPlayer().getName();
    229. World lobbyWorld = plugin.getServer().getWorld(plugin.getConfig().getString("lobbySpawn.World"));
    230. double xLobby = plugin.getConfig().getDouble("lobbySpawn.X");
    231. double yLobby = plugin.getConfig().getDouble("lobbySpawn.Y");
    232. double zLobby = plugin.getConfig().getDouble("lobbySpawn.Z");
    233. float LobbyPitch = plugin.getConfig().getInt("lobbySpawn.Pitch");
    234. float LobbyYaw = plugin.getConfig().getInt("lobbySpawn.Yaw");
    235.  
    236. Location lobby = new Location(lobbyWorld, xLobby, yLobby, zLobby, LobbyPitch, LobbyYaw);
    237.  
    238. if ((event.getEntity() instanceof Player)) {
    239. if (this.blue.contains(player)) {
    240. this.blue.remove(player);
    241. }
    242. if (this.red.contains(player)) {
    243. this.red.remove(player);
    244. }
    245. if (this.gamePlayerList.contains(player)) {
    246. this.gamePlayerList.remove(player);
    247. }
    248.  
    249. if (this.red.size() == 0) {
    250. for (Player online : Bukkit.getOnlinePlayers()) {
    251. if (gamePlayerList.contains(online.getName())){
    252. online.sendMessage(ChatColor.BLUE + "Blue has won this game of Tron!");
    253. online.teleport(lobby);
    254. }
    255. }
    256. for (Location loc : this.blocksChanged) {
    257. loc.getBlock().setType(Material.OBSIDIAN);
    258. }
    259. this.blue.clear();
    260. this.red.clear();
    261. this.gamePlayerList.clear();
    262. this.blocksChanged.clear();
    263. this.gameTimer();
    264. }
    265. if (this.blue.size() == 0) {
    266. for (Player online : Bukkit.getOnlinePlayers()) {
    267. if (gamePlayerList.contains(online.getName())){
    268. online.sendMessage(ChatColor.RED + "Red has won this game of Tron!");
    269. online.teleport(lobby);
    270. }
    271. }
    272. for (Location loc : this.blocksChanged) {
    273. loc.getBlock().setType(Material.OBSIDIAN);
    274. }
    275. this.blue.clear();
    276. this.red.clear();
    277. this.gamePlayerList.clear();
    278. this.blocksChanged.clear();
    279. this.gameTimer();
    280. }
    281. }
    282. }
    283. }
    284.  



    Config.yml
    Show Spoiler

    Code:
    Game_Begin_Time: 10
     
    blueSpawn.World: world
    blueSpawn.X: 2
    blueSpawn.Y: 2
    blueSpawn.Yaw: 2
    blueSpawn.Pitch: 2
     
    redSpawn.World: world
    redSpawn.X: 2
    redSpawn.Y: 2
    redSpawn.Yaw: 2
    redSpawn.Pitch: 2
     
    lobbySpawn.World: world
    lobbySpawn.X: 2
    lobbySpawn.Y: 2
    lobbySpawn.Yaw: 2
    lobbySpawn.Pitch: 2



    Thanks to whoever is kind enough to try to help me.

    ~ Heracles
     
  2. Offline

    Chinwe

    If you save something to a .yml with the path "bluSpawn.X" (using getConfig().set("bluSpawn.X", location.getBlockX()) for example), it will actually be saved like this:
    Code:
    bluSpawn:
      X: <value>
    So try saving your config like this instead:
    Code:
    blueSpawn:
      World: world
      X: 2
      Y: 2
      Yaw: 2
      Pitch: 2
     
      // etc
     
  3. Offline

    Heracles421


    I tried to do this, but even after changing the config I still get the same error.
    New Config:
    Code:
    beginTime: 30
     
    blueSpawn:
      World: world
      X: 2
      Y: 2
      Yaw: 2
      Pitch: 2
     
    redSpawn:
      World: world
      X: 2
      Y: 2
      Yaw: 2
      Pitch: 2
     
    lobbySpawn:
      World: world
      X: 2
      Y: 2
      Yaw: 2
      Pitch: 2
     
  4. Offline

    Chinwe

    Hmm, the possible causes of this NPE (looking at line 47 double yLobby = plugin.getConfig().getDouble("lobbySpawn.Y");) would be either plugin == null, plugin.getConfig() == null/the file isn't found, or the value isn't found in the config (which would throw the NPE from the Location constructor). Could you try printing to console the values of various variables such as plugin, plugin.getConfig() and each of the values/coords you get from the config, to see if any of them are null?
     
  5. Offline

    Heracles421

    Chinwe Ok, I did this, and for my surprise the problem is with plugin, it is null. That's why everything I try to get using plugin is returning NPE errors.
    But now, I have no idea how to fix it, because I'm already giving plugin a value that somehow is returning null.

    Code:java
    1. public Tron plugin;
    2. public GameManager(Tron tron) {
    3. plugin = tron;
    4. }
     
  6. Offline

    jimuskin

    Heracles421
    Change
    Code:java
    1. public Tron plugin;
    2. public GameManager(Tron tron) {
    3. plugin = tron;
    4. }


    to
    Code:java
    1. public Tron plugin;
    2. public GameManager(Tron tron) {
    3. this.plugin = tron;
    4. }
     
  7. Offline

    Heracles421


    Thanks!
    This and changing the commands class made the trick!
     
Thread Status:
Not open for further replies.

Share This Page