Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-19 14:30:16 +01:00
Rename ComponentRewriter->TextRewriter
Now that item components with 1.20.5+ are a thing the name component rewriter became even more unclear than before, TextRewriter better reflections what the rewriter actually does.
Dieser Commit ist enthalten in:
Ursprung
23255c2a09
Commit
3d23745b89
@ -33,7 +33,7 @@ import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
|
||||
import com.viaversion.viaversion.api.protocol.packet.State;
|
||||
import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.rewriter.ComponentRewriter;
|
||||
import com.viaversion.viaversion.api.rewriter.TextRewriter;
|
||||
import com.viaversion.viaversion.api.rewriter.EntityRewriter;
|
||||
import com.viaversion.viaversion.api.rewriter.ItemRewriter;
|
||||
import com.viaversion.viaversion.api.rewriter.TagRewriter;
|
||||
@ -383,7 +383,7 @@ public interface Protocol<CU extends ClientboundPacketType, CM extends Clientbou
|
||||
return null;
|
||||
}
|
||||
|
||||
default @Nullable ComponentRewriter getComponentRewriter() {
|
||||
default @Nullable TextRewriter getTextRewriter() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ import com.viaversion.nbt.tag.Tag;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public interface ComponentRewriter {
|
||||
public interface TextRewriter {
|
||||
|
||||
void processTag(UserConnection connection, @Nullable Tag tag);
|
||||
|
@ -23,13 +23,13 @@ import com.google.gson.JsonObject;
|
||||
import com.viaversion.viaversion.api.Via;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.protocols.v1_9_1to1_9_3.packet.ClientboundPackets1_9_3;
|
||||
import com.viaversion.viaversion.rewriter.ComponentRewriter;
|
||||
import com.viaversion.viaversion.rewriter.TextRewriter;
|
||||
import com.viaversion.viaversion.util.SerializerVersion;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class TranslateRewriter {
|
||||
|
||||
private static final ComponentRewriter<ClientboundPackets1_9_3> ACHIEVEMENT_TEXT_REWRITER = new ComponentRewriter<>(null, ComponentRewriter.ReadType.JSON) {
|
||||
private static final TextRewriter<ClientboundPackets1_9_3> ACHIEVEMENT_TEXT_REWRITER = new TextRewriter<>(null, TextRewriter.ReadType.JSON) {
|
||||
@Override
|
||||
protected void handleTranslate(JsonObject object, String translate) {
|
||||
String text = AchievementTranslations1_12.get(translate);
|
||||
|
@ -54,7 +54,7 @@ import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ServerboundPacke
|
||||
import com.viaversion.viaversion.protocols.v1_12_2to1_13.provider.BlockEntityProvider;
|
||||
import com.viaversion.viaversion.protocols.v1_12_2to1_13.provider.PaintingProvider;
|
||||
import com.viaversion.viaversion.protocols.v1_12_2to1_13.provider.PlayerLookTargetProvider;
|
||||
import com.viaversion.viaversion.protocols.v1_12_2to1_13.rewriter.ComponentRewriter1_13;
|
||||
import com.viaversion.viaversion.protocols.v1_12_2to1_13.rewriter.TextRewriter1_13;
|
||||
import com.viaversion.viaversion.protocols.v1_12_2to1_13.rewriter.EntityPacketRewriter1_13;
|
||||
import com.viaversion.viaversion.protocols.v1_12_2to1_13.rewriter.ItemPacketRewriter1_13;
|
||||
import com.viaversion.viaversion.protocols.v1_12_2to1_13.rewriter.WorldPacketRewriter1_13;
|
||||
@ -85,7 +85,7 @@ public class Protocol1_12_2To1_13 extends AbstractProtocol<ClientboundPackets1_1
|
||||
private static final Set<Character> FORMATTING_CODES = Sets.newHashSet('k', 'l', 'm', 'n', 'o', 'r');
|
||||
private final EntityPacketRewriter1_13 entityRewriter = new EntityPacketRewriter1_13(this);
|
||||
private final ItemPacketRewriter1_13 itemRewriter = new ItemPacketRewriter1_13(this);
|
||||
private final ComponentRewriter1_13<ClientboundPackets1_12_1> componentRewriter = new ComponentRewriter1_13<>(this);
|
||||
private final TextRewriter1_13<ClientboundPackets1_12_1> textRewriter = new TextRewriter1_13<>(this);
|
||||
|
||||
static {
|
||||
SCOREBOARD_TEAM_NAME_REWRITE.put('0', 'g');
|
||||
@ -174,7 +174,7 @@ public class Protocol1_12_2To1_13 extends AbstractProtocol<ClientboundPackets1_1
|
||||
WorldPacketRewriter1_13.register(this);
|
||||
|
||||
registerClientbound(State.LOGIN, ClientboundLoginPackets.LOGIN_DISCONNECT.getId(), ClientboundLoginPackets.LOGIN_DISCONNECT.getId(), wrapper -> {
|
||||
componentRewriter.processText(wrapper.user(), wrapper.passthrough(Types.COMPONENT));
|
||||
textRewriter.processText(wrapper.user(), wrapper.passthrough(Types.COMPONENT));
|
||||
});
|
||||
|
||||
registerClientbound(State.STATUS, ClientboundStatusPackets.STATUS_RESPONSE.getId(), ClientboundStatusPackets.STATUS_RESPONSE.getId(), new PacketHandlers() {
|
||||
@ -245,8 +245,8 @@ public class Protocol1_12_2To1_13 extends AbstractProtocol<ClientboundPackets1_1
|
||||
});
|
||||
|
||||
|
||||
componentRewriter.registerBossEvent(ClientboundPackets1_12_1.BOSS_EVENT);
|
||||
componentRewriter.registerComponentPacket(ClientboundPackets1_12_1.CHAT);
|
||||
textRewriter.registerBossEvent(ClientboundPackets1_12_1.BOSS_EVENT);
|
||||
textRewriter.registerTextPacket(ClientboundPackets1_12_1.CHAT);
|
||||
|
||||
registerClientbound(ClientboundPackets1_12_1.COMMAND_SUGGESTIONS, wrapper -> {
|
||||
wrapper.write(Types.VAR_INT, wrapper.user().get(TabCompleteTracker.class).getTransactionId());
|
||||
@ -286,7 +286,7 @@ public class Protocol1_12_2To1_13 extends AbstractProtocol<ClientboundPackets1_1
|
||||
public void register() {
|
||||
map(Types.UNSIGNED_BYTE); // Id
|
||||
map(Types.STRING); // Window type
|
||||
handler(wrapper -> componentRewriter.processText(wrapper.user(), wrapper.passthrough(Types.COMPONENT))); // Title
|
||||
handler(wrapper -> textRewriter.processText(wrapper.user(), wrapper.passthrough(Types.COMPONENT))); // Title
|
||||
}
|
||||
});
|
||||
|
||||
@ -321,7 +321,7 @@ public class Protocol1_12_2To1_13 extends AbstractProtocol<ClientboundPackets1_1
|
||||
}
|
||||
});
|
||||
|
||||
componentRewriter.registerComponentPacket(ClientboundPackets1_12_1.DISCONNECT);
|
||||
textRewriter.registerTextPacket(ClientboundPackets1_12_1.DISCONNECT);
|
||||
|
||||
registerClientbound(ClientboundPackets1_12_1.LEVEL_EVENT, new PacketHandlers() {
|
||||
@Override
|
||||
@ -351,7 +351,7 @@ public class Protocol1_12_2To1_13 extends AbstractProtocol<ClientboundPackets1_1
|
||||
}
|
||||
});
|
||||
|
||||
componentRewriter.registerPlayerCombat(ClientboundPackets1_12_1.PLAYER_COMBAT);
|
||||
textRewriter.registerPlayerCombat(ClientboundPackets1_12_1.PLAYER_COMBAT);
|
||||
|
||||
registerClientbound(ClientboundPackets1_12_1.MAP_ITEM_DATA, new PacketHandlers() {
|
||||
@Override
|
||||
@ -494,15 +494,15 @@ public class Protocol1_12_2To1_13 extends AbstractProtocol<ClientboundPackets1_1
|
||||
wrapper.write(Types.STRING, displayName);
|
||||
});
|
||||
|
||||
componentRewriter.registerTitle(ClientboundPackets1_12_1.SET_TITLES);
|
||||
textRewriter.registerTitle(ClientboundPackets1_12_1.SET_TITLES);
|
||||
|
||||
// New 0x4C - Stop Sound
|
||||
|
||||
new SoundRewriter<>(this).registerSound(ClientboundPackets1_12_1.SOUND);
|
||||
|
||||
registerClientbound(ClientboundPackets1_12_1.TAB_LIST, wrapper -> {
|
||||
componentRewriter.processText(wrapper.user(), wrapper.passthrough(Types.COMPONENT));
|
||||
componentRewriter.processText(wrapper.user(), wrapper.passthrough(Types.COMPONENT));
|
||||
textRewriter.processText(wrapper.user(), wrapper.passthrough(Types.COMPONENT));
|
||||
textRewriter.processText(wrapper.user(), wrapper.passthrough(Types.COMPONENT));
|
||||
});
|
||||
|
||||
registerClientbound(ClientboundPackets1_12_1.UPDATE_ADVANCEMENTS, wrapper -> {
|
||||
@ -515,8 +515,8 @@ public class Protocol1_12_2To1_13 extends AbstractProtocol<ClientboundPackets1_1
|
||||
|
||||
// Display data
|
||||
if (wrapper.passthrough(Types.BOOLEAN)) {
|
||||
componentRewriter.processText(wrapper.user(), wrapper.passthrough(Types.COMPONENT)); // Title
|
||||
componentRewriter.processText(wrapper.user(), wrapper.passthrough(Types.COMPONENT)); // Description
|
||||
textRewriter.processText(wrapper.user(), wrapper.passthrough(Types.COMPONENT)); // Title
|
||||
textRewriter.processText(wrapper.user(), wrapper.passthrough(Types.COMPONENT)); // Description
|
||||
Item icon = wrapper.read(Types.ITEM1_8);
|
||||
itemRewriter.handleItemToClient(wrapper.user(), icon);
|
||||
wrapper.write(Types.ITEM1_13, icon); // Translate item to flat item
|
||||
@ -919,7 +919,8 @@ public class Protocol1_12_2To1_13 extends AbstractProtocol<ClientboundPackets1_1
|
||||
return itemRewriter;
|
||||
}
|
||||
|
||||
public ComponentRewriter1_13 getComponentRewriter() {
|
||||
return componentRewriter;
|
||||
@Override
|
||||
public TextRewriter1_13 getTextRewriter() {
|
||||
return textRewriter;
|
||||
}
|
||||
}
|
@ -41,7 +41,7 @@ public class CommandBlockHandler implements BlockEntityProvider.BlockEntityHandl
|
||||
StringTag out = tag.getStringTag("LastOutput");
|
||||
if (out != null) {
|
||||
JsonElement value = JsonParser.parseString(out.getValue());
|
||||
protocol.getComponentRewriter().processText(user, value);
|
||||
protocol.getTextRewriter().processText(user, value);
|
||||
out.setValue(value.toString());
|
||||
}
|
||||
return -1;
|
||||
|
@ -30,14 +30,14 @@ import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.protocols.v1_12_2to1_13.Protocol1_12_2To1_13;
|
||||
import com.viaversion.viaversion.rewriter.ComponentRewriter;
|
||||
import com.viaversion.viaversion.rewriter.TextRewriter;
|
||||
import com.viaversion.viaversion.util.ComponentUtil;
|
||||
import com.viaversion.viaversion.util.SerializerVersion;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class ComponentRewriter1_13<C extends ClientboundPacketType> extends ComponentRewriter<C> {
|
||||
public class TextRewriter1_13<C extends ClientboundPacketType> extends TextRewriter<C> {
|
||||
|
||||
public ComponentRewriter1_13(Protocol<C, ?, ?, ?> protocol) {
|
||||
public TextRewriter1_13(Protocol<C, ?, ?, ?> protocol) {
|
||||
super(protocol, ReadType.JSON);
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ import com.viaversion.viaversion.api.type.types.version.Types1_13_2;
|
||||
import com.viaversion.viaversion.api.type.types.version.Types1_14;
|
||||
import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ClientboundPackets1_13;
|
||||
import com.viaversion.viaversion.protocols.v1_12_2to1_13.packet.ServerboundPackets1_13;
|
||||
import com.viaversion.viaversion.protocols.v1_13_2to1_14.rewriter.ComponentRewriter1_14;
|
||||
import com.viaversion.viaversion.protocols.v1_13_2to1_14.rewriter.TextRewriter1_14;
|
||||
import com.viaversion.viaversion.protocols.v1_13_2to1_14.data.MappingData1_14;
|
||||
import com.viaversion.viaversion.protocols.v1_13_2to1_14.packet.ClientboundPackets1_14;
|
||||
import com.viaversion.viaversion.protocols.v1_13_2to1_14.packet.ServerboundPackets1_14;
|
||||
@ -38,7 +38,7 @@ import com.viaversion.viaversion.protocols.v1_13_2to1_14.rewriter.PlayerPacketRe
|
||||
import com.viaversion.viaversion.protocols.v1_13_2to1_14.rewriter.WorldPacketRewriter1_14;
|
||||
import com.viaversion.viaversion.protocols.v1_13_2to1_14.storage.EntityTracker1_14;
|
||||
import com.viaversion.viaversion.rewriter.CommandRewriter;
|
||||
import com.viaversion.viaversion.rewriter.ComponentRewriter;
|
||||
import com.viaversion.viaversion.rewriter.TextRewriter;
|
||||
import com.viaversion.viaversion.rewriter.SoundRewriter;
|
||||
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
|
||||
import com.viaversion.viaversion.rewriter.TagRewriter;
|
||||
@ -65,8 +65,8 @@ public class Protocol1_13_2To1_14 extends AbstractProtocol<ClientboundPackets1_1
|
||||
new SoundRewriter<>(this).registerSound(ClientboundPackets1_13.SOUND);
|
||||
new StatisticsRewriter<>(this).register(ClientboundPackets1_13.AWARD_STATS);
|
||||
|
||||
ComponentRewriter<ClientboundPackets1_13> componentRewriter = new ComponentRewriter1_14<>(this);
|
||||
componentRewriter.registerComponentPacket(ClientboundPackets1_13.CHAT);
|
||||
TextRewriter<ClientboundPackets1_13> textRewriter = new TextRewriter1_14<>(this);
|
||||
textRewriter.registerTextPacket(ClientboundPackets1_13.CHAT);
|
||||
|
||||
CommandRewriter<ClientboundPackets1_13> commandRewriter = new CommandRewriter<>(this) {
|
||||
@Override
|
||||
|
@ -37,7 +37,7 @@ import com.viaversion.viaversion.protocols.v1_13_2to1_14.Protocol1_13_2To1_14;
|
||||
import com.viaversion.viaversion.protocols.v1_13_2to1_14.packet.ClientboundPackets1_14;
|
||||
import com.viaversion.viaversion.protocols.v1_13_2to1_14.packet.ServerboundPackets1_14;
|
||||
import com.viaversion.viaversion.protocols.v1_13_2to1_14.storage.EntityTracker1_14;
|
||||
import com.viaversion.viaversion.rewriter.ComponentRewriter;
|
||||
import com.viaversion.viaversion.rewriter.TextRewriter;
|
||||
import com.viaversion.viaversion.rewriter.ItemRewriter;
|
||||
import com.viaversion.viaversion.rewriter.RecipeRewriter;
|
||||
import com.viaversion.viaversion.util.ComponentUtil;
|
||||
@ -47,7 +47,7 @@ import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class ItemPacketRewriter1_14 extends ItemRewriter<ClientboundPackets1_13, ServerboundPackets1_14, Protocol1_13_2To1_14> {
|
||||
private static final Set<String> REMOVED_RECIPE_TYPES = Sets.newHashSet("crafting_special_banneraddpattern", "crafting_special_repairitem");
|
||||
private static final ComponentRewriter<ClientboundPackets1_13> COMPONENT_REWRITER = new ComponentRewriter<>(null, ComponentRewriter.ReadType.JSON) {
|
||||
private static final TextRewriter<ClientboundPackets1_13> TEXT_REWRITER = new TextRewriter<>(null, TextRewriter.ReadType.JSON) {
|
||||
@Override
|
||||
protected void handleTranslate(JsonObject object, String translate) {
|
||||
super.handleTranslate(object, translate);
|
||||
@ -71,7 +71,7 @@ public class ItemPacketRewriter1_14 extends ItemRewriter<ClientboundPackets1_13,
|
||||
Short windowId = wrapper.read(Types.UNSIGNED_BYTE);
|
||||
String type = wrapper.read(Types.STRING);
|
||||
JsonElement title = wrapper.read(Types.COMPONENT);
|
||||
COMPONENT_REWRITER.processText(wrapper.user(), title);
|
||||
TEXT_REWRITER.processText(wrapper.user(), title);
|
||||
Short slots = wrapper.read(Types.UNSIGNED_BYTE);
|
||||
|
||||
if (type.equals("EntityHorse")) {
|
||||
|
@ -20,11 +20,11 @@ package com.viaversion.viaversion.protocols.v1_13_2to1_14.rewriter;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.protocols.v1_12_2to1_13.rewriter.ComponentRewriter1_13;
|
||||
import com.viaversion.viaversion.protocols.v1_12_2to1_13.rewriter.TextRewriter1_13;
|
||||
|
||||
public class ComponentRewriter1_14<C extends ClientboundPacketType> extends ComponentRewriter1_13<C> {
|
||||
public class TextRewriter1_14<C extends ClientboundPacketType> extends TextRewriter1_13<C> {
|
||||
|
||||
public ComponentRewriter1_14(Protocol<C, ?, ?, ?> protocol) {
|
||||
public TextRewriter1_14(Protocol<C, ?, ?, ?> protocol) {
|
||||
super(protocol);
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ import com.viaversion.viaversion.protocols.v1_14_4to1_15.packet.ClientboundPacke
|
||||
import com.viaversion.viaversion.protocols.v1_15_2to1_16.packet.ClientboundPackets1_16;
|
||||
import com.viaversion.viaversion.protocols.v1_15_2to1_16.packet.ServerboundPackets1_16;
|
||||
import com.viaversion.viaversion.protocols.v1_15_2to1_16.provider.PlayerAbilitiesProvider;
|
||||
import com.viaversion.viaversion.protocols.v1_15_2to1_16.rewriter.ComponentRewriter1_16;
|
||||
import com.viaversion.viaversion.protocols.v1_15_2to1_16.rewriter.TextRewriter1_16;
|
||||
import com.viaversion.viaversion.protocols.v1_15_2to1_16.rewriter.EntityPacketRewriter1_16;
|
||||
import com.viaversion.viaversion.protocols.v1_15_2to1_16.rewriter.ItemPacketRewriter1_16;
|
||||
import com.viaversion.viaversion.protocols.v1_15_2to1_16.rewriter.WorldPacketRewriter1_16;
|
||||
@ -63,7 +63,7 @@ public class Protocol1_15_2To1_16 extends AbstractProtocol<ClientboundPackets1_1
|
||||
public static final MappingData MAPPINGS = new MappingDataBase("1.15", "1.16");
|
||||
private final EntityPacketRewriter1_16 entityRewriter = new EntityPacketRewriter1_16(this);
|
||||
private final ItemPacketRewriter1_16 itemRewriter = new ItemPacketRewriter1_16(this);
|
||||
private final ComponentRewriter1_16 componentRewriter = new ComponentRewriter1_16(this);
|
||||
private final TextRewriter1_16 textRewriter = new TextRewriter1_16(this);
|
||||
private final TagRewriter<ClientboundPackets1_15> tagRewriter = new TagRewriter<>(this);
|
||||
|
||||
public Protocol1_15_2To1_16() {
|
||||
@ -129,14 +129,14 @@ public class Protocol1_15_2To1_16 extends AbstractProtocol<ClientboundPackets1_1
|
||||
map(Types.COMPONENT);
|
||||
map(Types.BYTE);
|
||||
handler(wrapper -> {
|
||||
componentRewriter.processText(wrapper.user(), wrapper.get(Types.COMPONENT, 0));
|
||||
textRewriter.processText(wrapper.user(), wrapper.get(Types.COMPONENT, 0));
|
||||
wrapper.write(Types.UUID, ZERO_UUID); // Sender uuid - always send as 'system'
|
||||
});
|
||||
}
|
||||
});
|
||||
componentRewriter.registerBossEvent(ClientboundPackets1_15.BOSS_EVENT);
|
||||
componentRewriter.registerTitle(ClientboundPackets1_15.SET_TITLES);
|
||||
componentRewriter.registerPlayerCombat(ClientboundPackets1_15.PLAYER_COMBAT);
|
||||
textRewriter.registerBossEvent(ClientboundPackets1_15.BOSS_EVENT);
|
||||
textRewriter.registerTitle(ClientboundPackets1_15.SET_TITLES);
|
||||
textRewriter.registerPlayerCombat(ClientboundPackets1_15.PLAYER_COMBAT);
|
||||
|
||||
SoundRewriter<ClientboundPackets1_15> soundRewriter = new SoundRewriter<>(this);
|
||||
soundRewriter.registerSound(ClientboundPackets1_15.SOUND);
|
||||
@ -255,8 +255,9 @@ public class Protocol1_15_2To1_16 extends AbstractProtocol<ClientboundPackets1_1
|
||||
return itemRewriter;
|
||||
}
|
||||
|
||||
public ComponentRewriter1_16 getComponentRewriter() {
|
||||
return componentRewriter;
|
||||
@Override
|
||||
public TextRewriter1_16 getTextRewriter() {
|
||||
return textRewriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -159,7 +159,7 @@ public class ItemPacketRewriter1_16 extends ItemRewriter<ClientboundPackets1_15,
|
||||
ListTag<StringTag> pages = tag.getListTag("pages", StringTag.class);
|
||||
if (pages != null) {
|
||||
for (StringTag pageTag : pages) {
|
||||
pageTag.setValue(protocol.getComponentRewriter().processText(connection, pageTag.getValue()).toString());
|
||||
pageTag.setValue(protocol.getTextRewriter().processText(connection, pageTag.getValue()).toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -23,14 +23,14 @@ import com.google.gson.JsonPrimitive;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.protocols.v1_14_4to1_15.packet.ClientboundPackets1_15;
|
||||
import com.viaversion.viaversion.protocols.v1_15_2to1_16.Protocol1_15_2To1_16;
|
||||
import com.viaversion.viaversion.rewriter.ComponentRewriter;
|
||||
import com.viaversion.viaversion.rewriter.TextRewriter;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ComponentRewriter1_16 extends ComponentRewriter<ClientboundPackets1_15> {
|
||||
public class TextRewriter1_16 extends TextRewriter<ClientboundPackets1_15> {
|
||||
private final Map<String, String> mappings = new HashMap<>();
|
||||
|
||||
public ComponentRewriter1_16(Protocol1_15_2To1_16 protocol) {
|
||||
public TextRewriter1_16(Protocol1_15_2To1_16 protocol) {
|
||||
super(protocol, ReadType.JSON);
|
||||
mappings.put("attribute.name.generic.armorToughness", "attribute.name.generic.armor_toughness");
|
||||
mappings.put("attribute.name.generic.attackDamage", "attribute.name.generic.attack_damage");
|
@ -112,7 +112,7 @@ public class WorldPacketRewriter1_16 {
|
||||
for (int i = 1; i <= 4; i++) {
|
||||
StringTag line = compoundTag.getStringTag("Text" + i);
|
||||
if (line != null) {
|
||||
JsonElement text = protocol.getComponentRewriter().processText(connection, line.getValue());
|
||||
JsonElement text = protocol.getTextRewriter().processText(connection, line.getValue());
|
||||
compoundTag.putString("Text" + i, text.toString());
|
||||
}
|
||||
}
|
||||
|
@ -47,11 +47,11 @@ import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundCon
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPacket1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.rewriter.BlockItemPacketRewriter1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.rewriter.ComponentRewriter1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.rewriter.TextRewriter1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.rewriter.EntityPacketRewriter1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.storage.AcknowledgedMessagesStorage;
|
||||
import com.viaversion.viaversion.protocols.v1_20to1_20_2.packet.ServerboundConfigurationPackets1_20_2;
|
||||
import com.viaversion.viaversion.rewriter.ComponentRewriter;
|
||||
import com.viaversion.viaversion.rewriter.TextRewriter;
|
||||
import com.viaversion.viaversion.rewriter.SoundRewriter;
|
||||
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
|
||||
import com.viaversion.viaversion.rewriter.TagRewriter;
|
||||
@ -70,7 +70,7 @@ public final class Protocol1_20_3To1_20_5 extends AbstractProtocol<ClientboundPa
|
||||
private final EntityPacketRewriter1_20_5 entityRewriter = new EntityPacketRewriter1_20_5(this);
|
||||
private final BlockItemPacketRewriter1_20_5 itemRewriter = new BlockItemPacketRewriter1_20_5(this);
|
||||
private final TagRewriter<ClientboundPacket1_20_3> tagRewriter = new TagRewriter<>(this);
|
||||
private final ComponentRewriter1_20_5<ClientboundPacket1_20_3> componentRewriter = new ComponentRewriter1_20_5<>(this, Types1_20_5.STRUCTURED_DATA);
|
||||
private final TextRewriter1_20_5<ClientboundPacket1_20_3> textRewriter = new TextRewriter1_20_5<>(this, Types1_20_5.STRUCTURED_DATA);
|
||||
|
||||
public Protocol1_20_3To1_20_5() {
|
||||
super(ClientboundPacket1_20_3.class, ClientboundPacket1_20_5.class, ServerboundPacket1_20_3.class, ServerboundPacket1_20_5.class);
|
||||
@ -89,9 +89,9 @@ public final class Protocol1_20_3To1_20_5 extends AbstractProtocol<ClientboundPa
|
||||
|
||||
new StatisticsRewriter<>(this).register(ClientboundPackets1_20_3.AWARD_STATS);
|
||||
|
||||
componentRewriter.registerComponentPacket(ClientboundPackets1_20_3.SYSTEM_CHAT);
|
||||
componentRewriter.registerComponentPacket(ClientboundPackets1_20_3.DISGUISED_CHAT);
|
||||
componentRewriter.registerPlayerCombatKill1_20(ClientboundPackets1_20_3.PLAYER_COMBAT_KILL);
|
||||
textRewriter.registerTextPacket(ClientboundPackets1_20_3.SYSTEM_CHAT);
|
||||
textRewriter.registerTextPacket(ClientboundPackets1_20_3.DISGUISED_CHAT);
|
||||
textRewriter.registerPlayerCombatKill1_20(ClientboundPackets1_20_3.PLAYER_COMBAT_KILL);
|
||||
|
||||
registerClientbound(State.LOGIN, ClientboundLoginPackets.HELLO, wrapper -> {
|
||||
wrapper.passthrough(Types.STRING); // Server ID
|
||||
@ -317,8 +317,9 @@ public final class Protocol1_20_3To1_20_5 extends AbstractProtocol<ClientboundPa
|
||||
return tagRewriter;
|
||||
}
|
||||
|
||||
public ComponentRewriter<ClientboundPacket1_20_3> getComponentRewriter() {
|
||||
return componentRewriter;
|
||||
@Override
|
||||
public TextRewriter<ClientboundPacket1_20_3> getTextRewriter() {
|
||||
return textRewriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1194,7 +1194,7 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
|
||||
private Tag jsonToTag(final UserConnection connection, final StringTag stringTag) {
|
||||
// Use the same version for deserializing and serializing, as the only write changes are in hovers, which we handle ourselves
|
||||
final Tag tag = ComponentUtil.jsonStringToTag(stringTag.getValue(), SerializerVersion.V1_20_3, SerializerVersion.V1_20_3);
|
||||
protocol.getComponentRewriter().processTag(connection, tag);
|
||||
protocol.getTextRewriter().processTag(connection, tag);
|
||||
return tag;
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,7 @@ import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.data.PotionEffects1_2
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.data.Potions1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.data.TrimMaterials1_20_3;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.data.TrimPatterns1_20_3;
|
||||
import com.viaversion.viaversion.rewriter.ComponentRewriter;
|
||||
import com.viaversion.viaversion.rewriter.TextRewriter;
|
||||
import com.viaversion.viaversion.util.ComponentUtil;
|
||||
import com.viaversion.viaversion.util.Either;
|
||||
import com.viaversion.viaversion.util.Key;
|
||||
@ -101,7 +101,7 @@ import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class ComponentRewriter1_20_5<C extends ClientboundPacketType> extends ComponentRewriter<C> {
|
||||
public class TextRewriter1_20_5<C extends ClientboundPacketType> extends TextRewriter<C> {
|
||||
|
||||
private final Map<StructuredDataKey<?>, ConverterPair<?>> converters = new Reference2ObjectOpenHashMap<>();
|
||||
private final StructuredDataType structuredDataType;
|
||||
@ -110,7 +110,7 @@ public class ComponentRewriter1_20_5<C extends ClientboundPacketType> extends Co
|
||||
* @param protocol protocol
|
||||
* @param structuredDataType unmapped structured data type
|
||||
*/
|
||||
public ComponentRewriter1_20_5(final Protocol<C, ?, ?, ?> protocol, final StructuredDataType structuredDataType) {
|
||||
public TextRewriter1_20_5(final Protocol<C, ?, ?, ?> protocol, final StructuredDataType structuredDataType) {
|
||||
super(protocol, ReadType.NBT);
|
||||
this.structuredDataType = structuredDataType;
|
||||
|
@ -42,10 +42,10 @@ import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfi
|
||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPacket1_21;
|
||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21;
|
||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.rewriter.BlockItemPacketRewriter1_21;
|
||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.rewriter.ComponentRewriter1_21;
|
||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.rewriter.TextRewriter1_21;
|
||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.rewriter.EntityPacketRewriter1_21;
|
||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.storage.EfficiencyAttributeStorage;
|
||||
import com.viaversion.viaversion.rewriter.ComponentRewriter;
|
||||
import com.viaversion.viaversion.rewriter.TextRewriter;
|
||||
import com.viaversion.viaversion.rewriter.SoundRewriter;
|
||||
import com.viaversion.viaversion.rewriter.StatisticsRewriter;
|
||||
import com.viaversion.viaversion.rewriter.TagRewriter;
|
||||
@ -62,7 +62,7 @@ public final class Protocol1_20_5To1_21 extends AbstractProtocol<ClientboundPack
|
||||
private final EntityPacketRewriter1_21 entityRewriter = new EntityPacketRewriter1_21(this);
|
||||
private final BlockItemPacketRewriter1_21 itemRewriter = new BlockItemPacketRewriter1_21(this);
|
||||
private final TagRewriter<ClientboundPacket1_20_5> tagRewriter = new TagRewriter<>(this);
|
||||
private final ComponentRewriter<ClientboundPacket1_20_5> componentRewriter = new ComponentRewriter1_21(this);
|
||||
private final TextRewriter<ClientboundPacket1_20_5> textRewriter = new TextRewriter1_21(this);
|
||||
|
||||
public Protocol1_20_5To1_21() {
|
||||
super(ClientboundPacket1_20_5.class, ClientboundPacket1_21.class, ServerboundPacket1_20_5.class, ServerboundPacket1_20_5.class);
|
||||
@ -81,18 +81,18 @@ public final class Protocol1_20_5To1_21 extends AbstractProtocol<ClientboundPack
|
||||
|
||||
new StatisticsRewriter<>(this).register(ClientboundPackets1_20_5.AWARD_STATS);
|
||||
|
||||
componentRewriter.registerOpenScreen(ClientboundPackets1_20_5.OPEN_SCREEN);
|
||||
componentRewriter.registerComponentPacket(ClientboundPackets1_20_5.SET_ACTION_BAR_TEXT);
|
||||
componentRewriter.registerComponentPacket(ClientboundPackets1_20_5.SET_TITLE_TEXT);
|
||||
componentRewriter.registerComponentPacket(ClientboundPackets1_20_5.SET_SUBTITLE_TEXT);
|
||||
componentRewriter.registerBossEvent(ClientboundPackets1_20_5.BOSS_EVENT);
|
||||
componentRewriter.registerComponentPacket(ClientboundPackets1_20_5.DISCONNECT);
|
||||
componentRewriter.registerTabList(ClientboundPackets1_20_5.TAB_LIST);
|
||||
componentRewriter.registerPlayerCombatKill1_20(ClientboundPackets1_20_5.PLAYER_COMBAT_KILL);
|
||||
componentRewriter.registerComponentPacket(ClientboundPackets1_20_5.SYSTEM_CHAT);
|
||||
textRewriter.registerOpenScreen(ClientboundPackets1_20_5.OPEN_SCREEN);
|
||||
textRewriter.registerTextPacket(ClientboundPackets1_20_5.SET_ACTION_BAR_TEXT);
|
||||
textRewriter.registerTextPacket(ClientboundPackets1_20_5.SET_TITLE_TEXT);
|
||||
textRewriter.registerTextPacket(ClientboundPackets1_20_5.SET_SUBTITLE_TEXT);
|
||||
textRewriter.registerBossEvent(ClientboundPackets1_20_5.BOSS_EVENT);
|
||||
textRewriter.registerTextPacket(ClientboundPackets1_20_5.DISCONNECT);
|
||||
textRewriter.registerTabList(ClientboundPackets1_20_5.TAB_LIST);
|
||||
textRewriter.registerPlayerCombatKill1_20(ClientboundPackets1_20_5.PLAYER_COMBAT_KILL);
|
||||
textRewriter.registerTextPacket(ClientboundPackets1_20_5.SYSTEM_CHAT);
|
||||
|
||||
registerClientbound(ClientboundPackets1_20_5.DISGUISED_CHAT, wrapper -> {
|
||||
componentRewriter.processTag(wrapper.user(), wrapper.passthrough(Types.TAG)); // Message
|
||||
textRewriter.processTag(wrapper.user(), wrapper.passthrough(Types.TAG)); // Message
|
||||
|
||||
// Holder time
|
||||
final int chatType = wrapper.read(Types.VAR_INT);
|
||||
@ -114,7 +114,7 @@ public final class Protocol1_20_5To1_21 extends AbstractProtocol<ClientboundPack
|
||||
}
|
||||
}
|
||||
|
||||
componentRewriter.processTag(wrapper.user(), wrapper.passthrough(Types.OPTIONAL_TAG)); // Unsigned content
|
||||
textRewriter.processTag(wrapper.user(), wrapper.passthrough(Types.OPTIONAL_TAG)); // Unsigned content
|
||||
|
||||
final int filterMaskType = wrapper.passthrough(Types.VAR_INT);
|
||||
if (filterMaskType == 2) {
|
||||
@ -245,8 +245,8 @@ public final class Protocol1_20_5To1_21 extends AbstractProtocol<ClientboundPack
|
||||
}
|
||||
|
||||
@Override
|
||||
public ComponentRewriter<ClientboundPacket1_20_5> getComponentRewriter() {
|
||||
return componentRewriter;
|
||||
public TextRewriter<ClientboundPacket1_20_5> getTextRewriter() {
|
||||
return textRewriter;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -22,15 +22,15 @@ import com.viaversion.nbt.tag.ListTag;
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPacket1_20_5;
|
||||
import com.viaversion.viaversion.protocols.v1_20_5to1_21.Protocol1_20_5To1_21;
|
||||
import com.viaversion.viaversion.rewriter.ComponentRewriter;
|
||||
import com.viaversion.viaversion.rewriter.TextRewriter;
|
||||
import com.viaversion.viaversion.util.SerializerVersion;
|
||||
import com.viaversion.viaversion.util.TagUtil;
|
||||
import com.viaversion.viaversion.util.UUIDUtil;
|
||||
import java.util.UUID;
|
||||
|
||||
public final class ComponentRewriter1_21 extends ComponentRewriter<ClientboundPacket1_20_5> {
|
||||
public final class TextRewriter1_21 extends TextRewriter<ClientboundPacket1_20_5> {
|
||||
|
||||
public ComponentRewriter1_21(final Protocol1_20_5To1_21 protocol) {
|
||||
public TextRewriter1_21(final Protocol1_20_5To1_21 protocol) {
|
||||
super(protocol, ReadType.NBT);
|
||||
}
|
||||
|
@ -231,7 +231,7 @@ public abstract class EntityRewriter<C extends ClientboundPacketType, T extends
|
||||
}
|
||||
} else if (type == componentType || type == optionalComponentType) {
|
||||
final Tag component = data.value();
|
||||
protocol.getComponentRewriter().processTag(event.user(), component);
|
||||
protocol.getTextRewriter().processTag(event.user(), component);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandler;
|
||||
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
|
||||
import com.viaversion.viaversion.api.rewriter.ComponentRewriter;
|
||||
import com.viaversion.viaversion.api.rewriter.TextRewriter;
|
||||
import com.viaversion.viaversion.api.rewriter.RewriterBase;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.api.type.Types;
|
||||
@ -397,10 +397,10 @@ public class ItemRewriter<C extends ClientboundPacketType, S extends Serverbound
|
||||
if (wrapper.passthrough(Types.BOOLEAN)) {
|
||||
final Tag title = wrapper.passthrough(Types.TAG);
|
||||
final Tag description = wrapper.passthrough(Types.TAG);
|
||||
final ComponentRewriter componentRewriter = protocol.getComponentRewriter();
|
||||
if (componentRewriter != null) {
|
||||
componentRewriter.processTag(wrapper.user(), title);
|
||||
componentRewriter.processTag(wrapper.user(), description);
|
||||
final TextRewriter textRewriter = protocol.getTextRewriter();
|
||||
if (textRewriter != null) {
|
||||
textRewriter.processTag(wrapper.user(), title);
|
||||
textRewriter.processTag(wrapper.user(), description);
|
||||
}
|
||||
|
||||
handleClientboundItem(wrapper); // Icon
|
||||
|
@ -29,7 +29,7 @@ import com.viaversion.viaversion.api.minecraft.item.Item;
|
||||
import com.viaversion.viaversion.api.protocol.Protocol;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType;
|
||||
import com.viaversion.viaversion.api.protocol.packet.ServerboundPacketType;
|
||||
import com.viaversion.viaversion.api.rewriter.ComponentRewriter;
|
||||
import com.viaversion.viaversion.api.rewriter.TextRewriter;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import it.unimi.dsi.fastutil.ints.Int2IntFunction;
|
||||
import java.util.Map;
|
||||
@ -66,8 +66,8 @@ public class StructuredItemRewriter<C extends ClientboundPacketType, S extends S
|
||||
}
|
||||
}
|
||||
|
||||
final ComponentRewriter componentRewriter = protocol.getComponentRewriter();
|
||||
if (componentRewriter != null) {
|
||||
final TextRewriter textRewriter = protocol.getTextRewriter();
|
||||
if (textRewriter != null) {
|
||||
// Handle name and lore components
|
||||
updateComponent(connection, item, StructuredDataKey.ITEM_NAME, "item_name");
|
||||
updateComponent(connection, item, StructuredDataKey.CUSTOM_NAME, "custom_name");
|
||||
@ -75,7 +75,7 @@ public class StructuredItemRewriter<C extends ClientboundPacketType, S extends S
|
||||
final StructuredData<Tag[]> loreData = dataContainer.getNonEmpty(StructuredDataKey.LORE);
|
||||
if (loreData != null) {
|
||||
for (final Tag tag : loreData.value()) {
|
||||
componentRewriter.processTag(connection, tag);
|
||||
textRewriter.processTag(connection, tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -165,7 +165,7 @@ public class StructuredItemRewriter<C extends ClientboundPacketType, S extends S
|
||||
}
|
||||
|
||||
final Tag originalName = name.value().copy();
|
||||
protocol.getComponentRewriter().processTag(connection, name.value());
|
||||
protocol.getTextRewriter().processTag(connection, name.value());
|
||||
if (!name.value().equals(originalName)) {
|
||||
saveTag(createCustomTag(item), originalName, backupKey);
|
||||
}
|
||||
|
@ -41,25 +41,25 @@ import com.viaversion.viaversion.util.SerializerVersion;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
/**
|
||||
* Handles json and tag components, containing methods to override certain parts of the handling.
|
||||
* Also contains methods to register a few of the packets using components.
|
||||
* Handles json and tag text components, containing methods to override certain parts of the handling.
|
||||
* Also contains methods to register a few of the packets using text components.
|
||||
*/
|
||||
public class ComponentRewriter<C extends ClientboundPacketType> implements com.viaversion.viaversion.api.rewriter.ComponentRewriter {
|
||||
public class TextRewriter<C extends ClientboundPacketType> implements com.viaversion.viaversion.api.rewriter.TextRewriter {
|
||||
protected final Protocol<C, ?, ?, ?> protocol;
|
||||
protected final ReadType type;
|
||||
|
||||
public ComponentRewriter(final Protocol<C, ?, ?, ?> protocol, final ReadType type) {
|
||||
public TextRewriter(final Protocol<C, ?, ?, ?> protocol, final ReadType type) {
|
||||
this.protocol = protocol;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes components at the beginning of the packet.
|
||||
* Processes text components at the beginning of the packet.
|
||||
* Used for packets that have components as their very first value, so no special pre-reading is necessary.
|
||||
*
|
||||
* @param packetType clientbound packet type
|
||||
*/
|
||||
public void registerComponentPacket(final C packetType) {
|
||||
public void registerTextPacket(final C packetType) {
|
||||
protocol.registerClientbound(packetType, this::passthroughAndProcess);
|
||||
}
|
||||
|
||||
@ -80,7 +80,7 @@ public class ComponentRewriter<C extends ClientboundPacketType> implements com.v
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles sub 1.17 combat event components.
|
||||
* Handles sub 1.17 combat event text components.
|
||||
*/
|
||||
public void registerPlayerCombat(final C packetType) {
|
||||
protocol.registerClientbound(packetType, wrapper -> {
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren