From a0905ba2d35d990711c56801a9a5ae88b7ec7512 Mon Sep 17 00:00:00 2001 From: Ghost_chu <2908803755@qq.com> Date: Thu, 2 Aug 2018 17:33:23 +0800 Subject: [PATCH] Finished Util-Holomessage Former-commit-id: 875b13f7eb2f59396a8e9631c0470fd91451e8dd --- pom.xml | 4 + .../org/maxgamer/quickshop/Util/Util.java | 86 +++++++++++++++++++ src/main/resources/enchi18n.yml | 35 ++++++++ 3 files changed, 125 insertions(+) diff --git a/pom.xml b/pom.xml index 842aafa43..3179c0665 100644 --- a/pom.xml +++ b/pom.xml @@ -44,6 +44,10 @@ + + fanciful-repo + https://github.com/mkremins/fanciful/tree/mvn-repo + bukkit-repo https://hub.spigotmc.org/nexus/content/groups/public/ diff --git a/src/main/java/org/maxgamer/quickshop/Util/Util.java b/src/main/java/org/maxgamer/quickshop/Util/Util.java index 892235a8f..be4e44db1 100644 --- a/src/main/java/org/maxgamer/quickshop/Util/Util.java +++ b/src/main/java/org/maxgamer/quickshop/Util/Util.java @@ -3,11 +3,13 @@ package org.maxgamer.quickshop.Util; import java.lang.reflect.Method; import java.text.DecimalFormat; import java.util.AbstractMap.SimpleEntry; +import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; + import java.util.Set; import org.apache.commons.lang.StringUtils; @@ -26,11 +28,16 @@ import org.bukkit.inventory.Inventory; import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.meta.EnchantmentStorageMeta; +import org.bukkit.inventory.meta.ItemMeta; import org.bukkit.material.MaterialData; import org.bukkit.material.Sign; import org.maxgamer.quickshop.QuickShop; import org.maxgamer.quickshop.Shop.Shop; +import net.md_5.bungee.api.chat.ComponentBuilder; +import net.md_5.bungee.api.chat.HoverEvent; +import net.md_5.bungee.api.chat.TextComponent; + @SuppressWarnings("deprecation") public class Util { private static HashSet tools = new HashSet(); @@ -612,4 +619,83 @@ public class Util { } } } + + @SuppressWarnings("null") + public void sendItemholochat(ItemStack itemStack, Player player, String normalText, String actionText) { + String Itemname = null; + List Itemlore = null; + String finalItemdata = null; + Map enchs = null; + Map Itemenchs = null; + if (itemStack.hasItemMeta()) { + ItemMeta iMeta = itemStack.getItemMeta(); + if (iMeta.hasDisplayName()) { + Itemname = iMeta.getDisplayName(); + } else { + Itemname = MsgUtil.getItemi18n(itemStack.getType().name()); + } + if (iMeta.hasLore()) { + } else { + Itemlore = new ArrayList(); + } + if (iMeta.hasEnchants()) { + enchs = iMeta.getEnchants(); + for (Entry entries : enchs.entrySet()) { + String i18n = MsgUtil.getEnchi18n(entries.getKey()); + if (i18n != null) { + Itemenchs.put(i18n, entries.getValue()); + } else { + Itemenchs = null; + } + } + } + } else { + Itemname = MsgUtil.getItemi18n(itemStack.getType().name()); + Itemlore = null; + Itemenchs = null; + } + + finalItemdata = Itemname; + finalItemdata += "\n"; + List a = new ArrayList<>(); + List b = new ArrayList<>(); + + a.addAll(Itemenchs.keySet()); + b.addAll(Itemenchs.values()); + for (int i = 0; i < a.size(); i++) { + finalItemdata += ChatColor.GRAY + a.get(i) + " " + Util.formatEnchLevel(b.get(i)) + "\n"; + } + + if (Itemlore != null) { + for (String string : Itemlore) { + finalItemdata += string + "\n"; + } + } + TextComponent normalmessage = new TextComponent(normalText); + TextComponent actionmessage = new TextComponent(actionText); + ComponentBuilder cBuilder = new ComponentBuilder(finalItemdata); + HoverEvent he = new HoverEvent(HoverEvent.Action.SHOW_TEXT, cBuilder.create()); + actionmessage.setHoverEvent(he); + normalmessage.addExtra(actionmessage); + player.sendRawMessage(normalmessage.getText()); + + } + private static String formatEnchLevel(Integer level) { + switch (level) { + case 1: + return "I"; + case 2: + return "II"; + case 3: + return "III"; + case 4: + return "IV"; + case 5: + return "V"; + default: + return String.valueOf(level); + + } + } + } diff --git a/src/main/resources/enchi18n.yml b/src/main/resources/enchi18n.yml index e69de29bb..162d7b0ff 100644 --- a/src/main/resources/enchi18n.yml +++ b/src/main/resources/enchi18n.yml @@ -0,0 +1,35 @@ +enchi18n: + fire_protection: fire_protection + sharpness: sharpness + flame: flame + aqua_affinity: aqua_affinity + punch: punch + loyalty: loyalty + depth_strider: depth_strider + vanishing_curse: vanishing_curse + unbreaking: unbreaking + knockback: knockback + luck_of_the_sea: luck_of_the_sea + binding_curse: binding_curse + fortune: fortune + protection: protection + efficiency: efficiency + mending: mending + frost_walker: frost_walker + lure: lure + looting: looting + blast_protection: blast_protection + smite: smite + fire_aspect: fire_aspect + channeling: channeling + sweeping: sweeping + thorns: thorns + bane_of_arthropods: bane_of_arthropods + respiration: respiration + riptide: riptide + silk_touch: silk_touch + projectile_protection: projectile_protection + impaling: impaling + feather_falling: feather_falling + power: power + infinity: infinity