Ejemplo n.º 1
0
  public Map<String, ItemStack> getCreativeArmor() {
    if (getEnabled()) {
      Map<String, ItemStack> armor = new HashMap<String, ItemStack>();
      for (Map.Entry<String, Object> entry : config.getValues(false).entrySet()) {
        if (!entry.getKey().equals("enabled") && !entry.getKey().equals("fixed")) {
          if (entry.getValue() instanceof ItemStack) {
            armor.put(entry.getKey(), (ItemStack) entry.getValue());
          } else {
            MaterialData md = null;
            try {
              md = ItemUtils.parseMaterial((String) entry.getValue());
            } catch (MaterialNotRecognizedException e) {
              getLog().warn(L("exception.config.material_not_found", entry.getValue()));
            } catch (MaterialDataNotRecognizedException e) {
              getLog().warn(L("exception.config.materiak_data_not_found", entry.getValue()));
            }

            if (md != null) armor.put(entry.getKey(), md.toItemStack(1));
          }
        }
      }
      return armor.size() > 0 ? armor : null;
    }
    return null;
  }
Ejemplo n.º 2
0
  @Override
  public void changeBlock(Block block) {
    currentJob.addBlock(block.getState());

    block.setType(item.getItemType());
    block.setData(item.getData());
  }
Ejemplo n.º 3
0
  public ItemStack getOutcome(boolean isFixedDrops) {
    if (Math.random() * 100.0D < percentage && material != null) {
      int dropAmount =
          isFixedDrops
              ? range.getMaximumInteger()
              : range.getMinimumInteger()
                  + random.nextInt(
                      Math.abs(range.getMaximumInteger() - range.getMinimumInteger() + 1));

      if (dropAmount > 0) {
        ItemStack itemStack;
        if (data == null) {
          itemStack = new ItemStack(material, dropAmount);
        } else {
          MaterialData materialData = new MaterialData(material, data);
          itemStack = materialData.toItemStack(dropAmount);
          if (durability != null) {
            itemStack.setDurability(durability);
          }
        }
        itemStack.addEnchantments(ItemEnchantment.getOutcome(enchantments));
        if (itemStack.getAmount() > 0) {
          return itemStack;
        }
      }
    }
    return null;
  }
  /** Build and return a new {@link ItemStack}. */
  public ItemStack build() {

    ItemStack itemStack = new ItemStack(_materialData.getItemType());
    itemStack.setData(_materialData.clone());
    itemStack.setAmount(_amount);

    if (_durability != null) itemStack.setDurability(_durability);

    if (_display != null) ItemStackUtils.setDisplayName(itemStack, _display);

    if (_lore != null) ItemStackUtils.setLore(itemStack, _lore);

    if (_enchantments != null) {

      for (IEnchantmentLevel wrapper : _enchantments) {
        itemStack.addUnsafeEnchantment(wrapper.getEnchantment(), wrapper.getLevel());
      }
    }

    if (_color != null) {
      ItemStackUtils.setColor(itemStack, _color);
    }

    return itemStack;
  }
Ejemplo n.º 5
0
 /**
  * Gets mythic material name.
  *
  * @param matData the mat data
  * @return the mythic material name
  */
 public String getMythicMaterialName(MaterialData matData) {
   String comb =
       String.format(
           "%s;%s", String.valueOf(matData.getItemTypeId()), String.valueOf(matData.getData()));
   String comb2;
   if (matData.getData() == (byte) 0) {
     comb2 = String.valueOf(matData.getItemTypeId());
   } else {
     comb2 = comb;
   }
   String mythicMatName =
       getPlugin()
           .getConfigurationManager()
           .getConfiguration(MythicConfigurationFile.LANGUAGE)
           .getString(comb.toLowerCase());
   if (mythicMatName == null) {
     mythicMatName =
         getPlugin()
             .getConfigurationManager()
             .getConfiguration(MythicConfigurationFile.LANGUAGE)
             .getString(comb2.toLowerCase());
     if (mythicMatName == null) {
       mythicMatName = getMinecraftMaterialName(matData.getItemType());
     }
   }
   return StringUtils.getInitCappedString(mythicMatName.split(" "));
 }
Ejemplo n.º 6
0
 private void highlightBoardSquare(int row, int col) {
   Cuboid sq = getSquare(row, col);
   MaterialData squareHighlightColor = boardStyle.getHighlightMaterial(col + (row % 2) % 2 == 1);
   switch (boardStyle.getHighlightStyle()) {
     case EDGES:
       sq.getFace(CuboidDirection.East).fill(squareHighlightColor);
       sq.getFace(CuboidDirection.North).fill(squareHighlightColor);
       sq.getFace(CuboidDirection.West).fill(squareHighlightColor);
       sq.getFace(CuboidDirection.South).fill(squareHighlightColor);
       break;
     case CORNERS:
       for (Block b : sq.corners()) {
         b.setTypeIdAndData(
             squareHighlightColor.getItemTypeId(), squareHighlightColor.getData(), false);
       }
       break;
     case CHECKERED:
     case CHEQUERED:
       for (Block b : sq) {
         if ((b.getLocation().getBlockX() - b.getLocation().getBlockZ()) % 2 == 0) {
           b.setTypeIdAndData(
               squareHighlightColor.getItemTypeId(), squareHighlightColor.getData(), false);
         }
       }
       break;
     default:
       break;
   }
   if (ChessCraft.getInstance().getDynmapIntegration() != null) {
     ChessCraft.getInstance().getDynmapIntegration().triggerUpdate(sq);
   }
 }
Ejemplo n.º 7
0
  @Override
  public void changeBlock(Block block) {
    if (block.getTypeId() == match.getItemTypeId()
        && (match.getData() == 0 || block.getData() == match.getData())) {

      player.sendBlockChange(block.getLocation(), item.getItemType(), item.getData());
    }
  }
Ejemplo n.º 8
0
 private void writeMaterialData(final Object data) {
   final MaterialData matData = (MaterialData) data;
   writeMaterial(matData.getItemType());
   if (matData.getData() > 0) {
     writer.print(':');
     writer.print(matData.getData());
   }
 }
Ejemplo n.º 9
0
 public boolean giveItem(String name, int id, int quant, int data) throws Exception {
   try {
     byte realData = Byte.valueOf(String.valueOf(data));
     Player p = getPlayerExact(name);
     MaterialData materialData = new MaterialData(id, realData);
     p.getInventory().addItem(materialData.toItemStack(quant));
     p.saveData();
     return true;
   } catch (NullPointerException e) {
     return false;
   }
 }
  @Override
  public MagicMaterial resolveItem(String string) {
    if (string == null || string.isEmpty()) return null;

    // first check for predefined material datas
    MaterialData matData = materialDataMap.get(string.toLowerCase());
    if (matData != null) {
      if (matData.getItemType().isBlock()) {
        return new MagicBlockMaterial(matData);
      } else {
        return new MagicItemMaterial(matData);
      }
    }

    // split type and data
    String stype;
    String sdata;
    if (string.contains(":")) {
      String[] split = string.split(":", 2);
      stype = split[0].toLowerCase();
      sdata = split[1].toLowerCase();
    } else if (string.contains(" ")) {
      String[] split = string.split(" ", 2);
      sdata = split[0].toLowerCase();
      stype = split[1].toLowerCase();
    } else {
      stype = string.toLowerCase();
      sdata = "";
    }

    Material type = materialMap.get(stype);
    if (type == null) {
      return resolveUnknown(stype, sdata);
    }

    if (type.isBlock()) {
      return new MagicBlockMaterial(resolveBlockData(type, sdata));
    } else {
      if (sdata.equals("*")) return new MagicItemAnyDataMaterial(type);
      MaterialData itemData = resolveItemData(type, sdata);
      if (itemData != null) {
        return new MagicItemMaterial(itemData);
      }
      short durability = 0;
      try {
        durability = Short.parseShort(sdata);
      } catch (NumberFormatException e) {
        // DebugHandler.debugNumberFormat(e);
      }
      return new MagicItemMaterial(type, durability);
    }
  }
Ejemplo n.º 11
0
  @HawkEvent(dataType = {DataType.LAVA_FLOW, DataType.WATER_FLOW})
  public void onBlockFromTo(BlockFromToEvent event) {
    List<Integer> fluidBlocks =
        Arrays.asList(
            0, 27, 28, 31, 32, 37, 38, 39, 40, 50, 51, 55, 59, 66, 69, 70, 75, 76, 78, 93, 94);

    Location loc = event.getToBlock().getLocation();
    BlockState from = event.getBlock().getState();
    BlockState to = event.getToBlock().getState();
    MaterialData data = from.getData();

    // Lava
    if (from.getTypeId() == 10 || from.getTypeId() == 11) {

      // Flowing into a normal block
      if (fluidBlocks.contains(to.getTypeId())) {
        data.setData((byte) (from.getRawData() + 1));
        from.setData(data);
      }

      // Flowing into water
      else if (to.getTypeId() == 8 || to.getTypeId() == 9) {
        from.setTypeId(event.getFace() == BlockFace.DOWN ? 10 : 4);
        data.setData((byte) 0);
        from.setData(data);
      }
      DataManager.addEntry(new BlockChangeEntry("Environment", DataType.LAVA_FLOW, loc, to, from));

    }

    // Water
    else if (from.getTypeId() == 8 || from.getTypeId() == 9) {

      // Normal block
      if (fluidBlocks.contains(to.getTypeId())) {
        data.setData((byte) (from.getRawData() + 1));
        from.setData(data);
        DataManager.addEntry(
            new BlockChangeEntry("Environment", DataType.WATER_FLOW, loc, to, from));
      }

      // If we are flowing over lava, cobble or obsidian will form
      BlockState lower = event.getToBlock().getRelative(BlockFace.DOWN).getState();
      if (lower.getTypeId() == 10 || lower.getTypeId() == 11) {
        from.setTypeId(lower.getData().getData() == 0 ? 49 : 4);
        loc.setY(loc.getY() - 1);
        DataManager.addEntry(
            new BlockChangeEntry("Environment", DataType.WATER_FLOW, loc, lower, from));
      }
    }
  }
Ejemplo n.º 12
0
  /**
   * Checks if the block matches any one from the given material list.
   *
   * @param anchorBlock block to check relative to
   * @param initiator initiator
   * @return checkReturn if at least one block matches
   */
  public boolean check(Block anchorBlock, SagaPatternInitiator initiator) {

    for (int i = 0; i < checkMaterialData.length; i++) {
      MaterialData metadata =
          anchorBlock
              .getRelative(getxOffset(initiator), getyOffset(initiator), getzOffset(initiator))
              .getState()
              .getData();
      if (metadata.equals(checkMaterialData[i])) {
        return true;
      }
    }
    return false;
  }
Ejemplo n.º 13
0
  @SuppressWarnings("javadoc")
  @Deprecated
  public short parseDurability(final String string, final Material material) {
    try {
      return Short.parseShort(string);
    } catch (final NumberFormatException e) {
    }

    final String s = string.replace(' ', '_').toUpperCase();
    MaterialData data = null;

    try {
      switch (material) {
        case COAL:
          data = new Coal(CoalType.valueOf(s));
          break;
        case WOOD:
        case LOG:
          data = new Tree(TreeSpecies.valueOf(s));
          break;
        case LEAVES:
          data = new Leaves(TreeSpecies.valueOf(s));
          break;
        case STEP:
        case DOUBLE_STEP:
          data = new Step(Material.valueOf(s));
          break;
        case INK_SACK:
          data = new Dye();
          ((Dye) data).setColor(DyeColor.valueOf(s));
          break;
        case WOOL:
          data = new Wool(DyeColor.valueOf(s));
          break;
        case MONSTER_EGGS:
          data = new MonsterEggs(Material.valueOf(s));
          break;
        case SMOOTH_BRICK:
          data = new SmoothBrick(Material.valueOf(s));
          break;
        case SANDSTONE:
          data = new Sandstone(Material.valueOf(s));
      }
    } catch (final IllegalArgumentException e) {
    }

    return data == null ? 0 : (short) data.getData();
  } // */
Ejemplo n.º 14
0
  @Override
  public void placeBlock(
      GlowPlayer player,
      GlowBlockState state,
      BlockFace face,
      ItemStack holding,
      Vector clickedLoc) {
    super.placeBlock(player, state, face, holding, clickedLoc);

    // No Tree2 MaterialData
    MaterialData data = state.getData();

    data.setData(setTree(face, (byte) holding.getDurability()));

    state.setData(data);
  }
Ejemplo n.º 15
0
  public void setItemStack(int slot, ItemStack[] is) {
    BItemStack[] convert = new BItemStack[52];
    for (int i = 0; i < convert.length; i++) {
      if (is[i] == null) convert[i] = null;
      else {

        MaterialData data = is[i].getData();

        try {
          if (data == null)
            convert[i] =
                new BItemStack(
                    is[i].getTypeId(),
                    is[i].getAmount(),
                    is[i].getDurability(),
                    null,
                    is[i].getEnchantments());
          else
            convert[i] =
                new BItemStack(
                    is[i].getTypeId(),
                    is[i].getAmount(),
                    is[i].getDurability(),
                    data.getData(),
                    is[i].getEnchantments());
        } catch (NullPointerException e) {
          if (data == null)
            convert[i] =
                new BItemStack(
                    is[i].getTypeId(),
                    is[i].getAmount(),
                    is[i].getDurability(),
                    null,
                    new HashMap<Enchantment, Integer>());
          else
            convert[i] =
                new BItemStack(
                    is[i].getTypeId(),
                    is[i].getAmount(),
                    is[i].getDurability(),
                    data.getData(),
                    new HashMap<Enchantment, Integer>());
        }
      }
    }
    slots.put(slot, convert);
  }
Ejemplo n.º 16
0
  /**
   * Sets the MaterialData for this stack of items
   *
   * @param data New MaterialData for this item
   */
  public void setData(MaterialData data) {
    Material mat = getType();

    if (data == null || mat == null || mat.getData() == null) {
      this.data = data;
    } else {
      if ((data.getClass() == mat.getData()) || (data.getClass() == MaterialData.class)) {
        this.data = data;
      } else {
        throw new IllegalArgumentException(
            "Provided data is not of type "
                + mat.getData().getName()
                + ", found "
                + data.getClass().getName());
      }
    }
  }
Ejemplo n.º 17
0
  /**
   * Use Bresenham's algorithm to draw line between two squares on the board
   *
   * @param from Square index of the first square
   * @param to Square index of the second square
   * @param isHighlighting True if drawing a highlight, false if erasing it
   */
  private void drawHighlightLine(int from, int to, boolean isHighlighting) {
    if (from < 0 || to < 0 || from >= 64 || to >= 64) {
      return;
    }

    Cuboid s1 = getSquare(Chess.sqiToRow(from), Chess.sqiToCol(from));
    Cuboid s2 = getSquare(Chess.sqiToRow(to), Chess.sqiToCol(to));
    Location loc1 = s1.getRelativeBlock(s1.getSizeX() / 2, 0, s1.getSizeZ() / 2).getLocation();
    Location loc2 = s2.getRelativeBlock(s2.getSizeX() / 2, 0, s2.getSizeZ() / 2).getLocation();

    int dx = Math.abs(loc1.getBlockX() - loc2.getBlockX());
    int dz = Math.abs(loc1.getBlockZ() - loc2.getBlockZ());
    int sx = loc1.getBlockX() < loc2.getBlockX() ? 1 : -1;
    int sz = loc1.getBlockZ() < loc2.getBlockZ() ? 1 : -1;
    int err = dx - dz;

    while (loc1.getBlockX() != loc2.getBlockX() || loc1.getBlockZ() != loc2.getBlockZ()) {
      int sqi = getSquareAt(loc1);
      MaterialData m =
          isHighlighting
              ? boardStyle.getHighlightMaterial(Chess.isWhiteSquare(sqi))
              : (Chess.isWhiteSquare(sqi)
                  ? boardStyle.getWhiteSquareMaterial()
                  : boardStyle.getBlackSquareMaterial());
      loc1.getBlock().setTypeIdAndData(m.getItemTypeId(), m.getData(), false);
      int e2 = 2 * err;
      if (e2 > -dz) {
        err -= dz;
        loc1.add(sx, 0, 0);
      }
      if (e2 < dx) {
        err += dx;
        loc1.add(0, 0, sz);
      }
    }
  }
Ejemplo n.º 18
0
  @EventHandler
  public void onPlayerCommand(PlayerCommandPreprocessEvent evt) {

    Player p = evt.getPlayer();

    String fCmd = evt.getMessage();

    String cmd = fCmd.substring(1).split(" ", 1)[0];

    String[] args = fCmd.substring(cmd.length() + 1).split(" ");

    if (cmd.equalsIgnoreCase("startexport")) {

      p.sendMessage("Starting export!");

      bSets.put(p.getName(), new BlockSet());

      evt.setCancelled(true);

    } else if (cmd.equalsIgnoreCase("export")) {

      BlockSet bs = bSets.get(p.getName());

      if (bs == null) {

        p.sendMessage("You must first use the /startexport command!");

        evt.setCancelled(true);

        return;
      }

      p.sendMessage("Exporting...");

      List<NiceBlock> niceBlocks = new ArrayList<NiceBlock>();

      Vector firstBlock = bs.getFirstBlock();
      Vector secondBlock = bs.getSecondBlock();

      World w = p.getWorld();

      // http://forums.bukkit.org/threads/block-listed-within-cuboid-x-y-coodinates.103681/

      int topBlockX =
          (firstBlock.getBlockX() < secondBlock.getBlockX()
              ? secondBlock.getBlockX()
              : firstBlock.getBlockX());
      int bottomBlockX =
          (firstBlock.getBlockX() > secondBlock.getBlockX()
              ? secondBlock.getBlockX()
              : firstBlock.getBlockX());

      int topBlockY =
          (firstBlock.getBlockY() < secondBlock.getBlockY()
              ? secondBlock.getBlockY()
              : firstBlock.getBlockY());
      int bottomBlockY =
          (firstBlock.getBlockY() > secondBlock.getBlockY()
              ? secondBlock.getBlockY()
              : firstBlock.getBlockY());

      int topBlockZ =
          (firstBlock.getBlockZ() < secondBlock.getBlockZ()
              ? secondBlock.getBlockZ()
              : firstBlock.getBlockZ());
      int bottomBlockZ =
          (firstBlock.getBlockZ() > secondBlock.getBlockZ()
              ? secondBlock.getBlockZ()
              : firstBlock.getBlockZ());

      int xCtr = 0;

      for (int x = bottomBlockX; x <= topBlockX; x++) {

        int zCtr = 0;

        for (int z = bottomBlockZ; z <= topBlockZ; z++) {

          int yCtr = 0;

          for (int y = bottomBlockY; y <= topBlockY; y++) {

            Block b = w.getBlockAt(x, y, z);

            MaterialData data = b.getState().getData();

            NiceBlock nb = new NiceBlock(b.getTypeId(), xCtr, yCtr, zCtr, data.getData());

            niceBlocks.add(nb);

            yCtr++;
          }

          zCtr++;
        }

        xCtr++;
      }

      File exportFolder = new File("block_exports");

      if (!exportFolder.exists()) {
        exportFolder.mkdir();
      }

      try {

        File datFile = new File(exportFolder, "export.dat");

        if (!datFile.exists()) {
          datFile.createNewFile();
        }

        FileOutputStream fos = new FileOutputStream(datFile);

        ObjectOutputStream oos = new ObjectOutputStream(fos);

        oos.writeObject(niceBlocks);
        oos.close();

      } catch (Exception ex) {
        ex.printStackTrace();
      }

      p.sendMessage("Done!");

      bSets.remove(p.getName());

      evt.setCancelled(true);
    }
  }
  /**
   * Constructor.
   *
   * @param materialData The item {@link MaterialData}.
   */
  public ItemStackBuilder(MaterialData materialData) {
    PreCon.notNull(materialData);

    _materialData = materialData.clone();
  }
  /**
   * Set the meta magic value.
   *
   * @param meta The meta magic value.
   * @return Self for chaining.
   */
  public ItemStackBuilder meta(int meta) {
    _materialData.setData((byte) meta);

    return this;
  }
Ejemplo n.º 21
0
 @Override
 public void setBlock(int x, int y, int z, MaterialData material) {
   setBlock(x, y, z, material.getItemTypeId(), material.getData());
 }
Ejemplo n.º 22
0
 @Override
 public void setRegion(
     int xMin, int yMin, int zMin, int xMax, int yMax, int zMax, MaterialData material) {
   setRegion(xMin, yMin, zMin, xMax, yMax, zMax, material.getItemTypeId(), material.getData());
 }
 @Override
 public boolean equals(MaterialData matData) {
   return matData.getItemTypeId() == type && matData.getData() == data;
 }