下面列出了org.bukkit.Material#toString ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public static boolean isApplicationCorrect(Application app, Material matToApplyTo) {
String mat = matToApplyTo.toString();
if (app == Application.BOW && mat.equals(Material.BOW.toString()))
return true;
else if (app == Application.BOOTS && mat.endsWith("BOOTS"))
return true;
else if (app == Application.HELMET && mat.endsWith("HELMET"))
return true;
else if (app == Application.ARMOR && (mat.endsWith("HELMET") || mat.endsWith("CHESTPLATE") || mat.endsWith("LEGGINGS") || mat.endsWith("BOOTS")))
return true;
else if (app == Application.TOOL && (mat.endsWith("PICKAXE") || mat.endsWith("SPADE") || mat.endsWith("AXE") || mat.endsWith("HOE")))
return true;
return false;
}
public static Application getApplicationByMaterial(Material material) {
String mat = material.toString();
if (mat.equals(Material.BOW.toString()))
return Application.BOW;
else if (mat.endsWith("BOOTS"))
return Application.BOOTS;
else if (mat.endsWith("HELMET"))
return Application.HELMET;
else if (mat.endsWith("BOOTS") || mat.endsWith("LEGGINGS") || mat.endsWith("CHESTPLATE") || mat.endsWith("HELMET"))
return Application.ARMOR;
else if (mat.endsWith("PICKAXE") || mat.endsWith("SPADE") || mat.endsWith("AXE") || mat.endsWith("HOE"))
return Application.TOOL;
return Application.GLOBAL;
}
@SuppressWarnings("deprecation")
public String resolveProtectionConfiguration(BlockState state, String node) {
Material material = state.getType();
String cacheKey = state.getRawData() + "-" + material.toString() + "-" + node;
if (protectionConfigurationCache.containsKey(cacheKey)) {
return protectionConfigurationCache.get(cacheKey);
}
List<String> names = new ArrayList<String>();
String materialName = normalizeMaterialName(material);
// add the name & the block id
names.add(materialName);
names.add(materialName + ":" + state.getRawData());
// add both upper and lower material name
names.add(material.toString());
names.add(material.toString().toLowerCase());
// Add the wildcards last so it can be overriden
names.add("*");
if (materialName.contains("_")) { // Prefix wildcarding for shulker boxes & gates
names.add("*_" + materialName.substring(materialName.indexOf("_") + 1));
}
String value = configuration.getString("protections." + node);
for (String name : names) {
String temp = configuration.getString("protections.blocks." + name + "." + node);
if (temp != null && !temp.isEmpty()) {
value = temp;
}
}
protectionConfigurationCache.put(cacheKey, value);
return value;
}
/**
* Get the appropriate config value for the block (protections.block.node)
*
* @param material
* @param node
* @return
*/
public String resolveProtectionConfiguration(Material material, String node) {
if (material == null) {
return null;
}
String cacheKey = "00-" + material.toString() + "-" + node;
if (protectionConfigurationCache.containsKey(cacheKey)) {
return protectionConfigurationCache.get(cacheKey);
}
List<String> names = new ArrayList<>();
String materialName = normalizeMaterialName(material);
// add the name & the block id
names.add(materialName);
// add both upper and lower material name
names.add(material.toString());
names.add(material.toString().toLowerCase());
// Add the wildcards last so it can be overriden
names.add("*");
String value = configuration.getString("protections." + node);
for (String name : names) {
String temp = configuration.getString("protections.blocks." + name + "." + node);
if (temp != null && !temp.isEmpty()) {
value = temp;
}
}
protectionConfigurationCache.put(cacheKey, value);
return value;
}
/**
* Get a durability value that does not use a texture for the specified
* Material. If there are no more durability points left, an error will be
* printed.
*
* @param material
* The Material for which you want a free durability point.
* @return The durability value that is available for the specified Material.
*/
public short getFreeDurability(Material material) {
String m = material.toString();
List<Short> durabilitiesUsed = new ArrayList<Short>();
for (String string : items) {
String[] line = string.split(";");
if (line[0].equals(m)) {
durabilitiesUsed.add(Short.valueOf(line[1]));
}
}
Debug.saySuper("Included in durabilities used:");
for (Short s : durabilitiesUsed)
Debug.saySuper(s.toString());
if (durabilitiesUsed.isEmpty()) {
Debug.saySuper("No Durabilities Used for Material: " + material);
return material.getMaxDurability();
} else {
if (material.getMaxDurability() != 0) {
short durability = material.getMaxDurability();
while (durabilitiesUsed.contains(durability))
durability--;
Debug.saySuper("Available Durability for Material " + material + ": " + durability);
if (durability <= 0) {
Debug.sayError("***********************");
Debug.sayError("TEXTURE LIMIT REACHED FOR MATERIAL: " + material);
Debug.sayError("REMOVE ANY CUSTOM ITEMS FROM THE DATA.YML FILE THAT ARE FROM REMOVED PLUGINS!");
Debug.sayError("***********************");
return (short) (material.getMaxDurability() + 1);
} else {
return durability;
}
} else {
Debug.saySuper("Returning default durability for Material: " + material);
return material.getMaxDurability();
}
}
}
public static String getFriendlyItemName(Material m){
String str = m.toString();
str = str.replace('_',' ');
str = str.substring(0, 1).toUpperCase() +
str.substring(1).toLowerCase();
return str;
}
public static boolean hasGravity(Material material) {
switch (material.toString()) {
case "DRAGON_EGG":
case "SAND":
case "GRAVEL":
case "ANVIL":
case "CONCRETE_POWDER":
return true;
default:
return false;
}
}
public static String getMaterialName(Material material) {
PluginConfiguration config = FunnyGuilds.getInstance().getPluginConfiguration();
if (!config.translatedMaterialsEnable) {
return material.toString();
}
if (config.translatedMaterials.containsKey(material)) {
return ChatUtils.colored(FunnyGuilds.getInstance().getPluginConfiguration().translatedMaterials.get(material));
}
return StringUtils.replaceChars(material.toString().toLowerCase(), '_', ' ');
}
/**
* Get the appropriate config value for the block (protections.block.node)
*
* @param block
* @param node
* @return
*/
@SuppressWarnings("deprecation")
public String resolveProtectionConfiguration(Block block, String node) {
Material material = block.getType();
if (material == null) {
return null;
}
String cacheKey = block.getData() + "-" + material.toString() + "-" + node;
if (protectionConfigurationCache.containsKey(cacheKey)) {
return protectionConfigurationCache.get(cacheKey);
}
List<String> names = new ArrayList<>();
String materialName = normalizeMaterialName(material);
// add the name & the block id
names.add(materialName);
names.add(materialName + ":" + block.getData());
// add both upper and lower material name
names.add(material.toString());
names.add(material.toString().toLowerCase());
// Add the wildcards last so it can be overriden
names.add("*");
if (materialName.contains("_")) { // Prefix wildcarding for shulker boxes & gates
names.add("*_" + materialName.substring(materialName.indexOf("_") + 1));
}
String value = configuration.getString("protections." + node);
for (String name : names) {
String temp = configuration.getString("protections.blocks." + name + "." + node);
if (temp != null && !temp.isEmpty()) {
value = temp;
}
}
protectionConfigurationCache.put(cacheKey, value);
return value;
}
public String getIngString(Material m, int durability, int amount) {
return m.toString() + "," + durability + "," + amount;
}
public String getIngString(Material m, int durability, int amount) {
return m.toString() + "," + durability + "," + amount;
}
public String getIngString(Material m, int durability, int amount) {
return m.toString() + "," + durability + "," + amount;
}
/**
* Obtains a {@link StorageCustomItem} with the specified values. If the
* {@link StorageCustomItem} does not exist, it will return null.
*
* @param material
* The Material of the {@link StorageCustomItem}.
* @param durability
* The durability of the {@link StorageCustomItem}
* @return The {@link StorageCustomItem} with the above values, as well as its
* ID Name and Texture Name.
*/
public StorageCustomItem getCustomItem(Material material, short durability) {
String m = material.toString();
String d = Short.toString(durability);
for (String string : items) {
String[] line = string.split(";");
if (line[0].equals(m) && line[1].equals(d))
return new StorageCustomItem(material, durability, line[2], line[3]);
}
return null;
}