예제 #1
0
 private static GroupResult checkRange(
     final String string, final char[] charArray, int endIndex, final long data) {
   final Long min, max;
   {
     boolean sign = true;
     for (final int charArrayLength = charArray.length; endIndex < charArrayLength; endIndex++) {
       final char c = charArray[endIndex];
       if (sign) {
         sign = false;
         if ((c == '+') || (c == '-')) {
           continue;
         }
       }
       if ((c < '0') || (c > '9')) {
         break;
       }
     }
     if (endIndex == 0) {
       return new GroupResult(false, false, 0);
     }
     min = DioriteMathUtils.asLong(string.substring(0, endIndex));
     if (min == null) {
       return new GroupResult(false, false, 0);
     }
   }
   if (charArray[endIndex++] != '-') {
     return new GroupResult(false, false, 0);
   }
   final int start = endIndex;
   {
     boolean sign = true;
     for (final int charArrayLength = charArray.length; endIndex < charArrayLength; endIndex++) {
       final char c = charArray[endIndex];
       if (sign) {
         sign = false;
         if ((c == '+') || (c == '-')) {
           continue;
         }
       }
       if ((c < '0') || (c > '9')) {
         break;
       }
     }
     if (endIndex == 0) {
       return new GroupResult(false, false, 0);
     }
     max = DioriteMathUtils.asLong(string.substring(start, endIndex));
     if (max == null) {
       return new GroupResult(false, false, 0);
     }
   }
   return new GroupResult(true, (data >= min) && (data <= max), endIndex);
 }
예제 #2
0
 private static boolean checkIfValidRange(final String string) {
   final int index = string.lastIndexOf('-');
   if (index == -1) {
     return false;
   }
   final int index2 = string.lastIndexOf('-', index - 1); // to handle negative values in ranges
   if ((index2 == 0) || (index2 == -1)) {
     return (DioriteMathUtils.asLong(string.substring(0, index)) != null)
         && (DioriteMathUtils.asLong(string.substring(index + 1)) != null);
   }
   return (DioriteMathUtils.asLong(string.substring(0, index2)) != null)
       && (DioriteMathUtils.asLong(string.substring(index2 + 1)) != null);
 }
예제 #3
0
 @Override
 public Long parseValueData(final String data) {
   if (data == null) {
     return null;
   }
   return DioriteMathUtils.asLong(data);
 }
예제 #4
0
 private static LongRange parseSingleRange(final String string) {
   final int index = string.lastIndexOf('-');
   if (index == -1) {
     return null;
   }
   final int index2 = string.lastIndexOf('-', index - 1); // to handle negative values in ranges
   final Long a;
   final Long b;
   if ((index2 == 0) || (index2 == -1)) {
     a = DioriteMathUtils.asLong(string.substring(0, index));
     b = DioriteMathUtils.asLong(string.substring(index + 1));
   } else {
     a = DioriteMathUtils.asLong(string.substring(0, index2));
     b = DioriteMathUtils.asLong(string.substring(index2 + 1));
   }
   if ((a == null) || (b == null)) {
     return null;
   }
   return new LongRange(a, b);
 }
예제 #5
0
 /**
  * Returns one of DiamondLeggings-type based on name (selected by diorite team). If block contains
  * only one type, sub-name of it will be this same as name of material.<br>
  * Returns null if name can't be parsed to int and it isn't "NEW" one.
  *
  * @param name name of sub-type
  * @return sub-type of DiamondLeggings.
  */
 public static DiamondLeggingsMat getByEnumName(final String name) {
   final DiamondLeggingsMat mat = byName.get(name);
   if (mat == null) {
     final Integer idType = DioriteMathUtils.asInt(name);
     if (idType == null) {
       return null;
     }
     return getByID(idType);
   }
   return mat;
 }
예제 #6
0
 @Override
 public boolean isValidValue(final String string) {
   return DioriteMathUtils.asLong(string) != null;
 }
예제 #7
0
  public FlyCmd() {
    super(
        "fly",
        Pattern.compile("(fly)(:(?<speed>((\\d+|)(\\.\\d+|)))|)", Pattern.CASE_INSENSITIVE),
        CommandPriority.LOW);
    this.setCommandExecutor(
        (sender, command, label, matchedPattern, args) -> {
          final String speedArg = matchedPattern.group("speed");
          final double speed;
          final Player target;
          Boolean on = null;

          if (args.length() >= 2) {
            target = args.asPlayer(0);
            on = args.asBoolean(1);
          } else {
            target =
                args.has(0)
                    ? args.asPlayer(0)
                    : ((sender instanceof Player) ? (Player) sender : null);
          }

          if (target == null) {
            sender.sendSimpleColoredMessage("&4No target...");
            return;
          }

          if (speedArg == null) {
            speed = Player.FLY_SPEED;
          } else if (speedArg.isEmpty()) {
            speed = target.getFlySpeed();
          } else {
            speed = (Arguments.asDouble(speedArg) / 100);
          }
          if (speed > 1) {
            sender.sendSimpleColoredMessage("&4Speed can't by larger than 100");
            return;
          }

          if (on == null) {
            on = !((speedArg == null) || speedArg.isEmpty()) || !target.canFly();
          }
          target.setCanFly(on, speed);

          //noinspection ObjectEquality
          if (target == sender) // this should be this same object
          {
            sender.sendSimpleColoredMessage(
                "&7Fly &3"
                    + (target.canFly() ? "enabled" : "disabled")
                    + "&7! (Speed: &3"
                    + DioriteMathUtils.formatSimpleDecimal(target.getFlySpeed() * 100)
                    + "&7)");
          } else {
            sender.sendSimpleColoredMessage(
                "&7Fly &3"
                    + (target.canFly() ? "enabled" : "disabled")
                    + "&7 for &3"
                    + target.getName()
                    + "&7! (Speed: &3"
                    + DioriteMathUtils.formatSimpleDecimal(target.getFlySpeed() * 100)
                    + "&7)");
          }
        });
  }