From f7bc9b950f0594cd9fffc06de1663b24418aa3b6 Mon Sep 17 00:00:00 2001 From: filoghost Date: Wed, 3 Mar 2021 10:53:49 +0100 Subject: [PATCH] Small cleanup --- .../core/hologram/StandardHologram.java | 3 - .../core/nms/ChatComponentAdapter.java | 26 ------ ...ava => ChatComponentCustomNameEditor.java} | 49 ++++++----- .../core/nms/CustomNameEditor.java | 12 +++ .../core/nms/NMSCommons.java | 2 +- .../core/nms/NMSManager.java | 2 +- .../core/nms/StringCustomNameEditor.java | 22 +++++ .../nms/v1_10_R1/EntityNMSItem.java | 2 +- .../nms/v1_10_R1/VersionNMSManager.java | 11 +-- .../nms/v1_11_R1/EntityNMSItem.java | 2 +- .../nms/v1_11_R1/VersionNMSManager.java | 11 +-- .../nms/v1_12_R1/EntityNMSItem.java | 2 +- .../nms/v1_12_R1/VersionNMSManager.java | 11 +-- .../nms/v1_13_R1/EntityNMSItem.java | 2 +- .../nms/v1_13_R1/VersionNMSManager.java | 61 ++++++------- .../nms/v1_13_R2/EntityNMSItem.java | 2 +- .../nms/v1_13_R2/VersionNMSManager.java | 61 ++++++------- .../nms/v1_14_R1/EntityNMSItem.java | 2 +- .../nms/v1_14_R1/VersionNMSManager.java | 85 +++++++++---------- .../nms/v1_15_R1/EntityNMSItem.java | 2 +- .../nms/v1_15_R1/VersionNMSManager.java | 61 ++++++------- .../nms/v1_16_R1/EntityNMSItem.java | 2 +- .../nms/v1_16_R1/VersionNMSManager.java | 63 ++++++-------- .../nms/v1_16_R2/EntityNMSItem.java | 2 +- .../nms/v1_16_R2/VersionNMSManager.java | 63 ++++++-------- .../nms/v1_16_R3/EntityNMSItem.java | 2 +- .../nms/v1_16_R3/VersionNMSManager.java | 63 ++++++-------- .../nms/v1_8_R2/EntityNMSItem.java | 2 +- .../nms/v1_8_R2/VersionNMSManager.java | 11 +-- .../nms/v1_8_R3/EntityNMSItem.java | 2 +- .../nms/v1_8_R3/VersionNMSManager.java | 11 +-- .../nms/v1_9_R1/EntityNMSItem.java | 2 +- .../nms/v1_9_R1/VersionNMSManager.java | 11 +-- .../nms/v1_9_R2/EntityNMSItem.java | 2 +- .../nms/v1_9_R2/VersionNMSManager.java | 11 +-- .../bridge/protocollib/MetadataHelper.java | 44 +++++----- .../bridge/protocollib/PacketListener.java | 5 +- .../commands/subs/CreateCommand.java | 3 +- .../commands/subs/ReadimageCommand.java | 2 +- .../disk/HologramLineParser.java | 6 +- .../object/api/APIHologram.java | 16 +++- .../object/api/APIItemLine.java | 5 +- .../object/api/APITextLine.java | 5 +- .../object/base/BaseHologram.java | 5 +- .../object/base/BaseHologramLine.java | 18 ++-- .../object/base/BaseItemLine.java | 5 +- .../object/base/BaseTextLine.java | 5 +- .../object/base/BaseTouchableLine.java | 14 +-- .../object/internal/InternalHologram.java | 9 ++ .../object/internal/InternalItemLine.java | 6 +- .../object/internal/InternalTextLine.java | 6 +- 51 files changed, 416 insertions(+), 416 deletions(-) delete mode 100644 core/src/main/java/me/filoghost/holographicdisplays/core/nms/ChatComponentAdapter.java rename core/src/main/java/me/filoghost/holographicdisplays/core/nms/{CustomNameHelper.java => ChatComponentCustomNameEditor.java} (56%) create mode 100644 core/src/main/java/me/filoghost/holographicdisplays/core/nms/CustomNameEditor.java create mode 100644 core/src/main/java/me/filoghost/holographicdisplays/core/nms/StringCustomNameEditor.java diff --git a/core/src/main/java/me/filoghost/holographicdisplays/core/hologram/StandardHologram.java b/core/src/main/java/me/filoghost/holographicdisplays/core/hologram/StandardHologram.java index e1488088..2467d359 100644 --- a/core/src/main/java/me/filoghost/holographicdisplays/core/hologram/StandardHologram.java +++ b/core/src/main/java/me/filoghost/holographicdisplays/core/hologram/StandardHologram.java @@ -5,7 +5,6 @@ */ package me.filoghost.holographicdisplays.core.hologram; -import me.filoghost.holographicdisplays.core.nms.NMSManager; import org.bukkit.Chunk; import org.bukkit.Location; import org.bukkit.entity.Player; @@ -43,6 +42,4 @@ public interface StandardHologram { void setDeleted(); - NMSManager getNMSManager(); - } diff --git a/core/src/main/java/me/filoghost/holographicdisplays/core/nms/ChatComponentAdapter.java b/core/src/main/java/me/filoghost/holographicdisplays/core/nms/ChatComponentAdapter.java deleted file mode 100644 index 4ff5e62f..00000000 --- a/core/src/main/java/me/filoghost/holographicdisplays/core/nms/ChatComponentAdapter.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (C) filoghost and contributors - * - * SPDX-License-Identifier: GPL-3.0-or-later - */ -package me.filoghost.holographicdisplays.core.nms; - -import java.util.List; - -public interface ChatComponentAdapter { - - T cast(Object chatComponentObject); - - String getText(T chatComponent); - - List getSiblings(T chatComponent); - - void addSibling(T chatComponent, T newSibling); - - default T cloneComponent(T chatComponent) { - return cloneComponent(chatComponent, getText(chatComponent)); - } - - T cloneComponent(T chatComponent, String newText); - -} diff --git a/core/src/main/java/me/filoghost/holographicdisplays/core/nms/CustomNameHelper.java b/core/src/main/java/me/filoghost/holographicdisplays/core/nms/ChatComponentCustomNameEditor.java similarity index 56% rename from core/src/main/java/me/filoghost/holographicdisplays/core/nms/CustomNameHelper.java rename to core/src/main/java/me/filoghost/holographicdisplays/core/nms/ChatComponentCustomNameEditor.java index 10672583..6f5f0e56 100644 --- a/core/src/main/java/me/filoghost/holographicdisplays/core/nms/CustomNameHelper.java +++ b/core/src/main/java/me/filoghost/holographicdisplays/core/nms/ChatComponentCustomNameEditor.java @@ -7,37 +7,30 @@ package me.filoghost.holographicdisplays.core.nms; import java.util.List; -public class CustomNameHelper { +public interface ChatComponentCustomNameEditor extends CustomNameEditor { - - public static String replaceCustomNameString(Object customNameObject, String target, String replacement) { - String customName = (String) customNameObject; - if (customName.contains(target)) { - return customName.replace(target, replacement); - } else { - return customName; - } - } - - public static T replaceCustomNameChatComponent(ChatComponentAdapter versionAdapter, Object customNameObject, String target, String replacement) { + @Override + default T replaceCustomName(Object customNameObject, String target, String replacement) { // Custom name is expected to be a ChatComponentText with empty text and child components (called "siblings") that do not contain more components. - T rootComponent = versionAdapter.cast(customNameObject); - if (!versionAdapter.getText(rootComponent).isEmpty()) { + @SuppressWarnings("unchecked") + T rootComponent = (T) customNameObject; + + if (!getText(rootComponent).isEmpty()) { throw new IllegalArgumentException("Expected root component with empty text"); } boolean[] childrenContainingTarget = null; - List children = versionAdapter.getSiblings(rootComponent); + List children = getSiblings(rootComponent); int childrenSize = children.size(); for (int i = 0; i < childrenSize; i++) { - T childComponent = versionAdapter.cast(children.get(i)); + T childComponent = children.get(i); - if (!versionAdapter.getSiblings(childComponent).isEmpty()) { + if (!getSiblings(childComponent).isEmpty()) { throw new IllegalArgumentException("Expected child component without sub-nodes"); } - if (versionAdapter.getText(childComponent).contains(target)) { + if (getText(childComponent).contains(target)) { // Lazy initialization for performance, since this method can be called frequently. if (childrenContainingTarget == null) { childrenContainingTarget = new boolean[childrenSize]; @@ -52,20 +45,32 @@ public class CustomNameHelper { } // Clone all the objects and apply replacements where needed. - T clonedRoot = versionAdapter.cloneComponent(rootComponent); + T clonedRoot = cloneComponent(rootComponent); for (int i = 0; i < childrenSize; i++) { T childComponent = children.get(i); - String newText = versionAdapter.getText(childComponent); + String newText = getText(childComponent); if (childrenContainingTarget[i]) { newText = newText.replace(target, replacement); } - T clonedChild = versionAdapter.cloneComponent(childComponent, newText); - versionAdapter.addSibling(clonedRoot, clonedChild); + T clonedChild = cloneComponent(childComponent, newText); + addSibling(clonedRoot, clonedChild); } return clonedRoot; } + String getText(T chatComponent); + + List getSiblings(T chatComponent); + + void addSibling(T chatComponent, T newSibling); + + default T cloneComponent(T chatComponent) { + return cloneComponent(chatComponent, getText(chatComponent)); + } + + T cloneComponent(T chatComponent, String newText); + } diff --git a/core/src/main/java/me/filoghost/holographicdisplays/core/nms/CustomNameEditor.java b/core/src/main/java/me/filoghost/holographicdisplays/core/nms/CustomNameEditor.java new file mode 100644 index 00000000..749e8a2f --- /dev/null +++ b/core/src/main/java/me/filoghost/holographicdisplays/core/nms/CustomNameEditor.java @@ -0,0 +1,12 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.core.nms; + +public interface CustomNameEditor { + + Object replaceCustomName(Object customNameObject, String target, String replacement); + +} diff --git a/core/src/main/java/me/filoghost/holographicdisplays/core/nms/NMSCommons.java b/core/src/main/java/me/filoghost/holographicdisplays/core/nms/NMSCommons.java index d0d76452..270e92dd 100644 --- a/core/src/main/java/me/filoghost/holographicdisplays/core/nms/NMSCommons.java +++ b/core/src/main/java/me/filoghost/holographicdisplays/core/nms/NMSCommons.java @@ -11,7 +11,7 @@ import org.bukkit.ChatColor; public class NMSCommons { // This is used on hologram icons, to prevent vanilla items from merging with them. - public static final String ANTISTACK_LORE = ChatColor.BLACK.toString() + Math.random(); + public static final String ANTI_STACK_LORE = ChatColor.BLACK.toString() + Math.random(); private static final boolean IS_PAPER_SERVER = Bukkit.getName().equals("Paper"); diff --git a/core/src/main/java/me/filoghost/holographicdisplays/core/nms/NMSManager.java b/core/src/main/java/me/filoghost/holographicdisplays/core/nms/NMSManager.java index 4110445a..bf842fda 100644 --- a/core/src/main/java/me/filoghost/holographicdisplays/core/nms/NMSManager.java +++ b/core/src/main/java/me/filoghost/holographicdisplays/core/nms/NMSManager.java @@ -30,6 +30,6 @@ public interface NMSManager { NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID); - Object replaceCustomNameText(Object customNameObject, String target, String replacement); + CustomNameEditor getCustomNameChatComponentEditor(); } diff --git a/core/src/main/java/me/filoghost/holographicdisplays/core/nms/StringCustomNameEditor.java b/core/src/main/java/me/filoghost/holographicdisplays/core/nms/StringCustomNameEditor.java new file mode 100644 index 00000000..a1c05389 --- /dev/null +++ b/core/src/main/java/me/filoghost/holographicdisplays/core/nms/StringCustomNameEditor.java @@ -0,0 +1,22 @@ +/* + * Copyright (C) filoghost and contributors + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ +package me.filoghost.holographicdisplays.core.nms; + +public enum StringCustomNameEditor implements CustomNameEditor { + + INSTANCE; + + @Override + public String replaceCustomName(Object customNameNMSObject, String target, String replacement) { + String customName = (String) customNameNMSObject; + if (customName.contains(target)) { + return customName.replace(target, replacement); + } else { + return customName; + } + } + +} diff --git a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityNMSItem.java b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityNMSItem.java index 1590aa8c..5069b895 100644 --- a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityNMSItem.java +++ b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/EntityNMSItem.java @@ -194,7 +194,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem { } NBTTagList tagList = new NBTTagList(); - tagList.add(new NBTTagString(NMSCommons.ANTISTACK_LORE)); // Antistack lore + tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE)); // Antistack lore display.set("Lore", tagList); setItemStack(newItem); diff --git a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionNMSManager.java b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionNMSManager.java index 3e90fb00..5ad6a80a 100644 --- a/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionNMSManager.java +++ b/nms/v1_10_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_10_R1/VersionNMSManager.java @@ -10,14 +10,15 @@ import me.filoghost.fcommons.reflection.ClassToken; import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.fcommons.reflection.ReflectMethod; import me.filoghost.holographicdisplays.core.DebugLogger; -import me.filoghost.holographicdisplays.core.nms.CustomNameHelper; +import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; +import me.filoghost.holographicdisplays.core.hologram.StandardItemLine; +import me.filoghost.holographicdisplays.core.nms.CustomNameEditor; import me.filoghost.holographicdisplays.core.nms.NMSManager; import me.filoghost.holographicdisplays.core.nms.PacketController; +import me.filoghost.holographicdisplays.core.nms.StringCustomNameEditor; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase; import me.filoghost.holographicdisplays.core.nms.entity.NMSItem; -import me.filoghost.holographicdisplays.core.hologram.StandardItemLine; -import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; import net.minecraft.server.v1_10_R1.Entity; import net.minecraft.server.v1_10_R1.EntityTypes; import net.minecraft.server.v1_10_R1.MathHelper; @@ -142,8 +143,8 @@ public class VersionNMSManager implements NMSManager { } @Override - public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { - return CustomNameHelper.replaceCustomNameString(customNameObject, target, replacement); + public CustomNameEditor getCustomNameChatComponentEditor() { + return StringCustomNameEditor.INSTANCE; } } diff --git a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityNMSItem.java b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityNMSItem.java index 88091660..e9cf3d0c 100644 --- a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityNMSItem.java +++ b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/EntityNMSItem.java @@ -168,7 +168,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem { } NBTTagList tagList = new NBTTagList(); - tagList.add(new NBTTagString(NMSCommons.ANTISTACK_LORE)); // Antistack lore + tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE)); // Antistack lore display.set("Lore", tagList); setItemStack(newItem); diff --git a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionNMSManager.java b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionNMSManager.java index 4c20e487..f717c6dc 100644 --- a/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionNMSManager.java +++ b/nms/v1_11_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_11_R1/VersionNMSManager.java @@ -10,14 +10,15 @@ import me.filoghost.fcommons.reflection.ClassToken; import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.fcommons.reflection.ReflectMethod; import me.filoghost.holographicdisplays.core.DebugLogger; -import me.filoghost.holographicdisplays.core.nms.CustomNameHelper; +import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; +import me.filoghost.holographicdisplays.core.hologram.StandardItemLine; +import me.filoghost.holographicdisplays.core.nms.CustomNameEditor; import me.filoghost.holographicdisplays.core.nms.NMSManager; import me.filoghost.holographicdisplays.core.nms.PacketController; +import me.filoghost.holographicdisplays.core.nms.StringCustomNameEditor; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase; import me.filoghost.holographicdisplays.core.nms.entity.NMSItem; -import me.filoghost.holographicdisplays.core.hologram.StandardItemLine; -import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; import net.minecraft.server.v1_11_R1.Entity; import net.minecraft.server.v1_11_R1.EntityTypes; import net.minecraft.server.v1_11_R1.MathHelper; @@ -150,8 +151,8 @@ public class VersionNMSManager implements NMSManager { } @Override - public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { - return CustomNameHelper.replaceCustomNameString(customNameObject, target, replacement); + public CustomNameEditor getCustomNameChatComponentEditor() { + return StringCustomNameEditor.INSTANCE; } } diff --git a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityNMSItem.java b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityNMSItem.java index 0089d56b..9b58ce33 100644 --- a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityNMSItem.java +++ b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/EntityNMSItem.java @@ -168,7 +168,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem { } NBTTagList tagList = new NBTTagList(); - tagList.add(new NBTTagString(NMSCommons.ANTISTACK_LORE)); // Antistack lore + tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE)); // Antistack lore display.set("Lore", tagList); setItemStack(newItem); diff --git a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionNMSManager.java b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionNMSManager.java index 9aa51180..4d008e4d 100644 --- a/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionNMSManager.java +++ b/nms/v1_12_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_12_R1/VersionNMSManager.java @@ -10,14 +10,15 @@ import me.filoghost.fcommons.reflection.ClassToken; import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.fcommons.reflection.ReflectMethod; import me.filoghost.holographicdisplays.core.DebugLogger; -import me.filoghost.holographicdisplays.core.nms.CustomNameHelper; +import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; +import me.filoghost.holographicdisplays.core.hologram.StandardItemLine; +import me.filoghost.holographicdisplays.core.nms.CustomNameEditor; import me.filoghost.holographicdisplays.core.nms.NMSManager; import me.filoghost.holographicdisplays.core.nms.PacketController; +import me.filoghost.holographicdisplays.core.nms.StringCustomNameEditor; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase; import me.filoghost.holographicdisplays.core.nms.entity.NMSItem; -import me.filoghost.holographicdisplays.core.hologram.StandardItemLine; -import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; import net.minecraft.server.v1_12_R1.Entity; import net.minecraft.server.v1_12_R1.EntityTypes; import net.minecraft.server.v1_12_R1.MathHelper; @@ -150,8 +151,8 @@ public class VersionNMSManager implements NMSManager { } @Override - public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { - return CustomNameHelper.replaceCustomNameString(customNameObject, target, replacement); + public CustomNameEditor getCustomNameChatComponentEditor() { + return StringCustomNameEditor.INSTANCE; } } diff --git a/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/EntityNMSItem.java b/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/EntityNMSItem.java index 84efbf88..646701c4 100644 --- a/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/EntityNMSItem.java +++ b/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/EntityNMSItem.java @@ -168,7 +168,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem { } NBTTagList tagList = new NBTTagList(); - tagList.add(new NBTTagString(NMSCommons.ANTISTACK_LORE)); // Antistack lore + tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE)); // Antistack lore display.set("Lore", tagList); setItemStack(newItem); diff --git a/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/VersionNMSManager.java b/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/VersionNMSManager.java index 7e8952fd..2189a00f 100644 --- a/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/VersionNMSManager.java +++ b/nms/v1_13_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R1/VersionNMSManager.java @@ -10,8 +10,8 @@ import me.filoghost.fcommons.reflection.ClassToken; import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.fcommons.reflection.ReflectMethod; import me.filoghost.holographicdisplays.core.DebugLogger; -import me.filoghost.holographicdisplays.core.nms.ChatComponentAdapter; -import me.filoghost.holographicdisplays.core.nms.CustomNameHelper; +import me.filoghost.holographicdisplays.core.nms.CustomNameEditor; +import me.filoghost.holographicdisplays.core.nms.ChatComponentCustomNameEditor; import me.filoghost.holographicdisplays.core.nms.NMSCommons; import me.filoghost.holographicdisplays.core.nms.NMSManager; import me.filoghost.holographicdisplays.core.nms.PacketController; @@ -167,41 +167,34 @@ public class VersionNMSManager implements NMSManager { } @Override - public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { - return CustomNameHelper.replaceCustomNameChatComponent(NMSChatComponentAdapter.INSTANCE, customNameObject, target, replacement); + public CustomNameEditor getCustomNameChatComponentEditor() { + return VersionChatComponentCustomNameEditor.INSTANCE; } - private enum NMSChatComponentAdapter implements ChatComponentAdapter { + private enum VersionChatComponentCustomNameEditor implements ChatComponentCustomNameEditor { - INSTANCE { - - @Override - public ChatComponentText cast(Object chatComponentObject) { - return (ChatComponentText) chatComponentObject; - } - - @Override - public String getText(IChatBaseComponent chatComponent) { - return chatComponent.getText(); - } - - @Override - public List getSiblings(IChatBaseComponent chatComponent) { - return chatComponent.a(); - } - - @Override - public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) { - chatComponent.addSibling(newSibling); - } - - @Override - public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) { - ChatComponentText clonedChatComponent = new ChatComponentText(newText); - clonedChatComponent.setChatModifier(chatComponent.getChatModifier().clone()); - return clonedChatComponent; - } - + INSTANCE; + + @Override + public String getText(IChatBaseComponent chatComponent) { + return chatComponent.getText(); + } + + @Override + public List getSiblings(IChatBaseComponent chatComponent) { + return chatComponent.a(); + } + + @Override + public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) { + chatComponent.addSibling(newSibling); + } + + @Override + public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) { + ChatComponentText clonedChatComponent = new ChatComponentText(newText); + clonedChatComponent.setChatModifier(chatComponent.getChatModifier().clone()); + return clonedChatComponent; } } diff --git a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityNMSItem.java b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityNMSItem.java index c728f7ca..6d4beb75 100644 --- a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityNMSItem.java +++ b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/EntityNMSItem.java @@ -168,7 +168,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem { } NBTTagList tagList = new NBTTagList(); - tagList.add(new NBTTagString(NMSCommons.ANTISTACK_LORE)); // Antistack lore + tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE)); // Antistack lore display.set("Lore", tagList); setItemStack(newItem); diff --git a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionNMSManager.java b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionNMSManager.java index e6c58ae3..089c047f 100644 --- a/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionNMSManager.java +++ b/nms/v1_13_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_13_R2/VersionNMSManager.java @@ -10,8 +10,8 @@ import me.filoghost.fcommons.reflection.ClassToken; import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.fcommons.reflection.ReflectMethod; import me.filoghost.holographicdisplays.core.DebugLogger; -import me.filoghost.holographicdisplays.core.nms.ChatComponentAdapter; -import me.filoghost.holographicdisplays.core.nms.CustomNameHelper; +import me.filoghost.holographicdisplays.core.nms.CustomNameEditor; +import me.filoghost.holographicdisplays.core.nms.ChatComponentCustomNameEditor; import me.filoghost.holographicdisplays.core.nms.NMSCommons; import me.filoghost.holographicdisplays.core.nms.NMSManager; import me.filoghost.holographicdisplays.core.nms.PacketController; @@ -168,41 +168,34 @@ public class VersionNMSManager implements NMSManager { } @Override - public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { - return CustomNameHelper.replaceCustomNameChatComponent(NMSChatComponentAdapter.INSTANCE, customNameObject, target, replacement); + public CustomNameEditor getCustomNameChatComponentEditor() { + return VersionChatComponentCustomNameEditor.INSTANCE; } - private enum NMSChatComponentAdapter implements ChatComponentAdapter { + private enum VersionChatComponentCustomNameEditor implements ChatComponentCustomNameEditor { - INSTANCE { - - @Override - public ChatComponentText cast(Object chatComponentObject) { - return (ChatComponentText) chatComponentObject; - } - - @Override - public String getText(IChatBaseComponent chatComponent) { - return chatComponent.getText(); - } - - @Override - public List getSiblings(IChatBaseComponent chatComponent) { - return chatComponent.a(); - } - - @Override - public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) { - chatComponent.addSibling(newSibling); - } - - @Override - public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) { - ChatComponentText clonedChatComponent = new ChatComponentText(newText); - clonedChatComponent.setChatModifier(chatComponent.getChatModifier().clone()); - return clonedChatComponent; - } - + INSTANCE; + + @Override + public String getText(IChatBaseComponent chatComponent) { + return chatComponent.getText(); + } + + @Override + public List getSiblings(IChatBaseComponent chatComponent) { + return chatComponent.a(); + } + + @Override + public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) { + chatComponent.addSibling(newSibling); + } + + @Override + public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) { + ChatComponentText clonedChatComponent = new ChatComponentText(newText); + clonedChatComponent.setChatModifier(chatComponent.getChatModifier().clone()); + return clonedChatComponent; } } diff --git a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityNMSItem.java b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityNMSItem.java index b1114002..37508dda 100644 --- a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityNMSItem.java +++ b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/EntityNMSItem.java @@ -170,7 +170,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem { } NBTTagList tagList = new NBTTagList(); - tagList.add(new NBTTagString(NMSCommons.ANTISTACK_LORE)); // Antistack lore + tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE)); // Antistack lore display.set("Lore", tagList); setItemStack(newItem); diff --git a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionNMSManager.java b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionNMSManager.java index aff79f39..3154c555 100644 --- a/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionNMSManager.java +++ b/nms/v1_14_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_14_R1/VersionNMSManager.java @@ -10,8 +10,8 @@ import me.filoghost.fcommons.reflection.ClassToken; import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.fcommons.reflection.ReflectMethod; import me.filoghost.holographicdisplays.core.DebugLogger; -import me.filoghost.holographicdisplays.core.nms.ChatComponentAdapter; -import me.filoghost.holographicdisplays.core.nms.CustomNameHelper; +import me.filoghost.holographicdisplays.core.nms.CustomNameEditor; +import me.filoghost.holographicdisplays.core.nms.ChatComponentCustomNameEditor; import me.filoghost.holographicdisplays.core.nms.NMSManager; import me.filoghost.holographicdisplays.core.nms.PacketController; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; @@ -155,58 +155,51 @@ public class VersionNMSManager implements NMSManager { } @Override - public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { - return CustomNameHelper.replaceCustomNameChatComponent(NMSChatComponentAdapter.INSTANCE, customNameObject, target, replacement); + public CustomNameEditor getCustomNameChatComponentEditor() { + return VersionChatComponentCustomNameEditor.INSTANCE; } - private enum NMSChatComponentAdapter implements ChatComponentAdapter { + private enum VersionChatComponentCustomNameEditor implements ChatComponentCustomNameEditor { - INSTANCE { + INSTANCE; - private boolean useNewGetSiblingsMethod = true; - private final ReflectField> OLD_SIBLINGS_FIELD = ReflectField.lookup(new ClassToken>(){}, ChatBaseComponent.class, "a"); - - @Override - public ChatComponentText cast(Object chatComponentObject) { - return (ChatComponentText) chatComponentObject; - } - - @Override - public String getText(IChatBaseComponent chatComponent) { - return chatComponent.getText(); - } - - @Override - public List getSiblings(IChatBaseComponent chatComponent) { - if (useNewGetSiblingsMethod) { - try { - return chatComponent.getSiblings(); - } catch (NoSuchMethodError e) { - // The method was named differently in older 1.14 versions, use workaround. - useNewGetSiblingsMethod = false; - } - } - - // Access siblings field directly in older 1.14 versions. + private boolean useNewGetSiblingsMethod = true; + private final ReflectField> OLD_SIBLINGS_FIELD = ReflectField.lookup(new ClassToken>(){}, ChatBaseComponent.class, "a"); + + @Override + public String getText(IChatBaseComponent chatComponent) { + return chatComponent.getText(); + } + + @Override + public List getSiblings(IChatBaseComponent chatComponent) { + if (useNewGetSiblingsMethod) { try { - return OLD_SIBLINGS_FIELD.get(chatComponent); - } catch (ReflectiveOperationException e) { - throw new RuntimeException(e); + return chatComponent.getSiblings(); + } catch (NoSuchMethodError e) { + // The method was named differently in older 1.14 versions, use workaround. + useNewGetSiblingsMethod = false; } } - - @Override - public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) { - chatComponent.addSibling(newSibling); - } - - @Override - public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) { - ChatComponentText clonedChatComponent = new ChatComponentText(newText); - clonedChatComponent.setChatModifier(chatComponent.getChatModifier().clone()); - return clonedChatComponent; - } + // Access siblings field directly in older 1.14 versions. + try { + return OLD_SIBLINGS_FIELD.get(chatComponent); + } catch (ReflectiveOperationException e) { + throw new RuntimeException(e); + } + } + + @Override + public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) { + chatComponent.addSibling(newSibling); + } + + @Override + public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) { + ChatComponentText clonedChatComponent = new ChatComponentText(newText); + clonedChatComponent.setChatModifier(chatComponent.getChatModifier().clone()); + return clonedChatComponent; } } diff --git a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityNMSItem.java b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityNMSItem.java index 83d8d8b0..3ce2e4cc 100644 --- a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityNMSItem.java +++ b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/EntityNMSItem.java @@ -170,7 +170,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem { } NBTTagList tagList = new NBTTagList(); - tagList.add(NBTTagString.a(NMSCommons.ANTISTACK_LORE)); // Antistack lore + tagList.add(NBTTagString.a(NMSCommons.ANTI_STACK_LORE)); // Antistack lore display.set("Lore", tagList); setItemStack(newItem); diff --git a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionNMSManager.java b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionNMSManager.java index c2c55671..fbfe1347 100644 --- a/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionNMSManager.java +++ b/nms/v1_15_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_15_R1/VersionNMSManager.java @@ -10,8 +10,8 @@ import me.filoghost.fcommons.reflection.ClassToken; import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.fcommons.reflection.ReflectMethod; import me.filoghost.holographicdisplays.core.DebugLogger; -import me.filoghost.holographicdisplays.core.nms.ChatComponentAdapter; -import me.filoghost.holographicdisplays.core.nms.CustomNameHelper; +import me.filoghost.holographicdisplays.core.nms.CustomNameEditor; +import me.filoghost.holographicdisplays.core.nms.ChatComponentCustomNameEditor; import me.filoghost.holographicdisplays.core.nms.NMSManager; import me.filoghost.holographicdisplays.core.nms.PacketController; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; @@ -154,41 +154,34 @@ public class VersionNMSManager implements NMSManager { } @Override - public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { - return CustomNameHelper.replaceCustomNameChatComponent(NMSChatComponentAdapter.INSTANCE, customNameObject, target, replacement); + public CustomNameEditor getCustomNameChatComponentEditor() { + return VersionChatComponentCustomNameEditor.INSTANCE; } - private enum NMSChatComponentAdapter implements ChatComponentAdapter { + private enum VersionChatComponentCustomNameEditor implements ChatComponentCustomNameEditor { - INSTANCE { - - @Override - public ChatComponentText cast(Object chatComponentObject) { - return (ChatComponentText) chatComponentObject; - } - - @Override - public String getText(IChatBaseComponent chatComponent) { - return chatComponent.getText(); - } - - @Override - public List getSiblings(IChatBaseComponent chatComponent) { - return chatComponent.getSiblings(); - } - - @Override - public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) { - chatComponent.addSibling(newSibling); - } - - @Override - public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) { - ChatComponentText clonedChatComponent = new ChatComponentText(newText); - clonedChatComponent.setChatModifier(chatComponent.getChatModifier().clone()); - return clonedChatComponent; - } - + INSTANCE; + + @Override + public String getText(IChatBaseComponent chatComponent) { + return chatComponent.getText(); + } + + @Override + public List getSiblings(IChatBaseComponent chatComponent) { + return chatComponent.getSiblings(); + } + + @Override + public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) { + chatComponent.addSibling(newSibling); + } + + @Override + public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) { + ChatComponentText clonedChatComponent = new ChatComponentText(newText); + clonedChatComponent.setChatModifier(chatComponent.getChatModifier().clone()); + return clonedChatComponent; } } diff --git a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityNMSItem.java b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityNMSItem.java index 0951b6bb..ae0d24ed 100644 --- a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityNMSItem.java +++ b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/EntityNMSItem.java @@ -170,7 +170,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem { } NBTTagList tagList = new NBTTagList(); - tagList.add(NBTTagString.a(NMSCommons.ANTISTACK_LORE)); // Antistack lore + tagList.add(NBTTagString.a(NMSCommons.ANTI_STACK_LORE)); // Antistack lore display.set("Lore", tagList); setItemStack(newItem); diff --git a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionNMSManager.java b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionNMSManager.java index 7ab7e97d..1dfc9e14 100644 --- a/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionNMSManager.java +++ b/nms/v1_16_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R1/VersionNMSManager.java @@ -10,8 +10,8 @@ import me.filoghost.fcommons.reflection.ClassToken; import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.fcommons.reflection.ReflectMethod; import me.filoghost.holographicdisplays.core.DebugLogger; -import me.filoghost.holographicdisplays.core.nms.ChatComponentAdapter; -import me.filoghost.holographicdisplays.core.nms.CustomNameHelper; +import me.filoghost.holographicdisplays.core.nms.CustomNameEditor; +import me.filoghost.holographicdisplays.core.nms.ChatComponentCustomNameEditor; import me.filoghost.holographicdisplays.core.nms.NMSManager; import me.filoghost.holographicdisplays.core.nms.PacketController; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; @@ -154,42 +154,35 @@ public class VersionNMSManager implements NMSManager { } @Override - public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { - return CustomNameHelper.replaceCustomNameChatComponent(NMSChatComponentAdapter.INSTANCE, customNameObject, target, replacement); + public CustomNameEditor getCustomNameChatComponentEditor() { + return VersionChatComponentCustomNameEditor.INSTANCE; } - private enum NMSChatComponentAdapter implements ChatComponentAdapter { + private enum VersionChatComponentCustomNameEditor implements ChatComponentCustomNameEditor { - INSTANCE { - - @Override - public ChatComponentText cast(Object chatComponentObject) { - return (ChatComponentText) chatComponentObject; - } - - @Override - public String getText(IChatBaseComponent chatComponent) { - return chatComponent.getText(); - } - - @Override - public List getSiblings(IChatBaseComponent chatComponent) { - return chatComponent.getSiblings(); - } - - @Override - public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) { - newSibling.getChatModifier().setChatModifier(chatComponent.getChatModifier()); - chatComponent.getSiblings().add(newSibling); - } - - @Override - public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) { - ChatComponentText clonedChatComponent = new ChatComponentText(newText); - clonedChatComponent.setChatModifier(chatComponent.getChatModifier().a()); - return clonedChatComponent; - } - + INSTANCE; + + @Override + public String getText(IChatBaseComponent chatComponent) { + return chatComponent.getText(); + } + + @Override + public List getSiblings(IChatBaseComponent chatComponent) { + return chatComponent.getSiblings(); + } + + @Override + public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) { + newSibling.getChatModifier().setChatModifier(chatComponent.getChatModifier()); + chatComponent.getSiblings().add(newSibling); + } + + @Override + public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) { + ChatComponentText clonedChatComponent = new ChatComponentText(newText); + clonedChatComponent.setChatModifier(chatComponent.getChatModifier().a()); + return clonedChatComponent; } } diff --git a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityNMSItem.java b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityNMSItem.java index e9c12b26..aec0324f 100644 --- a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityNMSItem.java +++ b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/EntityNMSItem.java @@ -170,7 +170,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem { } NBTTagList tagList = new NBTTagList(); - tagList.add(NBTTagString.a(NMSCommons.ANTISTACK_LORE)); // Antistack lore + tagList.add(NBTTagString.a(NMSCommons.ANTI_STACK_LORE)); // Antistack lore display.set("Lore", tagList); setItemStack(newItem); diff --git a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionNMSManager.java b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionNMSManager.java index 5382e4bc..a48d1073 100644 --- a/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionNMSManager.java +++ b/nms/v1_16_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R2/VersionNMSManager.java @@ -10,8 +10,8 @@ import me.filoghost.fcommons.reflection.ClassToken; import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.fcommons.reflection.ReflectMethod; import me.filoghost.holographicdisplays.core.DebugLogger; -import me.filoghost.holographicdisplays.core.nms.ChatComponentAdapter; -import me.filoghost.holographicdisplays.core.nms.CustomNameHelper; +import me.filoghost.holographicdisplays.core.nms.CustomNameEditor; +import me.filoghost.holographicdisplays.core.nms.ChatComponentCustomNameEditor; import me.filoghost.holographicdisplays.core.nms.NMSManager; import me.filoghost.holographicdisplays.core.nms.PacketController; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; @@ -145,42 +145,35 @@ public class VersionNMSManager implements NMSManager { } @Override - public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { - return CustomNameHelper.replaceCustomNameChatComponent(NMSChatComponentAdapter.INSTANCE, customNameObject, target, replacement); + public CustomNameEditor getCustomNameChatComponentEditor() { + return VersionChatComponentCustomNameEditor.INSTANCE; } - private enum NMSChatComponentAdapter implements ChatComponentAdapter { + private enum VersionChatComponentCustomNameEditor implements ChatComponentCustomNameEditor { - INSTANCE { - - @Override - public ChatComponentText cast(Object chatComponentObject) { - return (ChatComponentText) chatComponentObject; - } - - @Override - public String getText(IChatBaseComponent chatComponent) { - return chatComponent.getText(); - } - - @Override - public List getSiblings(IChatBaseComponent chatComponent) { - return chatComponent.getSiblings(); - } - - @Override - public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) { - newSibling.getChatModifier().setChatModifier(chatComponent.getChatModifier()); - chatComponent.getSiblings().add(newSibling); - } - - @Override - public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) { - ChatComponentText clonedChatComponent = new ChatComponentText(newText); - clonedChatComponent.setChatModifier(chatComponent.getChatModifier().a()); - return clonedChatComponent; - } - + INSTANCE; + + @Override + public String getText(IChatBaseComponent chatComponent) { + return chatComponent.getText(); + } + + @Override + public List getSiblings(IChatBaseComponent chatComponent) { + return chatComponent.getSiblings(); + } + + @Override + public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) { + newSibling.getChatModifier().setChatModifier(chatComponent.getChatModifier()); + chatComponent.getSiblings().add(newSibling); + } + + @Override + public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) { + ChatComponentText clonedChatComponent = new ChatComponentText(newText); + clonedChatComponent.setChatModifier(chatComponent.getChatModifier().a()); + return clonedChatComponent; } } diff --git a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityNMSItem.java b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityNMSItem.java index aa63f977..79d60d7b 100644 --- a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityNMSItem.java +++ b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/EntityNMSItem.java @@ -170,7 +170,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem { } NBTTagList tagList = new NBTTagList(); - tagList.add(NBTTagString.a(NMSCommons.ANTISTACK_LORE)); // Antistack lore + tagList.add(NBTTagString.a(NMSCommons.ANTI_STACK_LORE)); // Antistack lore display.set("Lore", tagList); setItemStack(newItem); diff --git a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionNMSManager.java b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionNMSManager.java index 189e4217..1d7dad19 100644 --- a/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionNMSManager.java +++ b/nms/v1_16_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_16_R3/VersionNMSManager.java @@ -10,8 +10,8 @@ import me.filoghost.fcommons.reflection.ClassToken; import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.fcommons.reflection.ReflectMethod; import me.filoghost.holographicdisplays.core.DebugLogger; -import me.filoghost.holographicdisplays.core.nms.ChatComponentAdapter; -import me.filoghost.holographicdisplays.core.nms.CustomNameHelper; +import me.filoghost.holographicdisplays.core.nms.CustomNameEditor; +import me.filoghost.holographicdisplays.core.nms.ChatComponentCustomNameEditor; import me.filoghost.holographicdisplays.core.nms.NMSManager; import me.filoghost.holographicdisplays.core.nms.PacketController; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; @@ -145,42 +145,35 @@ public class VersionNMSManager implements NMSManager { } @Override - public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { - return CustomNameHelper.replaceCustomNameChatComponent(NMSChatComponentAdapter.INSTANCE, customNameObject, target, replacement); + public CustomNameEditor getCustomNameChatComponentEditor() { + return VersionChatComponentCustomNameEditor.INSTANCE; } - private enum NMSChatComponentAdapter implements ChatComponentAdapter { + private enum VersionChatComponentCustomNameEditor implements ChatComponentCustomNameEditor { - INSTANCE { - - @Override - public ChatComponentText cast(Object chatComponentObject) { - return (ChatComponentText) chatComponentObject; - } - - @Override - public String getText(IChatBaseComponent chatComponent) { - return chatComponent.getText(); - } - - @Override - public List getSiblings(IChatBaseComponent chatComponent) { - return chatComponent.getSiblings(); - } - - @Override - public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) { - newSibling.getChatModifier().setChatModifier(chatComponent.getChatModifier()); - chatComponent.getSiblings().add(newSibling); - } - - @Override - public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) { - ChatComponentText clonedChatComponent = new ChatComponentText(newText); - clonedChatComponent.setChatModifier(chatComponent.getChatModifier().a()); - return clonedChatComponent; - } - + INSTANCE; + + @Override + public String getText(IChatBaseComponent chatComponent) { + return chatComponent.getText(); + } + + @Override + public List getSiblings(IChatBaseComponent chatComponent) { + return chatComponent.getSiblings(); + } + + @Override + public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) { + newSibling.getChatModifier().setChatModifier(chatComponent.getChatModifier()); + chatComponent.getSiblings().add(newSibling); + } + + @Override + public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) { + ChatComponentText clonedChatComponent = new ChatComponentText(newText); + clonedChatComponent.setChatModifier(chatComponent.getChatModifier().a()); + return clonedChatComponent; } } diff --git a/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/EntityNMSItem.java b/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/EntityNMSItem.java index d4378210..e4a5f177 100644 --- a/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/EntityNMSItem.java +++ b/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/EntityNMSItem.java @@ -154,7 +154,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem { } NBTTagList tagList = new NBTTagList(); - tagList.add(new NBTTagString(NMSCommons.ANTISTACK_LORE)); // Antistack lore + tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE)); // Antistack lore display.set("Lore", tagList); setItemStack(newItem); diff --git a/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/VersionNMSManager.java b/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/VersionNMSManager.java index 0a45e757..d20cd11f 100644 --- a/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/VersionNMSManager.java +++ b/nms/v1_8_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R2/VersionNMSManager.java @@ -10,14 +10,15 @@ import me.filoghost.fcommons.reflection.ClassToken; import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.fcommons.reflection.ReflectMethod; import me.filoghost.holographicdisplays.core.DebugLogger; -import me.filoghost.holographicdisplays.core.nms.CustomNameHelper; +import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; +import me.filoghost.holographicdisplays.core.hologram.StandardItemLine; +import me.filoghost.holographicdisplays.core.nms.CustomNameEditor; import me.filoghost.holographicdisplays.core.nms.NMSManager; import me.filoghost.holographicdisplays.core.nms.PacketController; +import me.filoghost.holographicdisplays.core.nms.StringCustomNameEditor; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase; import me.filoghost.holographicdisplays.core.nms.entity.NMSItem; -import me.filoghost.holographicdisplays.core.hologram.StandardItemLine; -import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; import net.minecraft.server.v1_8_R2.Entity; import net.minecraft.server.v1_8_R2.EntityTypes; import net.minecraft.server.v1_8_R2.MathHelper; @@ -147,8 +148,8 @@ public class VersionNMSManager implements NMSManager { } @Override - public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { - return CustomNameHelper.replaceCustomNameString(customNameObject, target, replacement); + public CustomNameEditor getCustomNameChatComponentEditor() { + return StringCustomNameEditor.INSTANCE; } } diff --git a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityNMSItem.java b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityNMSItem.java index bbe6df42..e4505b8d 100644 --- a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityNMSItem.java +++ b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/EntityNMSItem.java @@ -154,7 +154,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem { } NBTTagList tagList = new NBTTagList(); - tagList.add(new NBTTagString(NMSCommons.ANTISTACK_LORE)); // Antistack lore + tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE)); // Antistack lore display.set("Lore", tagList); setItemStack(newItem); diff --git a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionNMSManager.java b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionNMSManager.java index 39158610..47d8cd17 100644 --- a/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionNMSManager.java +++ b/nms/v1_8_r3/src/main/java/me/filoghost/holographicdisplays/nms/v1_8_R3/VersionNMSManager.java @@ -10,14 +10,15 @@ import me.filoghost.fcommons.reflection.ClassToken; import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.fcommons.reflection.ReflectMethod; import me.filoghost.holographicdisplays.core.DebugLogger; -import me.filoghost.holographicdisplays.core.nms.CustomNameHelper; +import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; +import me.filoghost.holographicdisplays.core.hologram.StandardItemLine; +import me.filoghost.holographicdisplays.core.nms.CustomNameEditor; import me.filoghost.holographicdisplays.core.nms.NMSManager; import me.filoghost.holographicdisplays.core.nms.PacketController; +import me.filoghost.holographicdisplays.core.nms.StringCustomNameEditor; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase; import me.filoghost.holographicdisplays.core.nms.entity.NMSItem; -import me.filoghost.holographicdisplays.core.hologram.StandardItemLine; -import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; import net.minecraft.server.v1_8_R3.Entity; import net.minecraft.server.v1_8_R3.EntityTypes; import net.minecraft.server.v1_8_R3.MathHelper; @@ -147,8 +148,8 @@ public class VersionNMSManager implements NMSManager { } @Override - public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { - return CustomNameHelper.replaceCustomNameString(customNameObject, target, replacement); + public CustomNameEditor getCustomNameChatComponentEditor() { + return StringCustomNameEditor.INSTANCE; } } diff --git a/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/EntityNMSItem.java b/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/EntityNMSItem.java index b40e2dd0..10fafb9b 100644 --- a/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/EntityNMSItem.java +++ b/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/EntityNMSItem.java @@ -192,7 +192,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem { } NBTTagList tagList = new NBTTagList(); - tagList.add(new NBTTagString(NMSCommons.ANTISTACK_LORE)); // Antistack lore + tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE)); // Antistack lore display.set("Lore", tagList); setItemStack(newItem); diff --git a/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/VersionNMSManager.java b/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/VersionNMSManager.java index b6f618b0..887489fa 100644 --- a/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/VersionNMSManager.java +++ b/nms/v1_9_r1/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R1/VersionNMSManager.java @@ -10,14 +10,15 @@ import me.filoghost.fcommons.reflection.ClassToken; import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.fcommons.reflection.ReflectMethod; import me.filoghost.holographicdisplays.core.DebugLogger; -import me.filoghost.holographicdisplays.core.nms.CustomNameHelper; +import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; +import me.filoghost.holographicdisplays.core.hologram.StandardItemLine; +import me.filoghost.holographicdisplays.core.nms.CustomNameEditor; import me.filoghost.holographicdisplays.core.nms.NMSManager; import me.filoghost.holographicdisplays.core.nms.PacketController; +import me.filoghost.holographicdisplays.core.nms.StringCustomNameEditor; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase; import me.filoghost.holographicdisplays.core.nms.entity.NMSItem; -import me.filoghost.holographicdisplays.core.hologram.StandardItemLine; -import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; import net.minecraft.server.v1_9_R1.Entity; import net.minecraft.server.v1_9_R1.EntityTypes; import net.minecraft.server.v1_9_R1.MathHelper; @@ -142,8 +143,8 @@ public class VersionNMSManager implements NMSManager { } @Override - public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { - return CustomNameHelper.replaceCustomNameString(customNameObject, target, replacement); + public CustomNameEditor getCustomNameChatComponentEditor() { + return StringCustomNameEditor.INSTANCE; } } diff --git a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityNMSItem.java b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityNMSItem.java index 75d90285..f9267b2a 100644 --- a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityNMSItem.java +++ b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/EntityNMSItem.java @@ -194,7 +194,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem { } NBTTagList tagList = new NBTTagList(); - tagList.add(new NBTTagString(NMSCommons.ANTISTACK_LORE)); // Antistack lore + tagList.add(new NBTTagString(NMSCommons.ANTI_STACK_LORE)); // Antistack lore display.set("Lore", tagList); setItemStack(newItem); diff --git a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionNMSManager.java b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionNMSManager.java index 9a1acf79..5736ec2f 100644 --- a/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionNMSManager.java +++ b/nms/v1_9_r2/src/main/java/me/filoghost/holographicdisplays/nms/v1_9_R2/VersionNMSManager.java @@ -10,14 +10,15 @@ import me.filoghost.fcommons.reflection.ClassToken; import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.fcommons.reflection.ReflectMethod; import me.filoghost.holographicdisplays.core.DebugLogger; -import me.filoghost.holographicdisplays.core.nms.CustomNameHelper; +import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; +import me.filoghost.holographicdisplays.core.hologram.StandardItemLine; +import me.filoghost.holographicdisplays.core.nms.CustomNameEditor; import me.filoghost.holographicdisplays.core.nms.NMSManager; import me.filoghost.holographicdisplays.core.nms.PacketController; +import me.filoghost.holographicdisplays.core.nms.StringCustomNameEditor; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase; import me.filoghost.holographicdisplays.core.nms.entity.NMSItem; -import me.filoghost.holographicdisplays.core.hologram.StandardItemLine; -import me.filoghost.holographicdisplays.core.hologram.StandardHologramLine; import net.minecraft.server.v1_9_R2.Entity; import net.minecraft.server.v1_9_R2.EntityTypes; import net.minecraft.server.v1_9_R2.MathHelper; @@ -142,8 +143,8 @@ public class VersionNMSManager implements NMSManager { } @Override - public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { - return CustomNameHelper.replaceCustomNameString(customNameObject, target, replacement); + public CustomNameEditor getCustomNameChatComponentEditor() { + return StringCustomNameEditor.INSTANCE; } } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/MetadataHelper.java b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/MetadataHelper.java index 474a0b29..a1bf00fb 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/MetadataHelper.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/MetadataHelper.java @@ -17,25 +17,27 @@ import java.util.List; import java.util.Optional; class MetadataHelper { - + private final int itemSlotIndex; private final int entityStatusIndex; - private final int airLevelWatcherIndex; + private final int airLevelIndex; private final int customNameIndex; private final int customNameVisibleIndex; private final int noGravityIndex; private final int armorStandStatusIndex; private final int slimeSizeIndex; + private final boolean customNameUsesChatComponents; + private Serializer itemSerializer; private Serializer intSerializer; private Serializer byteSerializer; private Serializer stringSerializer; private Serializer booleanSerializer; private Serializer chatComponentSerializer; - - - public MetadataHelper() { + + + public MetadataHelper() { if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_14_R1)) { itemSlotIndex = 7; } else if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_10_R1)) { @@ -53,7 +55,7 @@ class MetadataHelper { } entityStatusIndex = 0; - airLevelWatcherIndex = 1; + airLevelIndex = 1; customNameIndex = 2; customNameVisibleIndex = 3; noGravityIndex = 5; @@ -68,7 +70,10 @@ class MetadataHelper { } if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) { + customNameUsesChatComponents = true; chatComponentSerializer = Registry.get(MinecraftReflection.getIChatBaseComponentClass(), true); + } else { + customNameUsesChatComponents = false; } } @@ -101,7 +106,7 @@ class MetadataHelper { return null; } - if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) { + if (customNameUsesChatComponents) { if (!(customNameNMSObject instanceof Optional)) { throw new IllegalArgumentException("Expected custom name of type " + Optional.class); } @@ -119,7 +124,7 @@ class MetadataHelper { public void setCustomNameNMSObject(WrappedWatchableObject customNameWatchableObject, Object customNameNMSObject) { - if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) { + if (customNameUsesChatComponents) { customNameWatchableObject.setValue(Optional.ofNullable(customNameNMSObject)); } else { customNameWatchableObject.setValue(customNameNMSObject); @@ -130,32 +135,31 @@ class MetadataHelper { public void setCustomNameNMSObject(WrappedDataWatcher dataWatcher, Object customNameNMSObject) { requireMinimumVersion(NMSVersion.v1_9_R1); - if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) { + if (customNameUsesChatComponents) { dataWatcher.setObject(new WrappedDataWatcherObject(customNameIndex, chatComponentSerializer), Optional.ofNullable(customNameNMSObject)); } else { dataWatcher.setObject(new WrappedDataWatcherObject(customNameIndex, stringSerializer), customNameNMSObject); } } - public void setCustomNameVisible(WrappedDataWatcher dataWatcher, boolean customNameVisible) { requireMinimumVersion(NMSVersion.v1_9_R1); dataWatcher.setObject(new WrappedDataWatcherObject(customNameVisibleIndex, booleanSerializer), customNameVisible); } - + public void setNoGravity(WrappedDataWatcher dataWatcher, boolean noGravity) { requireMinimumVersion(NMSVersion.v1_9_R1); dataWatcher.setObject(new WrappedDataWatcherObject(noGravityIndex, booleanSerializer), noGravity); } - + public void setArmorStandStatus(WrappedDataWatcher dataWatcher, byte statusBitmask) { requireMinimumVersion(NMSVersion.v1_9_R1); dataWatcher.setObject(new WrappedDataWatcherObject(armorStandStatusIndex, byteSerializer), statusBitmask); } - + public void setItemMetadata(WrappedDataWatcher dataWatcher, Object nmsItemStack) { if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_9_R1)) { if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_11_R1)) { @@ -163,26 +167,26 @@ class MetadataHelper { } else { dataWatcher.setObject(new WrappedDataWatcherObject(itemSlotIndex, itemSerializer), com.google.common.base.Optional.of(nmsItemStack)); } - dataWatcher.setObject(new WrappedDataWatcherObject(airLevelWatcherIndex, intSerializer), 300); + dataWatcher.setObject(new WrappedDataWatcherObject(airLevelIndex, intSerializer), 300); dataWatcher.setObject(new WrappedDataWatcherObject(entityStatusIndex, byteSerializer), (byte) 0); } else { dataWatcher.setObject(itemSlotIndex, nmsItemStack); - dataWatcher.setObject(airLevelWatcherIndex, 300); + dataWatcher.setObject(airLevelIndex, 300); dataWatcher.setObject(entityStatusIndex, (byte) 0); } } - - + + public void setSlimeSize(WrappedDataWatcher dataWatcher, int size) { requireMinimumVersion(NMSVersion.v1_15_R1); dataWatcher.setObject(new WrappedDataWatcherObject(slimeSizeIndex, intSerializer), size); } - - + + private static void requireMinimumVersion(NMSVersion minimumVersion) { if (!NMSVersion.isGreaterEqualThan(minimumVersion)) { throw new UnsupportedOperationException("Method only available from NMS version " + minimumVersion); } } - + } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/PacketListener.java b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/PacketListener.java index 52eb685b..1582bdef 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/PacketListener.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/bridge/protocollib/PacketListener.java @@ -174,7 +174,10 @@ class PacketListener extends PacketAdapter { Object replacedCustomNameNMSObject = originalCustomNameNMSObject; for (RelativePlaceholder relativePlaceholder : relativePlaceholders) { - replacedCustomNameNMSObject = nmsManager.replaceCustomNameText(replacedCustomNameNMSObject, relativePlaceholder.getTextPlaceholder(), relativePlaceholder.getReplacement(player)); + replacedCustomNameNMSObject = nmsManager.getCustomNameChatComponentEditor().replaceCustomName( + replacedCustomNameNMSObject, + relativePlaceholder.getTextPlaceholder(), + relativePlaceholder.getReplacement(player)); } if (replacedCustomNameNMSObject == originalCustomNameNMSObject) { diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/subs/CreateCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/subs/CreateCommand.java index f31acd3c..396d8f9f 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/subs/CreateCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/subs/CreateCommand.java @@ -16,7 +16,6 @@ import me.filoghost.holographicdisplays.disk.ConfigManager; import me.filoghost.holographicdisplays.object.internal.InternalHologram; import me.filoghost.holographicdisplays.object.internal.InternalHologramLine; import me.filoghost.holographicdisplays.object.internal.InternalHologramManager; -import me.filoghost.holographicdisplays.object.internal.InternalTextLine; import org.bukkit.ChatColor; import org.bukkit.Location; import org.bukkit.command.CommandSender; @@ -71,7 +70,7 @@ public class CreateCommand extends HologramSubCommand { } else { String defaultText = "Default hologram. Change it with " + Colors.PRIMARY + "/" + context.getRootLabel() + " edit " + hologram.getName(); - line = new InternalTextLine(hologram, defaultText, defaultText.replace(ChatColor.COLOR_CHAR, '&')); + line = hologram.createTextLine(defaultText, defaultText.replace(ChatColor.COLOR_CHAR, '&')); } hologram.getLinesUnsafe().add(line); diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/subs/ReadimageCommand.java b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/subs/ReadimageCommand.java index 9e01b100..2d284bc2 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/commands/subs/ReadimageCommand.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/commands/subs/ReadimageCommand.java @@ -114,7 +114,7 @@ public class ReadimageCommand extends LineEditingCommand { hologram.clearLines(); } for (String newLine : newLines) { - InternalTextLine line = new InternalTextLine(hologram, newLine, newLine); + InternalTextLine line = hologram.createTextLine(newLine, newLine); hologram.getLinesUnsafe().add(line); } hologram.refresh(); diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/disk/HologramLineParser.java b/plugin/src/main/java/me/filoghost/holographicdisplays/disk/HologramLineParser.java index 0dc6c2db..14b5abb3 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/disk/HologramLineParser.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/disk/HologramLineParser.java @@ -11,8 +11,6 @@ import me.filoghost.holographicdisplays.nbt.parser.MojangsonParseException; import me.filoghost.holographicdisplays.nbt.parser.MojangsonParser; import me.filoghost.holographicdisplays.object.internal.InternalHologram; import me.filoghost.holographicdisplays.object.internal.InternalHologramLine; -import me.filoghost.holographicdisplays.object.internal.InternalItemLine; -import me.filoghost.holographicdisplays.object.internal.InternalTextLine; import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.inventory.ItemStack; @@ -28,7 +26,7 @@ public class HologramLineParser { if (serializedLine.toLowerCase().startsWith(ICON_PREFIX)) { String serializedIcon = serializedLine.substring(ICON_PREFIX.length()); ItemStack icon = parseItemStack(serializedIcon, checkMaterialValidity); - hologramLine = new InternalItemLine(hologram, icon, serializedLine); + hologramLine = hologram.createItemLine(icon, serializedLine); } else { String displayText; @@ -38,7 +36,7 @@ public class HologramLineParser { displayText = StringConverter.toReadableFormat(serializedLine); } - hologramLine = new InternalTextLine(hologram, displayText, serializedLine); + hologramLine = hologram.createTextLine(displayText, serializedLine); } return hologramLine; diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/object/api/APIHologram.java b/plugin/src/main/java/me/filoghost/holographicdisplays/object/api/APIHologram.java index 392700d3..fdfd8285 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/object/api/APIHologram.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/object/api/APIHologram.java @@ -57,7 +57,7 @@ public class APIHologram extends BaseHologram implements Hologram { public TextLine appendTextLine(String text) { checkState(); - APITextLine line = new APITextLine(this, text); + APITextLine line = createTextLine(text); lines.add(line); refresh(); return line; @@ -68,7 +68,7 @@ public class APIHologram extends BaseHologram implements Hologram { checkState(); Preconditions.notNull(itemStack, "itemStack"); - APIItemLine line = new APIItemLine(this, itemStack); + APIItemLine line = createItemLine(itemStack); lines.add(line); refresh(); return line; @@ -78,7 +78,7 @@ public class APIHologram extends BaseHologram implements Hologram { public TextLine insertTextLine(int index, String text) { checkState(); - APITextLine line = new APITextLine(this, text); + APITextLine line = createTextLine(text); lines.add(index, line); refresh(); return line; @@ -89,12 +89,20 @@ public class APIHologram extends BaseHologram implements Hologram { checkState(); Preconditions.notNull(itemStack, "itemStack"); - APIItemLine line = new APIItemLine(this, itemStack); + APIItemLine line = createItemLine(itemStack); lines.add(index, line); refresh(); return line; } + private APITextLine createTextLine(String text) { + return new APITextLine(this, getNMSManager(), text); + } + + private APIItemLine createItemLine(ItemStack itemStack) { + return new APIItemLine(this, getNMSManager(), itemStack); + } + @Override public HologramLine getLine(int index) { return lines.get(index); diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/object/api/APIItemLine.java b/plugin/src/main/java/me/filoghost/holographicdisplays/object/api/APIItemLine.java index 2ef2e58a..fc05f8ad 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/object/api/APIItemLine.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/object/api/APIItemLine.java @@ -2,6 +2,7 @@ package me.filoghost.holographicdisplays.object.api; import me.filoghost.holographicdisplays.api.Hologram; import me.filoghost.holographicdisplays.api.line.ItemLine; +import me.filoghost.holographicdisplays.core.nms.NMSManager; import me.filoghost.holographicdisplays.object.base.BaseItemLine; import org.bukkit.inventory.ItemStack; @@ -9,8 +10,8 @@ public class APIItemLine extends BaseItemLine implements ItemLine, APIHologramLi private final APIHologram parent; - public APIItemLine(APIHologram parent, ItemStack itemStack) { - super(parent, itemStack); + public APIItemLine(APIHologram parent, NMSManager nmsManager, ItemStack itemStack) { + super(parent, nmsManager, itemStack); this.parent = parent; } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/object/api/APITextLine.java b/plugin/src/main/java/me/filoghost/holographicdisplays/object/api/APITextLine.java index f860545c..b0fa709a 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/object/api/APITextLine.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/object/api/APITextLine.java @@ -2,14 +2,15 @@ package me.filoghost.holographicdisplays.object.api; import me.filoghost.holographicdisplays.api.Hologram; import me.filoghost.holographicdisplays.api.line.TextLine; +import me.filoghost.holographicdisplays.core.nms.NMSManager; import me.filoghost.holographicdisplays.object.base.BaseTextLine; public class APITextLine extends BaseTextLine implements TextLine, APIHologramLine { private final APIHologram parent; - public APITextLine(APIHologram parent, String text) { - super(parent, text); + public APITextLine(APIHologram parent, NMSManager nmsManager, String text) { + super(parent, nmsManager, text); this.parent = parent; } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/object/base/BaseHologram.java b/plugin/src/main/java/me/filoghost/holographicdisplays/object/base/BaseHologram.java index f61bcbae..c4c7c21c 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/object/base/BaseHologram.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/object/base/BaseHologram.java @@ -39,9 +39,8 @@ public abstract class BaseHologram extends BaseHologramComponent implements Stan clearLines(); } } - - @Override - public NMSManager getNMSManager() { + + protected final NMSManager getNMSManager() { return nmsManager; } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/object/base/BaseHologramLine.java b/plugin/src/main/java/me/filoghost/holographicdisplays/object/base/BaseHologramLine.java index 0416332e..961e73f7 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/object/base/BaseHologramLine.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/object/base/BaseHologramLine.java @@ -13,22 +13,24 @@ import org.bukkit.World; public abstract class BaseHologramLine extends BaseHologramComponent implements StandardHologramLine { - private final StandardHologram parent; - + private final StandardHologram hologram; + private final NMSManager nmsManager; + private boolean isSpawned; - protected BaseHologramLine(StandardHologram parent) { - Preconditions.notNull(parent, "parent hologram"); - this.parent = parent; + protected BaseHologramLine(StandardHologram hologram, NMSManager nmsManager) { + Preconditions.notNull(hologram, "parent hologram"); + this.hologram = hologram; + this.nmsManager = nmsManager; } @Override public final StandardHologram getHologram() { - return parent; + return hologram; } protected final NMSManager getNMSManager() { - return parent.getNMSManager(); + return nmsManager; } @Override @@ -61,7 +63,7 @@ public abstract class BaseHologramLine extends BaseHologramComponent implements isSpawned = false; } - protected boolean isSpawned() { + protected final boolean isSpawned() { return isSpawned; } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/object/base/BaseItemLine.java b/plugin/src/main/java/me/filoghost/holographicdisplays/object/base/BaseItemLine.java index 8e79477a..9792c9ff 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/object/base/BaseItemLine.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/object/base/BaseItemLine.java @@ -10,6 +10,7 @@ import me.filoghost.fcommons.logging.Log; import me.filoghost.holographicdisplays.api.handler.PickupHandler; import me.filoghost.holographicdisplays.core.hologram.StandardHologram; import me.filoghost.holographicdisplays.core.hologram.StandardItemLine; +import me.filoghost.holographicdisplays.core.nms.NMSManager; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; import me.filoghost.holographicdisplays.core.nms.entity.NMSItem; import org.bukkit.World; @@ -26,8 +27,8 @@ public abstract class BaseItemLine extends BaseTouchableLine implements Standard private NMSArmorStand vehicleEntity; private PickupHandler pickupHandler; - public BaseItemLine(StandardHologram parent, ItemStack itemStack) { - super(parent); + public BaseItemLine(StandardHologram hologram, NMSManager nmsManager, ItemStack itemStack) { + super(hologram, nmsManager); setItemStack(itemStack); } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/object/base/BaseTextLine.java b/plugin/src/main/java/me/filoghost/holographicdisplays/object/base/BaseTextLine.java index ffbb28ac..1c42da95 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/object/base/BaseTextLine.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/object/base/BaseTextLine.java @@ -7,6 +7,7 @@ package me.filoghost.holographicdisplays.object.base; import me.filoghost.holographicdisplays.core.hologram.StandardHologram; import me.filoghost.holographicdisplays.core.hologram.StandardTextLine; +import me.filoghost.holographicdisplays.core.nms.NMSManager; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; import me.filoghost.holographicdisplays.core.placeholder.RelativePlaceholder; import me.filoghost.holographicdisplays.placeholder.PlaceholdersManager; @@ -21,8 +22,8 @@ public abstract class BaseTextLine extends BaseTouchableLine implements Standard private String text; private NMSArmorStand nameableEntity; - public BaseTextLine(StandardHologram parent, String text) { - super(parent); + public BaseTextLine(StandardHologram hologram, NMSManager nmsManager, String text) { + super(hologram, nmsManager); this.relativePlaceholders = new ArrayList<>(); setText(text); } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/object/base/BaseTouchableLine.java b/plugin/src/main/java/me/filoghost/holographicdisplays/object/base/BaseTouchableLine.java index 0ca15b77..3f0529c9 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/object/base/BaseTouchableLine.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/object/base/BaseTouchableLine.java @@ -9,6 +9,7 @@ import me.filoghost.fcommons.logging.Log; import me.filoghost.holographicdisplays.api.handler.TouchHandler; import me.filoghost.holographicdisplays.core.hologram.StandardHologram; import me.filoghost.holographicdisplays.core.hologram.StandardTouchableLine; +import me.filoghost.holographicdisplays.core.nms.NMSManager; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; import me.filoghost.holographicdisplays.core.nms.entity.NMSSlime; import org.bukkit.World; @@ -26,7 +27,7 @@ public abstract class BaseTouchableLine extends BaseHologramLine implements Stan private static final double SLIME_HEIGHT = 0.5; - private static final Map anticlickSpam = new WeakHashMap<>(); + private static final Map lastClickByPlayer = new WeakHashMap<>(); private TouchHandler touchHandler; @@ -34,8 +35,8 @@ public abstract class BaseTouchableLine extends BaseHologramLine implements Stan private NMSArmorStand vehicleEntity; - protected BaseTouchableLine(StandardHologram parent) { - super(parent); + protected BaseTouchableLine(StandardHologram hologram, NMSManager nmsManager) { + super(hologram, nmsManager); } @Override @@ -44,12 +45,13 @@ public abstract class BaseTouchableLine extends BaseHologramLine implements Stan return; } - Long lastClick = anticlickSpam.get(player); - if (lastClick != null && System.currentTimeMillis() - lastClick < 100) { + Long lastClick = lastClickByPlayer.get(player); + long now = System.currentTimeMillis(); + if (lastClick != null && now - lastClick < 100) { return; } - anticlickSpam.put(player, System.currentTimeMillis()); + lastClickByPlayer.put(player, now); try { touchHandler.onTouch(player); diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/object/internal/InternalHologram.java b/plugin/src/main/java/me/filoghost/holographicdisplays/object/internal/InternalHologram.java index 476bf08f..96f09c94 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/object/internal/InternalHologram.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/object/internal/InternalHologram.java @@ -10,6 +10,7 @@ import me.filoghost.holographicdisplays.core.nms.NMSManager; import me.filoghost.holographicdisplays.object.base.BaseHologram; import org.bukkit.Location; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; import org.bukkit.plugin.Plugin; import java.util.ArrayList; @@ -30,6 +31,14 @@ public class InternalHologram extends BaseHologram { return name; } + public InternalTextLine createTextLine(String text, String serializedConfigValue) { + return new InternalTextLine(this, getNMSManager(), text, serializedConfigValue); + } + + public InternalItemLine createItemLine(ItemStack icon, String serializedConfigValue) { + return new InternalItemLine(this, getNMSManager(), icon, serializedConfigValue); + } + @Override public Plugin getOwnerPlugin() { return HolographicDisplays.getInstance(); diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/object/internal/InternalItemLine.java b/plugin/src/main/java/me/filoghost/holographicdisplays/object/internal/InternalItemLine.java index cda62052..1295c287 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/object/internal/InternalItemLine.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/object/internal/InternalItemLine.java @@ -6,6 +6,7 @@ package me.filoghost.holographicdisplays.object.internal; import me.filoghost.holographicdisplays.core.hologram.StandardHologram; +import me.filoghost.holographicdisplays.core.nms.NMSManager; import me.filoghost.holographicdisplays.object.base.BaseItemLine; import org.bukkit.inventory.ItemStack; @@ -13,11 +14,12 @@ public class InternalItemLine extends BaseItemLine implements InternalHologramLi private final String serializedConfigValue; - public InternalItemLine(StandardHologram parent, ItemStack itemStack, String serializedConfigValue) { - super(parent, itemStack); + protected InternalItemLine(StandardHologram hologram, NMSManager nmsManager, ItemStack itemStack, String serializedConfigValue) { + super(hologram, nmsManager, itemStack); this.serializedConfigValue = serializedConfigValue; } + @Override public String getSerializedConfigValue() { return serializedConfigValue; } diff --git a/plugin/src/main/java/me/filoghost/holographicdisplays/object/internal/InternalTextLine.java b/plugin/src/main/java/me/filoghost/holographicdisplays/object/internal/InternalTextLine.java index c0dfb15d..b202bb9b 100644 --- a/plugin/src/main/java/me/filoghost/holographicdisplays/object/internal/InternalTextLine.java +++ b/plugin/src/main/java/me/filoghost/holographicdisplays/object/internal/InternalTextLine.java @@ -6,14 +6,15 @@ package me.filoghost.holographicdisplays.object.internal; import me.filoghost.holographicdisplays.core.hologram.StandardHologram; +import me.filoghost.holographicdisplays.core.nms.NMSManager; import me.filoghost.holographicdisplays.object.base.BaseTextLine; public class InternalTextLine extends BaseTextLine implements InternalHologramLine { private final String serializedConfigValue; - public InternalTextLine(StandardHologram parent, String text, String serializedConfigValue) { - super(parent, text); + protected InternalTextLine(StandardHologram hologram, NMSManager nmsManager, String text, String serializedConfigValue) { + super(hologram, nmsManager, text); this.serializedConfigValue = serializedConfigValue; } @@ -22,6 +23,7 @@ public class InternalTextLine extends BaseTextLine implements InternalHologramLi return true; } + @Override public String getSerializedConfigValue() { return serializedConfigValue; }