else if in the wrong spot?

Discussion in 'Plugin Development' started by ThePluginMaker, Aug 3, 2014.

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

    ThePluginMaker

    Code:
    Code:java
    1. @Override
    2. public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
    3. Player player = null;
    4. if (sender instanceof Player) {
    5. player = (Player) sender;
    6. }
    7. if (command.getName().equalsIgnoreCase("ffa")) {
    8. if (player != null) {
    9. if (args.length >= 1) {
    10. if (args.length > 1){
    11. String arenaname = args[1];
    12.  
    13. if (args[0].equalsIgnoreCase("define") && player.hasPermission(command.getPermission() + ".define")) {
    14. BlockVector p1 = Selection.getP1();
    15. BlockVector p2 = Selection.getP2();
    16. if (p1 != null && p2 != null) {
    17. ffaconfig.setRegion(arenaname, player.getWorld(), p1, p2);
    18. arenas.put(arenaname, new Arena(ffaconfig.getRegion(args[1]), null));
    19. sender.sendMessage(prefix + "Region has been defined.");
    20. return true;
    21. } else {
    22. sender.sendMessage(prefix + "You need to select both points");
    23. return true;
    24. }
    25. }
    26. else if (!arenas.containsKey(arenaname)){
    27. sender.sendMessage(ChatColor.DARK_BLUE + "Arena not found!");
    28. return true;
    29. }
    30.  
    31. if (args.length > 1) {
    32. if (args[0].equalsIgnoreCase("setspawn") && player.hasPermission(command.getPermission() + ".setspawn")) {
    33. ffaconfig.setSpawn(arenaname, args[2], player.getLocation());
    34. sender.sendMessage(prefix + "spawn " + args[2] + " has been set in arena " + arenaname + ".");
    35. return true;
    36. }
    37. if (args[0].equalsIgnoreCase("removespawn") && player.hasPermission(command.getPermission() + ".removespawn")) {
    38. if (ffaconfig.removeSpawn(arenaname, args[2])) {
    39. sender.sendMessage(prefix + "Spawn " + args[2] + " has been removed from arena " + arenaname + ".");
    40. return true;
    41. }
    42. sender.sendMessage(prefix + "Unable to find spawn " + args[2]);
    43. return true;
    44. }
    45.  
    46. sender.sendMessage(prefix + "incorrect number of args.");
    47. sender.sendMessage(prefix + "/ffa setspawn/removespawn [arena] [name]");
    48. return true;
    49. }
    50.  
    51. if (args[0].equalsIgnoreCase("healregion") && player.hasPermission(command.getPermission() + ".healregion")) {
    52. BlockVector p1 = Selection.getP1();
    53. BlockVector p2 = Selection.getP2();
    54. if (p1 != null && p2 != null) {
    55. ffaconfig.setHealRegion(arenaname, player.getWorld(), p1, p2);
    56. registerHealRegion(arenaname, ffaconfig.getHealRegion(arenaname));
    57. arenas.get(arenaname).setRegion(ffaconfig.getRegion(arenaname));
    58. sender.sendMessage(prefix + "Heal region has been defined.");
    59. return true;
    60. } else {
    61. sender.sendMessage(prefix + "You need to select both points");
    62. return true;
    63. }
    64. } else if (args[0].equalsIgnoreCase("spawns") && player.hasPermission(command.getPermission() + ".spawns")) {
    65. sender.sendMessage(ChatColor.DARK_AQUA + " Spawns from arena " + arenaname + ": " + ChatColor.BLUE + Arrays.toString(ffaconfig.getSpawnNames(arenaname).toArray()).replace("[", "").replace("]", ""));
    66. return true;
    67. }
    68.  
    69. return false;
    70. } else if (args[0].equalsIgnoreCase("reload") && player.hasPermission(command.getPermission() + ".reload")) {
    71. config = YamlConfiguration.loadConfiguration(cfile);
    72. reloadConfig();
    73. ffaconfig.load();
    74. loadArenas();
    75. sender.sendMessage(ChatColor.DARK_AQUA + "[FreeForAll]" + ChatColor.BLUE + " config reloaded.");
    76. return true;
    77. } else if (args[0].equalsIgnoreCase("shutdown") && player.hasPermission(command.getPermission() + ".shutdown")) {
    78. getServer().getPluginManager().disablePlugin(this);
    79. sender.sendMessage(prefix + "has been shut down.");
    80. return true;
    81. } else if (args[0].equalsIgnoreCase("version")) {
    82. sender.sendMessage(ChatColor.DARK_AQUA + "Name: " + ChatColor.BLUE + this.getDescription().getName());
    83. sender.sendMessage(ChatColor.DARK_AQUA + "Description: " + ChatColor.BLUE + this.getDescription().getDescription());
    84. if (this.getDescription().getVersion().contains("EB")) {
    85. sender.sendMessage(ChatColor.DARK_AQUA + "Version: " + ChatColor.BLUE + this.getDescription().getVersion() + ChatColor.DARK_AQUA + " (" + ChatColor.DARK_BLUE + "Experimental" + ChatColor.DARK_AQUA + ")");
    86. } else {
    87. sender.sendMessage(ChatColor.DARK_AQUA + "Version: " + ChatColor.BLUE + this.getDescription().getVersion());
    88. }
    89. sender.sendMessage(ChatColor.DARK_AQUA + "Author: " + ChatColor.BLUE + Arrays.toString(this.getDescription().getAuthors().toArray()).replace("[", "").replace("]", ""));
    90.  
    91. return true;
    92. } else if (args[0].equalsIgnoreCase("debug")) {
    93. if (this.isDebugMode) {
    94. this.isDebugMode = false;
    95. sender.sendMessage(prefix + "Debug mode disabled.");
    96. } else {
    97. this.isDebugMode = true;
    98. sender.sendMessage(prefix + "Debug mode enabled.");
    99. }
    100. return true;
    101. } else if (args[0].equalsIgnoreCase("list")){
    102. sender.sendMessage(prefix + "Arenas: " + Arrays.toString(arenas.keySet().toArray()).replace("[", "").replace("]", ""));
    103. return true;
    104. } else if (arenas.containsKey(args[0].toLowerCase())){
    105. final Player fp = player;
    106.  
    107. if (isInArena(fp)){
    108. sender.sendMessage(prefix + "You are already in an arena!");
    109. return true;
    110. } else if (!hasSpawns(args[0])){
    111. sender.sendMessage(prefix + "Arena " + args[0].toLowerCase() + " does not have any spawnpoints defined!");
    112. sender.sendMessage(prefix + "Arenas: " + Arrays.toString(arenas.keySet().toArray()).replace("[", "").replace("]", ""));
    113. return true;
    114. }
    115.  
    116.  
    117. if(isInTeleportQueue(fp)){
    118. removePlayerFromTeleportQueue(fp);
    119. }
    120.  
    121. addPlayerToTeleportQueue(args[0].toLowerCase(), fp);
    122. sender.sendMessage(prefix + "Teleporting to the " + args[0].toLowerCase() + " arena. Please wait 5 seconds.");
    123. return true;
    124.  
    125. } else if (args[0].equalsIgnoreCase("top") && player.hasPermission(command.getPermission() + ".top")) {
    126. String dispFormat = ChatColor.BLUE + "{0}: " + ChatColor.BLUE + "{1}" + ChatColor.DARK_AQUA + " ---- " + ChatColor.BLUE + " {2}";
    127. String titleFormat = (ChatColor.DARK_AQUA + "---------==[" + ChatColor.BLUE + "FFA Top {0}" + ChatColor.DARK_AQUA + "]==---------");
    128. String bottomFormat = ChatColor.DARK_AQUA + "-----------==[" + ChatColor.BLUE + "FreeForAll" + ChatColor.DARK_AQUA + "]==-----------";
    129. int count = 1;
    130. if (args.length == 2) {
    131. if (args[1].equalsIgnoreCase("kills")) {
    132. player.sendMessage(titleFormat.replace("{0}", "Kills"));
    133. ArrayList<String> top_Kills = DB.getTopKills();
    134. for (String name : top_Kills) {
    135. int player_id = DB.getPlayerId(name);
    136. int kill_count = DB.getKillCount(player_id);
    137. player.sendMessage(dispFormat.replace("{0}", "" + count).replace("{2}", name).replace("{1}", "" + kill_count));
    138. count++;
    139. }
    140. player.sendMessage(bottomFormat);
    141. }
    142. if (args[1].equalsIgnoreCase("streak")) {
    143. player.sendMessage(titleFormat.replace("{0}", "KillStreak"));
    144. ArrayList<String> top_Streaks = DB.getTopStreak();
    145. for (String name : top_Streaks) {
    146. int player_id = DB.getPlayerId(name);
    147. int kill_streak = DB.getKillStreak(player_id);
    148. player.sendMessage(dispFormat.replace("{0}", "" + count).replace("{2}", name).replace("{1}", "" + kill_streak));
    149. count++;
    150. }
    151. player.sendMessage(bottomFormat);
    152. }
    153. }
    154. if (args.length == 1) {
    155. player.sendMessage(titleFormat.replace("{0}", "Kills"));
    156. ArrayList<String> top_Kills = DB.getTopKills();
    157. for (String name : top_Kills) {
    158. int player_id = DB.getPlayerId(name);
    159. int kill_count = DB.getKillCount(player_id);
    160. player.sendMessage(dispFormat.replace("{0}", "" + count).replace("{2}", name).replace("{1}", "" + kill_count));
    161. count++;
    162. }
    163. player.sendMessage(bottomFormat);
    164. }
    165. if (args.length > 2) {
    166. player.sendMessage(prefix + "Invalid number of arguements.");
    167. player.sendMessage(prefix + "/ffa top <kills;streak>");
    168. }
    169. return true;
    170. } else if (args[0].equalsIgnoreCase("stats")) {
    171. String titleFormat = (ChatColor.DARK_AQUA + "---------==[" + ChatColor.BLUE + "{0}'s Stats" + ChatColor.DARK_AQUA + "]==---------");
    172. String dispFormat = ChatColor.BLUE + "{0} " + ChatColor.DARK_AQUA + ":" + ChatColor.BLUE + " {1}";
    173. String bottomFormat = ChatColor.DARK_AQUA + "-----------==[" + ChatColor.BLUE + "FreeForAll" + ChatColor.DARK_AQUA + "]==-----------";
    174. if (args.length == 2) {
    175. int player_id = DB.getPlayerId(args[1]);
    176. if (player_id != 0) {
    177. double kills = DB.getKillCount(player_id);
    178. int killstreak = DB.getKillStreak(player_id);
    179. double deaths = DB.getDeathCount(player_id);
    180. double kdr = 0;
    181. if (deaths > 0) {
    182. kdr = roundTwoDecimals(kills / deaths);
    183. }
    184. player.sendMessage(titleFormat.replace("{0}", args[1]));
    185. player.sendMessage(dispFormat.replace("{0}", "Kills").replace("{1}", "" + kills));
    186. player.sendMessage(dispFormat.replace("{0}", "Streak").replace("{1}", "" + killstreak));
    187. player.sendMessage(dispFormat.replace("{0}", "Deaths").replace("{1}", "" + deaths));
    188. player.sendMessage(dispFormat.replace("{0}", "K/D Ratio").replace("{1}", "" + kdr));
    189. player.sendMessage(bottomFormat);
    190. } else {
    191. player.sendMessage(ChatColor.DARK_AQUA + "[FreeForAll]" + ChatColor.BLUE + " Unable to find player.");
    192. }
    193. } else if (args.length == 1) {
    194. int player_id = DB.getPlayerId(player.getName());
    195. double kills = DB.getKillCount(player_id);
    196. int killstreak = DB.getKillStreak(player_id);
    197. double deaths = DB.getDeathCount(player_id);
    198. double kdr = 0;
    199. if (deaths > 0) {
    200. kdr = roundTwoDecimals(kills / deaths);
    201. }
    202. player.sendMessage(titleFormat.replace("{0}", player.getName()));
    203. player.sendMessage(dispFormat.replace("{0}", "Kills").replace("{1}", "" + kills));
    204. player.sendMessage(dispFormat.replace("{0}", "Streak").replace("{1}", "" + killstreak));
    205. player.sendMessage(dispFormat.replace("{0}", "Deaths").replace("{1}", "" + deaths));
    206. player.sendMessage(dispFormat.replace("{0}", "K/D Ratio").replace("{1}", "" + kdr));
    207. player.sendMessage(bottomFormat);
    208. }
    209. return true;
    210. }
    211. } else {
    212. World w = player.getWorld();
    213. player.openInventory(getArenasInventory(player));
    214. w.playSound(player.getLocation(), Sound.LEVEL_UP, 100, 1);
    215. }
    216. } else {
    217. sender.sendMessage("[FreeForAll] requires a player.");
    218. return true;
    219. }
    220. }
    221. sender.sendMessage(ChatColor.DARK_AQUA+ "------------------==[" + ChatColor.BLUE + "FreeForAll " + ChatColor.DARK_AQUA + "]==------------------");
    222. sender.sendMessage(ChatColor.DARK_AQUA + " Download FFA [URL]http://dev.bukkit.org/bukkit-plugins/ffa-free-all/[/URL] ");
    223. sender.sendMessage("");
    224. sender.sendMessage(ChatColor.DARK_AQUA + " Bionicangel1098 coded this plugin for FearPvP.net! ");
    225. sender.sendMessage(ChatColor.DARK_AQUA + "-------------------==[" + ChatColor.BLUE + "FreeForAll" + ChatColor.DARK_AQUA + "]==------------------");
    226. return true;
    227. }

    If you see at the top of my code where it says arena not found, that will display if i type /ffa stats [player] it'll say Around not found!, as you can see at the top of the code i have an else if for that but i guess it's in the wrong spot. Any ideas?

    Addon: If i type anything for example /ffa lelasfa lasdha (as long as there's 2 args just like creating the arena but not using the /ffa create command, i would like it so say the ffa message like where it says it's made for fear coded by bionicangel1098 because it says that if i type anything that's not a command with only 1 arg.

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

    hugokk

    Your else and if statements are totally screwed up, Try making it more simple, like this: (Pseudo-code)
    Code:java
    1. if(args.length=0)
    2. sendmessage not enough args / credits
    3. else if(args.length>=1)
    4. if(args1==option1)
    5. if(args.length==1)
    6. sendmessage not enough args
    7. else if(args.length>=2)
    8. sendmessage succes
    9. handle option1 with 1 argument
    10. else if(args1==option2)
    11. sendmessage succes
    12. handle option2 with no arguments
    13. return true
     
Thread Status:
Not open for further replies.

Share This Page