Here are the examples of the java api @org.bukkit.Utility taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
20 Examples
19
View Complete Implementation : ItemStack.java
Copyright GNU General Public License v3.0
Author : Bukkit
Copyright GNU General Public License v3.0
Author : Bukkit
/**
* Adds the specified enchantments to this item stack in an unsafe manner.
* <p>
* This method is the same as calling {@link
* #addUnsafeEnchantment(org.bukkit.enchantments.Enchantment, int)} for
* each element of the map.
*
* @param enchantments Enchantments to add
*/
@Utility
public void addUnsafeEnchantments(Map<Enchantment, Integer> enchantments) {
for (Map.Entry<Enchantment, Integer> entry : enchantments.entrySet()) {
addUnsafeEnchantment(entry.getKey(), entry.getValue());
}
}
19
View Complete Implementation : ItemStack.java
Copyright GNU General Public License v3.0
Author : Bukkit
Copyright GNU General Public License v3.0
Author : Bukkit
/**
* Gets the type of this item
*
* @return Type of the items in this stack
*/
@Utility
public Material getType() {
return getType0(getTypeId());
}
19
View Complete Implementation : ItemStack.java
Copyright GNU General Public License v3.0
Author : Bukkit
Copyright GNU General Public License v3.0
Author : Bukkit
/**
* This method is the same as equals, but does not consider stack size
* (amount).
*
* @param stack the item stack to compare to
* @return true if the two stacks are equal, ignoring the amount
*/
@Utility
public boolean isSimilar(ItemStack stack) {
if (stack == null) {
return false;
}
if (stack == this) {
return true;
}
return getTypeId() == stack.getTypeId() && getDurability() == stack.getDurability() && hasItemMeta() == stack.hasItemMeta() && (hasItemMeta() ? Bukkit.gereplacedemFactory().equals(gereplacedemMeta(), stack.gereplacedemMeta()) : true);
}
19
View Complete Implementation : ItemStack.java
Copyright GNU Lesser General Public License v3.0
Author : GMatrixGames
Copyright GNU Lesser General Public License v3.0
Author : GMatrixGames
/**
* Adds the specified enchantments to this item stack.
* <p>
* This method is the same as calling {@link
* #addEnchantment(Enchantment, int)} for each
* element of the map.
*
* @param enchantments Enchantments to add
* @throws IllegalArgumentException if the specified enchantments is null
* @throws IllegalArgumentException if any specific enchantment or level
* is null. <b>Warning</b>: Some enchantments may be added before this
* exception is thrown.
*/
@Utility
public void addEnchantments(Map<Enchantment, Integer> enchantments) {
Validate.notNull(enchantments, "Enchantments cannot be null");
for (Map.Entry<Enchantment, Integer> entry : enchantments.entrySet()) {
addEnchantment(entry.getKey(), entry.getValue());
}
}
19
View Complete Implementation : ItemStack.java
Copyright GNU Lesser General Public License v3.0
Author : GMatrixGames
Copyright GNU Lesser General Public License v3.0
Author : GMatrixGames
/**
* Adds the specified enchantments to this item stack in an unsafe manner.
* <p>
* This method is the same as calling {@link
* #addUnsafeEnchantment(Enchantment, int)} for
* each element of the map.
*
* @param enchantments Enchantments to add
*/
@Utility
public void addUnsafeEnchantments(Map<Enchantment, Integer> enchantments) {
for (Map.Entry<Enchantment, Integer> entry : enchantments.entrySet()) {
addUnsafeEnchantment(entry.getKey(), entry.getValue());
}
}
19
View Complete Implementation : ItemStack.java
Copyright MIT License
Author : kmecpp
Copyright MIT License
Author : kmecpp
/**
* Gets the type of this item
*
* @return Type of the items in this stack
*/
@Utility
public Material getType() {
return type;
}
18
View Complete Implementation : ItemStack.java
Copyright GNU General Public License v3.0
Author : Bukkit
Copyright GNU General Public License v3.0
Author : Bukkit
@Override
@Utility
public final int hashCode() {
int hash = 1;
hash = hash * 31 + getTypeId();
hash = hash * 31 + getAmount();
hash = hash * 31 + (getDurability() & 0xffff);
hash = hash * 31 + (hasItemMeta() ? (meta == null ? gereplacedemMeta().hashCode() : meta.hashCode()) : 0);
return hash;
}
18
View Complete Implementation : ItemStack.java
Copyright GNU General Public License v3.0
Author : Bukkit
Copyright GNU General Public License v3.0
Author : Bukkit
@Override
@Utility
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (!(obj instanceof ItemStack)) {
return false;
}
ItemStack stack = (ItemStack) obj;
return getAmount() == stack.getAmount() && isSimilar(stack);
}
18
View Complete Implementation : ItemStack.java
Copyright GNU General Public License v3.0
Author : Bukkit
Copyright GNU General Public License v3.0
Author : Bukkit
/**
* Get the maximum stacksize for the material hold in this ItemStack.
* (Returns -1 if it has no idea)
*
* @return The maximum you can stack this material to.
*/
@Utility
public int getMaxStackSize() {
Material material = getType();
if (material != null) {
return material.getMaxStackSize();
}
return -1;
}
18
View Complete Implementation : ItemStack.java
Copyright GNU General Public License v3.0
Author : Bukkit
Copyright GNU General Public License v3.0
Author : Bukkit
@Override
@Utility
public String toString() {
StringBuilder toString = new StringBuilder("ItemStack{").append(getType().name()).append(" x ").append(getAmount());
if (hasItemMeta()) {
toString.append(", ").append(gereplacedemMeta());
}
return toString.append('}').toString();
}
18
View Complete Implementation : ItemStack.java
Copyright GNU General Public License v3.0
Author : Bukkit
Copyright GNU General Public License v3.0
Author : Bukkit
/**
* Adds the specified enchantments to this item stack.
* <p>
* This method is the same as calling {@link
* #addEnchantment(org.bukkit.enchantments.Enchantment, int)} for each
* element of the map.
*
* @param enchantments Enchantments to add
* @throws IllegalArgumentException if the specified enchantments is null
* @throws IllegalArgumentException if any specific enchantment or level
* is null. <b>Warning</b>: Some enchantments may be added before this
* exception is thrown.
*/
@Utility
public void addEnchantments(Map<Enchantment, Integer> enchantments) {
Validate.notNull(enchantments, "Enchantments cannot be null");
for (Map.Entry<Enchantment, Integer> entry : enchantments.entrySet()) {
addEnchantment(entry.getKey(), entry.getValue());
}
}
18
View Complete Implementation : ItemStack.java
Copyright GNU General Public License v2.0
Author : GelandiAssociation
Copyright GNU General Public License v2.0
Author : GelandiAssociation
@Override
@Utility
public int hashCode() {
int hash = 1;
hash = hash * 31 + getTypeId();
hash = hash * 31 + getAmount();
hash = hash * 31 + (getDurability() & 0xffff);
hash = hash * 31 + (hasItemMeta() ? (meta == null ? gereplacedemMeta().hashCode() : meta.hashCode()) : 0);
return hash;
}
18
View Complete Implementation : ItemStack.java
Copyright GNU Lesser General Public License v3.0
Author : GMatrixGames
Copyright GNU Lesser General Public License v3.0
Author : GMatrixGames
/**
* Sets the type of this item
* <p>
* Note that in doing so you will reset the MaterialData for this stack
*
* @param type New type to set the items in this stack to
*/
@Utility
public void setType(Material type) {
Validate.notNull(type, "Material cannot be null");
setTypeId(type.getId());
}
18
View Complete Implementation : ItemStack.java
Copyright GNU Lesser General Public License v3.0
Author : GMatrixGames
Copyright GNU Lesser General Public License v3.0
Author : GMatrixGames
/**
* Adds the specified {@link Enchantment} to this item stack.
* <p>
* If this item stack already contained the given enchantment (at any
* level), it will be replaced.
*
* @param ench Enchantment to add
* @param level Level of the enchantment
* @throws IllegalArgumentException if enchantment null, or enchantment is
* not applicable
*/
@Utility
public void addEnchantment(Enchantment ench, int level) {
Validate.notNull(ench, "Enchantment cannot be null");
if ((level < ench.getStartLevel()) || (level > ench.getMaxLevel())) {
throw new IllegalArgumentException("Enchantment level is either too low or too high (given " + level + ", bounds are " + ench.getStartLevel() + " to " + ench.getMaxLevel() + ")");
} else if (!ench.canEnchanreplacedem(this)) {
throw new IllegalArgumentException("Specified enchantment cannot be applied to this itemstack");
}
addUnsafeEnchantment(ench, level);
}
18
View Complete Implementation : ItemStack.java
Copyright MIT License
Author : kmecpp
Copyright MIT License
Author : kmecpp
/**
* This method is the same as equals, but does not consider stack size
* (amount).
*
* @param stack the item stack to compare to
* @return true if the two stacks are equal, ignoring the amount
*/
@Utility
public boolean isSimilar(ItemStack stack) {
if (stack == null) {
return false;
}
if (stack == this) {
return true;
}
// This may be called from legacy item stacks, try to get the right material
Material comparisonType = Bukkit.getUnsafe().fromLegacy(this.getType());
return comparisonType == stack.getType() && getDurability() == stack.getDurability() && hasItemMeta() == stack.hasItemMeta() && (hasItemMeta() ? Bukkit.gereplacedemFactory().equals(gereplacedemMeta(), stack.gereplacedemMeta()) : true);
}
18
View Complete Implementation : ItemStack.java
Copyright MIT License
Author : kmecpp
Copyright MIT License
Author : kmecpp
@Override
@Utility
public int hashCode() {
int hash = 1;
hash = hash * 31 + getType().hashCode();
hash = hash * 31 + getAmount();
hash = hash * 31 + (getDurability() & 0xffff);
hash = hash * 31 + (hasItemMeta() ? (meta == null ? gereplacedemMeta().hashCode() : meta.hashCode()) : 0);
return hash;
}
17
View Complete Implementation : ItemStack.java
Copyright MIT License
Author : kmecpp
Copyright MIT License
Author : kmecpp
/**
* Sets the type of this item
* <p>
* Note that in doing so you will reset the MaterialData for this stack
*
* @param type New type to set the items in this stack to
*/
@Utility
public void setType(Material type) {
Validate.notNull(type, "Material cannot be null");
this.type = type;
if (this.meta != null) {
this.meta = Bukkit.gereplacedemFactory().asMetaFor(meta, type);
}
if (type.isLegacy()) {
createData((byte) 0);
}
}
16
View Complete Implementation : ItemStack.java
Copyright GNU General Public License v3.0
Author : Bukkit
Copyright GNU General Public License v3.0
Author : Bukkit
@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 = gereplacedemMeta();
if (!Bukkit.gereplacedemFactory().equals(meta, null)) {
result.put("meta", meta);
}
return result;
}
16
View Complete Implementation : ItemStack.java
Copyright GNU General Public License v3.0
Author : Mohist-Community
Copyright GNU General Public License v3.0
Author : Mohist-Community
@Utility
public Map<String, Object> serialize() {
Map<String, Object> result = new LinkedHashMap<>();
result.put("type", getType().name());
if (getDurability() != 0) {
result.put("damage", getDurability());
}
if (getAmount() != 1) {
result.put("amount", getAmount());
}
ItemMeta meta = gereplacedemMeta();
if (!Bukkit.gereplacedemFactory().equals(meta, null)) {
result.put("meta", meta);
}
return result;
}
15
View Complete Implementation : ItemStack.java
Copyright MIT License
Author : kmecpp
Copyright MIT License
Author : kmecpp
@Utility
public Map<String, Object> serialize() {
Map<String, Object> result = new LinkedHashMap<String, Object>();
// Include version to indicate we are using modern material names (or LEGACY prefix)
result.put("v", Bukkit.getUnsafe().getDataVersion());
result.put("type", getType().name());
if (getAmount() != 1) {
result.put("amount", getAmount());
}
ItemMeta meta = gereplacedemMeta();
if (!Bukkit.gereplacedemFactory().equals(meta, null)) {
result.put("meta", meta);
}
return result;
}