How to get the length of a custom argument?

Discussion in 'Plugin Development' started by FlameFlare9, May 12, 2014.

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

    FlameFlare9

    Hello,
    I wanted to test for the length of my args[0], because
    Code:
    args[0].length() >= 14
    doesn't work, so how do I get the length of this argument?
     
  2. Offline

    EgyptianKing

    Code:java
    1. int length = args[0].length();
     
  3. Offline

    FlameFlare9

    It still doesnt work
     
  4. Offline

    SnipsRevival

    Could you be more specific about what you mean when you say it "doesn't work"?
     
  5. Offline

    FlameFlare9

    I can't execute the command, and nothing shows up in the config!

    in the console*

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

    FabeGabeMC

    Code:java
    1. int length = args.length;
     
  7. Offline

    SnipsRevival

    Post your whole code then.
     
  8. Offline

    dentych

    FlameFlare9
    Have you declared the command in your plugin.yml?
    Did you override?
    Post more code.

    That is incorrect.
    The length of strings is found using the method in the String class called
    Code:java
    1. .length()

    Whereas
    Code:java
    1. .length
    is used to find the length of arrays, and is a constant variable, as the length of arrays are set when you initialize the array.

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

    theguynextdoor

    When making suggestions such as these, it is often best to double check that what your saying is actually true. In this instance you appear to be confusing the length variable which you can retrieve from the array, however in this case he is retrieving a String from the array, and there is no public length variable in the string class and so the parenthesis are needed to access the length() method, which does exist.

    Doing
    Code:java
    1. if (args[0].length() >= 14) {
    will work. The problem here is not this, but another problem existing in the main code of the plugin. Perhaps the command was not registered, or there is some other logic error in the code.
     
    dentych likes this.
  10. Offline

    JBoss925

    dentych theguynextdoor Sorry. I've been working a lot with javascript recently and the length arrays are used much more often than strings. My apologies, I forgot I was speaking in java.
     
  11. Offline

    FlameFlare9

    Code:
    if(cmd.getName().equalsIgnoreCase("nick")){
                if(p.hasPermission("smart.nick")){
                    if(args.length != 1){
                       
                        if(args[0].length() > 14||args[0].length() < 4){
                        p.sendMessage(SmartCraft+"Zu langer/kurzer Name! Max. 14 Zeichen und min. !");
                        }else
                           
                       
                           
                                if(args[0].equalsIgnoreCase("Chaosflo44")
                                        ||args[0].equalsIgnoreCase("Notch")
                                        ||args[0].equalsIgnoreCase("jeb_")
                                        ||args[0].equalsIgnoreCase("Dinnerbone")
                                        ||args[0].equalsIgnoreCase("Grumm")
                                        ||args[0].equalsIgnoreCase("SmartPlaysDE")
                                        ||args[0].equalsIgnoreCase("FlamyYT")
                                        ||args[0].equalsIgnoreCase("AnilzHDx")
                                        ||args[0].equalsIgnoreCase("FunPr0G4mer")
                                        ||args[0].equalsIgnoreCase("HaloPVP")
                                        ||args[0].equalsIgnoreCase("LabyStudio")
                                        ||args[0].equalsIgnoreCase("Timminator235")
                                        ||args[0].equalsIgnoreCase("Halbzwilling")
                                        ||args[0].equalsIgnoreCase("PXLWLF")
                                        ||args[0].equalsIgnoreCase("SurpimeGames")
                                        ||args[0].equalsIgnoreCase("Rotpilz")
                                        ||args[0].equalsIgnoreCase("ungespielt")
                                        ||args[0].equalsIgnoreCase("DnerDrk")
                                        ||args[0].equalsIgnoreCase("MCExpertDE")
                                        ||args[0].equalsIgnoreCase("xxst3gixx")
                                        ||args[0].equalsIgnoreCase("anyartlp")
                                        ||args[0].equalsIgnoreCase("GamerKlinik")
                                        ||args[0].equalsIgnoreCase("KranCrafter")
                                        ||args[0].equalsIgnoreCase("Calibur")
                                        ||args[0].equalsIgnoreCase("WolfWins")
                                        ||args[0].equalsIgnoreCase("castcrafter")
                                        ||args[0].equalsIgnoreCase("mrmoregame")
                                        ||args[0].equalsIgnoreCase("concrafer")
                                        ||args[0].equalsIgnoreCase("thekedoszone")
                                        ||args[0].equalsIgnoreCase("debitorlp")
                                        ||args[0].equalsIgnoreCase("rewinside")
                                        ||args[0].equalsIgnoreCase("delaylp")
                                        ||args[0].equalsIgnoreCase("h0llylp")
                                        ||args[0].equalsIgnoreCase("herrbergmann_org")
                                        ||args[0].equalsIgnoreCase("denotin")
                                        ||args[0].equalsIgnoreCase("shufflelp")
                                        ||args[0].equalsIgnoreCase("earliboy")
                                        ||args[0].equalsIgnoreCase("germanletsplay")
                                        ||args[0].equalsIgnoreCase("z0mb3y")
                                        ||args[0].equalsIgnoreCase("gommehd")
                                        ||args[0].equalsIgnoreCase("zeronikhd")
                                        ||args[0].equalsIgnoreCase("letstaddl")
                                        ||args[0].equalsIgnoreCase("paluten")
                                        ||args[0].equalsIgnoreCase("sturmwaffellp")
                                        ||args[0].equalsIgnoreCase("petritlp")
                                        ||args[0].equalsIgnoreCase("doim94")
                                        ||args[0].equalsIgnoreCase("Zander21")
                                        ||args[0].equalsIgnoreCase("SibstLP")
                                        ||args[0].equalsIgnoreCase("Sparkofphoenix")
                                        ||args[0].equalsIgnoreCase("Gronkh")
                                        ||args[0].equalsIgnoreCase("SkyDoesMinecraft")
                                        ||args[0].equalsIgnoreCase("Sarazar")
                                        ||args[0].equalsIgnoreCase("Derkev")
                                        ){
                                    p.sendMessage(SmartCraft +"Dies ist leider ein verbotener Name!");
                                }else{
                       
                                    Player target = (Bukkit.getServer().getPlayer(args[0]));
                                    if(target == null){
                                   
                                    nicked.add(p);
                                    p.setPlayerListName( ChatColor.GOLD+args[0]);
                                    p.setDisplayName(ChatColor.GOLD+args[0]);
                                TagAPI.refreshPlayer(p);
                                p.sendMessage(SmartCraft+ChatColor.GRAY+"Dein Name ist jetzt: "+ChatColor.GREEN + args[0]);
                                    }
                                    else{
                                        p.sendMessage(SmartCraft+"This name is in use!");
                                    }
                                }
                            }
                       
                }
            }
    Main Plugin!
    Code:
    name: SmartCraft
    version: 1.0 Beta
    author: Flamy
    main: eu.flamy.www.smarty.Main
     
    depend: [TagAPI]
     
    commands:
        kickall:
              description: Kickall
              usage: </command>
        nick:
              description: Rename yourself!
              usage: </command>
    Plugin.yml

    Okay Solved I simply removed the" if(args.length =1) "

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 8, 2016
Thread Status:
Not open for further replies.

Share This Page