From 922829c4a5664cadcb0175d05f5672387a56f722 Mon Sep 17 00:00:00 2001 From: Auxilor Date: Wed, 16 Dec 2020 13:02:33 +0000 Subject: [PATCH] Fixed hide-enchants in chatcomponent API --- .../ecoenchants/nms/v1_16_R1/ChatComponent.java | 17 +++++++++++++++-- .../ecoenchants/nms/v1_16_R2/ChatComponent.java | 17 +++++++++++++++-- .../ecoenchants/nms/v1_16_R3/ChatComponent.java | 17 +++++++++++++++-- 3 files changed, 45 insertions(+), 6 deletions(-) diff --git a/NMS/v1_16_R1/src/main/java/com/willfp/ecoenchants/nms/v1_16_R1/ChatComponent.java b/NMS/v1_16_R1/src/main/java/com/willfp/ecoenchants/nms/v1_16_R1/ChatComponent.java index 3a07f94f..4081a5b5 100644 --- a/NMS/v1_16_R1/src/main/java/com/willfp/ecoenchants/nms/v1_16_R1/ChatComponent.java +++ b/NMS/v1_16_R1/src/main/java/com/willfp/ecoenchants/nms/v1_16_R1/ChatComponent.java @@ -5,10 +5,17 @@ import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.willfp.ecoenchants.nms.api.ChatComponentWrapper; -import net.minecraft.server.v1_16_R1.*; +import net.minecraft.server.v1_16_R1.ChatBaseComponent; +import net.minecraft.server.v1_16_R1.ChatHoverable; +import net.minecraft.server.v1_16_R1.ChatMessage; +import net.minecraft.server.v1_16_R1.ChatModifier; +import net.minecraft.server.v1_16_R1.IChatBaseComponent; +import net.minecraft.server.v1_16_R1.MojangsonParser; import org.bukkit.Material; import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack; +import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.EnchantmentStorageMeta; import java.lang.reflect.InvocationTargetException; import java.util.Arrays; @@ -47,8 +54,14 @@ public class ChatComponent implements ChatComponentWrapper { String id = json.getAsJsonObject().get("id").toString(); String tag = json.getAsJsonObject().get("tag").toString(); ItemStack itemStack = getFromTag(tag, id); + boolean hideEnchants = false; + if(itemStack.getItemMeta() != null) { + if(itemStack.getItemMeta().hasItemFlag(ItemFlag.HIDE_ENCHANTS)) hideEnchants = true; + if(itemStack.getItemMeta() instanceof EnchantmentStorageMeta && itemStack.getItemMeta().hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)) hideEnchants = true; + } + try { - itemStack = (ItemStack) Class.forName("com.willfp.ecoenchants.display.EnchantDisplay").getMethod("displayEnchantments", ItemStack.class).invoke(null, itemStack); + itemStack = (ItemStack) Class.forName("com.willfp.ecoenchants.display.EnchantDisplay").getMethod("displayEnchantments", ItemStack.class, boolean.class).invoke(null, itemStack, hideEnchants); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException | ClassNotFoundException e) { e.printStackTrace(); } diff --git a/NMS/v1_16_R2/src/main/java/com/willfp/ecoenchants/nms/v1_16_R2/ChatComponent.java b/NMS/v1_16_R2/src/main/java/com/willfp/ecoenchants/nms/v1_16_R2/ChatComponent.java index a918d576..5c180fdd 100644 --- a/NMS/v1_16_R2/src/main/java/com/willfp/ecoenchants/nms/v1_16_R2/ChatComponent.java +++ b/NMS/v1_16_R2/src/main/java/com/willfp/ecoenchants/nms/v1_16_R2/ChatComponent.java @@ -5,10 +5,17 @@ import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.willfp.ecoenchants.nms.api.ChatComponentWrapper; -import net.minecraft.server.v1_16_R2.*; +import net.minecraft.server.v1_16_R2.ChatBaseComponent; +import net.minecraft.server.v1_16_R2.ChatHoverable; +import net.minecraft.server.v1_16_R2.ChatMessage; +import net.minecraft.server.v1_16_R2.ChatModifier; +import net.minecraft.server.v1_16_R2.IChatBaseComponent; +import net.minecraft.server.v1_16_R2.MojangsonParser; import org.bukkit.Material; import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack; +import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.EnchantmentStorageMeta; import java.lang.reflect.InvocationTargetException; import java.util.Arrays; @@ -47,8 +54,14 @@ public class ChatComponent implements ChatComponentWrapper { String id = json.getAsJsonObject().get("id").toString(); String tag = json.getAsJsonObject().get("tag").toString(); ItemStack itemStack = getFromTag(tag, id); + boolean hideEnchants = false; + if(itemStack.getItemMeta() != null) { + if(itemStack.getItemMeta().hasItemFlag(ItemFlag.HIDE_ENCHANTS)) hideEnchants = true; + if(itemStack.getItemMeta() instanceof EnchantmentStorageMeta && itemStack.getItemMeta().hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)) hideEnchants = true; + } + try { - itemStack = (ItemStack) Class.forName("com.willfp.ecoenchants.display.EnchantDisplay").getMethod("displayEnchantments", ItemStack.class).invoke(null, itemStack); + itemStack = (ItemStack) Class.forName("com.willfp.ecoenchants.display.EnchantDisplay").getMethod("displayEnchantments", ItemStack.class, boolean.class).invoke(null, itemStack, hideEnchants); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException | ClassNotFoundException e) { e.printStackTrace(); } diff --git a/NMS/v1_16_R3/src/main/java/com/willfp/ecoenchants/nms/v1_16_R3/ChatComponent.java b/NMS/v1_16_R3/src/main/java/com/willfp/ecoenchants/nms/v1_16_R3/ChatComponent.java index 7f097ad8..18133260 100644 --- a/NMS/v1_16_R3/src/main/java/com/willfp/ecoenchants/nms/v1_16_R3/ChatComponent.java +++ b/NMS/v1_16_R3/src/main/java/com/willfp/ecoenchants/nms/v1_16_R3/ChatComponent.java @@ -5,10 +5,17 @@ import com.google.gson.JsonObject; import com.google.gson.JsonPrimitive; import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.willfp.ecoenchants.nms.api.ChatComponentWrapper; -import net.minecraft.server.v1_16_R3.*; +import net.minecraft.server.v1_16_R3.ChatBaseComponent; +import net.minecraft.server.v1_16_R3.ChatHoverable; +import net.minecraft.server.v1_16_R3.ChatMessage; +import net.minecraft.server.v1_16_R3.ChatModifier; +import net.minecraft.server.v1_16_R3.IChatBaseComponent; +import net.minecraft.server.v1_16_R3.MojangsonParser; import org.bukkit.Material; import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack; +import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemStack; +import org.bukkit.inventory.meta.EnchantmentStorageMeta; import java.lang.reflect.InvocationTargetException; import java.util.Arrays; @@ -47,8 +54,14 @@ public class ChatComponent implements ChatComponentWrapper { String id = json.getAsJsonObject().get("id").toString(); String tag = json.getAsJsonObject().get("tag").toString(); ItemStack itemStack = getFromTag(tag, id); + boolean hideEnchants = false; + if(itemStack.getItemMeta() != null) { + if(itemStack.getItemMeta().hasItemFlag(ItemFlag.HIDE_ENCHANTS)) hideEnchants = true; + if(itemStack.getItemMeta() instanceof EnchantmentStorageMeta && itemStack.getItemMeta().hasItemFlag(ItemFlag.HIDE_POTION_EFFECTS)) hideEnchants = true; + } + try { - itemStack = (ItemStack) Class.forName("com.willfp.ecoenchants.display.EnchantDisplay").getMethod("displayEnchantments", ItemStack.class).invoke(null, itemStack); + itemStack = (ItemStack) Class.forName("com.willfp.ecoenchants.display.EnchantDisplay").getMethod("displayEnchantments", ItemStack.class, boolean.class).invoke(null, itemStack, hideEnchants); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException | ClassNotFoundException e) { e.printStackTrace(); }