From acfd97638c89949783ef884ea5860439f0d11655 Mon Sep 17 00:00:00 2001 From: Dereku Date: Tue, 6 Jun 2017 17:25:24 +0700 Subject: [PATCH] Woohoo --- .../dereku/itemtooltips/ItemTooltips.java | 49 ++++---- .../dereku/itemtooltips/Listeners.java | 112 ++++++++++++++---- .../implementations/Implementation.java | 90 -------------- .../implementations/v1_10_R1.java | 61 ---------- .../implementations/v1_11_R1.java | 67 ----------- .../itemtooltips/implementations/v1_8_R3.java | 61 ---------- .../itemtooltips/implementations/v1_9_R1.java | 62 ---------- .../itemtooltips/implementations/v1_9_R2.java | 62 ---------- src/plugin.yml | 2 +- 9 files changed, 117 insertions(+), 449 deletions(-) delete mode 100644 src/club/without/dereku/itemtooltips/implementations/Implementation.java delete mode 100644 src/club/without/dereku/itemtooltips/implementations/v1_10_R1.java delete mode 100644 src/club/without/dereku/itemtooltips/implementations/v1_11_R1.java delete mode 100644 src/club/without/dereku/itemtooltips/implementations/v1_8_R3.java delete mode 100644 src/club/without/dereku/itemtooltips/implementations/v1_9_R1.java delete mode 100644 src/club/without/dereku/itemtooltips/implementations/v1_9_R2.java diff --git a/src/club/without/dereku/itemtooltips/ItemTooltips.java b/src/club/without/dereku/itemtooltips/ItemTooltips.java index 70a4049..92808be 100644 --- a/src/club/without/dereku/itemtooltips/ItemTooltips.java +++ b/src/club/without/dereku/itemtooltips/ItemTooltips.java @@ -23,15 +23,15 @@ */ package club.without.dereku.itemtooltips; -import club.without.dereku.itemtooltips.implementations.*; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStreamReader; import java.nio.charset.Charset; import java.util.List; +import java.util.Properties; import java.util.logging.Level; -import org.bukkit.World; +import java.util.stream.Collectors; import org.bukkit.configuration.InvalidConfigurationException; import org.bukkit.plugin.java.JavaPlugin; @@ -41,44 +41,45 @@ */ public class ItemTooltips extends JavaPlugin { + public final Properties keys = new Properties(); private String language; private ResourceDownloader rd; - private Implementation impl; public List worlds; @Override public void onEnable() { this.saveDefaultConfig(); this.language = this.getConfig().getString("lang", "en_US"); - this.impl = Implementation.getImpl(this.getServer().getBukkitVersion()); - if (this.impl == null) { - this.getLogger().info("Not implemented yet."); - this.getPluginLoader().disablePlugin(this); - return; - } - - this.getLogger().log(Level.INFO, "Using implementation with version {0}", this.impl.getVersion()); if (!this.language.equals("en_US")) { - this.downloadAndApplyLanguage(this.impl.getAssetsVersion(), this.language); + //TODO + this.downloadAndApplyLanguage("", this.language); } this.worlds = this.getConfig().getStringList("worlds"); - if (worlds.isEmpty()) { - for (World world : this.getServer().getWorlds()) { - worlds.add(world.getName()); - } + if (this.worlds.isEmpty()) { + this.worlds.addAll( + this.getServer().getWorlds().stream() + .map(w -> w.getName()) + .collect(Collectors.toList()) + ); this.getConfig().set("worlds", this.worlds); this.saveConfig(); } - this.getServer().getPluginManager().registerEvents(new Listeners(this), this); + + Listeners listeners; + try { + listeners = new Listeners(this); + } catch (ClassNotFoundException | SecurityException | NoSuchMethodException ex) { + this.getLogger().log(Level.SEVERE, "Failed to init listeners", ex); + this.getPluginLoader().disablePlugin(this); + return; + } + + this.getServer().getPluginManager().registerEvents(listeners, this); this.getLogger().info("Enabled."); } - public Implementation getImpl() { - return this.impl; - } - public void downloadAndApplyLanguage(String version, String lang) { File file = new File(this.getDataFolder().toString() + File.separator + "lang" + File.separator + version, lang + ".lang"); if (!file.exists()) { @@ -89,7 +90,7 @@ public void downloadAndApplyLanguage(String version, String lang) { } catch (IOException | InvalidConfigurationException | IllegalArgumentException ex) { this.getLogger().log(Level.WARNING, "Failed to download " + file.getName(), ex); this.getLogger().log(Level.WARNING, "Using en_US language."); - this.impl.keys.clear(); + this.keys.clear(); return; } } @@ -99,11 +100,11 @@ public void downloadAndApplyLanguage(String version, String lang) { public void loadLanguage(File file) { Charset charset = Charset.forName("UTF-8"); try (InputStreamReader is = new InputStreamReader(new FileInputStream(file), charset)) { - this.impl.keys.load(is); + this.keys.load(is); } catch (IOException ex) { this.getLogger().log(Level.WARNING, "Failed to load " + file.getName(), ex); this.getLogger().log(Level.WARNING, "Using en_US language."); - this.impl.keys.clear(); + this.keys.clear(); } } } diff --git a/src/club/without/dereku/itemtooltips/Listeners.java b/src/club/without/dereku/itemtooltips/Listeners.java index 869ba6c..2246b6f 100644 --- a/src/club/without/dereku/itemtooltips/Listeners.java +++ b/src/club/without/dereku/itemtooltips/Listeners.java @@ -23,13 +23,20 @@ */ package club.without.dereku.itemtooltips; +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.logging.Level; +import org.apache.commons.lang3.ClassUtils; import org.bukkit.ChatColor; +import org.bukkit.Material; import org.bukkit.entity.Item; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.entity.ItemMergeEvent; import org.bukkit.event.entity.ItemSpawnEvent; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.BannerMeta; import org.bukkit.inventory.meta.ItemMeta; /** @@ -39,40 +46,103 @@ public class Listeners implements Listener { private final ItemTooltips plugin; + private final String withoutAmount; + private final String withAmount; - public Listeners(ItemTooltips aThis) { + private final Class obcbCraftItemStack; + private final Class nmsItemStack; + private final Method asNMSCopy; + private final Method itemStack_getName; + private final Method itemStack_getI18n; + + public Listeners(ItemTooltips aThis) throws ClassNotFoundException, SecurityException, NoSuchMethodException { this.plugin = aThis; + this.withAmount = ChatColor.translateAlternateColorCodes('&', + this.plugin.getConfig().getString("format.withAmount", "%name%") + ); + this.withoutAmount = ChatColor.translateAlternateColorCodes('&', + this.plugin.getConfig().getString("format.withoutAmount", "%name%") + ); + + String pckg = Arrays.stream(Package.getPackages()) + .filter(pk -> pk.getName().startsWith("net.minecraft.server")) + .map(pk -> pk.getName()).findFirst().orElse(null); + + if (pckg == null) { + throw new RuntimeException("Failed to recognize nms version."); + } + + String nmsVersion = pckg.substring(21); + this.nmsItemStack = ClassUtils.getClass("net.minecraft.server." + nmsVersion + ".ItemStack"); + this.obcbCraftItemStack = ClassUtils.getClass("org.bukkit.craftbukkit." + nmsVersion + ".CraftItemStack"); + this.asNMSCopy = this.obcbCraftItemStack.getMethod("asNMSCopy", ItemStack.class); + this.itemStack_getName = this.nmsItemStack.getDeclaredMethod("getName", (Class[]) null); + this.itemStack_getI18n = this.nmsItemStack.getDeclaredMethod("a", (Class[]) null); } - - @EventHandler(ignoreCancelled=true) + + @EventHandler(ignoreCancelled = true) public void onItemSpawnEvent(ItemSpawnEvent event) { + if (!this.plugin.worlds.contains(event.getEntity().getLocation().getWorld().getName())) { + return; + } this.setName(event.getEntity(), event.getEntity().getItemStack()); } - - @EventHandler(ignoreCancelled=true) + + @EventHandler(ignoreCancelled = true) public void onItemMergeEvent(ItemMergeEvent event) { + if (!this.plugin.worlds.contains(event.getTarget().getLocation().getWorld().getName())) { + return; + } ItemStack is = event.getEntity().getItemStack().clone(); is.setAmount(is.getAmount() + event.getTarget().getItemStack().getAmount()); this.setName(event.getTarget(), is); } - + private void setName(Item item, ItemStack itemStack) { - if (!this.plugin.worlds.contains(item.getLocation().getWorld().getName())) { - return; - } ItemMeta im = item.getItemStack().getItemMeta(); - String name = this.plugin.getConfig().getString("format.withoutAmount", "%name%"); - if (itemStack.getAmount() > 1) { - name = this.plugin.getConfig().getString("format.withAmount", "%name% x%amount%"); - } - - String displayName = im.hasDisplayName() ? im.getDisplayName() : this.plugin.getImpl().getName(item); - item.setCustomName( - ChatColor.translateAlternateColorCodes('&', - name - .replace("%name%", displayName) - .replace("%amount%", Integer.toString(itemStack.getAmount()))) - ); + String name = itemStack.getAmount() > 1 ? this.withAmount : this.withoutAmount; + String displayName = im.hasDisplayName() ? im.getDisplayName() : this.getName(item); + item.setCustomName(name.replace("%name%", displayName).replace("%amount%", Integer.toString(itemStack.getAmount()))); item.setCustomNameVisible(true); } + + private String getName(Item item) { + String i18n; + try { + Object nmsis = this.asNMSCopy.invoke(null, item.getItemStack()); + if (this.plugin.keys.isEmpty()) { + return (String) this.itemStack_getName.invoke(nmsis, (Object) null); + } + i18n = (String) this.itemStack_getI18n.invoke(nmsis, (Object) null); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { + this.plugin.getLogger().log(Level.WARNING, "Failed to get name", ex); + return null; + } + + String out = this.getBannerKey(item); + if (out == null) { + out = i18n.concat(".name"); + } + + return this.plugin.keys.getProperty(out, out); + } + + public String getBannerKey(Item item) { + if (!item.getItemStack().getType().equals(Material.BANNER)) { + return null; + } + StringBuilder out = new StringBuilder(); + BannerMeta bm = (BannerMeta) item.getItemStack().getItemMeta(); + System.out.println(item + ": " + item.getName() + ", " + bm); + System.out.println(bm.getBaseColor()); + try { + out.append(item.getName().replace("tile.", "")) + .append(".") + .append(bm.getBaseColor().toString().toLowerCase().replace("light_blue", "lightBlue")) + .append(".name"); + } catch (Exception ex) { + out.append(ex.getMessage()); + } + return out.toString(); + } } diff --git a/src/club/without/dereku/itemtooltips/implementations/Implementation.java b/src/club/without/dereku/itemtooltips/implementations/Implementation.java deleted file mode 100644 index 24e16ae..0000000 --- a/src/club/without/dereku/itemtooltips/implementations/Implementation.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * The MIT License - * - * Copyright 2015 Dereku. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package club.without.dereku.itemtooltips.implementations; - -import java.util.Properties; -import java.util.logging.Level; -import org.bukkit.Bukkit; -import org.bukkit.Material; -import org.bukkit.entity.Item; -import org.bukkit.inventory.meta.BannerMeta; - -/** - * - * @author Dereku - */ -public abstract class Implementation { - - public final Properties keys = new Properties(); - - public abstract String getName(Item item); - - public abstract String getVersion(); - - public abstract String getAssetsVersion(); - - public String getBannerKey(Item item) { - if (!item.getItemStack().getType().equals(Material.BANNER)) { - return null; - } - StringBuilder out = new StringBuilder(); - BannerMeta bm = (BannerMeta) item.getItemStack().getItemMeta(); - System.out.println(item + ": " + item.getName() + ", " + bm); - System.out.println(bm.getBaseColor()); - try { - out.append(item.getName().replace("tile.", "")) - .append(".") - .append(bm.getBaseColor().toString().toLowerCase().replace("light_blue", "lightBlue")) - .append(".name"); - } catch (Exception ex) { - out.append(ex.getMessage()); - } - return out.toString(); - } - - public static Implementation getImpl(String version) { - if (version.startsWith("1.8.8")) { - return new v1_8_R3(); - } - if (version.startsWith("1.9")) { - char subvc = version.charAt(4); - int subversion; - try { - subversion = Integer.parseInt(String.valueOf(subvc)); - } catch (Exception ex) { - return new v1_9_R1(); - } - - return subversion < 4 ? new v1_9_R1() : new v1_9_R2(); - } - if (version.startsWith("1.10")) { - return new v1_10_R1(); - } - if (version.startsWith("1.11")) { - return new v1_11_R1(); - } - Bukkit.getLogger().log(Level.WARNING, "Failed to parse \"{0}\"", version); - return null; - } -} diff --git a/src/club/without/dereku/itemtooltips/implementations/v1_10_R1.java b/src/club/without/dereku/itemtooltips/implementations/v1_10_R1.java deleted file mode 100644 index 011cd14..0000000 --- a/src/club/without/dereku/itemtooltips/implementations/v1_10_R1.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * The MIT License - * - * Copyright 2016 Dereku. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package club.without.dereku.itemtooltips.implementations; - -import net.minecraft.server.v1_10_R1.ItemStack; -import org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack; -import org.bukkit.entity.Item; - -/** - * - * @author Dereku - */ -public class v1_10_R1 extends Implementation { - - @Override - public String getName(Item item) { - ItemStack nms = CraftItemStack.asNMSCopy(item.getItemStack()); - - if (this.keys.isEmpty()) { - return nms.getName(); - } - - String out = this.getBannerKey(item); - if (out == null) { - out = nms.a().concat(".name"); - } - - return this.keys.getProperty(out, out); - } - - @Override - public String getAssetsVersion() { - return "1.10"; - } - - @Override - public String getVersion() { - return "1.10"; - } -} diff --git a/src/club/without/dereku/itemtooltips/implementations/v1_11_R1.java b/src/club/without/dereku/itemtooltips/implementations/v1_11_R1.java deleted file mode 100644 index e40bbb1..0000000 --- a/src/club/without/dereku/itemtooltips/implementations/v1_11_R1.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * The MIT License - * - * Copyright 2016 Dereku. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package club.without.dereku.itemtooltips.implementations; - -import net.minecraft.server.v1_11_R1.ItemStack; -import org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack; -import org.bukkit.entity.Item; - -/** - * Исходный файл класса v1_11_R1 написан в NetBeans IDE 8.1 - * - * @author Dereku - * @email dereku@default.im - * @date 18.11.2016 - * @time 21:01:34 - * @version 1.0 - */ -public class v1_11_R1 extends Implementation { - - @Override - public String getName(Item item) { - ItemStack nms = CraftItemStack.asNMSCopy(item.getItemStack()); - - if (this.keys.isEmpty()) { - return nms.getName(); - } - - String out = this.getBannerKey(item); - if (out == null) { - out = nms.a().concat(".name"); - } - - return this.keys.getProperty(out, out); - } - - @Override - public String getAssetsVersion() { - return "1.11"; - } - - @Override - public String getVersion() { - return "1.11"; - } - -} diff --git a/src/club/without/dereku/itemtooltips/implementations/v1_8_R3.java b/src/club/without/dereku/itemtooltips/implementations/v1_8_R3.java deleted file mode 100644 index 7d24145..0000000 --- a/src/club/without/dereku/itemtooltips/implementations/v1_8_R3.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * The MIT License - * - * Copyright 2015 Dereku. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package club.without.dereku.itemtooltips.implementations; - -import net.minecraft.server.v1_8_R3.ItemStack; -import org.bukkit.entity.Item; -import org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack; - -/** - * - * @author Dereku - */ -public class v1_8_R3 extends Implementation { - - @Override - public String getName(Item item) { - ItemStack nms = CraftItemStack.asNMSCopy(item.getItemStack()); - - if (this.keys.isEmpty()) { - return nms.getName(); - } - - String out = this.getBannerKey(item); - if (out == null) { - out = nms.a().concat(".name"); - } - - return this.keys.getProperty(out, out); - } - - @Override - public String getAssetsVersion() { - return "1.8"; - } - - @Override - public String getVersion() { - return "1.8.7"; - } -} diff --git a/src/club/without/dereku/itemtooltips/implementations/v1_9_R1.java b/src/club/without/dereku/itemtooltips/implementations/v1_9_R1.java deleted file mode 100644 index eedaf2c..0000000 --- a/src/club/without/dereku/itemtooltips/implementations/v1_9_R1.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * The MIT License - * - * Copyright 2016 Dereku. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package club.without.dereku.itemtooltips.implementations; - -import net.minecraft.server.v1_9_R1.ItemStack; -import org.bukkit.craftbukkit.v1_9_R1.inventory.CraftItemStack; -import org.bukkit.entity.Item; - -/** - * - * @author Dereku - */ -public class v1_9_R1 extends Implementation { - - @Override - public String getName(Item item) { - ItemStack nms = CraftItemStack.asNMSCopy(item.getItemStack()); - - if (this.keys.isEmpty()) { - return nms.getName(); - } - - String out = this.getBannerKey(item); - if (out == null) { - out = nms.a().concat(".name"); - } - - return this.keys.getProperty(out, out); - } - - @Override - public String getVersion() { - return "1.9"; - } - - @Override - public String getAssetsVersion() { - return "1.9"; - } - -} diff --git a/src/club/without/dereku/itemtooltips/implementations/v1_9_R2.java b/src/club/without/dereku/itemtooltips/implementations/v1_9_R2.java deleted file mode 100644 index 3111b77..0000000 --- a/src/club/without/dereku/itemtooltips/implementations/v1_9_R2.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * The MIT License - * - * Copyright 2016 Dereku. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ -package club.without.dereku.itemtooltips.implementations; - -import net.minecraft.server.v1_9_R2.ItemStack; -import org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack; -import org.bukkit.entity.Item; - -/** - * - * @author Dereku - */ -public class v1_9_R2 extends Implementation { - - @Override - public String getName(Item item) { - ItemStack nms = CraftItemStack.asNMSCopy(item.getItemStack()); - - if (this.keys.isEmpty()) { - return nms.getName(); - } - - String out = this.getBannerKey(item); - if (out == null) { - out = nms.a().concat(".name"); - } - - return this.keys.getProperty(out, out); - } - - @Override - public String getVersion() { - return "1.9.4"; - } - - @Override - public String getAssetsVersion() { - return "1.9"; - } - -} diff --git a/src/plugin.yml b/src/plugin.yml index 51e1e46..464a37f 100644 --- a/src/plugin.yml +++ b/src/plugin.yml @@ -1,5 +1,5 @@ name: ItemTooltips -version: 1.3.6 +version: 2.0.0-dev author: Dereku email: [dereku@default.im, dereku@without.club] site: https://github.com/Dereku/ItemTooltips