Exemple #1
0
 @Command(min = 1, max = 5, usage = "{<click>} {[block]} {[item]} {[location]} [range]")
 public static Objective fromCommand(final QuesterCommandContext context) throws CommandException {
   Material mat = null, hmat = null;
   int dat = -1, hdat = -1, rng = 0, click = 0;
   Location loc = null;
   int[] itm;
   click = SerUtils.parseAction(context.getString(0));
   if (context.length() > 1) {
     if (!context.getString(1).equalsIgnoreCase("ANY")) {
       itm = SerUtils.parseItem(context.getString(1));
       if (itm[0] > 255) {
         throw new CommandException(context.getSenderLang().get("ERROR_CMD_BLOCK_UNKNOWN"));
       }
       mat = Material.getMaterial(itm[0]);
       dat = itm[1];
     }
     if (context.length() > 2) {
       if (!context.getString(2).equalsIgnoreCase("ANY")) {
         itm = SerUtils.parseItem(context.getString(2));
         hmat = Material.getMaterial(itm[0]);
         hdat = itm[1];
       }
       if (context.length() > 3) {
         loc = SerUtils.getLoc(context.getPlayer(), context.getString(3));
         if (context.length() > 4) {
           rng = Integer.parseInt(context.getString(4));
         }
       }
     }
   }
   return new ActionObjective(mat, dat, hmat, hdat, click, loc, rng);
 }
Exemple #2
0
 @Override
 protected void save(final StorageKey key) {
   if (block != null) {
     key.setString("block", SerUtils.serializeItem(block, blockData));
   }
   if (inHand != null) {
     key.setString("hand", SerUtils.serializeItem(inHand, inHandData));
   }
   if (click > 0 && click < 4) {
     key.setInt("click", click);
   }
   if (location != null) {
     key.setString("location", SerUtils.serializeLocString(location));
     if (range > 0) {
       key.setInt("range", range);
     }
   }
 }
Exemple #3
0
  protected static Objective load(final StorageKey key) {
    Material mat = null, hnd = null;
    Location loc = null;
    int dat = -1, hdat = -1, rng = 0, clck = 0;
    int[] itm;
    try {
      itm = SerUtils.parseItem(key.getString("block", ""));
      mat = Material.getMaterial(itm[0]);
      dat = itm[1];
    } catch (final IllegalArgumentException ignore) {
    }
    try {
      itm = SerUtils.parseItem(key.getString("hand", ""));
      hnd = Material.getMaterial(itm[0]);
      hdat = itm[1];
    } catch (final IllegalArgumentException ignore) {
    }
    clck = key.getInt("click", 0);
    loc = SerUtils.deserializeLocString(key.getString("location", ""));
    rng = key.getInt("range", 0);

    return new ActionObjective(mat, dat, hnd, hdat, clck, loc, rng);
  }
Exemple #4
0
 @Override
 protected String info() {
   final String datStr = blockData < 0 ? "" : ":" + blockData;
   final String blockStr =
       block == null ? "ANY" : block.name() + "[" + block.getId() + datStr + "]";
   final String handDatStr = inHandData < 0 ? "" : ":" + inHandData;
   final String handStr =
       inHand == null ? "ANY" : inHand.name() + "[" + inHand.getId() + handDatStr + "]";
   final String clickStr =
       click == 1 ? "LEFT" : click == 2 ? "RIGHT" : click == 3 ? "PUSH" : "ALL";
   return clickStr
       + "; BLOCK: "
       + blockStr
       + "; HAND: "
       + handStr
       + "; LOC: "
       + SerUtils.displayLocation(location)
       + "; RNG: "
       + range;
 }
Exemple #5
0
 @Override
 protected String show(final int progress) {
   final String clickStr =
       click == 1 ? "Left-click" : click == 2 ? "Right-click" : click == 3 ? "Walk on" : "Click";
   String blockStr = block == null ? "" : " " + block.name().toLowerCase().replace('_', ' ');
   if (blockStr.isEmpty() && click == 3) {
     blockStr = " pressure plate";
   }
   final String datStr = blockData < 0 ? "" : "(data" + blockData + ")";
   final String handStr =
       inHand == null
           ? ""
           : inHand == Material.AIR
               ? " with empty hand "
               : " with " + inHand.name().toLowerCase().replace('_', ' ') + " in hand";
   final String handDatStr = inHandData < 0 ? "" : "(data" + inHandData + ")";
   final String locStr =
       location == null
           ? ""
           : " " + range + " blocks close to " + SerUtils.displayLocation(location);
   return clickStr + blockStr + datStr + handStr + handDatStr + locStr + ".";
 }