Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-08 17:20:24 +01:00
Ursprung
91f3d0fdb7
Commit
95e0cff03c
@ -2,7 +2,6 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2;
|
|||||||
|
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import net.md_5.bungee.api.ChatColor;
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import net.md_5.bungee.api.chat.BaseComponent;
|
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import net.md_5.bungee.chat.ComponentSerializer;
|
import net.md_5.bungee.chat.ComponentSerializer;
|
||||||
import us.myles.ViaVersion.api.rewriters.ComponentRewriter;
|
import us.myles.ViaVersion.api.rewriters.ComponentRewriter;
|
||||||
@ -10,15 +9,14 @@ import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.ComponentRewriter
|
|||||||
import us.myles.ViaVersion.util.GsonUtil;
|
import us.myles.ViaVersion.util.GsonUtil;
|
||||||
|
|
||||||
public class ChatRewriter {
|
public class ChatRewriter {
|
||||||
private static final BaseComponent[] EMPTY_COMPONENTS = new BaseComponent[0];
|
|
||||||
private static final ComponentRewriter COMPONENT_REWRITER = new ComponentRewriter1_13();
|
private static final ComponentRewriter COMPONENT_REWRITER = new ComponentRewriter1_13();
|
||||||
|
|
||||||
// Based on https://github.com/SpigotMC/BungeeCord/blob/master/chat/src/main/java/net/md_5/bungee/api/chat/TextComponent.java
|
// Based on https://github.com/SpigotMC/BungeeCord/blob/master/chat/src/main/java/net/md_5/bungee/api/chat/TextComponent.java
|
||||||
public static String fromLegacyTextAsString(String message, ChatColor defaultColor, boolean lore) {
|
public static String fromLegacyTextAsString(String message, ChatColor defaultColor, boolean itemData) {
|
||||||
TextComponent headComponent = new TextComponent();
|
TextComponent headComponent = new TextComponent();
|
||||||
TextComponent component = new TextComponent();
|
TextComponent component = new TextComponent();
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
if (lore) {
|
if (itemData) {
|
||||||
// Workaround for all italic lore
|
// Workaround for all italic lore
|
||||||
headComponent.setItalic(false);
|
headComponent.setItalic(false);
|
||||||
//TODO set first child to italics if it doesn't have a color
|
//TODO set first child to italics if it doesn't have a color
|
||||||
|
@ -9,6 +9,7 @@ import com.github.steveice10.opennbt.tag.builtin.StringTag;
|
|||||||
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
import com.github.steveice10.opennbt.tag.builtin.Tag;
|
||||||
import com.google.common.base.Joiner;
|
import com.google.common.base.Joiner;
|
||||||
import com.google.common.primitives.Ints;
|
import com.google.common.primitives.Ints;
|
||||||
|
import net.md_5.bungee.api.ChatColor;
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
import us.myles.ViaVersion.api.PacketWrapper;
|
||||||
import us.myles.ViaVersion.api.Via;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.minecraft.item.Item;
|
import us.myles.ViaVersion.api.minecraft.item.Item;
|
||||||
@ -303,7 +304,7 @@ public class InventoryPackets {
|
|||||||
if (display.get("Name") instanceof StringTag) {
|
if (display.get("Name") instanceof StringTag) {
|
||||||
StringTag name = display.get("Name");
|
StringTag name = display.get("Name");
|
||||||
display.put(new StringTag(NBT_TAG_NAME + "|Name", name.getValue()));
|
display.put(new StringTag(NBT_TAG_NAME + "|Name", name.getValue()));
|
||||||
name.setValue(ChatRewriter.legacyTextToJsonString(name.getValue()));
|
name.setValue(ChatRewriter.fromLegacyTextAsString(name.getValue(), ChatColor.WHITE, true));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// ench is now Enchantments and now uses identifiers
|
// ench is now Enchantments and now uses identifiers
|
||||||
@ -521,16 +522,18 @@ public class InventoryPackets {
|
|||||||
if (tag != null) {
|
if (tag != null) {
|
||||||
if (isDamageable(item.getIdentifier())) {
|
if (isDamageable(item.getIdentifier())) {
|
||||||
if (tag.get("Damage") instanceof IntTag) {
|
if (tag.get("Damage") instanceof IntTag) {
|
||||||
if (!gotRawIdFromTag)
|
if (!gotRawIdFromTag) {
|
||||||
item.setData((short) (int) tag.get("Damage").getValue());
|
item.setData((short) (int) tag.get("Damage").getValue());
|
||||||
|
}
|
||||||
tag.remove("Damage");
|
tag.remove("Damage");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (item.getIdentifier() == 358) { // map
|
if (item.getIdentifier() == 358) { // map
|
||||||
if (tag.get("map") instanceof IntTag) {
|
if (tag.get("map") instanceof IntTag) {
|
||||||
if (!gotRawIdFromTag)
|
if (!gotRawIdFromTag) {
|
||||||
item.setData((short) (int) tag.get("map").getValue());
|
item.setData((short) (int) tag.get("map").getValue());
|
||||||
|
}
|
||||||
tag.remove("map");
|
tag.remove("map");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -555,15 +558,10 @@ public class InventoryPackets {
|
|||||||
// Display Name now uses JSON
|
// Display Name now uses JSON
|
||||||
if (tag.get("display") instanceof CompoundTag) {
|
if (tag.get("display") instanceof CompoundTag) {
|
||||||
CompoundTag display = tag.get("display");
|
CompoundTag display = tag.get("display");
|
||||||
if (((CompoundTag) tag.get("display")).get("Name") instanceof StringTag) {
|
if (display.get("Name") instanceof StringTag) {
|
||||||
StringTag name = display.get("Name");
|
StringTag name = display.get("Name");
|
||||||
StringTag via = display.get(NBT_TAG_NAME + "|Name");
|
StringTag via = display.remove(NBT_TAG_NAME + "|Name");
|
||||||
name.setValue(
|
name.setValue(via != null ? via.getValue() : ChatRewriter.jsonTextToLegacy(name.getValue()));
|
||||||
via != null ? via.getValue() : ChatRewriter.jsonTextToLegacy(
|
|
||||||
name.getValue()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
display.remove(NBT_TAG_NAME + "|Name");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -580,12 +578,7 @@ public class InventoryPackets {
|
|||||||
oldId = Short.valueOf(newId.substring(18));
|
oldId = Short.valueOf(newId.substring(18));
|
||||||
}
|
}
|
||||||
if (oldId != null) {
|
if (oldId != null) {
|
||||||
enchEntry.put(
|
enchEntry.put(new ShortTag("id", oldId));
|
||||||
new ShortTag(
|
|
||||||
"id",
|
|
||||||
oldId
|
|
||||||
)
|
|
||||||
);
|
|
||||||
enchEntry.put(new ShortTag("lvl", (Short) ((CompoundTag) enchantmentEntry).get("lvl").getValue()));
|
enchEntry.put(new ShortTag("lvl", (Short) ((CompoundTag) enchantmentEntry).get("lvl").getValue()));
|
||||||
ench.add(enchEntry);
|
ench.add(enchEntry);
|
||||||
}
|
}
|
||||||
@ -606,12 +599,7 @@ public class InventoryPackets {
|
|||||||
oldId = Short.valueOf(newId.substring(18));
|
oldId = Short.valueOf(newId.substring(18));
|
||||||
}
|
}
|
||||||
if (oldId != null) {
|
if (oldId != null) {
|
||||||
enchEntry.put(
|
enchEntry.put(new ShortTag("id", oldId));
|
||||||
new ShortTag(
|
|
||||||
"id",
|
|
||||||
oldId
|
|
||||||
)
|
|
||||||
);
|
|
||||||
enchEntry.put(new ShortTag("lvl", (Short) ((CompoundTag) enchantmentEntry).get("lvl").getValue()));
|
enchEntry.put(new ShortTag("lvl", (Short) ((CompoundTag) enchantmentEntry).get("lvl").getValue()));
|
||||||
newStoredEnch.add(enchEntry);
|
newStoredEnch.add(enchEntry);
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren