Skip to content

Commit

Permalink
Fixed Item TextDecoration in legacy versions
Browse files Browse the repository at this point in the history
  • Loading branch information
LOOHP committed Jan 6, 2025
1 parent 0bafa4d commit b13d308
Show file tree
Hide file tree
Showing 11 changed files with 47 additions and 24 deletions.
6 changes: 3 additions & 3 deletions V1_10/src/main/java/com/loohp/interactivechat/nms/V1_10.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public net.minecraft.server.v1_10_R1.ItemStack toNMSCopy(ItemStack itemstack) {
@Override
public Component getItemStackDisplayName(ItemStack itemStack) {
net.minecraft.server.v1_10_R1.ItemStack nmsItemStack = toNMSCopy(itemStack);
return LegacyComponentSerializer.legacySection().deserialize(nmsItemStack.getName());
return l(nmsItemStack.getName());
}

@Override
Expand All @@ -170,7 +170,7 @@ public List<Component> getItemStackLore(ItemStack itemStack) {
if (lore == null) {
return Collections.emptyList();
}
return lore.stream().map(s -> LegacyComponentSerializer.legacySection().deserialize(s)).collect(Collectors.toList());
return lore.stream().map(s -> l(s)).collect(Collectors.toList());
}

@Override
Expand All @@ -191,7 +191,7 @@ public Component getSkullOwner(ItemStack itemStack) {
net.minecraft.server.v1_10_R1.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
ItemSkull skull = (ItemSkull) nmsItemStack.getItem();
String owner = skull.a(nmsItemStack);
return LegacyComponentSerializer.legacySection().deserialize(owner);
return l(owner);
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions V1_11/src/main/java/com/loohp/interactivechat/nms/V1_11.java
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public net.minecraft.server.v1_11_R1.ItemStack toNMSCopy(ItemStack itemstack) {
@Override
public Component getItemStackDisplayName(ItemStack itemStack) {
net.minecraft.server.v1_11_R1.ItemStack nmsItemStack = toNMSCopy(itemStack);
return LegacyComponentSerializer.legacySection().deserialize(nmsItemStack.getName());
return l(nmsItemStack.getName());
}

@Override
Expand All @@ -173,7 +173,7 @@ public List<Component> getItemStackLore(ItemStack itemStack) {
if (lore == null) {
return Collections.emptyList();
}
return lore.stream().map(s -> LegacyComponentSerializer.legacySection().deserialize(s)).collect(Collectors.toList());
return lore.stream().map(s -> l(s)).collect(Collectors.toList());
}

@Override
Expand All @@ -194,7 +194,7 @@ public Component getSkullOwner(ItemStack itemStack) {
net.minecraft.server.v1_11_R1.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
ItemSkull skull = (ItemSkull) nmsItemStack.getItem();
String owner = skull.b(nmsItemStack);
return LegacyComponentSerializer.legacySection().deserialize(owner);
return l(owner);
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions V1_12/src/main/java/com/loohp/interactivechat/nms/V1_12.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public net.minecraft.server.v1_12_R1.ItemStack toNMSCopy(ItemStack itemstack) {
@Override
public Component getItemStackDisplayName(ItemStack itemStack) {
net.minecraft.server.v1_12_R1.ItemStack nmsItemStack = toNMSCopy(itemStack);
return LegacyComponentSerializer.legacySection().deserialize(nmsItemStack.getName());
return l(nmsItemStack.getName());
}

@Override
Expand All @@ -185,7 +185,7 @@ public List<Component> getItemStackLore(ItemStack itemStack) {
if (lore == null) {
return Collections.emptyList();
}
return lore.stream().map(s -> LegacyComponentSerializer.legacySection().deserialize(s)).collect(Collectors.toList());
return lore.stream().map(s -> l(s)).collect(Collectors.toList());
}

@Override
Expand All @@ -206,7 +206,7 @@ public Component getSkullOwner(ItemStack itemStack) {
net.minecraft.server.v1_12_R1.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
ItemSkull skull = (ItemSkull) nmsItemStack.getItem();
String owner = skull.b(nmsItemStack);
return LegacyComponentSerializer.legacySection().deserialize(owner);
return l(owner);
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions V1_8/src/main/java/com/loohp/interactivechat/nms/V1_8.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public net.minecraft.server.v1_8_R1.ItemStack toNMSCopy(ItemStack itemstack) {
@Override
public Component getItemStackDisplayName(ItemStack itemStack) {
net.minecraft.server.v1_8_R1.ItemStack nmsItemStack = toNMSCopy(itemStack);
return LegacyComponentSerializer.legacySection().deserialize(nmsItemStack.getName());
return l(nmsItemStack.getName());
}

@Override
Expand All @@ -167,7 +167,7 @@ public List<Component> getItemStackLore(ItemStack itemStack) {
if (lore == null) {
return Collections.emptyList();
}
return lore.stream().map(s -> LegacyComponentSerializer.legacySection().deserialize(s)).collect(Collectors.toList());
return lore.stream().map(s -> l(s)).collect(Collectors.toList());
}

@Override
Expand All @@ -188,7 +188,7 @@ public Component getSkullOwner(ItemStack itemStack) {
net.minecraft.server.v1_8_R1.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
ItemSkull skull = (ItemSkull) nmsItemStack.getItem();
String owner = skull.a(nmsItemStack);
return LegacyComponentSerializer.legacySection().deserialize(owner);
return l(owner);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public net.minecraft.server.v1_8_R2.ItemStack toNMSCopy(ItemStack itemstack) {
@Override
public Component getItemStackDisplayName(ItemStack itemStack) {
net.minecraft.server.v1_8_R2.ItemStack nmsItemStack = toNMSCopy(itemStack);
return LegacyComponentSerializer.legacySection().deserialize(nmsItemStack.getName());
return l(nmsItemStack.getName());
}

@Override
Expand All @@ -168,7 +168,7 @@ public List<Component> getItemStackLore(ItemStack itemStack) {
if (lore == null) {
return Collections.emptyList();
}
return lore.stream().map(s -> LegacyComponentSerializer.legacySection().deserialize(s)).collect(Collectors.toList());
return lore.stream().map(s -> l(s)).collect(Collectors.toList());
}

@Override
Expand All @@ -189,7 +189,7 @@ public Component getSkullOwner(ItemStack itemStack) {
net.minecraft.server.v1_8_R2.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
ItemSkull skull = (ItemSkull) nmsItemStack.getItem();
String owner = skull.a(nmsItemStack);
return LegacyComponentSerializer.legacySection().deserialize(owner);
return l(owner);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ public net.minecraft.server.v1_8_R3.ItemStack toNMSCopy(ItemStack itemstack) {
@Override
public Component getItemStackDisplayName(ItemStack itemStack) {
net.minecraft.server.v1_8_R3.ItemStack nmsItemStack = toNMSCopy(itemStack);
return LegacyComponentSerializer.legacySection().deserialize(nmsItemStack.getName());
return l(nmsItemStack.getName());
}

@Override
Expand All @@ -168,7 +168,7 @@ public List<Component> getItemStackLore(ItemStack itemStack) {
if (lore == null) {
return Collections.emptyList();
}
return lore.stream().map(s -> LegacyComponentSerializer.legacySection().deserialize(s)).collect(Collectors.toList());
return lore.stream().map(s -> l(s)).collect(Collectors.toList());
}

@Override
Expand All @@ -189,7 +189,7 @@ public Component getSkullOwner(ItemStack itemStack) {
net.minecraft.server.v1_8_R3.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
ItemSkull skull = (ItemSkull) nmsItemStack.getItem();
String owner = skull.a(nmsItemStack);
return LegacyComponentSerializer.legacySection().deserialize(owner);
return l(owner);
}

@Override
Expand Down
6 changes: 3 additions & 3 deletions V1_9/src/main/java/com/loohp/interactivechat/nms/V1_9.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public net.minecraft.server.v1_9_R1.ItemStack toNMSCopy(ItemStack itemstack) {
@Override
public Component getItemStackDisplayName(ItemStack itemStack) {
net.minecraft.server.v1_9_R1.ItemStack nmsItemStack = toNMSCopy(itemStack);
return LegacyComponentSerializer.legacySection().deserialize(nmsItemStack.getName());
return l(nmsItemStack.getName());
}

@Override
Expand All @@ -170,7 +170,7 @@ public List<Component> getItemStackLore(ItemStack itemStack) {
if (lore == null) {
return Collections.emptyList();
}
return lore.stream().map(s -> LegacyComponentSerializer.legacySection().deserialize(s)).collect(Collectors.toList());
return lore.stream().map(s -> l(s)).collect(Collectors.toList());
}

@Override
Expand All @@ -191,7 +191,7 @@ public Component getSkullOwner(ItemStack itemStack) {
net.minecraft.server.v1_9_R1.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
ItemSkull skull = (ItemSkull) nmsItemStack.getItem();
String owner = skull.a(nmsItemStack);
return LegacyComponentSerializer.legacySection().deserialize(owner);
return l(owner);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public net.minecraft.server.v1_9_R2.ItemStack toNMSCopy(ItemStack itemstack) {
@Override
public Component getItemStackDisplayName(ItemStack itemStack) {
net.minecraft.server.v1_9_R2.ItemStack nmsItemStack = toNMSCopy(itemStack);
return LegacyComponentSerializer.legacySection().deserialize(nmsItemStack.getName());
return l(nmsItemStack.getName());
}

@Override
Expand All @@ -170,7 +170,7 @@ public List<Component> getItemStackLore(ItemStack itemStack) {
if (lore == null) {
return Collections.emptyList();
}
return lore.stream().map(s -> LegacyComponentSerializer.legacySection().deserialize(s)).collect(Collectors.toList());
return lore.stream().map(s -> l(s)).collect(Collectors.toList());
}

@Override
Expand All @@ -191,7 +191,7 @@ public Component getSkullOwner(ItemStack itemStack) {
net.minecraft.server.v1_9_R2.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
ItemSkull skull = (ItemSkull) nmsItemStack.getItem();
String owner = skull.a(nmsItemStack);
return LegacyComponentSerializer.legacySection().deserialize(owner);
return l(owner);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,13 @@
import com.loohp.interactivechat.objectholders.CustomTabCompletionAction;
import com.loohp.interactivechat.objectholders.IICPlayer;
import com.loohp.interactivechat.objectholders.ValuePairs;
import com.loohp.interactivechat.utils.ComponentFlattening;
import net.kyori.adventure.key.Key;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.event.DataComponentValue;
import net.kyori.adventure.text.format.Style;
import net.kyori.adventure.text.format.TextDecoration;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.md_5.bungee.api.ChatColor;
import net.querz.nbt.io.NamedTag;
import org.bukkit.Material;
Expand All @@ -39,6 +43,7 @@
import org.bukkit.plugin.Plugin;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -66,11 +71,29 @@ public static void setup(NMSWrapper instance, Plugin plugin) {
}

static final ItemStack ITEM_STACK_AIR = new ItemStack(Material.AIR);
static final Style STYLE_ALL_FALSE = Style.style()
.decoration(TextDecoration.BOLD, TextDecoration.State.FALSE)
.decoration(TextDecoration.ITALIC, TextDecoration.State.FALSE)
.decoration(TextDecoration.UNDERLINED, TextDecoration.State.FALSE)
.decoration(TextDecoration.STRIKETHROUGH, TextDecoration.State.FALSE)
.decoration(TextDecoration.OBFUSCATED, TextDecoration.State.FALSE)
.build();

static PacketContainer p(Object packet) {
return PacketContainer.fromPacket(packet);
}

static Component l(String text) {
List<Component> children = new ArrayList<>(ComponentFlattening.flatten(LegacyComponentSerializer.legacySection().deserialize(text)).children());
for (int i = 0; i < children.size(); i++) {
Component child = children.get(i);
if (child.color() != null) {
children.set(i, child.style(child.style().merge(STYLE_ALL_FALSE, Style.Merge.Strategy.IF_ABSENT_ON_TARGET)));
}
}
return Component.empty().children(children);
}

public abstract boolean getColorSettingsFromClientInformationPacket(PacketContainer packet);

public abstract ValuePairs<Integer, ?> readCommandSuggestionPacket(PacketContainer packet);
Expand Down

0 comments on commit b13d308

Please sign in to comment.