From c20719f0b0670457b5403fc6a4fbf0c1494ac7dc Mon Sep 17 00:00:00 2001 From: minoneer Date: Fri, 15 Jan 2021 13:26:02 +0100 Subject: [PATCH] Update item groupings to post 1.13 item format Item groupings were still using deprecated durability for different item variants. These have not been around since 1.13 and using deprecated material types for item construction could potentially cause issues. --- src/me/desht/clicksort/ItemGrouping.java | 44 ++++++++---------------- 1 file changed, 14 insertions(+), 30 deletions(-) diff --git a/src/me/desht/clicksort/ItemGrouping.java b/src/me/desht/clicksort/ItemGrouping.java index 431d668..f8bad90 100644 --- a/src/me/desht/clicksort/ItemGrouping.java +++ b/src/me/desht/clicksort/ItemGrouping.java @@ -8,7 +8,6 @@ import org.bukkit.configuration.Configuration; import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.inventory.ItemStack; -import org.bukkit.material.MaterialData; import java.io.File; import java.util.HashMap; @@ -16,7 +15,7 @@ public class ItemGrouping { - private static final String mapFile = "groups.yml"; + private static final String MAP_FILE = "groups.yml"; private final ClickSortPlugin plugin; private final Map mapping; @@ -26,12 +25,12 @@ public ItemGrouping(ClickSortPlugin plugin) this.mapping = new HashMap(); this.plugin = plugin; - new JARUtil(plugin).extractResource(mapFile, plugin.getDataFolder()); + new JARUtil(plugin).extractResource(MAP_FILE, plugin.getDataFolder()); } public void load() { - File map = new File(plugin.getDataFolder(), mapFile); + File map = new File(plugin.getDataFolder(), MAP_FILE); Configuration cfg = YamlConfiguration.loadConfiguration(map); mapping.clear(); @@ -45,8 +44,7 @@ public void load() } catch (IllegalArgumentException e) { - LogUtils.warning("Unknown material name '" + matName + "' in group '" - + grpName + "'"); + LogUtils.warning("Unknown material name '" + matName + "' in group '" + grpName + "'"); } } } @@ -57,20 +55,20 @@ private void addMapping(String matName, String grpName) addMapping(parseMaterial(matName), grpName); } - private void addMapping(MaterialData mat, String grpName) + private void addMapping(Material material, String grpName) { - if (mat == null) + if (material == null) { throw new IllegalArgumentException(); } - String key = getKey(mat); - mapping.put(getKey(mat), grpName); + String key = getKey(material); + mapping.put(key, grpName); Debugger.getInstance().debug(2, "addMapping: " + key + " = " + grpName); } public String getGroup(ItemStack stack) { - String group = mapping.get(getKey(stack.getData())); + String group = mapping.get(getKey(stack.getType())); if (group == null) { group = plugin.getConfig().getString("default_group_name", "000-default"); @@ -84,27 +82,13 @@ public boolean isAvailable() return !mapping.isEmpty(); } - private String getKey(MaterialData mat) + private String getKey(Material material) { - // Items with durability should not use the current damage level as part - // of - // grouping criteria. Items which don't have durability *should* use the - // data - // value, e.g. 351:4 is lapis, which could be considered either a dye or - // a gem - return hasDurability(mat) ? mat.getItemType().toString() : mat.toString(); + return material.toString(); } - - private boolean hasDurability(MaterialData mat) - { - return mat.getItemType().getMaxDurability() > 0; - } - - private MaterialData parseMaterial(String s) + + private Material parseMaterial(String name) { - String[] f = s.split(":"); - Material mat = Material.matchMaterial(f[0]); - short dur = f.length == 2 ? Short.parseShort(f[1]) : 0; - return new ItemStack(mat, 1, dur).getData(); + return Material.matchMaterial(name); } }