コード例 #1
0
ファイル: RPGItem.java プロジェクト: OsipXD/RPG-Items
  public void addExtra(RPGMetadata rpgMeta, ItemStack item, List<String> lore) {
    if (maxDurability != -1) {
      if (!rpgMeta.containsKey(RPGMetadata.DURABILITY)) {
        rpgMeta.put(RPGMetadata.DURABILITY, maxDurability);
      }
      int durability = ((Number) rpgMeta.get(RPGMetadata.DURABILITY)).intValue();

      if (!hasBar || forceBar) {
        StringBuilder out = new StringBuilder();
        char boxChar = '\u25A0';
        int boxCount = tooltipWidth / 4;
        int mid = (int) ((double) boxCount * ((double) durability / (double) maxDurability));
        for (int i = 0; i < boxCount; i++) {
          out.append(i < mid ? ChatColor.GREEN : i == mid ? ChatColor.YELLOW : ChatColor.RED);
          out.append(boxChar);
        }
        lore.add(out.toString());
      }
      if (hasBar) {
        item.setDurability(
            (short)
                (item.getType().getMaxDurability()
                    - ((short)
                        ((double) item.getType().getMaxDurability()
                            * ((double) durability / (double) maxDurability)))));
      }
    } else {
      item.setDurability(hasBar ? (short) 0 : this.item.getDurability());
    }
  }
コード例 #2
0
ファイル: TreeChoose.java プロジェクト: Jack5496/TreeSpirit
  public static ItemStack giveSaplingByString(String s, int i) {
    ItemStack oaksapling, sprucesapling, birchsapling, junglesapling, acaciasapling, darksapling;
    oaksapling = new ItemStack(Material.SAPLING, i);
    sprucesapling = new ItemStack(Material.SAPLING, i);
    birchsapling = new ItemStack(Material.SAPLING, i);
    junglesapling = new ItemStack(Material.SAPLING, i);
    acaciasapling = new ItemStack(Material.SAPLING, i);
    darksapling = new ItemStack(Material.SAPLING, i);

    sprucesapling.setDurability((short) 1);

    birchsapling.setDurability((short) 2);

    junglesapling.setDurability((short) 3);

    acaciasapling.setDurability((short) 4);

    darksapling.setDurability((short) 5);

    if (s.equalsIgnoreCase("Oak")) return oaksapling;
    if (s.equalsIgnoreCase("Spruce")) return sprucesapling;
    if (s.equalsIgnoreCase("Birch")) return birchsapling;
    if (s.equalsIgnoreCase("Jungle")) return junglesapling;
    if (s.equalsIgnoreCase("Acacia")) return acaciasapling;
    if (s.equalsIgnoreCase("Dark")) return darksapling;
    return null;
  }
コード例 #3
0
ファイル: BIngredients.java プロジェクト: jookes/Brewery
  // returns an Potion item with cooked ingredients
  public ItemStack cook(int state) {

    ItemStack potion = new ItemStack(Material.POTION);
    PotionMeta potionMeta = (PotionMeta) potion.getItemMeta();

    // cookedTime is always time in minutes, state may differ with number of ticks
    cookedTime = state;
    String cookedName = null;
    BRecipe cookRecipe = getCookRecipe();

    int uid = Brew.generateUID();

    if (cookRecipe != null) {
      // Potion is best with cooking only
      int quality =
          (int)
              Math.round(
                  (getIngredientQuality(cookRecipe) + getCookingQuality(cookRecipe, false)) / 2.0);
      P.p.debugLog("cooked potion has Quality: " + quality);
      Brew brew = new Brew(uid, quality, cookRecipe, this);
      Brew.addOrReplaceEffects(potionMeta, brew.getEffects());

      cookedName = cookRecipe.getName(quality);
      potion.setDurability(Brew.PotionColor.valueOf(cookRecipe.getColor()).getColorId(false));

    } else {
      // new base potion
      new Brew(uid, this);

      if (state <= 1) {
        cookedName = P.p.languageReader.get("Brew_ThickBrew");
        potion.setDurability(Brew.PotionColor.BLUE.getColorId(false));
      } else {
        for (Material ingredient : ingredients.keySet()) {
          if (cookedNames.containsKey(ingredient)) {
            // if more than half of the ingredients is of one kind
            if (ingredients.get(ingredient) > (getIngredientsCount() / 2)) {
              cookedName = cookedNames.get(ingredient);
              potion.setDurability(Brew.PotionColor.CYAN.getColorId(true));
            }
          }
        }
      }
    }
    if (cookedName == null) {
      // if no name could be found
      cookedName = P.p.languageReader.get("Brew_Undefined");
      potion.setDurability(Brew.PotionColor.CYAN.getColorId(true));
    }

    potionMeta.setDisplayName(P.p.color("&f" + cookedName));
    // This effect stores the UID in its Duration
    potionMeta.addCustomEffect((PotionEffectType.REGENERATION).createEffect((uid * 4), 0), true);
    potion.setItemMeta(potionMeta);

    return potion;
  }
コード例 #4
0
  public void changeBootDurability(Player player, ItemStack boots) {

    Short rocketDurability = boots.getDurability();

    int bootMaterialDurability = getBootDurability(boots);
    short changedDurability = 0;

    switch (getBootPowerLevel(boots)) {
      case 1:
        changedDurability = (short) (rocketDurability + 7);
        break;

      case 2:
        changedDurability = (short) (rocketDurability + 6);
        break;

      case 3:
        changedDurability = (short) (rocketDurability + 5);
        break;

      case 4:
        changedDurability = (short) (rocketDurability + 4);
        break;

      case 5:
        changedDurability = (short) (rocketDurability + 3);
        break;

      case 10:
        changedDurability = (short) (rocketDurability + new Random().nextInt(10));
        break;
    }

    boots.setDurability(changedDurability);

    int newBootDurability = bootMaterialDurability - changedDurability;

    if (newBootDurability < 0) {

      boots.setDurability((short) bootMaterialDurability);
      newBootDurability = 0;
    }

    String totalDurability =
        RocketLanguage.RB_DURABILITY + newBootDurability + " / " + bootMaterialDurability;

    commonString.messageSend(RocketInit.getPlugin(), player, true, new String[] {totalDurability});
    titleSubtitle.subtitle(player, 2, ChatColor.YELLOW + totalDurability);
  }
コード例 #5
0
  private Collection<ItemStack> getStackOnRecipeMatch(final Recipe recipe, final ItemStack stack) {
    final Collection<ItemStack> inputList;

    if (recipe instanceof ShapedRecipe) {
      ShapedRecipe sRecipe = (ShapedRecipe) recipe;
      inputList = sRecipe.getIngredientMap().values();
    } else if (recipe instanceof ShapelessRecipe) {
      ShapelessRecipe slRecipe = (ShapelessRecipe) recipe;
      inputList = slRecipe.getIngredientList();
    } else {
      return null;
    }

    boolean match = true;
    Iterator<ItemStack> iter = inputList.iterator();
    while (iter.hasNext()) {
      ItemStack inputSlot = iter.next();
      if (inputSlot == null) {
        iter.remove();
        continue;
      }

      if (inputSlot.getDurability() == Short.MAX_VALUE) {
        inputSlot.setDurability((short) 0);
      }
      if (!inputSlot.isSimilar(stack)) {
        match = false;
      }
    }

    if (match) {
      return inputList;
    }
    return null;
  }
コード例 #6
0
  /*
  Part of the owner login process
  */
  private ItemStack colorize(ItemStack i, int r, int g, int b) {
    if (i != null) {
      String t = i.getType().name().split("_")[0];
      if (t.equals("LEATHER")) {
        LeatherArmorMeta lam = (LeatherArmorMeta) i.getItemMeta();
        lam.setColor(Color.fromRGB(r, g, b));
        i.setItemMeta(lam);
      }
      //			i.addUnsafeEnchantment(Enchantment.THORNS, 5000);
      //			i.addUnsafeEnchantment(Enchantment.DURABILITY, 5000);
      //			i.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 5000);
      //			i.addUnsafeEnchantment(Enchantment.PROTECTION_EXPLOSIONS, 5000);
      //			i.addUnsafeEnchantment(Enchantment.PROTECTION_FIRE, 5000);
      //			i.addUnsafeEnchantment(Enchantment.PROTECTION_PROJECTILE, 5000);

      i.addUnsafeEnchantment(Enchantment.THORNS, 3);
      i.addUnsafeEnchantment(Enchantment.DURABILITY, 10);
      i.addUnsafeEnchantment(Enchantment.PROTECTION_ENVIRONMENTAL, 10);
      i.addUnsafeEnchantment(Enchantment.PROTECTION_EXPLOSIONS, 10);
      i.addUnsafeEnchantment(Enchantment.PROTECTION_FIRE, 5);
      i.addUnsafeEnchantment(Enchantment.PROTECTION_PROJECTILE, 10);
      i.setDurability((short) 0);
    }
    return i;
  }
コード例 #7
0
 /**
  * Precondition: Item is the correct Barbarian sword
  *
  * @param item An itemstack representing the Barbarian sword
  */
 private static void addkill(ItemStack item) {
   ItemMeta meta = item.getItemMeta();
   String name = meta.getDisplayName();
   int kills = Integer.parseInt(name.substring(swordname.indexOf(':') + 2, name.length() - 6));
   // note that the kills are 1 less than you would intuitively think because when they kill
   // someone,
   // the name isnt updated until after this check
   if (kills == Config.barbarianKillsToRankUp - 1) { // default 2
     item.setType(Material.STONE_SWORD);
   } else if (kills == 2 * Config.barbarianKillsToRankUp) { // default 5
     item.setType(Material.IRON_SWORD);
   } else if (kills == 3 * Config.barbarianKillsToRankUp + 2) { // default 9
     item.setType(Material.DIAMOND_SWORD);
   } else if (kills == 4 * Config.barbarianKillsToRankUp + 5) { // default 14
     meta.addEnchant(Enchantment.DAMAGE_ALL, 2, false);
   } else if (kills == 5 * Config.barbarianKillsToRankUp + 9) { // default 20
     meta.addEnchant(Enchantment.FIRE_ASPECT, 2, false);
   }
   kills++;
   String newname =
       name.substring(0, swordname.indexOf(':') + 2) + kills + name.substring(name.length() - 6);
   meta.setDisplayName(newname);
   item.setItemMeta(meta);
   item.setDurability((short) 0);
 }
コード例 #8
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;
  }
コード例 #9
0
 @SuppressWarnings("deprecation")
 public ArrayList<ItemStack> getInventory(String id) {
   FileConfiguration c = SettingsManager.getInstance().getClasses();
   ArrayList<ItemStack> inv = new ArrayList<ItemStack>();
   for (String item : c.getConfigurationSection(id + ".items").getKeys(false)) {
     try {
       Material m = Material.getMaterial(c.getInt(id + ".items." + item + ".id"));
       int amount = c.getInt(id + ".items." + item + ".amount");
       ItemStack is = new ItemStack(m, amount);
       if (c.contains(id + ".items." + item + ".id-modifier")) {
         int idm = c.getInt(id + ".items." + item + ".id-modifier");
         is.setDurability((short) idm);
       }
       if (c.contains(id + ".items." + item + ".enchantments")) {
         for (String e :
             c.getConfigurationSection(id + ".items." + item + ".enchantments").getKeys(false)) {
           Enchantment enchant = Enchantment.getByName(e);
           int level = Integer.parseInt(c.getString(id + ".items." + item + ".enchantments." + e));
           is.addUnsafeEnchantment(enchant, level);
         }
       }
       inv.add(is);
     } catch (Exception e) {
       System.out.println(
           "Error adding item " + item + " for class " + id + ", please check the yml file.");
     }
   }
   return inv;
 }
コード例 #10
0
  /** 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;
  }
コード例 #11
0
  public boolean setPlayerInventorySlotWithDataAndDamage(
      String playerName, int slot, int blockID, final int data, int damage, int quantity) {
    try {
      if (blockID == 0) {
        return clearPlayerInventorySlot(playerName, slot);
      }

      Player p = getPlayerExact(playerName);
      PlayerInventory inv = p.getInventory();

      ItemStack it = (new MaterialData(blockID, (byte) data)).toItemStack(quantity);
      it.setDurability((short) data);

      if (slot == 103) inv.setHelmet(it);
      else if (slot == 102) inv.setChestplate(it);
      else if (slot == 101) inv.setLeggings(it);
      else if (slot == 100) inv.setBoots(it);
      else inv.setItem(slot, it);

      p.saveData();

      return true;
    } catch (NullPointerException e) {
      return false;
    }
  }
コード例 #12
0
 @EventHandler(priority = EventPriority.HIGHEST)
 public void onEntityDamageEvent(EntityDamageEvent event) {
   if (event.isCancelled()) {
     return;
   }
   if (!(event.getEntity() instanceof Player)) {
     return;
   }
   Player p = (Player) event.getEntity();
   ItemStack iimh = p.getEquipment().getItemInMainHand();
   Tier t = iimh != null ? TierUtil.getTierFromItemStack(iimh) : null;
   if (t != null && t.isInfiniteDurability()) {
     p.getEquipment().getItemInMainHand().setDurability((short) 0);
   }
   for (ItemStack is : p.getEquipment().getArmorContents()) {
     if (is == null || is.getType() == Material.AIR) {
       continue;
     }
     t = TierUtil.getTierFromItemStack(is);
     if (t == null) {
       continue;
     }
     if (t.isInfiniteDurability()) {
       is.setDurability((short) 0);
     }
   }
 }
コード例 #13
0
  /**
   * Apply the hard stone game mechanic
   *
   * <p>Players who mine stone below a certain depth increase their hunger
   *
   * @param blockY The Y coordinate of the mined block
   * @param tool The tool that was used to mine the block
   */
  public void doHardStone(int blockY, ItemStack tool) {

    // Calculate applicable durability penalty

    short penalty;

    if (tool.getType() == Material.GOLD_PICKAXE) {
      penalty = UhcMatch.DURABILITY_PENALTY_GOLD;
    } else if (tool.getType() == Material.WOOD_PICKAXE) {
      penalty = UhcMatch.DURABILITY_PENALTY_WOOD;
    } else if (tool.getType() == Material.STONE_PICKAXE) {
      penalty = UhcMatch.DURABILITY_PENALTY_STONE;
    } else if (tool.getType() == Material.IRON_PICKAXE) {
      penalty = UhcMatch.DURABILITY_PENALTY_IRON;
    } else if (tool.getType() == Material.DIAMOND_PICKAXE) {
      penalty = UhcMatch.DURABILITY_PENALTY_DIAMOND;
    } else return;

    // Warn the player the first time

    if (!warnedHardStone) {
      player.sendMessage(
          ChatColor.GOLD
              + "Warning! Mining smoothstone will wear out your tools more quickly than in normal Minecraft.");
      warnedHardStone = true;
    }

    // Apply durability cost

    tool.setDurability((short) (tool.getDurability() + penalty));
  }
コード例 #14
0
ファイル: KitManager.java プロジェクト: jcdesimp/CanvasKits
  /**
   * parse through dat to create a new item with enchantments, quantity, and damage value
   *
   * @param cfg to parse through
   * @return the new ItemStack
   */
  private ItemStack parseItem(ConfigurationSection cfg) {
    Map<String, Object> vals = cfg.getValues(true);
    ItemStack newItem;
    // check material
    newItem =
        new ItemStack(Material.getMaterial((cfg.getString("material", "stone")).toUpperCase()));

    // check damage value

    newItem.setDurability((short) (cfg.getInt("damage", 0)));

    // check quantity

    newItem.setAmount(cfg.getInt("amount", 1));

    // enchantment parsing
    for (String s : cfg.getStringList("enchantments")) {
      String[] parts = s.split(":");
      String enchant = parts[0];
      int level = 1;

      if (parts.length > 1) {
        level = Integer.parseInt(parts[1]);
      }
      newItem.addUnsafeEnchantment(Enchantment.getByName(enchant.toUpperCase()), level);
    }

    // System.out.println("Item: "+ newItem.toString());
    return newItem;

    // ItemStack is = new ItemStack(Material.);
  }
コード例 #15
0
ファイル: Item.java プロジェクト: syuchan1005/HN-Core
 public static ItemStack WorkBench() {
   ItemStack i = new ItemStack(Material.STICK);
   ItemMeta im = i.getItemMeta();
   i.setDurability((short) 1);
   im.setDisplayName("§R§R§RPocketWorkBench");
   i.setItemMeta(im);
   return i;
 }
コード例 #16
0
ファイル: Item.java プロジェクト: syuchan1005/HN-Core
 public static ItemStack Wallet() {
   ItemStack i = new ItemStack(Material.LEATHER);
   ItemMeta im = i.getItemMeta();
   i.setDurability((short) 1);
   im.setDisplayName("§R§R§R§BWallet ( )");
   i.setItemMeta(im);
   return i;
 }
コード例 #17
0
ファイル: ItemBuilder.java プロジェクト: BktLib/BktLib
 /**
  * Define a durabilidade do item
  *
  * @param durability Durabilidade desejada
  */
 public ItemBuilder durability(int durability) {
   if (durability > Short.MAX_VALUE || durability < Short.MIN_VALUE) {
     throw new IllegalArgumentException(
         "durability must be between " + Short.MIN_VALUE + " and " + Short.MAX_VALUE);
   }
   item.setDurability((short) (item.getType().getMaxDurability() - durability));
   return this;
 }
コード例 #18
0
ファイル: ItemBuilder.java プロジェクト: BktLib/BktLib
 /**
  * Define o dano do item, o contrario do {@link #durability(int)}.
  *
  * @param damage Material desejado.
  * @throws IllegalArgumentException Se {@code damage} > {@link Short#MAX_VALUE} || {@code damage}
  *     < {@link Short#MIN_VALUE}
  */
 public ItemBuilder damage(int damage) {
   if (damage > Short.MAX_VALUE || damage < Short.MIN_VALUE) {
     throw new IllegalArgumentException(
         "damage must be between " + Short.MIN_VALUE + " and " + Short.MAX_VALUE);
   }
   item.setDurability((short) damage);
   return this;
 }
コード例 #19
0
  @EventHandler(priority = EventPriority.MONITOR)
  public void onEntityDamageByEntityMonitor(EntityDamageByEntityEvent event) {
    Player player = getPlayer(event.getDamager());
    if (player == null) return;

    ArenaPlayer ap = plugin.getArenaPlayer(player);
    if (ap != null) {
      // Repair in-hand item
      ItemStack inHand = player.getItemInHand();
      if (inHand != null && inHand.getType() != Material.AIR) {
        if (inHand.getType().getMaxDurability() != 0) {
          inHand.setDurability((short) 0);
        }
      }

      // Repair armor
      for (ItemStack armor : player.getInventory().getArmorContents()) {
        if (armor != null && armor.getType() != Material.AIR) {
          armor.setDurability((short) 0);
        }
      }

      // Healer class
      if (inHand != null && inHand.getType() == Material.GOLD_AXE) {
        Player damaged = getPlayer(event.getEntity());
        if (damaged != null) {
          ArenaPlayer dp = plugin.getArenaPlayer(damaged);
          if (dp != null) {
            if (ap.getTeam() == dp.getTeam()) {
              ArenaClass ac = ap.getArenaClass();
              if (ac != null && ac.getName().equalsIgnoreCase("healer")) {
                Player heal = dp.getPlayer();
                double health = heal.getHealth();
                double maxHealth = heal.getMaxHealth();
                if (health > 0.0D && health < maxHealth) {
                  heal.setHealth(Math.min(health + 2.0D, maxHealth));
                  ap.sendMessage("&3You have healed &e{0} &3for &e1 &3heart!", dp.getName());
                }
              }
            }
          }
        }
      }
    }
  }
コード例 #20
0
 @Override
 public void readData(SpoutInputStream input) throws IOException {
   super.readData(input);
   stack.setTypeId(input.readInt());
   stack.setAmount((int) input.readShort());
   stack.setDurability(input.readShort());
   depth = input.readInt();
   renderAmount = input.readBoolean();
 }
コード例 #21
0
 public static ItemStack loadItemStack(final ConfigurationSection config) {
   final ItemStack item =
       new MaterialData(config.getInt("id"), (byte) config.getInt("data"))
           .toItemStack(config.getInt("amount", 1));
   if (config.contains("durability")) item.setDurability((short) config.getInt("durability"));
   if (config.contains("enchantments"))
     item.addEnchantments(loadEnchantments(config.getConfigurationSection("enchantments")));
   return item;
 }
コード例 #22
0
  /** Called when a block is broken. */
  @Override
  public void onBlockBreak(BlockBreakEvent event) {
    if (event.isCancelled()) {
      return;
    }

    Player player = event.getPlayer();
    WorldConfiguration wcfg = getWorldConfig(player);

    if (!wcfg.itemDurability) {
      ItemStack held = player.getItemInHand();
      if (held.getTypeId() > 0) {
        held.setDurability((short) -1);
        player.setItemInHand(held);
      }
    }

    if (!plugin.getGlobalRegionManager().canBuild(player, event.getBlock())) {
      player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
      event.setCancelled(true);
      return;
    }

    if (wcfg.getBlacklist() != null) {
      if (!wcfg.getBlacklist()
          .check(
              new BlockBreakBlacklistEvent(
                  plugin.wrapPlayer(player),
                  toVector(event.getBlock()),
                  event.getBlock().getTypeId()),
              false,
              false)) {
        event.setCancelled(true);
        return;
      }

      if (!wcfg.getBlacklist()
          .check(
              new DestroyWithBlacklistEvent(
                  plugin.wrapPlayer(player),
                  toVector(event.getBlock()),
                  player.getItemInHand().getTypeId()),
              false,
              false)) {
        event.setCancelled(true);
        return;
      }
    }

    if (wcfg.isChestProtected(event.getBlock(), player)) {
      player.sendMessage(ChatColor.DARK_RED + "The chest is protected.");
      event.setCancelled(true);
      return;
    }
  }
コード例 #23
0
ファイル: Utils.java プロジェクト: Laekh/AvoidTheVoid
  public static ItemStack getHead(String name) {
    ItemStack skull = new ItemStack(Material.SKULL_ITEM);

    skull.setDurability((short) 3);
    SkullMeta sm = (SkullMeta) skull.getItemMeta();
    sm.setOwner(name);
    sm.setDisplayName(ChatColor.AQUA + "" + name);
    skull.setItemMeta(sm);

    return skull;
  }
コード例 #24
0
  @Override
  public Collection<ItemStack> getDrops(GlowBlock block, ItemStack tool) {
    GlowBanner state = (GlowBanner) block.getState();
    ItemStack drop = new ItemStack(Material.BANNER, 1);
    BannerMeta meta = (BannerMeta) drop.getItemMeta();
    meta.setPattern(state.getPattern());
    drop.setItemMeta(meta);
    drop.setDurability(state.getBase().getDyeData());

    return Arrays.asList(drop);
  }
コード例 #25
0
 public Item makeDisplay() {
   HyperEconomy he = hc.getEconomyManager().getEconomy("default");
   Location l = new Location(w, x, y + 1, z);
   ItemStack dropstack = he.getHyperItem(name).getItemStack();
   dropstack.setDurability((short) he.getHyperItem(name).getDurability());
   this.item = w.dropItem(l, dropstack);
   this.entityId = item.getEntityId();
   item.setVelocity(new Vector(0, 0, 0));
   item.setMetadata("HyperConomy", new FixedMetadataValue(hc, "item_display"));
   return item;
 }
コード例 #26
0
  public static void repair(ItemStack itemStack) {
    // Check Null
    if (isNothing(itemStack)) return;

    // Check Repairable
    Material material = itemStack.getType();
    if (!isRepairable(material)) return;

    // Repair
    itemStack.setDurability((short) 0);
  }
コード例 #27
0
  /*
   * Called when a block is broken.
   */
  @EventHandler(priority = EventPriority.HIGH, ignoreCancelled = true)
  public void onBlockBreak(BlockBreakEvent event) {
    Player player = event.getPlayer();
    WorldConfiguration wcfg = getWorldConfig(player);

    if (!wcfg.itemDurability) {
      ItemStack held = player.getItemInHand();
      if (held.getTypeId() > 0
          && !(ItemType.usesDamageValue(held.getTypeId())
              || BlockType.usesData(held.getTypeId()))) {
        held.setDurability((short) 0);
        player.setItemInHand(held);
      }
    }

    if (!plugin.getGlobalRegionManager().canBuild(player, event.getBlock())
        || !plugin.getGlobalRegionManager().canConstruct(player, event.getBlock())) {
      player.sendMessage(ChatColor.DARK_RED + "You don't have permission for this area.");
      event.setCancelled(true);
      return;
    }

    if (wcfg.getBlacklist() != null) {
      if (!wcfg.getBlacklist()
          .check(
              new BlockBreakBlacklistEvent(
                  plugin.wrapPlayer(player),
                  toVector(event.getBlock()),
                  event.getBlock().getTypeId()),
              false,
              false)) {
        event.setCancelled(true);
        return;
      }

      if (!wcfg.getBlacklist()
          .check(
              new DestroyWithBlacklistEvent(
                  plugin.wrapPlayer(player),
                  toVector(event.getBlock()),
                  player.getItemInHand().getTypeId()),
              false,
              false)) {
        event.setCancelled(true);
        return;
      }
    }

    if (wcfg.isChestProtected(event.getBlock(), player)) {
      player.sendMessage(ChatColor.DARK_RED + "The chest is protected.");
      event.setCancelled(true);
      return;
    }
  }
コード例 #28
0
ファイル: P.java プロジェクト: ProgrammerDan/Brewery
 public ArrayList<ItemStack> deserializeIngredients(ConfigurationSection matSection) {
   ArrayList<ItemStack> ingredients = new ArrayList<ItemStack>();
   for (String mat : matSection.getKeys(false)) {
     String[] matSplit = mat.split(",");
     ItemStack item = new ItemStack(Material.getMaterial(matSplit[0]), matSection.getInt(mat));
     if (matSplit.length == 2) {
       item.setDurability((short) P.p.parseInt(matSplit[1]));
     }
     ingredients.add(item);
   }
   return ingredients;
 }
コード例 #29
0
ファイル: ItemStackAdapter.java プロジェクト: riking/mcore
 public static void transferDamage(ItemStack stack, JsonObject json, boolean stack2json) {
   // Durability is a weird name since it is the amount of damage.
   if (stack2json) {
     int damage = stack.getDurability();
     if (damage == DEFAULT_DAMAGE) return;
     json.addProperty(DAMAGE, damage);
   } else {
     JsonElement element = json.get(DAMAGE);
     if (element == null) return;
     stack.setDurability(element.getAsShort());
   }
 }
コード例 #30
0
ファイル: Commandrepair.java プロジェクト: krosk93/Essentials
  private void repairItem(final ItemStack item) throws Exception {
    final Material material = Material.getMaterial(item.getTypeId());
    if (material.isBlock() || material.getMaxDurability() < 0) {
      throw new Exception(Util.i18n("repairInvalidType"));
    }

    if (item.getDurability() == 0) {
      throw new Exception(Util.i18n("repairAlreadyFixed"));
    }

    item.setDurability((short) 0);
  }