Command not reading my if statement?

Discussion in 'Plugin Development' started by Mrcool234, Jul 9, 2014.

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

    Mrcool234

    I'm making a 1v1 plugin and want to stop the null point exceptions even if the player types something null but even when I do that it's not sending them the message and I think i'm doing it right but it's not working can someone tell me why. Thank You!

    Code: http://pastebin.com/8QANcjTh
     
  2. Offline

    Necrodoom

    Did you check if you can actually access args[1] and args[0] with an args.length check? Strings in args array cannot be normally null, because it is split from a message.
     
  3. Offline

    Mrcool234

    Necrodoom Yes,I have tried that and it still does not work but Thank you for the fast reply!

    Bump

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

    maved145

    Code:java
    1. if(args[0].equalsIgnoreCase("join")){
    2. if(args[1].equalsIgnoreCase(args[1])){
    3.  
    4. if(args[1] != null){
    5. Bukkit.broadcastMessage("§7[§41§cv§41§7]: §4 " + player.getName() + " §2Has Joined§4 " + arenaname);
    6. final World w1 = Bukkit.getWorld((String) getConfig().get(arenaname + ".spawn1.world"));
    7. final double x1 = getConfig().getDouble(arenaname + ".spawn1.x");
    8. final double y1 = getConfig().getDouble(arenaname + ".spawn1.y");
    9. final double z1 = getConfig().getDouble(arenaname + ".spawn1.z");
    10.  
    11. final World w2 = Bukkit.getWorld((String) getConfig().get(arenaname + ".spawn2.world"));
    12. final double x2 = getConfig().getDouble(arenaname + ".spawn2.x");
    13. final double y2 = getConfig().getDouble(arenaname + ".spawn2.y");
    14. final double z2 = getConfig().getDouble(arenaname + ".spawn2.z”);
    15. }else{
    16. Bukkit.broadcastMessage("Working");
    17. player.sendMessage("§7[§41§cv§41§7]: §4You must Type an Arena or the Arena doesn't exist!”);
    18. }
    19. }
    20. }


    Try that. Mrcool234
     
  5. Offline

    Necrodoom

    maved145 ..............what. Your attempt makes even less sense.

    Mrcool234 paste your edited file then.
     
  6. Offline

    maved145

    Necrodoom How. Im simply making it check if args[1] doesn’t equal null then do something else(if it doe equal null) do something else.
     
  7. Offline

    Necrodoom

    maved145 1. An arg cannot ever equal null, it is done by splitting the command by spaces, you should make args.length checks like regular array logic.

    2. if(args[1].equalsIgnoreCase(args[1])) should speak for it self. If not, you seriously need to learn Java.
     
    indyetoile likes this.
  8. Offline

    maved145

    Necrodoom Well that bit wasn’t my code.
     
  9. Offline

    Necrodoom

    maved145 if you are going to fix someone else's code for him and spoonfeed, at least do it right.
     
    Zupsub likes this.
  10. Offline

    indyetoile

    maved145

    This is not going to work:
    Code:java
    1. if(args[1].equalsIgnoreCase(args[1])){

    You can't check if args[1] equals args[1].

    Code:java
    1. if(args[1] == null){

    Instead of checking if the argument is null (which is impossible), check if there's an arena which equals args[1].
     
  11. Offline

    maved145

    Necrodoom Your honestly a jerk. Just leave me alone.
     
  12. Offline

    Necrodoom

    maved145 I'm sorry that I don't like it when people feed code without checking if its correct.
     
    ZodiacTheories and indyetoile like this.
  13. Offline

    maved145

    Necrodoom i understand that, but you could do it more politely. I know i should of checked the code, but i was kinda in a rush :L
     
Thread Status:
Not open for further replies.

Share This Page