2020-07-02 17:53:21 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: MiniDigger <admin@minidigger.me>
|
|
|
|
Date: Sat, 6 Jun 2020 18:13:42 +0200
|
|
|
|
Subject: [PATCH] Support components in ItemMeta
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/IChatBaseComponent.java b/src/main/java/net/minecraft/server/IChatBaseComponent.java
|
2020-08-25 04:22:08 +02:00
|
|
|
index b8770066a86df25d6ba9ecf74d846c730d228c01..2eb45e8e05b1a2ad6b8fcb204f2d2b06f9861643 100644
|
2020-07-02 17:53:21 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/IChatBaseComponent.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/IChatBaseComponent.java
|
|
|
|
@@ -344,6 +344,7 @@ public interface IChatBaseComponent extends Message, IChatFormatted, Iterable<IC
|
|
|
|
return jsonobject;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ public static String componentToJson(IChatBaseComponent ichatbasecomponent) { return a(ichatbasecomponent);} // Paper - OBFHELPER
|
|
|
|
public static String a(IChatBaseComponent ichatbasecomponent) {
|
|
|
|
return IChatBaseComponent.ChatSerializer.a.toJson(ichatbasecomponent);
|
|
|
|
}
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
2021-01-01 05:03:19 +01:00
|
|
|
index 99495722455b27ba90523c6d6dfd874aa2a8b3fe..c981568c252843c5be5ebdc2554cd172f5f4b16c 100644
|
2020-07-02 17:53:21 +02:00
|
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
|
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaItem.java
|
2021-01-01 05:03:19 +01:00
|
|
|
@@ -861,11 +861,23 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
|
|
|
return CraftChatMessage.fromJSONComponent(displayName);
|
2020-07-02 17:53:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
+ @Override
|
|
|
|
+ public net.md_5.bungee.api.chat.BaseComponent[] getDisplayNameComponent() {
|
2021-01-01 05:03:19 +01:00
|
|
|
+ return net.md_5.bungee.chat.ComponentSerializer.parse(displayName);
|
2020-07-02 17:53:21 +02:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
@Override
|
|
|
|
public final void setDisplayName(String name) {
|
2021-01-01 05:03:19 +01:00
|
|
|
this.displayName = CraftChatMessage.fromStringOrNullToJSON(name);
|
2020-07-02 17:53:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
+ @Override
|
|
|
|
+ public void setDisplayNameComponent(net.md_5.bungee.api.chat.BaseComponent[] component) {
|
2021-01-01 05:03:19 +01:00
|
|
|
+ this.displayName = net.md_5.bungee.chat.ComponentSerializer.toString(component);
|
2020-07-02 17:53:21 +02:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
@Override
|
|
|
|
public boolean hasDisplayName() {
|
|
|
|
return displayName != null;
|
2021-01-01 05:03:19 +01:00
|
|
|
@@ -996,6 +1008,14 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
|
|
|
return this.lore == null ? null : new ArrayList<String>(Lists.transform(this.lore, CraftChatMessage::fromJSONComponent));
|
2020-07-02 17:53:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
+ @Override
|
|
|
|
+ public List<net.md_5.bungee.api.chat.BaseComponent[]> getLoreComponents() {
|
|
|
|
+ return this.lore == null ? null : new ArrayList<>(this.lore.stream().map(entry ->
|
2021-01-01 05:03:19 +01:00
|
|
|
+ net.md_5.bungee.chat.ComponentSerializer.parse(entry)
|
|
|
|
+ ).collect(java.util.stream.Collectors.toList()));
|
2020-07-02 17:53:21 +02:00
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
@Override
|
2021-01-01 05:03:19 +01:00
|
|
|
public void setLore(List<String> lore) {
|
|
|
|
if (lore == null || lore.isEmpty()) {
|
|
|
|
@@ -1010,6 +1030,21 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2020-07-02 17:53:21 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ // Paper start
|
|
|
|
+ @Override
|
|
|
|
+ public void setLoreComponents(List<net.md_5.bungee.api.chat.BaseComponent[]> lore) {
|
|
|
|
+ if (lore == null) {
|
|
|
|
+ this.lore = null;
|
|
|
|
+ } else {
|
|
|
|
+ if (this.lore == null) {
|
2021-01-01 05:03:19 +01:00
|
|
|
+ safelyAdd(lore, this.lore = new ArrayList<>(lore.size()), false);
|
2020-07-02 17:53:21 +02:00
|
|
|
+ } else {
|
|
|
|
+ this.lore.clear();
|
2021-01-01 05:03:19 +01:00
|
|
|
+ safelyAdd(lore, this.lore, false);
|
2020-07-02 17:53:21 +02:00
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // Paper end
|
|
|
|
@Override
|
|
|
|
public boolean hasCustomModelData() {
|
|
|
|
return customModelData != null;
|
2021-01-01 05:03:19 +01:00
|
|
|
@@ -1471,6 +1506,11 @@ class CraftMetaItem implements ItemMeta, Damageable, Repairable, BlockDataMeta {
|
2020-07-02 17:53:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for (Object object : addFrom) {
|
|
|
|
+ // Paper start - support components
|
|
|
|
+ if(object instanceof net.md_5.bungee.api.chat.BaseComponent[]) {
|
2021-01-01 05:03:19 +01:00
|
|
|
+ addTo.add(net.md_5.bungee.chat.ComponentSerializer.toString((net.md_5.bungee.api.chat.BaseComponent[]) object));
|
2020-07-02 17:53:21 +02:00
|
|
|
+ } else
|
|
|
|
+ // Paper end
|
|
|
|
if (!(object instanceof String)) {
|
|
|
|
if (object != null) {
|
|
|
|
throw new IllegalArgumentException(addFrom + " cannot contain non-string " + object.getClass().getName());
|