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

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;
public class CustomNameHelper {
public interface ChatComponentCustomNameEditor<T> 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> T replaceCustomNameChatComponent(ChatComponentAdapter<T> 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<T> children = versionAdapter.getSiblings(rootComponent);
List<T> 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<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 {
// 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");

View File

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

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();
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);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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<IChatBaseComponent> {
private enum VersionChatComponentCustomNameEditor implements ChatComponentCustomNameEditor<IChatBaseComponent> {
INSTANCE {
@Override
public ChatComponentText cast(Object chatComponentObject) {
return (ChatComponentText) chatComponentObject;
}
@Override
public String getText(IChatBaseComponent chatComponent) {
return chatComponent.getText();
}
@Override
public List<IChatBaseComponent> 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<IChatBaseComponent> 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;
}
}

View File

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

View File

@ -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<IChatBaseComponent> {
private enum VersionChatComponentCustomNameEditor implements ChatComponentCustomNameEditor<IChatBaseComponent> {
INSTANCE {
@Override
public ChatComponentText cast(Object chatComponentObject) {
return (ChatComponentText) chatComponentObject;
}
@Override
public String getText(IChatBaseComponent chatComponent) {
return chatComponent.getText();
}
@Override
public List<IChatBaseComponent> 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<IChatBaseComponent> 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;
}
}

View File

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

View File

@ -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<IChatBaseComponent> {
private enum VersionChatComponentCustomNameEditor implements ChatComponentCustomNameEditor<IChatBaseComponent> {
INSTANCE {
INSTANCE;
private boolean useNewGetSiblingsMethod = true;
private final ReflectField<List<IChatBaseComponent>> OLD_SIBLINGS_FIELD = ReflectField.lookup(new ClassToken<List<IChatBaseComponent>>(){}, ChatBaseComponent.class, "a");
@Override
public ChatComponentText cast(Object chatComponentObject) {
return (ChatComponentText) chatComponentObject;
}
@Override
public String getText(IChatBaseComponent chatComponent) {
return chatComponent.getText();
}
@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.
private boolean useNewGetSiblingsMethod = true;
private final ReflectField<List<IChatBaseComponent>> OLD_SIBLINGS_FIELD = ReflectField.lookup(new ClassToken<List<IChatBaseComponent>>(){}, ChatBaseComponent.class, "a");
@Override
public String getText(IChatBaseComponent chatComponent) {
return chatComponent.getText();
}
@Override
public List<IChatBaseComponent> 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;
}
}

View File

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

View File

@ -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<IChatBaseComponent> {
private enum VersionChatComponentCustomNameEditor implements ChatComponentCustomNameEditor<IChatBaseComponent> {
INSTANCE {
@Override
public ChatComponentText cast(Object chatComponentObject) {
return (ChatComponentText) chatComponentObject;
}
@Override
public String getText(IChatBaseComponent chatComponent) {
return chatComponent.getText();
}
@Override
public List<IChatBaseComponent> 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<IChatBaseComponent> 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;
}
}

View File

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

View File

@ -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<IChatBaseComponent> {
private enum VersionChatComponentCustomNameEditor implements ChatComponentCustomNameEditor<IChatBaseComponent> {
INSTANCE {
@Override
public ChatComponentText cast(Object chatComponentObject) {
return (ChatComponentText) chatComponentObject;
}
@Override
public String getText(IChatBaseComponent chatComponent) {
return chatComponent.getText();
}
@Override
public List<IChatBaseComponent> 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<IChatBaseComponent> 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;
}
}

View File

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

View File

@ -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<IChatBaseComponent> {
private enum VersionChatComponentCustomNameEditor implements ChatComponentCustomNameEditor<IChatBaseComponent> {
INSTANCE {
@Override
public ChatComponentText cast(Object chatComponentObject) {
return (ChatComponentText) chatComponentObject;
}
@Override
public String getText(IChatBaseComponent chatComponent) {
return chatComponent.getText();
}
@Override
public List<IChatBaseComponent> 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<IChatBaseComponent> 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;
}
}

View File

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

View File

@ -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<IChatBaseComponent> {
private enum VersionChatComponentCustomNameEditor implements ChatComponentCustomNameEditor<IChatBaseComponent> {
INSTANCE {
@Override
public ChatComponentText cast(Object chatComponentObject) {
return (ChatComponentText) chatComponentObject;
}
@Override
public String getText(IChatBaseComponent chatComponent) {
return chatComponent.getText();
}
@Override
public List<IChatBaseComponent> 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<IChatBaseComponent> 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;
}
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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) {

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.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);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

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

View File

@ -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<Player, Long> anticlickSpam = new WeakHashMap<>();
private static final Map<Player, Long> 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);

View File

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

View File

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

View File

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