Help me to read this

Discussion in 'Spigot Plugin Development' started by Raymart, Jun 25, 2015.

  1. Hello help me to read this code

    example code :
    Code (Text):
    e.getMessage().length() >= this.min ? 1 : 0
     
  2. what do you mean by help you 'read' this code?
     
  3. how you read it at english like this example :

    if (!p.haspermission)

    if player has no permission bla bla bla
     
  4. well in my mind, that code means

    the event message length is greater than or equal to the classes min - then the rest i have no clue

    also how does this help with plugin development? if this is not your code and you are using it in your plugin you should probably use something like google to help you figure it out
     
  5. Code (Java):

    return e.getMessage().length() >= this.min ? 1 : 0;
    // Is the same as
    if (e.getMessage().length() >= this.min) {
      return 1;
    } else {
      return 0;
    }
    // This is how it works
    return (conditional || boolean) ? (first value) : (second value);
    // You can also use it to set values
    String s = true ? "Potato" : "Sausage"; // s = "Potato" :P
     
    Essentially, it's a compact if/else statement :D
     
    • Informative Informative x 1
  6. another simple :p
     
  7. It is a tertiary statement.

    (e.getMessage().length() >= this.min) ? 1 : 0
    Conditional statement
    IF STATEMENT IS TRUE THAN THIS
    IF STATEMENT IS FALSE THAN THIS

    Colors represent the definition of the corresponding code with that color.

    Additionally as previous statement stated it has other uses. Not only can you use it in strings to set values but can also expand values....

    boolean x = false;

    String t = "X is " + (x ? "True" : "False");
     
  8. Well done on repeating what was already explained...
     
  9. I don't think anyone ever explained to him what it's actually called. I think that's kinda important information.

    Additionally it is useful to know you can use them in concatenations rather than just declarations.