Config.yml

Discussion in 'Plugin Development' started by bodhistrontg, Dec 25, 2013.

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

    bodhistrontg

    Merry Christmas! So It is not logging anything when i type the commands
    Code:java
    1.  
    2. int playerCheck = 1;
    3. public void onEnable(){
    4. getLogger().info("Plugin has been Enabled");
    5. Bukkit.getPluginManager().registerEvents(this, this);
    6. Bukkit.getPluginCommand("setPlayer1Map1").setExecutor(new Main());
    7. Bukkit.getPluginCommand("setPlayer2Map1").setExecutor(new Main());
    8. Bukkit.getPluginCommand("setPlayer3Map1").setExecutor(new Main());
    9. Bukkit.getPluginCommand("setPlayer4Map1").setExecutor(new Main());
    10. Bukkit.getPluginCommand("setPlayer5Map1").setExecutor(new Main());
    11. Bukkit.getPluginCommand("setPlayer6Map1").setExecutor(new Main());
    12. Bukkit.getPluginCommand("setPlayer7Map1").setExecutor(new Main());
    13. Bukkit.getPluginCommand("setPlayer8Map1").setExecutor(new Main());
    14. saveConfig();
    15. }
    16. public void onDisable(){
    17. getLogger().info("Plugin has been Disabled!");
    18. saveConfig();
    19. }
    20. public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
    21. if (cmd.getName().equalsIgnoreCase("setPlayer1Map1")) {
    22. if(sender instanceof Player){
    23. Player p = (Player) sender;
    24. getConfig().set("Map1" + ".Player1" + ".x", p.getLocation().getBlockX());
    25. getConfig().set("Map1" + ".Player1" + ".y", p.getLocation().getBlockY());
    26. getConfig().set("Map1" + ".Player1" + ".z", p.getLocation().getBlockZ());
    27. saveConfig();
    28. }else if(cmd.getName().equalsIgnoreCase("setPlayer2Map1")){
    29. if(sender instanceof Player){
    30. Player p = (Player) sender;
    31. p.sendMessage("worked");
    32. getConfig().set("Map1" + ".Player2" + ".x", p.getLocation().getBlockX());
    33. getConfig().set("Map1" + ".Player2" + ".y", p.getLocation().getBlockY());
    34. getConfig().set("Map1" + ".Player2" + ".z", p.getLocation().getBlockZ());
    35. saveConfig();
    36. }
    37. }else if(cmd.getName().equalsIgnoreCase("setPlayer3Map1")){
    38. if(sender instanceof Player){
    39. Player p = (Player) sender;
    40. getConfig().set("Map1" + ".Player3" + ".x", p.getLocation().getBlockX());
    41. getConfig().set("Map1" + ".Player3" + ".y", p.getLocation().getBlockY());
    42. getConfig().set("Map1" + ".Player3" + ".z", p.getLocation().getBlockZ());
    43. saveConfig();
    44. }
    45. }else if(cmd.getName().equalsIgnoreCase("setPlayer4Map1")){
    46. if(sender instanceof Player){
    47. Player p = (Player) sender;
    48. getConfig().set("Map1" + ".Player4" + ".x", p.getLocation().getBlockX());
    49. getConfig().set("Map1" + ".Player4" + ".y", p.getLocation().getBlockY());
    50. getConfig().set("Map1" + ".Player4" + ".z", p.getLocation().getBlockZ());
    51. saveConfig();
    52. }
    53. }else if(cmd.getName().equalsIgnoreCase("setPlayer5Map1")){
    54. if(sender instanceof Player){
    55. Player p = (Player) sender;
    56. getConfig().set("Map1" + ".Player5" + ".x", p.getLocation().getBlockX());
    57. getConfig().set("Map1" + ".Player5" + ".y", p.getLocation().getBlockY());
    58. getConfig().set("Map1" + ".Player5" + ".z", p.getLocation().getBlockZ());
    59. saveConfig();
    60. }
    61. }else if(cmd.getName().equalsIgnoreCase("setPlayer6Map1")){
    62. if(sender instanceof Player){
    63. Player p = (Player) sender;
    64. getConfig().set("Map1" + ".Player6" + ".x", p.getLocation().getBlockX());
    65. getConfig().set("Map1" + ".Player6" + ".y", p.getLocation().getBlockY());
    66. getConfig().set("Map1" + ".Player6" + ".z", p.getLocation().getBlockZ());
    67. saveConfig();
    68. }
    69. }else if(cmd.getName().equalsIgnoreCase("setPlayer7Map1")){
    70. if(sender instanceof Player){
    71. Player p = (Player) sender;
    72. getConfig().set("Map1" + ".Player7" + ".x", p.getLocation().getBlockX());
    73. getConfig().set("Map1" + ".Player7" + ".y", p.getLocation().getBlockY());
    74. getConfig().set("Map1" + ".Player7" + ".z", p.getLocation().getBlockZ());
    75. saveConfig();
    76. }
    77. }else if(cmd.getName().equalsIgnoreCase("setPlayer8Map1")){
    78. if(sender instanceof Player){
    79. Player p = (Player) sender;
    80. getConfig().set("Map1" + ".Player8" + ".x", p.getLocation().getBlockX());
    81. getConfig().set("Map1" + ".Player8" + ".y", p.getLocation().getBlockY());
    82. getConfig().set("Map1" + ".Player8" + ".z", p.getLocation().getBlockZ());
    83. saveConfig();
    84. }
    85. }
    86. }
    87. return false;
    88. }
    89.  
    90. @EventHandler
    91. public void onInteract(PlayerInteractEvent e) {
    92. if(!(e.getAction() == Action.RIGHT_CLICK_BLOCK)) return;
    93. if (!(e.getClickedBlock().getState() instanceof Sign)) return;
    94. Player player = e.getPlayer();
    95. Sign s = (Sign) e.getClickedBlock().getState();
    96. if(s.getLine(0).equalsIgnoreCase("Infected") && s.getLine(1).equalsIgnoreCase("Join 1")){
    97. if(playerCheck == 1){
    98. int x = getConfig().getInt("Map1" + ".Player3" + ".x");
    99. int y = getConfig().getInt("Map1" + ".Player3" + ".y");
    100. int z = getConfig().getInt("Map1" + ".Player3" + ".z");
    101. Location player1Start = new Location(player.getWorld(), x,y,z);
    102. player.teleport(player1Start);
    103. }
    104. if(playerCheck == 2){
    105. int x = getConfig().getInt("Map1" + ".Player3" + ".x");
    106. int y = getConfig().getInt("Map1" + ".Player3" + ".y");
    107. int z = getConfig().getInt("Map1" + ".Player3" + ".z");
    108. Location player1Start = new Location(player.getWorld(), x,y,z);
    109. player.teleport(player1Start);
    110.  
    111. }
    112. if(playerCheck == 3){
    113. int x = getConfig().getInt("Map1" + ".Player3" + ".x");
    114. int y = getConfig().getInt("Map1" + ".Player3" + ".y");
    115. int z = getConfig().getInt("Map1" + ".Player3" + ".z");
    116. Location player1Start = new Location(player.getWorld(), x,y,z);
    117. player.teleport(player1Start);
    118. }
    119. if(playerCheck == 4){
    120. int x = getConfig().getInt("Map1" + ".Player4" + ".x");
    121. int y = getConfig().getInt("Map1" + ".Player4" + ".y");
    122. int z = getConfig().getInt("Map1" + ".Player4" + ".z");
    123. Location player1Start = new Location(player.getWorld(), x,y,z);
    124. player.teleport(player1Start);
    125. }
    126. if(playerCheck == 5){
    127. int x = getConfig().getInt("Map1" + ".Player5" + ".x");
    128. int y = getConfig().getInt("Map1" + ".Player5" + ".y");
    129. int z = getConfig().getInt("Map1" + ".Player5" + ".z");
    130. Location player1Start = new Location(player.getWorld(), x,y,z);
    131. player.teleport(player1Start);
    132. }
    133. if(playerCheck == 6){
    134. int x = getConfig().getInt("Map1" + ".Player6" + ".x");
    135. int y = getConfig().getInt("Map1" + ".Player6" + ".y");
    136. int z = getConfig().getInt("Map1" + ".Player6" + ".z");
    137. Location player1Start = new Location(player.getWorld(), x,y,z);
    138. player.teleport(player1Start);
    139. }
    140. if(playerCheck == 7){
    141. int x = getConfig().getInt("Map1" + ".Player7" + ".x");
    142. int y = getConfig().getInt("Map1" + ".Player7" + ".y");
    143. int z = getConfig().getInt("Map1" + ".Player7" + ".z");
    144. Location player1Start = new Location(player.getWorld(), x,y,z);
    145. player.teleport(player1Start);
    146. }
    147. if(playerCheck == 8){
    148. int x = getConfig().getInt("Map1" + ".Player8" + ".x");
    149. int y = getConfig().getInt("Map1" + ".Player8" + ".y");
    150. int z = getConfig().getInt("Map1" + ".Player8" + ".z");
    151. Location player1Start = new Location(player.getWorld(), x,y,z);
    152. player.teleport(player1Start);
    153. }
    154. if(playerCheck == 9){
    155. player.sendMessage(ChatColor.RED + "Game is full");
    156. playerCheck--;
    157. }
    158. playerCheck++;
    159. }
    160. }
    161.  

    When I type anything other than /setPlayer1Map1 it wont do anything not even say improper command type /help it will just do nothing log nothing but when i type /setPlayer1Map1 it says
    null
    org.bukkit.command.CommandException: Unhandled exception executing command 'setplayer1map1' in plugin Infected v0.1
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46)
    at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:192)
    at org.bukkit.craftbukkit.v1_6_R3.CraftServer.dispatchCommand(CraftServer.java:528)
    at net.minecraft.server.v1_6_R3.PlayerConnection.handleCommand(PlayerConnection.java:968)
    at net.minecraft.server.v1_6_R3.PlayerConnection.chat(PlayerConnection.java:886)
    at net.minecraft.server.v1_6_R3.PlayerConnection.a(PlayerConnection.java:837)
    at net.minecraft.server.v1_6_R3.Packet3Chat.handle(SourceFile:49)
    at net.minecraft.server.v1_6_R3.NetworkManager.b(NetworkManager.java:296)
    at net.minecraft.server.v1_6_R3.PlayerConnection.e(PlayerConnection.java:116)
    at net.minecraft.server.v1_6_R3.ServerConnection.b(SourceFile:37)
    at net.minecraft.server.v1_6_R3.DedicatedServerConnection.b(SourceFile:30)
    at net.minecraft.server.v1_6_R3.MinecraftServer.t(MinecraftServer.java:592)
    at net.minecraft.server.v1_6_R3.DedicatedServer.t(DedicatedServer.java:227)
    at net.minecraft.server.v1_6_R3.MinecraftServer.s(MinecraftServer.java:488)
    at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:421)
    at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    Caused by: java.lang.IllegalArgumentException: File cannot be null
    at org.apache.commons.lang.Validate.notNull(Validate.java:203)
    at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:170)
    at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:117)
    at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:111)
    at me.bodhistrontg.Infected.Main.onCommand(Main.java:40)
    at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44)
    ... 15 more
     
  2. Offline

    WhatAaCow

    You have no config.yml file
     
  3. Offline

    bodhistrontg

    Okay thanks would you know how i fix it!
     
  4. Offline

    Rocoty

    Remove all the lines where you set command executors. The main instance is always the default executor. Furthermore, if it weren't the default executor you should definitely not be creating a bunch of new instances of the Main class....jeez
     
  5. Offline

    AoH_Ruthless

    ....

    Well you can just manually add a config.yml, the same way you add a plugin.yml.
    If you do that you'll want to use saveDefaultConfig(); in your onEnable() rather than saveConfig();.
     
  6. Offline

    Rocoty

    AoH_Ruthless I do believe he actually has a config.yml in resources. Because if he hadn't, the exception would have occured in onEnable. It didn't. It occured in onCommand. The reason? Fairly simple:
    Code:java
    1. new Main();
    2. new Main();
    3. new Main();
    4. new Main();
    5. new Main();
    6. new Main();
    7. new Main();
    8. new Main();
    9. new Main();
    10. new Main();
    11. new Main();
     
    ferrybig likes this.
  7. Offline

    WhatAaCow

    like he sad, change every "new Main()" into "this". Finished
     
  8. Offline

    Rocoty

    Rather, remove all those lines. Totally unnecessary.
     
Thread Status:
Not open for further replies.

Share This Page