Small cleanup

This commit is contained in:
filoghost 2021-03-03 10:53:49 +01:00
parent a96e9e516f
commit f7bc9b950f
51 changed files with 416 additions and 416 deletions

View File

@ -5,7 +5,6 @@
*/ */
package me.filoghost.holographicdisplays.core.hologram; package me.filoghost.holographicdisplays.core.hologram;
import me.filoghost.holographicdisplays.core.nms.NMSManager;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
@ -43,6 +42,4 @@ public interface StandardHologram {
void setDeleted(); void setDeleted();
NMSManager getNMSManager();
} }

View File

@ -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> {
T cast(Object chatComponentObject);
String getText(T chatComponent);
List<T> 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);
}

View File

@ -7,37 +7,30 @@ package me.filoghost.holographicdisplays.core.nms;
import java.util.List; import java.util.List;
public class CustomNameHelper { public interface ChatComponentCustomNameEditor<T> extends CustomNameEditor {
@Override
public static String replaceCustomNameString(Object customNameObject, String target, String replacement) { default T replaceCustomName(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> T replaceCustomNameChatComponent(ChatComponentAdapter<T> versionAdapter, 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. // 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); @SuppressWarnings("unchecked")
if (!versionAdapter.getText(rootComponent).isEmpty()) { T rootComponent = (T) customNameObject;
if (!getText(rootComponent).isEmpty()) {
throw new IllegalArgumentException("Expected root component with empty text"); throw new IllegalArgumentException("Expected root component with empty text");
} }
boolean[] childrenContainingTarget = null; boolean[] childrenContainingTarget = null;
List<T> children = versionAdapter.getSiblings(rootComponent); List<T> children = getSiblings(rootComponent);
int childrenSize = children.size(); int childrenSize = children.size();
for (int i = 0; i < childrenSize; i++) { 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"); 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. // Lazy initialization for performance, since this method can be called frequently.
if (childrenContainingTarget == null) { if (childrenContainingTarget == null) {
childrenContainingTarget = new boolean[childrenSize]; childrenContainingTarget = new boolean[childrenSize];
@ -52,20 +45,32 @@ public class CustomNameHelper {
} }
// Clone all the objects and apply replacements where needed. // 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++) { for (int i = 0; i < childrenSize; i++) {
T childComponent = children.get(i); T childComponent = children.get(i);
String newText = versionAdapter.getText(childComponent); String newText = getText(childComponent);
if (childrenContainingTarget[i]) { if (childrenContainingTarget[i]) {
newText = newText.replace(target, replacement); newText = newText.replace(target, replacement);
} }
T clonedChild = versionAdapter.cloneComponent(childComponent, newText); T clonedChild = cloneComponent(childComponent, newText);
versionAdapter.addSibling(clonedRoot, clonedChild); addSibling(clonedRoot, clonedChild);
} }
return clonedRoot; return clonedRoot;
} }
String getText(T chatComponent);
List<T> 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);
} }

View File

@ -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);
}

View File

@ -11,7 +11,7 @@ import org.bukkit.ChatColor;
public class NMSCommons { public class NMSCommons {
// This is used on hologram icons, to prevent vanilla items from merging with them. // 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"); private static final boolean IS_PAPER_SERVER = Bukkit.getName().equals("Paper");

View File

@ -30,6 +30,6 @@ public interface NMSManager {
NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID); NMSEntityBase getNMSEntityBaseFromID(org.bukkit.World bukkitWorld, int entityID);
Object replaceCustomNameText(Object customNameObject, String target, String replacement); CustomNameEditor getCustomNameChatComponentEditor();
} }

View File

@ -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;
}
}
}

View File

@ -194,7 +194,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
} }
NBTTagList tagList = new NBTTagList(); 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); display.set("Lore", tagList);
setItemStack(newItem); setItemStack(newItem);

View File

@ -10,14 +10,15 @@ import me.filoghost.fcommons.reflection.ClassToken;
import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.fcommons.reflection.ReflectField;
import me.filoghost.fcommons.reflection.ReflectMethod; import me.filoghost.fcommons.reflection.ReflectMethod;
import me.filoghost.holographicdisplays.core.DebugLogger; 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.NMSManager;
import me.filoghost.holographicdisplays.core.nms.PacketController; 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.NMSArmorStand;
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase; import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem; 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.Entity;
import net.minecraft.server.v1_10_R1.EntityTypes; import net.minecraft.server.v1_10_R1.EntityTypes;
import net.minecraft.server.v1_10_R1.MathHelper; import net.minecraft.server.v1_10_R1.MathHelper;
@ -142,8 +143,8 @@ public class VersionNMSManager implements NMSManager {
} }
@Override @Override
public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { public CustomNameEditor getCustomNameChatComponentEditor() {
return CustomNameHelper.replaceCustomNameString(customNameObject, target, replacement); return StringCustomNameEditor.INSTANCE;
} }
} }

View File

@ -168,7 +168,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
} }
NBTTagList tagList = new NBTTagList(); 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); display.set("Lore", tagList);
setItemStack(newItem); setItemStack(newItem);

View File

@ -10,14 +10,15 @@ import me.filoghost.fcommons.reflection.ClassToken;
import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.fcommons.reflection.ReflectField;
import me.filoghost.fcommons.reflection.ReflectMethod; import me.filoghost.fcommons.reflection.ReflectMethod;
import me.filoghost.holographicdisplays.core.DebugLogger; 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.NMSManager;
import me.filoghost.holographicdisplays.core.nms.PacketController; 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.NMSArmorStand;
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase; import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem; 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.Entity;
import net.minecraft.server.v1_11_R1.EntityTypes; import net.minecraft.server.v1_11_R1.EntityTypes;
import net.minecraft.server.v1_11_R1.MathHelper; import net.minecraft.server.v1_11_R1.MathHelper;
@ -150,8 +151,8 @@ public class VersionNMSManager implements NMSManager {
} }
@Override @Override
public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { public CustomNameEditor getCustomNameChatComponentEditor() {
return CustomNameHelper.replaceCustomNameString(customNameObject, target, replacement); return StringCustomNameEditor.INSTANCE;
} }
} }

View File

@ -168,7 +168,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
} }
NBTTagList tagList = new NBTTagList(); 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); display.set("Lore", tagList);
setItemStack(newItem); setItemStack(newItem);

View File

@ -10,14 +10,15 @@ import me.filoghost.fcommons.reflection.ClassToken;
import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.fcommons.reflection.ReflectField;
import me.filoghost.fcommons.reflection.ReflectMethod; import me.filoghost.fcommons.reflection.ReflectMethod;
import me.filoghost.holographicdisplays.core.DebugLogger; 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.NMSManager;
import me.filoghost.holographicdisplays.core.nms.PacketController; 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.NMSArmorStand;
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase; import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem; 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.Entity;
import net.minecraft.server.v1_12_R1.EntityTypes; import net.minecraft.server.v1_12_R1.EntityTypes;
import net.minecraft.server.v1_12_R1.MathHelper; import net.minecraft.server.v1_12_R1.MathHelper;
@ -150,8 +151,8 @@ public class VersionNMSManager implements NMSManager {
} }
@Override @Override
public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { public CustomNameEditor getCustomNameChatComponentEditor() {
return CustomNameHelper.replaceCustomNameString(customNameObject, target, replacement); return StringCustomNameEditor.INSTANCE;
} }
} }

View File

@ -168,7 +168,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
} }
NBTTagList tagList = new NBTTagList(); 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); display.set("Lore", tagList);
setItemStack(newItem); setItemStack(newItem);

View File

@ -10,8 +10,8 @@ import me.filoghost.fcommons.reflection.ClassToken;
import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.fcommons.reflection.ReflectField;
import me.filoghost.fcommons.reflection.ReflectMethod; import me.filoghost.fcommons.reflection.ReflectMethod;
import me.filoghost.holographicdisplays.core.DebugLogger; import me.filoghost.holographicdisplays.core.DebugLogger;
import me.filoghost.holographicdisplays.core.nms.ChatComponentAdapter; import me.filoghost.holographicdisplays.core.nms.CustomNameEditor;
import me.filoghost.holographicdisplays.core.nms.CustomNameHelper; import me.filoghost.holographicdisplays.core.nms.ChatComponentCustomNameEditor;
import me.filoghost.holographicdisplays.core.nms.NMSCommons; import me.filoghost.holographicdisplays.core.nms.NMSCommons;
import me.filoghost.holographicdisplays.core.nms.NMSManager; import me.filoghost.holographicdisplays.core.nms.NMSManager;
import me.filoghost.holographicdisplays.core.nms.PacketController; import me.filoghost.holographicdisplays.core.nms.PacketController;
@ -167,41 +167,34 @@ public class VersionNMSManager implements NMSManager {
} }
@Override @Override
public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { public CustomNameEditor getCustomNameChatComponentEditor() {
return CustomNameHelper.replaceCustomNameChatComponent(NMSChatComponentAdapter.INSTANCE, customNameObject, target, replacement); return VersionChatComponentCustomNameEditor.INSTANCE;
} }
private enum NMSChatComponentAdapter implements ChatComponentAdapter<IChatBaseComponent> { private enum VersionChatComponentCustomNameEditor implements ChatComponentCustomNameEditor<IChatBaseComponent> {
INSTANCE { INSTANCE;
@Override @Override
public ChatComponentText cast(Object chatComponentObject) { public String getText(IChatBaseComponent chatComponent) {
return (ChatComponentText) chatComponentObject; return chatComponent.getText();
} }
@Override @Override
public String getText(IChatBaseComponent chatComponent) { public List<IChatBaseComponent> getSiblings(IChatBaseComponent chatComponent) {
return chatComponent.getText(); return chatComponent.a();
} }
@Override @Override
public List<IChatBaseComponent> getSiblings(IChatBaseComponent chatComponent) { public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) {
return chatComponent.a(); chatComponent.addSibling(newSibling);
} }
@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;
}
@Override
public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) {
ChatComponentText clonedChatComponent = new ChatComponentText(newText);
clonedChatComponent.setChatModifier(chatComponent.getChatModifier().clone());
return clonedChatComponent;
} }
} }

View File

@ -168,7 +168,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
} }
NBTTagList tagList = new NBTTagList(); 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); display.set("Lore", tagList);
setItemStack(newItem); setItemStack(newItem);

View File

@ -10,8 +10,8 @@ import me.filoghost.fcommons.reflection.ClassToken;
import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.fcommons.reflection.ReflectField;
import me.filoghost.fcommons.reflection.ReflectMethod; import me.filoghost.fcommons.reflection.ReflectMethod;
import me.filoghost.holographicdisplays.core.DebugLogger; import me.filoghost.holographicdisplays.core.DebugLogger;
import me.filoghost.holographicdisplays.core.nms.ChatComponentAdapter; import me.filoghost.holographicdisplays.core.nms.CustomNameEditor;
import me.filoghost.holographicdisplays.core.nms.CustomNameHelper; import me.filoghost.holographicdisplays.core.nms.ChatComponentCustomNameEditor;
import me.filoghost.holographicdisplays.core.nms.NMSCommons; import me.filoghost.holographicdisplays.core.nms.NMSCommons;
import me.filoghost.holographicdisplays.core.nms.NMSManager; import me.filoghost.holographicdisplays.core.nms.NMSManager;
import me.filoghost.holographicdisplays.core.nms.PacketController; import me.filoghost.holographicdisplays.core.nms.PacketController;
@ -168,41 +168,34 @@ public class VersionNMSManager implements NMSManager {
} }
@Override @Override
public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { public CustomNameEditor getCustomNameChatComponentEditor() {
return CustomNameHelper.replaceCustomNameChatComponent(NMSChatComponentAdapter.INSTANCE, customNameObject, target, replacement); return VersionChatComponentCustomNameEditor.INSTANCE;
} }
private enum NMSChatComponentAdapter implements ChatComponentAdapter<IChatBaseComponent> { private enum VersionChatComponentCustomNameEditor implements ChatComponentCustomNameEditor<IChatBaseComponent> {
INSTANCE { INSTANCE;
@Override @Override
public ChatComponentText cast(Object chatComponentObject) { public String getText(IChatBaseComponent chatComponent) {
return (ChatComponentText) chatComponentObject; return chatComponent.getText();
} }
@Override @Override
public String getText(IChatBaseComponent chatComponent) { public List<IChatBaseComponent> getSiblings(IChatBaseComponent chatComponent) {
return chatComponent.getText(); return chatComponent.a();
} }
@Override @Override
public List<IChatBaseComponent> getSiblings(IChatBaseComponent chatComponent) { public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) {
return chatComponent.a(); chatComponent.addSibling(newSibling);
} }
@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;
}
@Override
public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) {
ChatComponentText clonedChatComponent = new ChatComponentText(newText);
clonedChatComponent.setChatModifier(chatComponent.getChatModifier().clone());
return clonedChatComponent;
} }
} }

View File

@ -170,7 +170,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
} }
NBTTagList tagList = new NBTTagList(); 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); display.set("Lore", tagList);
setItemStack(newItem); setItemStack(newItem);

View File

@ -10,8 +10,8 @@ import me.filoghost.fcommons.reflection.ClassToken;
import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.fcommons.reflection.ReflectField;
import me.filoghost.fcommons.reflection.ReflectMethod; import me.filoghost.fcommons.reflection.ReflectMethod;
import me.filoghost.holographicdisplays.core.DebugLogger; import me.filoghost.holographicdisplays.core.DebugLogger;
import me.filoghost.holographicdisplays.core.nms.ChatComponentAdapter; import me.filoghost.holographicdisplays.core.nms.CustomNameEditor;
import me.filoghost.holographicdisplays.core.nms.CustomNameHelper; import me.filoghost.holographicdisplays.core.nms.ChatComponentCustomNameEditor;
import me.filoghost.holographicdisplays.core.nms.NMSManager; import me.filoghost.holographicdisplays.core.nms.NMSManager;
import me.filoghost.holographicdisplays.core.nms.PacketController; import me.filoghost.holographicdisplays.core.nms.PacketController;
import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand;
@ -155,58 +155,51 @@ public class VersionNMSManager implements NMSManager {
} }
@Override @Override
public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { public CustomNameEditor getCustomNameChatComponentEditor() {
return CustomNameHelper.replaceCustomNameChatComponent(NMSChatComponentAdapter.INSTANCE, customNameObject, target, replacement); return VersionChatComponentCustomNameEditor.INSTANCE;
} }
private enum NMSChatComponentAdapter implements ChatComponentAdapter<IChatBaseComponent> { private enum VersionChatComponentCustomNameEditor implements ChatComponentCustomNameEditor<IChatBaseComponent> {
INSTANCE { INSTANCE;
private boolean useNewGetSiblingsMethod = true; private boolean useNewGetSiblingsMethod = true;
private final ReflectField<List<IChatBaseComponent>> OLD_SIBLINGS_FIELD = ReflectField.lookup(new ClassToken<List<IChatBaseComponent>>(){}, ChatBaseComponent.class, "a"); private final ReflectField<List<IChatBaseComponent>> OLD_SIBLINGS_FIELD = ReflectField.lookup(new ClassToken<List<IChatBaseComponent>>(){}, ChatBaseComponent.class, "a");
@Override @Override
public ChatComponentText cast(Object chatComponentObject) { public String getText(IChatBaseComponent chatComponent) {
return (ChatComponentText) chatComponentObject; return chatComponent.getText();
} }
@Override @Override
public String getText(IChatBaseComponent chatComponent) { public List<IChatBaseComponent> getSiblings(IChatBaseComponent chatComponent) {
return chatComponent.getText(); if (useNewGetSiblingsMethod) {
}
@Override
public List<IChatBaseComponent> 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.
try { try {
return OLD_SIBLINGS_FIELD.get(chatComponent); return chatComponent.getSiblings();
} catch (ReflectiveOperationException e) { } catch (NoSuchMethodError e) {
throw new RuntimeException(e); // The method was named differently in older 1.14 versions, use workaround.
useNewGetSiblingsMethod = false;
} }
} }
@Override // Access siblings field directly in older 1.14 versions.
public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) { try {
chatComponent.addSibling(newSibling); return OLD_SIBLINGS_FIELD.get(chatComponent);
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
} }
}
@Override @Override
public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) { public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) {
ChatComponentText clonedChatComponent = new ChatComponentText(newText); chatComponent.addSibling(newSibling);
clonedChatComponent.setChatModifier(chatComponent.getChatModifier().clone()); }
return clonedChatComponent;
}
@Override
public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) {
ChatComponentText clonedChatComponent = new ChatComponentText(newText);
clonedChatComponent.setChatModifier(chatComponent.getChatModifier().clone());
return clonedChatComponent;
} }
} }

View File

@ -170,7 +170,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
} }
NBTTagList tagList = new NBTTagList(); 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); display.set("Lore", tagList);
setItemStack(newItem); setItemStack(newItem);

View File

@ -10,8 +10,8 @@ import me.filoghost.fcommons.reflection.ClassToken;
import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.fcommons.reflection.ReflectField;
import me.filoghost.fcommons.reflection.ReflectMethod; import me.filoghost.fcommons.reflection.ReflectMethod;
import me.filoghost.holographicdisplays.core.DebugLogger; import me.filoghost.holographicdisplays.core.DebugLogger;
import me.filoghost.holographicdisplays.core.nms.ChatComponentAdapter; import me.filoghost.holographicdisplays.core.nms.CustomNameEditor;
import me.filoghost.holographicdisplays.core.nms.CustomNameHelper; import me.filoghost.holographicdisplays.core.nms.ChatComponentCustomNameEditor;
import me.filoghost.holographicdisplays.core.nms.NMSManager; import me.filoghost.holographicdisplays.core.nms.NMSManager;
import me.filoghost.holographicdisplays.core.nms.PacketController; import me.filoghost.holographicdisplays.core.nms.PacketController;
import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand;
@ -154,41 +154,34 @@ public class VersionNMSManager implements NMSManager {
} }
@Override @Override
public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { public CustomNameEditor getCustomNameChatComponentEditor() {
return CustomNameHelper.replaceCustomNameChatComponent(NMSChatComponentAdapter.INSTANCE, customNameObject, target, replacement); return VersionChatComponentCustomNameEditor.INSTANCE;
} }
private enum NMSChatComponentAdapter implements ChatComponentAdapter<IChatBaseComponent> { private enum VersionChatComponentCustomNameEditor implements ChatComponentCustomNameEditor<IChatBaseComponent> {
INSTANCE { INSTANCE;
@Override @Override
public ChatComponentText cast(Object chatComponentObject) { public String getText(IChatBaseComponent chatComponent) {
return (ChatComponentText) chatComponentObject; return chatComponent.getText();
} }
@Override @Override
public String getText(IChatBaseComponent chatComponent) { public List<IChatBaseComponent> getSiblings(IChatBaseComponent chatComponent) {
return chatComponent.getText(); return chatComponent.getSiblings();
} }
@Override @Override
public List<IChatBaseComponent> getSiblings(IChatBaseComponent chatComponent) { public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) {
return chatComponent.getSiblings(); chatComponent.addSibling(newSibling);
} }
@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;
}
@Override
public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) {
ChatComponentText clonedChatComponent = new ChatComponentText(newText);
clonedChatComponent.setChatModifier(chatComponent.getChatModifier().clone());
return clonedChatComponent;
} }
} }

View File

@ -170,7 +170,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
} }
NBTTagList tagList = new NBTTagList(); 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); display.set("Lore", tagList);
setItemStack(newItem); setItemStack(newItem);

View File

@ -10,8 +10,8 @@ import me.filoghost.fcommons.reflection.ClassToken;
import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.fcommons.reflection.ReflectField;
import me.filoghost.fcommons.reflection.ReflectMethod; import me.filoghost.fcommons.reflection.ReflectMethod;
import me.filoghost.holographicdisplays.core.DebugLogger; import me.filoghost.holographicdisplays.core.DebugLogger;
import me.filoghost.holographicdisplays.core.nms.ChatComponentAdapter; import me.filoghost.holographicdisplays.core.nms.CustomNameEditor;
import me.filoghost.holographicdisplays.core.nms.CustomNameHelper; import me.filoghost.holographicdisplays.core.nms.ChatComponentCustomNameEditor;
import me.filoghost.holographicdisplays.core.nms.NMSManager; import me.filoghost.holographicdisplays.core.nms.NMSManager;
import me.filoghost.holographicdisplays.core.nms.PacketController; import me.filoghost.holographicdisplays.core.nms.PacketController;
import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand;
@ -154,42 +154,35 @@ public class VersionNMSManager implements NMSManager {
} }
@Override @Override
public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { public CustomNameEditor getCustomNameChatComponentEditor() {
return CustomNameHelper.replaceCustomNameChatComponent(NMSChatComponentAdapter.INSTANCE, customNameObject, target, replacement); return VersionChatComponentCustomNameEditor.INSTANCE;
} }
private enum NMSChatComponentAdapter implements ChatComponentAdapter<IChatBaseComponent> { private enum VersionChatComponentCustomNameEditor implements ChatComponentCustomNameEditor<IChatBaseComponent> {
INSTANCE { INSTANCE;
@Override @Override
public ChatComponentText cast(Object chatComponentObject) { public String getText(IChatBaseComponent chatComponent) {
return (ChatComponentText) chatComponentObject; return chatComponent.getText();
} }
@Override @Override
public String getText(IChatBaseComponent chatComponent) { public List<IChatBaseComponent> getSiblings(IChatBaseComponent chatComponent) {
return chatComponent.getText(); return chatComponent.getSiblings();
} }
@Override @Override
public List<IChatBaseComponent> getSiblings(IChatBaseComponent chatComponent) { public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) {
return chatComponent.getSiblings(); newSibling.getChatModifier().setChatModifier(chatComponent.getChatModifier());
} chatComponent.getSiblings().add(newSibling);
}
@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;
}
@Override
public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) {
ChatComponentText clonedChatComponent = new ChatComponentText(newText);
clonedChatComponent.setChatModifier(chatComponent.getChatModifier().a());
return clonedChatComponent;
} }
} }

View File

@ -170,7 +170,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
} }
NBTTagList tagList = new NBTTagList(); 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); display.set("Lore", tagList);
setItemStack(newItem); setItemStack(newItem);

View File

@ -10,8 +10,8 @@ import me.filoghost.fcommons.reflection.ClassToken;
import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.fcommons.reflection.ReflectField;
import me.filoghost.fcommons.reflection.ReflectMethod; import me.filoghost.fcommons.reflection.ReflectMethod;
import me.filoghost.holographicdisplays.core.DebugLogger; import me.filoghost.holographicdisplays.core.DebugLogger;
import me.filoghost.holographicdisplays.core.nms.ChatComponentAdapter; import me.filoghost.holographicdisplays.core.nms.CustomNameEditor;
import me.filoghost.holographicdisplays.core.nms.CustomNameHelper; import me.filoghost.holographicdisplays.core.nms.ChatComponentCustomNameEditor;
import me.filoghost.holographicdisplays.core.nms.NMSManager; import me.filoghost.holographicdisplays.core.nms.NMSManager;
import me.filoghost.holographicdisplays.core.nms.PacketController; import me.filoghost.holographicdisplays.core.nms.PacketController;
import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand;
@ -145,42 +145,35 @@ public class VersionNMSManager implements NMSManager {
} }
@Override @Override
public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { public CustomNameEditor getCustomNameChatComponentEditor() {
return CustomNameHelper.replaceCustomNameChatComponent(NMSChatComponentAdapter.INSTANCE, customNameObject, target, replacement); return VersionChatComponentCustomNameEditor.INSTANCE;
} }
private enum NMSChatComponentAdapter implements ChatComponentAdapter<IChatBaseComponent> { private enum VersionChatComponentCustomNameEditor implements ChatComponentCustomNameEditor<IChatBaseComponent> {
INSTANCE { INSTANCE;
@Override @Override
public ChatComponentText cast(Object chatComponentObject) { public String getText(IChatBaseComponent chatComponent) {
return (ChatComponentText) chatComponentObject; return chatComponent.getText();
} }
@Override @Override
public String getText(IChatBaseComponent chatComponent) { public List<IChatBaseComponent> getSiblings(IChatBaseComponent chatComponent) {
return chatComponent.getText(); return chatComponent.getSiblings();
} }
@Override @Override
public List<IChatBaseComponent> getSiblings(IChatBaseComponent chatComponent) { public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) {
return chatComponent.getSiblings(); newSibling.getChatModifier().setChatModifier(chatComponent.getChatModifier());
} chatComponent.getSiblings().add(newSibling);
}
@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;
}
@Override
public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) {
ChatComponentText clonedChatComponent = new ChatComponentText(newText);
clonedChatComponent.setChatModifier(chatComponent.getChatModifier().a());
return clonedChatComponent;
} }
} }

View File

@ -170,7 +170,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
} }
NBTTagList tagList = new NBTTagList(); 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); display.set("Lore", tagList);
setItemStack(newItem); setItemStack(newItem);

View File

@ -10,8 +10,8 @@ import me.filoghost.fcommons.reflection.ClassToken;
import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.fcommons.reflection.ReflectField;
import me.filoghost.fcommons.reflection.ReflectMethod; import me.filoghost.fcommons.reflection.ReflectMethod;
import me.filoghost.holographicdisplays.core.DebugLogger; import me.filoghost.holographicdisplays.core.DebugLogger;
import me.filoghost.holographicdisplays.core.nms.ChatComponentAdapter; import me.filoghost.holographicdisplays.core.nms.CustomNameEditor;
import me.filoghost.holographicdisplays.core.nms.CustomNameHelper; import me.filoghost.holographicdisplays.core.nms.ChatComponentCustomNameEditor;
import me.filoghost.holographicdisplays.core.nms.NMSManager; import me.filoghost.holographicdisplays.core.nms.NMSManager;
import me.filoghost.holographicdisplays.core.nms.PacketController; import me.filoghost.holographicdisplays.core.nms.PacketController;
import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand; import me.filoghost.holographicdisplays.core.nms.entity.NMSArmorStand;
@ -145,42 +145,35 @@ public class VersionNMSManager implements NMSManager {
} }
@Override @Override
public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { public CustomNameEditor getCustomNameChatComponentEditor() {
return CustomNameHelper.replaceCustomNameChatComponent(NMSChatComponentAdapter.INSTANCE, customNameObject, target, replacement); return VersionChatComponentCustomNameEditor.INSTANCE;
} }
private enum NMSChatComponentAdapter implements ChatComponentAdapter<IChatBaseComponent> { private enum VersionChatComponentCustomNameEditor implements ChatComponentCustomNameEditor<IChatBaseComponent> {
INSTANCE { INSTANCE;
@Override @Override
public ChatComponentText cast(Object chatComponentObject) { public String getText(IChatBaseComponent chatComponent) {
return (ChatComponentText) chatComponentObject; return chatComponent.getText();
} }
@Override @Override
public String getText(IChatBaseComponent chatComponent) { public List<IChatBaseComponent> getSiblings(IChatBaseComponent chatComponent) {
return chatComponent.getText(); return chatComponent.getSiblings();
} }
@Override @Override
public List<IChatBaseComponent> getSiblings(IChatBaseComponent chatComponent) { public void addSibling(IChatBaseComponent chatComponent, IChatBaseComponent newSibling) {
return chatComponent.getSiblings(); newSibling.getChatModifier().setChatModifier(chatComponent.getChatModifier());
} chatComponent.getSiblings().add(newSibling);
}
@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;
}
@Override
public ChatComponentText cloneComponent(IChatBaseComponent chatComponent, String newText) {
ChatComponentText clonedChatComponent = new ChatComponentText(newText);
clonedChatComponent.setChatModifier(chatComponent.getChatModifier().a());
return clonedChatComponent;
} }
} }

View File

@ -154,7 +154,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
} }
NBTTagList tagList = new NBTTagList(); 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); display.set("Lore", tagList);
setItemStack(newItem); setItemStack(newItem);

View File

@ -10,14 +10,15 @@ import me.filoghost.fcommons.reflection.ClassToken;
import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.fcommons.reflection.ReflectField;
import me.filoghost.fcommons.reflection.ReflectMethod; import me.filoghost.fcommons.reflection.ReflectMethod;
import me.filoghost.holographicdisplays.core.DebugLogger; 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.NMSManager;
import me.filoghost.holographicdisplays.core.nms.PacketController; 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.NMSArmorStand;
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase; import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem; 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.Entity;
import net.minecraft.server.v1_8_R2.EntityTypes; import net.minecraft.server.v1_8_R2.EntityTypes;
import net.minecraft.server.v1_8_R2.MathHelper; import net.minecraft.server.v1_8_R2.MathHelper;
@ -147,8 +148,8 @@ public class VersionNMSManager implements NMSManager {
} }
@Override @Override
public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { public CustomNameEditor getCustomNameChatComponentEditor() {
return CustomNameHelper.replaceCustomNameString(customNameObject, target, replacement); return StringCustomNameEditor.INSTANCE;
} }
} }

View File

@ -154,7 +154,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
} }
NBTTagList tagList = new NBTTagList(); 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); display.set("Lore", tagList);
setItemStack(newItem); setItemStack(newItem);

View File

@ -10,14 +10,15 @@ import me.filoghost.fcommons.reflection.ClassToken;
import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.fcommons.reflection.ReflectField;
import me.filoghost.fcommons.reflection.ReflectMethod; import me.filoghost.fcommons.reflection.ReflectMethod;
import me.filoghost.holographicdisplays.core.DebugLogger; 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.NMSManager;
import me.filoghost.holographicdisplays.core.nms.PacketController; 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.NMSArmorStand;
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase; import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem; 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.Entity;
import net.minecraft.server.v1_8_R3.EntityTypes; import net.minecraft.server.v1_8_R3.EntityTypes;
import net.minecraft.server.v1_8_R3.MathHelper; import net.minecraft.server.v1_8_R3.MathHelper;
@ -147,8 +148,8 @@ public class VersionNMSManager implements NMSManager {
} }
@Override @Override
public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { public CustomNameEditor getCustomNameChatComponentEditor() {
return CustomNameHelper.replaceCustomNameString(customNameObject, target, replacement); return StringCustomNameEditor.INSTANCE;
} }
} }

View File

@ -192,7 +192,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
} }
NBTTagList tagList = new NBTTagList(); 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); display.set("Lore", tagList);
setItemStack(newItem); setItemStack(newItem);

View File

@ -10,14 +10,15 @@ import me.filoghost.fcommons.reflection.ClassToken;
import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.fcommons.reflection.ReflectField;
import me.filoghost.fcommons.reflection.ReflectMethod; import me.filoghost.fcommons.reflection.ReflectMethod;
import me.filoghost.holographicdisplays.core.DebugLogger; 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.NMSManager;
import me.filoghost.holographicdisplays.core.nms.PacketController; 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.NMSArmorStand;
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase; import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem; 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.Entity;
import net.minecraft.server.v1_9_R1.EntityTypes; import net.minecraft.server.v1_9_R1.EntityTypes;
import net.minecraft.server.v1_9_R1.MathHelper; import net.minecraft.server.v1_9_R1.MathHelper;
@ -142,8 +143,8 @@ public class VersionNMSManager implements NMSManager {
} }
@Override @Override
public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { public CustomNameEditor getCustomNameChatComponentEditor() {
return CustomNameHelper.replaceCustomNameString(customNameObject, target, replacement); return StringCustomNameEditor.INSTANCE;
} }
} }

View File

@ -194,7 +194,7 @@ public class EntityNMSItem extends EntityItem implements NMSItem {
} }
NBTTagList tagList = new NBTTagList(); 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); display.set("Lore", tagList);
setItemStack(newItem); setItemStack(newItem);

View File

@ -10,14 +10,15 @@ import me.filoghost.fcommons.reflection.ClassToken;
import me.filoghost.fcommons.reflection.ReflectField; import me.filoghost.fcommons.reflection.ReflectField;
import me.filoghost.fcommons.reflection.ReflectMethod; import me.filoghost.fcommons.reflection.ReflectMethod;
import me.filoghost.holographicdisplays.core.DebugLogger; 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.NMSManager;
import me.filoghost.holographicdisplays.core.nms.PacketController; 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.NMSArmorStand;
import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase; import me.filoghost.holographicdisplays.core.nms.entity.NMSEntityBase;
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem; 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.Entity;
import net.minecraft.server.v1_9_R2.EntityTypes; import net.minecraft.server.v1_9_R2.EntityTypes;
import net.minecraft.server.v1_9_R2.MathHelper; import net.minecraft.server.v1_9_R2.MathHelper;
@ -142,8 +143,8 @@ public class VersionNMSManager implements NMSManager {
} }
@Override @Override
public Object replaceCustomNameText(Object customNameObject, String target, String replacement) { public CustomNameEditor getCustomNameChatComponentEditor() {
return CustomNameHelper.replaceCustomNameString(customNameObject, target, replacement); return StringCustomNameEditor.INSTANCE;
} }
} }

View File

@ -20,13 +20,15 @@ class MetadataHelper {
private final int itemSlotIndex; private final int itemSlotIndex;
private final int entityStatusIndex; private final int entityStatusIndex;
private final int airLevelWatcherIndex; private final int airLevelIndex;
private final int customNameIndex; private final int customNameIndex;
private final int customNameVisibleIndex; private final int customNameVisibleIndex;
private final int noGravityIndex; private final int noGravityIndex;
private final int armorStandStatusIndex; private final int armorStandStatusIndex;
private final int slimeSizeIndex; private final int slimeSizeIndex;
private final boolean customNameUsesChatComponents;
private Serializer itemSerializer; private Serializer itemSerializer;
private Serializer intSerializer; private Serializer intSerializer;
private Serializer byteSerializer; private Serializer byteSerializer;
@ -53,7 +55,7 @@ class MetadataHelper {
} }
entityStatusIndex = 0; entityStatusIndex = 0;
airLevelWatcherIndex = 1; airLevelIndex = 1;
customNameIndex = 2; customNameIndex = 2;
customNameVisibleIndex = 3; customNameVisibleIndex = 3;
noGravityIndex = 5; noGravityIndex = 5;
@ -68,7 +70,10 @@ class MetadataHelper {
} }
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) { if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) {
customNameUsesChatComponents = true;
chatComponentSerializer = Registry.get(MinecraftReflection.getIChatBaseComponentClass(), true); chatComponentSerializer = Registry.get(MinecraftReflection.getIChatBaseComponentClass(), true);
} else {
customNameUsesChatComponents = false;
} }
} }
@ -101,7 +106,7 @@ class MetadataHelper {
return null; return null;
} }
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) { if (customNameUsesChatComponents) {
if (!(customNameNMSObject instanceof Optional)) { if (!(customNameNMSObject instanceof Optional)) {
throw new IllegalArgumentException("Expected custom name of type " + Optional.class); throw new IllegalArgumentException("Expected custom name of type " + Optional.class);
} }
@ -119,7 +124,7 @@ class MetadataHelper {
public void setCustomNameNMSObject(WrappedWatchableObject customNameWatchableObject, Object customNameNMSObject) { public void setCustomNameNMSObject(WrappedWatchableObject customNameWatchableObject, Object customNameNMSObject) {
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) { if (customNameUsesChatComponents) {
customNameWatchableObject.setValue(Optional.ofNullable(customNameNMSObject)); customNameWatchableObject.setValue(Optional.ofNullable(customNameNMSObject));
} else { } else {
customNameWatchableObject.setValue(customNameNMSObject); customNameWatchableObject.setValue(customNameNMSObject);
@ -130,14 +135,13 @@ class MetadataHelper {
public void setCustomNameNMSObject(WrappedDataWatcher dataWatcher, Object customNameNMSObject) { public void setCustomNameNMSObject(WrappedDataWatcher dataWatcher, Object customNameNMSObject) {
requireMinimumVersion(NMSVersion.v1_9_R1); requireMinimumVersion(NMSVersion.v1_9_R1);
if (NMSVersion.isGreaterEqualThan(NMSVersion.v1_13_R1)) { if (customNameUsesChatComponents) {
dataWatcher.setObject(new WrappedDataWatcherObject(customNameIndex, chatComponentSerializer), Optional.ofNullable(customNameNMSObject)); dataWatcher.setObject(new WrappedDataWatcherObject(customNameIndex, chatComponentSerializer), Optional.ofNullable(customNameNMSObject));
} else { } else {
dataWatcher.setObject(new WrappedDataWatcherObject(customNameIndex, stringSerializer), customNameNMSObject); dataWatcher.setObject(new WrappedDataWatcherObject(customNameIndex, stringSerializer), customNameNMSObject);
} }
} }
public void setCustomNameVisible(WrappedDataWatcher dataWatcher, boolean customNameVisible) { public void setCustomNameVisible(WrappedDataWatcher dataWatcher, boolean customNameVisible) {
requireMinimumVersion(NMSVersion.v1_9_R1); requireMinimumVersion(NMSVersion.v1_9_R1);
dataWatcher.setObject(new WrappedDataWatcherObject(customNameVisibleIndex, booleanSerializer), customNameVisible); dataWatcher.setObject(new WrappedDataWatcherObject(customNameVisibleIndex, booleanSerializer), customNameVisible);
@ -163,11 +167,11 @@ class MetadataHelper {
} else { } else {
dataWatcher.setObject(new WrappedDataWatcherObject(itemSlotIndex, itemSerializer), com.google.common.base.Optional.of(nmsItemStack)); 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); dataWatcher.setObject(new WrappedDataWatcherObject(entityStatusIndex, byteSerializer), (byte) 0);
} else { } else {
dataWatcher.setObject(itemSlotIndex, nmsItemStack); dataWatcher.setObject(itemSlotIndex, nmsItemStack);
dataWatcher.setObject(airLevelWatcherIndex, 300); dataWatcher.setObject(airLevelIndex, 300);
dataWatcher.setObject(entityStatusIndex, (byte) 0); dataWatcher.setObject(entityStatusIndex, (byte) 0);
} }
} }

View File

@ -174,7 +174,10 @@ class PacketListener extends PacketAdapter {
Object replacedCustomNameNMSObject = originalCustomNameNMSObject; Object replacedCustomNameNMSObject = originalCustomNameNMSObject;
for (RelativePlaceholder relativePlaceholder : relativePlaceholders) { 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) { if (replacedCustomNameNMSObject == originalCustomNameNMSObject) {

View File

@ -16,7 +16,6 @@ import me.filoghost.holographicdisplays.disk.ConfigManager;
import me.filoghost.holographicdisplays.object.internal.InternalHologram; import me.filoghost.holographicdisplays.object.internal.InternalHologram;
import me.filoghost.holographicdisplays.object.internal.InternalHologramLine; import me.filoghost.holographicdisplays.object.internal.InternalHologramLine;
import me.filoghost.holographicdisplays.object.internal.InternalHologramManager; import me.filoghost.holographicdisplays.object.internal.InternalHologramManager;
import me.filoghost.holographicdisplays.object.internal.InternalTextLine;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
@ -71,7 +70,7 @@ public class CreateCommand extends HologramSubCommand {
} else { } else {
String defaultText = "Default hologram. Change it with " String defaultText = "Default hologram. Change it with "
+ Colors.PRIMARY + "/" + context.getRootLabel() + " edit " + hologram.getName(); + 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); hologram.getLinesUnsafe().add(line);

View File

@ -114,7 +114,7 @@ public class ReadimageCommand extends LineEditingCommand {
hologram.clearLines(); hologram.clearLines();
} }
for (String newLine : newLines) { for (String newLine : newLines) {
InternalTextLine line = new InternalTextLine(hologram, newLine, newLine); InternalTextLine line = hologram.createTextLine(newLine, newLine);
hologram.getLinesUnsafe().add(line); hologram.getLinesUnsafe().add(line);
} }
hologram.refresh(); hologram.refresh();

View File

@ -11,8 +11,6 @@ import me.filoghost.holographicdisplays.nbt.parser.MojangsonParseException;
import me.filoghost.holographicdisplays.nbt.parser.MojangsonParser; import me.filoghost.holographicdisplays.nbt.parser.MojangsonParser;
import me.filoghost.holographicdisplays.object.internal.InternalHologram; import me.filoghost.holographicdisplays.object.internal.InternalHologram;
import me.filoghost.holographicdisplays.object.internal.InternalHologramLine; 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.Bukkit;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -28,7 +26,7 @@ public class HologramLineParser {
if (serializedLine.toLowerCase().startsWith(ICON_PREFIX)) { if (serializedLine.toLowerCase().startsWith(ICON_PREFIX)) {
String serializedIcon = serializedLine.substring(ICON_PREFIX.length()); String serializedIcon = serializedLine.substring(ICON_PREFIX.length());
ItemStack icon = parseItemStack(serializedIcon, checkMaterialValidity); ItemStack icon = parseItemStack(serializedIcon, checkMaterialValidity);
hologramLine = new InternalItemLine(hologram, icon, serializedLine); hologramLine = hologram.createItemLine(icon, serializedLine);
} else { } else {
String displayText; String displayText;
@ -38,7 +36,7 @@ public class HologramLineParser {
displayText = StringConverter.toReadableFormat(serializedLine); displayText = StringConverter.toReadableFormat(serializedLine);
} }
hologramLine = new InternalTextLine(hologram, displayText, serializedLine); hologramLine = hologram.createTextLine(displayText, serializedLine);
} }
return hologramLine; return hologramLine;

View File

@ -57,7 +57,7 @@ public class APIHologram extends BaseHologram implements Hologram {
public TextLine appendTextLine(String text) { public TextLine appendTextLine(String text) {
checkState(); checkState();
APITextLine line = new APITextLine(this, text); APITextLine line = createTextLine(text);
lines.add(line); lines.add(line);
refresh(); refresh();
return line; return line;
@ -68,7 +68,7 @@ public class APIHologram extends BaseHologram implements Hologram {
checkState(); checkState();
Preconditions.notNull(itemStack, "itemStack"); Preconditions.notNull(itemStack, "itemStack");
APIItemLine line = new APIItemLine(this, itemStack); APIItemLine line = createItemLine(itemStack);
lines.add(line); lines.add(line);
refresh(); refresh();
return line; return line;
@ -78,7 +78,7 @@ public class APIHologram extends BaseHologram implements Hologram {
public TextLine insertTextLine(int index, String text) { public TextLine insertTextLine(int index, String text) {
checkState(); checkState();
APITextLine line = new APITextLine(this, text); APITextLine line = createTextLine(text);
lines.add(index, line); lines.add(index, line);
refresh(); refresh();
return line; return line;
@ -89,12 +89,20 @@ public class APIHologram extends BaseHologram implements Hologram {
checkState(); checkState();
Preconditions.notNull(itemStack, "itemStack"); Preconditions.notNull(itemStack, "itemStack");
APIItemLine line = new APIItemLine(this, itemStack); APIItemLine line = createItemLine(itemStack);
lines.add(index, line); lines.add(index, line);
refresh(); refresh();
return line; 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 @Override
public HologramLine getLine(int index) { public HologramLine getLine(int index) {
return lines.get(index); return lines.get(index);

View File

@ -2,6 +2,7 @@ package me.filoghost.holographicdisplays.object.api;
import me.filoghost.holographicdisplays.api.Hologram; import me.filoghost.holographicdisplays.api.Hologram;
import me.filoghost.holographicdisplays.api.line.ItemLine; import me.filoghost.holographicdisplays.api.line.ItemLine;
import me.filoghost.holographicdisplays.core.nms.NMSManager;
import me.filoghost.holographicdisplays.object.base.BaseItemLine; import me.filoghost.holographicdisplays.object.base.BaseItemLine;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -9,8 +10,8 @@ public class APIItemLine extends BaseItemLine implements ItemLine, APIHologramLi
private final APIHologram parent; private final APIHologram parent;
public APIItemLine(APIHologram parent, ItemStack itemStack) { public APIItemLine(APIHologram parent, NMSManager nmsManager, ItemStack itemStack) {
super(parent, itemStack); super(parent, nmsManager, itemStack);
this.parent = parent; this.parent = parent;
} }

View File

@ -2,14 +2,15 @@ package me.filoghost.holographicdisplays.object.api;
import me.filoghost.holographicdisplays.api.Hologram; import me.filoghost.holographicdisplays.api.Hologram;
import me.filoghost.holographicdisplays.api.line.TextLine; import me.filoghost.holographicdisplays.api.line.TextLine;
import me.filoghost.holographicdisplays.core.nms.NMSManager;
import me.filoghost.holographicdisplays.object.base.BaseTextLine; import me.filoghost.holographicdisplays.object.base.BaseTextLine;
public class APITextLine extends BaseTextLine implements TextLine, APIHologramLine { public class APITextLine extends BaseTextLine implements TextLine, APIHologramLine {
private final APIHologram parent; private final APIHologram parent;
public APITextLine(APIHologram parent, String text) { public APITextLine(APIHologram parent, NMSManager nmsManager, String text) {
super(parent, text); super(parent, nmsManager, text);
this.parent = parent; this.parent = parent;
} }

View File

@ -40,8 +40,7 @@ public abstract class BaseHologram extends BaseHologramComponent implements Stan
} }
} }
@Override protected final NMSManager getNMSManager() {
public NMSManager getNMSManager() {
return nmsManager; return nmsManager;
} }

View File

@ -13,22 +13,24 @@ import org.bukkit.World;
public abstract class BaseHologramLine extends BaseHologramComponent implements StandardHologramLine { public abstract class BaseHologramLine extends BaseHologramComponent implements StandardHologramLine {
private final StandardHologram parent; private final StandardHologram hologram;
private final NMSManager nmsManager;
private boolean isSpawned; private boolean isSpawned;
protected BaseHologramLine(StandardHologram parent) { protected BaseHologramLine(StandardHologram hologram, NMSManager nmsManager) {
Preconditions.notNull(parent, "parent hologram"); Preconditions.notNull(hologram, "parent hologram");
this.parent = parent; this.hologram = hologram;
this.nmsManager = nmsManager;
} }
@Override @Override
public final StandardHologram getHologram() { public final StandardHologram getHologram() {
return parent; return hologram;
} }
protected final NMSManager getNMSManager() { protected final NMSManager getNMSManager() {
return parent.getNMSManager(); return nmsManager;
} }
@Override @Override
@ -61,7 +63,7 @@ public abstract class BaseHologramLine extends BaseHologramComponent implements
isSpawned = false; isSpawned = false;
} }
protected boolean isSpawned() { protected final boolean isSpawned() {
return isSpawned; return isSpawned;
} }

View File

@ -10,6 +10,7 @@ import me.filoghost.fcommons.logging.Log;
import me.filoghost.holographicdisplays.api.handler.PickupHandler; import me.filoghost.holographicdisplays.api.handler.PickupHandler;
import me.filoghost.holographicdisplays.core.hologram.StandardHologram; import me.filoghost.holographicdisplays.core.hologram.StandardHologram;
import me.filoghost.holographicdisplays.core.hologram.StandardItemLine; 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.NMSArmorStand;
import me.filoghost.holographicdisplays.core.nms.entity.NMSItem; import me.filoghost.holographicdisplays.core.nms.entity.NMSItem;
import org.bukkit.World; import org.bukkit.World;
@ -26,8 +27,8 @@ public abstract class BaseItemLine extends BaseTouchableLine implements Standard
private NMSArmorStand vehicleEntity; private NMSArmorStand vehicleEntity;
private PickupHandler pickupHandler; private PickupHandler pickupHandler;
public BaseItemLine(StandardHologram parent, ItemStack itemStack) { public BaseItemLine(StandardHologram hologram, NMSManager nmsManager, ItemStack itemStack) {
super(parent); super(hologram, nmsManager);
setItemStack(itemStack); setItemStack(itemStack);
} }

View File

@ -7,6 +7,7 @@ package me.filoghost.holographicdisplays.object.base;
import me.filoghost.holographicdisplays.core.hologram.StandardHologram; import me.filoghost.holographicdisplays.core.hologram.StandardHologram;
import me.filoghost.holographicdisplays.core.hologram.StandardTextLine; 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.nms.entity.NMSArmorStand;
import me.filoghost.holographicdisplays.core.placeholder.RelativePlaceholder; import me.filoghost.holographicdisplays.core.placeholder.RelativePlaceholder;
import me.filoghost.holographicdisplays.placeholder.PlaceholdersManager; import me.filoghost.holographicdisplays.placeholder.PlaceholdersManager;
@ -21,8 +22,8 @@ public abstract class BaseTextLine extends BaseTouchableLine implements Standard
private String text; private String text;
private NMSArmorStand nameableEntity; private NMSArmorStand nameableEntity;
public BaseTextLine(StandardHologram parent, String text) { public BaseTextLine(StandardHologram hologram, NMSManager nmsManager, String text) {
super(parent); super(hologram, nmsManager);
this.relativePlaceholders = new ArrayList<>(); this.relativePlaceholders = new ArrayList<>();
setText(text); setText(text);
} }

View File

@ -9,6 +9,7 @@ import me.filoghost.fcommons.logging.Log;
import me.filoghost.holographicdisplays.api.handler.TouchHandler; import me.filoghost.holographicdisplays.api.handler.TouchHandler;
import me.filoghost.holographicdisplays.core.hologram.StandardHologram; import me.filoghost.holographicdisplays.core.hologram.StandardHologram;
import me.filoghost.holographicdisplays.core.hologram.StandardTouchableLine; 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.NMSArmorStand;
import me.filoghost.holographicdisplays.core.nms.entity.NMSSlime; import me.filoghost.holographicdisplays.core.nms.entity.NMSSlime;
import org.bukkit.World; 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 double SLIME_HEIGHT = 0.5;
private static final Map<Player, Long> anticlickSpam = new WeakHashMap<>(); private static final Map<Player, Long> lastClickByPlayer = new WeakHashMap<>();
private TouchHandler touchHandler; private TouchHandler touchHandler;
@ -34,8 +35,8 @@ public abstract class BaseTouchableLine extends BaseHologramLine implements Stan
private NMSArmorStand vehicleEntity; private NMSArmorStand vehicleEntity;
protected BaseTouchableLine(StandardHologram parent) { protected BaseTouchableLine(StandardHologram hologram, NMSManager nmsManager) {
super(parent); super(hologram, nmsManager);
} }
@Override @Override
@ -44,12 +45,13 @@ public abstract class BaseTouchableLine extends BaseHologramLine implements Stan
return; return;
} }
Long lastClick = anticlickSpam.get(player); Long lastClick = lastClickByPlayer.get(player);
if (lastClick != null && System.currentTimeMillis() - lastClick < 100) { long now = System.currentTimeMillis();
if (lastClick != null && now - lastClick < 100) {
return; return;
} }
anticlickSpam.put(player, System.currentTimeMillis()); lastClickByPlayer.put(player, now);
try { try {
touchHandler.onTouch(player); touchHandler.onTouch(player);

View File

@ -10,6 +10,7 @@ import me.filoghost.holographicdisplays.core.nms.NMSManager;
import me.filoghost.holographicdisplays.object.base.BaseHologram; import me.filoghost.holographicdisplays.object.base.BaseHologram;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import java.util.ArrayList; import java.util.ArrayList;
@ -30,6 +31,14 @@ public class InternalHologram extends BaseHologram {
return name; 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 @Override
public Plugin getOwnerPlugin() { public Plugin getOwnerPlugin() {
return HolographicDisplays.getInstance(); return HolographicDisplays.getInstance();

View File

@ -6,6 +6,7 @@
package me.filoghost.holographicdisplays.object.internal; package me.filoghost.holographicdisplays.object.internal;
import me.filoghost.holographicdisplays.core.hologram.StandardHologram; import me.filoghost.holographicdisplays.core.hologram.StandardHologram;
import me.filoghost.holographicdisplays.core.nms.NMSManager;
import me.filoghost.holographicdisplays.object.base.BaseItemLine; import me.filoghost.holographicdisplays.object.base.BaseItemLine;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -13,11 +14,12 @@ public class InternalItemLine extends BaseItemLine implements InternalHologramLi
private final String serializedConfigValue; private final String serializedConfigValue;
public InternalItemLine(StandardHologram parent, ItemStack itemStack, String serializedConfigValue) { protected InternalItemLine(StandardHologram hologram, NMSManager nmsManager, ItemStack itemStack, String serializedConfigValue) {
super(parent, itemStack); super(hologram, nmsManager, itemStack);
this.serializedConfigValue = serializedConfigValue; this.serializedConfigValue = serializedConfigValue;
} }
@Override
public String getSerializedConfigValue() { public String getSerializedConfigValue() {
return serializedConfigValue; return serializedConfigValue;
} }

View File

@ -6,14 +6,15 @@
package me.filoghost.holographicdisplays.object.internal; package me.filoghost.holographicdisplays.object.internal;
import me.filoghost.holographicdisplays.core.hologram.StandardHologram; import me.filoghost.holographicdisplays.core.hologram.StandardHologram;
import me.filoghost.holographicdisplays.core.nms.NMSManager;
import me.filoghost.holographicdisplays.object.base.BaseTextLine; import me.filoghost.holographicdisplays.object.base.BaseTextLine;
public class InternalTextLine extends BaseTextLine implements InternalHologramLine { public class InternalTextLine extends BaseTextLine implements InternalHologramLine {
private final String serializedConfigValue; private final String serializedConfigValue;
public InternalTextLine(StandardHologram parent, String text, String serializedConfigValue) { protected InternalTextLine(StandardHologram hologram, NMSManager nmsManager, String text, String serializedConfigValue) {
super(parent, text); super(hologram, nmsManager, text);
this.serializedConfigValue = serializedConfigValue; this.serializedConfigValue = serializedConfigValue;
} }
@ -22,6 +23,7 @@ public class InternalTextLine extends BaseTextLine implements InternalHologramLi
return true; return true;
} }
@Override
public String getSerializedConfigValue() { public String getSerializedConfigValue() {
return serializedConfigValue; return serializedConfigValue;
} }