Solved Console error

Discussion in 'Plugin Development' started by Asgernohns, Jul 22, 2013.

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

    Asgernohns

    hello java coders

    I made this code, and one of my cmd works.
    But i made a /e help or /e ? command, and a /e list command. none of those are working i get
    an error in my console that says:
    Caused by: java.lang.ArrayIndexOutOfBoundsExpection: 1

    I think this means that i have an array problem in my code, but i can't find it.
    Hope that you guys can help me :)

    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    2.  
    3.  
    4.  
    5.  
    6. if(cmd.getName().equalsIgnoreCase("e")){
    7. if(args.length == 0){
    8. Player p = (Player) sender;
    9. p.sendMessage(ChatColor.DARK_GREEN+"Unknown command"+ChatColor.GREEN+" try /e help or /e ?");
    10. }else if(args.length == 1) {
    11. Player p = (Player) sender;
    12. Player targp = p.getServer().getPlayer(args[0]);
    13. //if statement for list of effects
    14. if(args[0].equals("list")){
    15. p.sendMessage(ChatColor.GREEN+"speed, slowness, haste,miningfatigue,strength, instanthealth, instantdamage, jumpboost"
    16. + " nausea, regeneration, resistance, fireresistance, waterbreathing, invisibility, blindness"
    17. + " nightvision, hunger, weakness, poison, wither, healthboost: "+ChatColor.WHITE+"Effects stands in effect id numerical order");
    18. }else{}
    19. //if statement for help
    20. if((args[0].equals("help") || (args[1].equals("?")))){
    21. p.sendMessage(ChatColor.GREEN+"-------"+ChatColor.DARK_GREEN+"Help"+ChatColor.GREEN+"-------"
    22. +ChatColor.AQUA + "/e list:"+ChatColor.YELLOW+" List of effect"
    23. +ChatColor.AQUA + "/e <player>:"+ChatColor.YELLOW+" Command to effect player");
    24. }else{}
    25. }else if(args.length == 2){
    26. Player p = (Player) sender;
    27. p.sendMessage(ChatColor.DARK_RED+"You need more arguments to effect player");
    28. p.sendMessage(ChatColor.DARK_RED+"Usage: /e <player> <effect id or name> <strength> <duralation in sec>");
    29. }else if(args.length == 3){
    30. Player p = (Player) sender;
    31. p.sendMessage(ChatColor.DARK_RED+"You need more arguments to effect player");
    32. p.sendMessage(ChatColor.DARK_RED+"Usage: /e <player> <effect id or name> <strength> <duralation in sec>");
    33. }else if(args.length == 4){
    34. Player p = (Player) sender;
    35. Player targp = p.getServer().getPlayer(args[0]);
    36. int time = Integer.parseInt(args[3]) * 20;
    37. int strength = Integer.parseInt(args[2]);
    38.  
    39.  
    40.  
    41.  
    42.  
    43.  
    44. //if statement for effects
    45. //SPEED or 1
    46. if((args[1].equals("speed") || (args[1].equals("1")))){
    47. p.sendMessage(ChatColor.AQUA+"Player has been effected with speed");
    48. targp.addPotionEffect(new PotionEffect(PotionEffectType.SPEED, time, strength));
    49. }
    50. //SLOWNESS or 2
    51. else if((args[1].equals("slowness") || (args[1].equals("2")))){
    52. p.sendMessage(ChatColor.AQUA+"Player has been effected with slowness");
    53. targp.addPotionEffect(new PotionEffect(PotionEffectType.SLOW, time, strength));
    54. }
    55. //HASTE or 3
    56. else if((args[1].equals("haste") || (args[1].equals("3")))){
    57. p.sendMessage(ChatColor.AQUA+"Player has been effected with haste");
    58. targp.addPotionEffect(new PotionEffect(PotionEffectType.FAST_DIGGING, time, strength));
    59. }
    60. //MININGFATIGUE or 4
    61. else if((args[1].equals("miningfatigue") || (args[1].equals("4")))){
    62. p.sendMessage(ChatColor.AQUA+"Player has been effected with mining fatigue");
    63. targp.addPotionEffect(new PotionEffect(PotionEffectType.SLOW_DIGGING, time, strength));
    64. }
    65. //STRENGTH or 5
    66. else if((args[1].equals("strength") || (args[1].equals("5")))){
    67. p.sendMessage(ChatColor.AQUA+"Player has been effected with strength");
    68. targp.addPotionEffect(new PotionEffect(PotionEffectType.INCREASE_DAMAGE, time, strength));
    69. }
    70. //INSTANTHEALTH or 6
    71. else if((args[1].equals("instanthealth") || (args[1].equals("6")))){
    72. p.sendMessage(ChatColor.AQUA+"Player has been effected with instant health");
    73. targp.addPotionEffect(new PotionEffect(PotionEffectType.HEAL, time, strength));
    74. }
    75. //INSTANTDAMAGE or 7
    76. else if((args[1].equals("instantdamage") || (args[1].equals("7")))){
    77. p.sendMessage(ChatColor.AQUA+"Player has been effected with instant damage");
    78. targp.addPotionEffect(new PotionEffect(PotionEffectType.HARM, time, strength));
    79. }
    80. //JUMPBOOST or 8
    81. else if((args[1].equals("jumpboost") || (args[1].equals("8")))){
    82. p.sendMessage(ChatColor.AQUA+"Player has been effected with jumpboost");
    83. targp.addPotionEffect(new PotionEffect(PotionEffectType.JUMP, time, strength));
    84. }
    85. //NAUSEA or 9
    86. else if((args[1].equals("nausea") || (args[1].equals("9")))){
    87. p.sendMessage(ChatColor.AQUA+"Player has been effected with nausea");
    88. targp.addPotionEffect(new PotionEffect(PotionEffectType.CONFUSION, time, strength));
    89. }
    90. //REGENERATION or 10
    91. else if((args[2].equals("regeneration") || (args[1].equals("10")))){
    92. p.sendMessage(ChatColor.AQUA+"Player has been effected with regenration");
    93. targp.addPotionEffect(new PotionEffect(PotionEffectType.REGENERATION, time, strength));
    94. }
    95. //RESISTANCE or 11
    96. else if((args[1].equals("resistance") || (args[1].equals("11")))){
    97. p.sendMessage(ChatColor.AQUA+"Player has been effected with resistance");
    98. targp.addPotionEffect(new PotionEffect(PotionEffectType.DAMAGE_RESISTANCE, time, strength));
    99. }
    100. //FIRERESISTANCE or 12
    101. else if((args[1].equals("fireresistance") || (args[1].equals("12")))){
    102. p.sendMessage(ChatColor.AQUA+"Player has been effected with fire resistance");
    103. targp.addPotionEffect(new PotionEffect(PotionEffectType.FIRE_RESISTANCE, time, strength));
    104. }
    105. //WATERBREATHING or 13
    106. else if((args[1].equals("waterbreathing") || (args[1].equals("13")))){
    107. p.sendMessage(ChatColor.AQUA+"Player has been effected with water breathing");
    108. targp.addPotionEffect(new PotionEffect(PotionEffectType.WATER_BREATHING, time, strength));
    109. }
    110. //INVISIBILITY or 14
    111. else if((args[1].equals("invisibility") || (args[1].equals("14")))){
    112. p.sendMessage(ChatColor.AQUA+"Player has been effected with invisibility");
    113. targp.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, time, strength));
    114. }
    115. //BLINDNESS or 15
    116. else if((args[1].equals("blindness") || (args[1].equals("15")))){
    117. p.sendMessage(ChatColor.AQUA+"Player has been effected with blindness");
    118. targp.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, time, strength));
    119. }
    120. //NIGHTVISION or 16
    121. else if((args[1].equals("nightvision") || (args[1].equals("16")))){
    122. p.sendMessage(ChatColor.AQUA+"Player has been effected with night vision");
    123. targp.addPotionEffect(new PotionEffect(PotionEffectType.NIGHT_VISION, time, strength));
    124. }
    125. //HUNGER or 17
    126. else if((args[1].equals("hunger") || (args[1].equals("17")))){
    127. p.sendMessage(ChatColor.AQUA+"Player has been effected with hunger");
    128. targp.addPotionEffect(new PotionEffect(PotionEffectType.HUNGER, time, strength));
    129. }
    130. //WEAKNESS or 18
    131. else if((args[1].equals("weakness") || (args[1].equals("18")))){
    132. p.sendMessage(ChatColor.AQUA+"Player has been effected with weakness");
    133. targp.addPotionEffect(new PotionEffect(PotionEffectType.WEAKNESS, time, strength));
    134. }
    135. //POISON or 19
    136. else if((args[1].equals("poison") || (args[1].equals("19")))){
    137. p.sendMessage(ChatColor.AQUA+"Player has been effected with poison");
    138. targp.addPotionEffect(new PotionEffect(PotionEffectType.POISON, time, strength));
    139. }
    140. //WITHER or 20
    141. else if((args[1].equals("wither") || (args[1].equals("20")))){
    142. p.sendMessage(ChatColor.AQUA+"Player has been effected with wither effect");
    143. targp.addPotionEffect(new PotionEffect(PotionEffectType.WITHER, time, strength));
    144. }
    145. //HEALTHBOOST or 21
    146. else if((args[1].equals("healthboost") || (args[1].equals("21")))){
    147. p.sendMessage(ChatColor.AQUA+"Player has been effected with healthboost");
    148. targp.addPotionEffect(new PotionEffect(PotionEffectType.HEALTH_BOOST, time, strength));
    149. }
    150. //ABSORPTION or 22
    151. else if((args[1].equals("absorption") || (args[1].equals("22")))){
    152. p.sendMessage(ChatColor.AQUA+"Player has been effected with absorption");
    153. targp.addPotionEffect(new PotionEffect(PotionEffectType.ABSORPTION, time, strength));
    154. }
    155. //SATURATION or 23
    156. else if((args[1].equals("saturation") || (args[1].equals("23")))){
    157. p.sendMessage(ChatColor.AQUA+"Player has been effected with saturation");
    158. targp.addPotionEffect(new PotionEffect(PotionEffectType.SATURATION, time, strength));
    159. }else{
    160. p.sendMessage("No such effect name or id");
    161. }
    162.  
    163. }else{}
    164. }else{}
    165. return false;
    166. }
     
  2. Offline

    chasechocolate

    Line 20 should be args[0], not args[1].
     
  3. Offline

    Asgernohns

Thread Status:
Not open for further replies.

Share This Page