Exemplo n.º 1
0
  /**
   * Applies a list of transformation on a block, if the block is not protected.
   *
   * @param toTransform the Bukkit block object to transform
   * @param transformations the list if transformations to apply
   */
  public static void transform(Block toTransform, List<List<String>> transformations) {
    if (isBlockProtected(toTransform)) {
      return;
    }

    for (List<String> toCheck : transformations) {
      ArrayList<String[]> stateIndex = new ArrayList<String[]>();

      for (int i = 0; i != 2; ++i) {
        String got = toCheck.get(i);

        if (got.contains(":")) { // Check for data _ appended.
          stateIndex.add(got.split(":"));
        } else {
          stateIndex.add(new String[] {got, "0"});
        }
      }

      String[] curState = stateIndex.get(0), toState = stateIndex.get(1);

      if (Integer.valueOf(curState[0]) == toTransform.getTypeId()
          && Integer.valueOf(curState[1]) == toTransform.getData()) {
        toTransform.setTypeIdAndData(Integer.valueOf(toState[0]), Byte.parseByte(toState[1]), true);
        return;
      }
    }
  }
Exemplo n.º 2
0
    public void printPage(CommandSender p, int pnum, int linesperpage) {
      if (ln.size() > 0) {

        int maxp = ln.size() / linesperpage;
        if ((ln.size() % linesperpage) > 0) maxp++;
        if (pnum > maxp) pnum = maxp;
        int maxl = linesperpage;
        if (pnum == maxp) {
          maxl = ln.size() % linesperpage;
          if (maxp == 1) maxl = ln.size();
        }
        if (maxl == 0) maxl = linesperpage;
        if (msg.containsKey(title_msgid)) printMsg(p, "&6&l" + getMSGnc(title_msgid));
        else printMsg(p, title_msgid);

        String numpx = "";
        for (int i = 0; i < maxl; i++) {
          if (shownum) numpx = "&3" + Integer.toString(1 + i + (pnum - 1) * linesperpage) + ". ";
          printMsg(p, numpx + "&a" + ln.get(i + (pnum - 1) * linesperpage));
        }
        if (maxp > 1) printMSG(p, this.footer_msgid, 'e', '6', pnum, maxp);
      } else printMSG(p, "lst_listisempty", 'c');
    }
  private static Map<String, List<Material>> initSynonyms() {

    Map<String, List<Material>> result = new HashMap<String, List<Material>>();
    // Blocks
    result.put("ANY_FURNACE", Arrays.asList(Material.FURNACE, Material.BURNING_FURNACE));
    result.put("ANY_SIGN", Arrays.asList(Material.SIGN, Material.SIGN_POST, Material.WALL_SIGN));
    result.put(
        "ANY_REDSTONE_ORE", Arrays.asList(Material.REDSTONE_ORE, Material.GLOWING_REDSTONE_ORE));
    result.put(
        "ANY_REDSTONE_TORCH",
        Arrays.asList(Material.REDSTONE_TORCH_OFF, Material.REDSTONE_TORCH_ON));
    result.put("ANY_DIODE_BLOCK", Arrays.asList(Material.DIODE_BLOCK_OFF, Material.DIODE_BLOCK_ON));
    // Tools
    result.put(
        "ANY_SPADE",
        Arrays.asList(
            Material.WOOD_SPADE,
            Material.STONE_SPADE,
            Material.GOLD_SPADE,
            Material.IRON_SPADE,
            Material.DIAMOND_SPADE));
    result.put(
        "ANY_AXE",
        Arrays.asList(
            Material.WOOD_AXE,
            Material.STONE_AXE,
            Material.GOLD_AXE,
            Material.IRON_AXE,
            Material.DIAMOND_AXE));
    result.put(
        "ANY_HOE",
        Arrays.asList(
            Material.WOOD_HOE,
            Material.STONE_HOE,
            Material.GOLD_HOE,
            Material.IRON_HOE,
            Material.DIAMOND_HOE));
    result.put(
        "ANY_PICKAXE",
        Arrays.asList(
            Material.WOOD_PICKAXE,
            Material.STONE_PICKAXE,
            Material.GOLD_PICKAXE,
            Material.IRON_PICKAXE,
            Material.DIAMOND_PICKAXE));
    result.put(
        "ANY_SWORD",
        Arrays.asList(
            Material.WOOD_SWORD,
            Material.STONE_SWORD,
            Material.GOLD_SWORD,
            Material.IRON_SWORD,
            Material.DIAMOND_SWORD));
    result.put(
        "ANY_BUCKET",
        Arrays.asList(
            Material.BUCKET, Material.LAVA_BUCKET, Material.WATER_BUCKET, Material.MILK_BUCKET));
    // Armour
    result.put(
        "ANY_HELMET",
        Arrays.asList(
            Material.LEATHER_HELMET,
            Material.CHAINMAIL_HELMET,
            Material.GOLD_HELMET,
            Material.IRON_HELMET,
            Material.DIAMOND_HELMET));
    result.put(
        "ANY_CHESTPLATE",
        Arrays.asList(
            Material.LEATHER_CHESTPLATE,
            Material.CHAINMAIL_CHESTPLATE,
            Material.GOLD_CHESTPLATE,
            Material.IRON_CHESTPLATE,
            Material.DIAMOND_CHESTPLATE));
    result.put(
        "ANY_LEGGINGS",
        Arrays.asList(
            Material.LEATHER_LEGGINGS,
            Material.CHAINMAIL_LEGGINGS,
            Material.GOLD_LEGGINGS,
            Material.IRON_LEGGINGS,
            Material.DIAMOND_LEGGINGS));
    result.put(
        "ANY_BOOTS",
        Arrays.asList(
            Material.LEATHER_BOOTS,
            Material.CHAINMAIL_BOOTS,
            Material.GOLD_BOOTS,
            Material.IRON_BOOTS,
            Material.DIAMOND_BOOTS));
    // Minecarts
    result.put(
        "ANY_MINECART",
        Arrays.asList(Material.MINECART, Material.POWERED_MINECART, Material.STORAGE_MINECART));
    result.put(
        "ANY_RAIL", Arrays.asList(Material.RAILS, Material.POWERED_RAIL, Material.DETECTOR_RAIL));
    // Wildcards
    List<Material> merger;

    merger = new ArrayList<Material>();
    merger.addAll(result.get("ANY_SPADE"));
    merger.addAll(result.get("ANY_AXE"));
    merger.addAll(result.get("ANY_HOE"));
    merger.addAll(result.get("ANY_PICKAXE"));
    merger.addAll(result.get("ANY_SWORD"));
    merger.addAll(result.get("ANY_BUCKET"));
    merger.addAll(
        Arrays.asList(
            Material.FLINT_AND_STEEL, Material.FISHING_ROD, Material.SADDLE, Material.BOW));
    result.put("ANY_TOOL", merger);

    merger = new ArrayList<Material>();
    merger.addAll(result.get("ANY_SWORD"));
    merger.addAll(Arrays.asList(Material.BOW, Material.ARROW));
    result.put("ANY_WEAPON", merger);

    merger = new ArrayList<Material>();
    merger.addAll(result.get("ANY_HELMET"));
    merger.addAll(result.get("ANY_CHESTPLATE"));
    merger.addAll(result.get("ANY_LEGGINGS"));
    merger.addAll(result.get("ANY_BOOTS"));
    result.put("ANY_ARMOR", merger);

    merger = new ArrayList<Material>();
    merger.addAll(Arrays.asList(Material.values()));
    result.put("ANY_OBJECT", merger);

    merger = new ArrayList<Material>();
    merger.addAll(Arrays.asList(Material.values()));
    for (int i = 0; i < merger.size(); i++) {
      if (!merger.get(i).isBlock()) merger.set(i, null);
    }
    while (merger.indexOf(null) >= 0) merger.remove(null);
    result.put("ANY_BLOCK", merger);

    merger = new ArrayList<Material>();
    merger.addAll(Arrays.asList(Material.values()));
    for (int i = 0; i < merger.size(); i++) {
      if (merger.get(i).isBlock()) merger.set(i, null);
    }
    while (merger.indexOf(null) >= 0) merger.remove(null);
    result.put("ANY_ITEM", merger);

    return Collections.unmodifiableMap(result);
  }