If multiple strings == true

Discussion in 'Plugin Development' started by isakglad, Aug 22, 2015.

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

    isakglad

    Hi. I have a problem with my code. It wont check if the string is true or not. It will go right to the else method. Ive tried multiple methods for getting this to work, but all off them have been unsuccsessfull.
    Help would be really appriciated. =)

    Code:
         if(settings.getData().getBoolean(settings.getData().getString("Player." + target.getName() + ".advarsler", "1")) == true) {
                         settings.getData().set("Player." + target.getName() + ".advarsel", settings.getData().get("Player." + target.getName() + ".advarsel") + ", " + advarsel);
                         settings.getData().set("Player." + target.getName() + ".advarsler", "2");
                         settings.saveData();
                     } else  if(settings.getData().getBoolean(settings.getData().getString("Player." + target.getName() + ".advarsler", "2")) == true) {        
                         settings.getData().set("Player." + target.getName() + ".advarsel", settings.getData().get("Player." + target.getName() + ".advarsel") + ", " + advarsel);
                         settings.getData().set("Player." + target.getName() + ".advarsler", "3");
                         settings.saveData();
                      } else  if(settings.getData().getBoolean(settings.getData().getString("Player." + target.getName() + ".advarsler", "3")) == true) {
                          settings.getData().set("Player." + target.getName() + ".advarsel", settings.getData().get("Player." + target.getName() + ".advarsel") + ", " + advarsel);
                          settings.saveData();
                          target.setBanned(true);
                          target.kickPlayer("§cDu er utestengt fra DødeligSurvival.\n§6Kjøp unban på §7butikk.dødeligsurvival.com.\n§7Grunn: §9" + settings.getData().get("Player." + target.getName() + ".melding"));
                      
                       settings.getData().set("Player." +target.getName() + ".melding", advarsel);
                       settings.saveData();
                       
                      } else {
                   
                     settings.getData().set("Player." + target.getName() + ".advarsel", advarsel);
                     settings.getData().set("Player." + target.getName() + ".advarsler", "1");
                     settings.saveData();
                      }
     
  2. Offline

    Shortninja66

    Strings do not return true or false, so you should be storing the data as just "true" or "false" without any quotations. However, you can try doing "string.equalsIgnoreCase("true")"
     
  3. Offline

    isakglad

    But i want to check multiple methods. Not just 2. Because i want to ban the person at the third check.
    And i dont want any warnings to be lost. So...
     
  4. Offline

    Shortninja66

    @isakglad I don't get what you mean. But the way you are doing it won't work, you can't get a boolean from a string like that. The way you store the data can be changed most likely.

    Getting a boolean from a String would be like:
    Code:
    boolean check = false;
    if(string.equalsIgnoreCase("true")
    {
      check = true;
    }
     
  5. Offline

    isakglad

    But i dont need to check if it is a boolean ??
    I just want to check if something is equal in the config. Is that so hard :/ ?
    the getBoolean was just a test because i tried alot of methods before.
     
  6. Offline

    au2001

    @isakglad Booleans are only True/False, you can't have several levels of warning.
    What I suggest you do is put a "warnsbeforeban" int in your config.
    Then save, for each player, an int saying how many times he has been warned.
    Each time, increment this number by one and if it is equal to the warnsbeforeban, ban him.
     
  7. Offline

    isakglad

    Thanks dude :) I wasnt thinking straight... There is always an easier way :/
     
  8. Offline

    au2001

    @isakglad You're welcome :p

    If you want more precision, I suggest you save each warn reason in an array list named "warns" for exemple.
    Then check for the list's size, and compare it to the configurable value I explained above :p
     
    Shortninja66 likes this.
  9. Offline

    mine-care

    Please mark the thread as solved,
    Also there is no point in comparing two booleans to end up in a final boolean...

    if(boolean == true/false) should be if(boolean) for true and if(!boolean) for false.
     
Thread Status:
Not open for further replies.

Share This Page