mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-11-29 05:26:12 +01:00
Update durability usage to modern API (Fixes #597)
This commit is contained in:
parent
bc1f80128b
commit
07dd3c7a70
@ -259,8 +259,12 @@ public class MaterialUtil {
|
|||||||
String itemName = itemStack.getType().toString();
|
String itemName = itemStack.getType().toString();
|
||||||
|
|
||||||
String durability = "";
|
String durability = "";
|
||||||
if (itemStack.getDurability() != 0) {
|
ItemMeta meta = itemStack.getItemMeta();
|
||||||
durability = ":" + itemStack.getDurability();
|
if (meta instanceof Damageable) {
|
||||||
|
Damageable damageable = (Damageable) meta;
|
||||||
|
if (damageable.hasDamage()) {
|
||||||
|
durability = ":" + damageable.getDamage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String metaData = "";
|
String metaData = "";
|
||||||
@ -386,8 +390,8 @@ public class MaterialUtil {
|
|||||||
split[i] = split[i].trim();
|
split[i] = split[i].trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
short durability = getDurability(itemName);
|
int durability = getDurability(itemName);
|
||||||
MaterialParseEvent parseEvent = new MaterialParseEvent(split[0], durability);
|
MaterialParseEvent parseEvent = new MaterialParseEvent(split[0], (short) durability);
|
||||||
Bukkit.getPluginManager().callEvent(parseEvent);
|
Bukkit.getPluginManager().callEvent(parseEvent);
|
||||||
Material material = parseEvent.getMaterial();
|
Material material = parseEvent.getMaterial();
|
||||||
if (material == null) {
|
if (material == null) {
|
||||||
@ -414,7 +418,7 @@ public class MaterialUtil {
|
|||||||
* @param itemName Item name
|
* @param itemName Item name
|
||||||
* @return Durability found
|
* @return Durability found
|
||||||
*/
|
*/
|
||||||
public static short getDurability(String itemName) {
|
public static int getDurability(String itemName) {
|
||||||
Matcher m = DURABILITY.matcher(itemName);
|
Matcher m = DURABILITY.matcher(itemName);
|
||||||
|
|
||||||
if (!m.find()) {
|
if (!m.find()) {
|
||||||
@ -429,7 +433,11 @@ public class MaterialUtil {
|
|||||||
|
|
||||||
data = data.substring(1);
|
data = data.substring(1);
|
||||||
|
|
||||||
return NumberUtil.isShort(data) ? Short.valueOf(data) : 0;
|
try {
|
||||||
|
return Integer.parseInt(data);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -11,7 +11,7 @@ public class MaterialParseEvent extends Event {
|
|||||||
private final short data;
|
private final short data;
|
||||||
private Material material = null;
|
private Material material = null;
|
||||||
|
|
||||||
public MaterialParseEvent(String materialString, short data) {
|
public MaterialParseEvent(String materialString, @Deprecated short data) {
|
||||||
this.materialString = materialString;
|
this.materialString = materialString;
|
||||||
this.data = data;
|
this.data = data;
|
||||||
}
|
}
|
||||||
@ -35,7 +35,9 @@ public class MaterialParseEvent extends Event {
|
|||||||
/**
|
/**
|
||||||
* Get the data of legacy materials that might result in different flattening materials
|
* Get the data of legacy materials that might result in different flattening materials
|
||||||
* @return The data
|
* @return The data
|
||||||
|
* @deprecated Modern materials don't use data values anymore
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
public short getData() {
|
public short getData() {
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ import org.bukkit.configuration.file.YamlConfiguration;
|
|||||||
import org.bukkit.configuration.file.YamlConstructor;
|
import org.bukkit.configuration.file.YamlConstructor;
|
||||||
import org.bukkit.configuration.file.YamlRepresenter;
|
import org.bukkit.configuration.file.YamlRepresenter;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
import org.bukkit.inventory.meta.Damageable;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
import org.yaml.snakeyaml.DumperOptions;
|
import org.yaml.snakeyaml.DumperOptions;
|
||||||
import org.yaml.snakeyaml.Yaml;
|
import org.yaml.snakeyaml.Yaml;
|
||||||
@ -140,7 +141,14 @@ public class ItemDatabase {
|
|||||||
try {
|
try {
|
||||||
ItemStack clone = new ItemStack(item);
|
ItemStack clone = new ItemStack(item);
|
||||||
clone.setAmount(1);
|
clone.setAmount(1);
|
||||||
clone.setDurability((short) 0);
|
|
||||||
|
ItemMeta meta = clone.getItemMeta();
|
||||||
|
if (meta instanceof Damageable) {
|
||||||
|
Damageable damageable = (Damageable) clone.getItemMeta();
|
||||||
|
if (damageable.hasDamage()) {
|
||||||
|
damageable.setDamage(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
String dumped = yaml.dump(clone);
|
String dumped = yaml.dump(clone);
|
||||||
ItemStack loadedItem = yaml.loadAs(dumped, ItemStack.class);
|
ItemStack loadedItem = yaml.loadAs(dumped, ItemStack.class);
|
||||||
|
Loading…
Reference in New Issue
Block a user