@Override @Utility public String toString() { StringBuilder toString = new StringBuilder("ItemStack{").append(getType().name()).append(" x ").append(getAmount()); if (hasItemMeta()) { toString.append(", ").append(getItemMeta()); } return toString.append('}').toString(); }
@Override public List<String> tabCompleteInternalMaterialName(String token, List<String> completions) { List<String> materialNames = new ArrayList<>(Material.values().length); for (Material mat : Material.values()) { materialNames.add(mat.name().toLowerCase()); } return StringUtil.copyPartialMatches(token, materialNames, completions); }
@Utility public Map<String, Object> serialize() { Map<String, Object> result = new LinkedHashMap<String, Object>(); result.put("type", getType().name()); if (getDurability() != 0) { result.put("damage", getDurability()); } if (getAmount() != 1) { result.put("amount", getAmount()); } ItemMeta meta = getItemMeta(); if (!Bukkit.getItemFactory().equals(meta, null)) { result.put("meta", meta); } return result; }
/** * Calculate total defense of a suit of armor. * * @param armor all armor items worn * @return the total defense */ public static int getDefense(ItemStack[] armor) { int defense = 0; for (ItemStack stack : armor) { if (InventoryUtil.isEmpty(stack)) { continue; } try { ArmorConstants constant = valueOf(stack.getType().name()); defense += constant.getDefense(); } catch (IllegalArgumentException ex) { continue; } } return defense; }
/** * Calculate total toughness of a suit of armor. * * @param armor all armor items worn * @return the total toughness */ public static int getToughness(ItemStack[] armor) { int toughness = 0; for (ItemStack stack : armor) { if (InventoryUtil.isEmpty(stack)) { continue; } try { ArmorConstants constant = valueOf(stack.getType().name()); toughness += constant.getToughness(); } catch (IllegalArgumentException ex) { continue; } } return toughness; } }
public static String fromMaterial(Material material) { if (material == null) return ""; return material.name().toLowerCase(); }
private boolean isBanned(Material type) { switch (type) { case ENDER_PEARL: case ENDER_CHEST: case SHULKER_SHELL: return true; } return type.name().endsWith("_SHULKER_BOX"); } }
/** * Determines whether the used material is a firework. * * @param material * @return true if the material is a firework, false otherwise */ private boolean isFirework(Material material) { return serverVersion >= 13 ? material == Material.FIREWORK_ROCKET : "FIREWORK".equals(material.name()); }
public double getContribution(Material fuelType) { if (contributionMap.containsKey(fuelType)) { return contributionMap.get(fuelType); } else { throw new NullPointerException(String.format("No contribution defined in the model for: [%s]", fuelType.name())); } } }
@Nullable @Override public String getBaseName() { if (material == null) { return null; } return material.name().toLowerCase().replace('_', ' '); }
public double getReduction(Material block) { if (reductionMap.containsKey(block)) { return reductionMap.get(block); } else { GlobalWarming.getInstance().getLogger().warning(String.format("No reduction defined in the model for: [%s]", block.name())); return 0; } } }
@Override public JsonElement serialize(WrappedBlockData src, Type typeOfSrc, JsonSerializationContext context) { JsonObject obj = new JsonObject(); obj.addProperty("type", src.getType().name()); obj.addProperty("data", src.getData()); return obj; }
public void write(CityWorldGenerator generator, ConfigurationSection section) { List<String> names = new ArrayList<String>(); if (items != null) { for (ItemStack item : items) { names.add(item.getType().name()); } } section.set(listName, names); }
@Override @Utility public String toString() { StringBuilder toString = new StringBuilder("ItemStack{").append(getType().name()).append(" x ").append(getAmount()); if (hasItemMeta()) { toString.append(", ").append(getItemMeta()); } return toString.append('}').toString(); }
private static JsonObject convertItemToJSON(ItemStack item) { JsonObject itemJSON = new JsonObject(); itemJSON.addProperty("item", "minecraft:" + item.getType().name().toLowerCase()); itemJSON.addProperty("amount", item.getAmount()); itemJSON.addProperty("data", item.getData().getData()); return itemJSON; }
@Override public String toString() { if (item != null) { return item.getType().name() + ":" + amount; } if (currency != null) { return currency.getKey() + ":" + amount; } return "Unknown Cost:" + amount; }
public static int getBlockPlaceHash(final Block block, final Material mat) { int hash = getCoordHash(block); if (mat != null) { hash |= mat.name().hashCode(); } hash |= block.getWorld().getName().hashCode(); return hash; }
private String getName() { ItemMeta meta = stack.getItemMeta(); if (meta.hasDisplayName()) { return meta.getDisplayName(); } return stack.getType() .name() .replace("_", " ") .toLowerCase(); } }
@Override public MCDyeColor getBaseColor() { DyeColor c = b.getBaseColor(); if(c != null) { return BukkitMCDyeColor.getConvertor().getAbstractedEnum(c); } // fallback method in case basecolor is incorrectly null return MCDyeColor.valueOf(b.getType().name().replace("_BANNER", "")); }