Skip to content

Commit 0f866d8

Browse files
Fix sign update component read types in 1.7<->1.9
Closes #613
1 parent 32d2651 commit 0f866d8

File tree

4 files changed

+55
-4
lines changed

4 files changed

+55
-4
lines changed

common/src/main/java/com/viaversion/viarewind/api/type/RewindTypes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@
2828
import com.viaversion.viaversion.api.minecraft.item.Item;
2929
import com.viaversion.viaversion.api.type.Type;
3030
import com.viaversion.viaversion.api.type.Types;
31-
import com.viaversion.viaversion.api.type.types.StringType;
31+
import com.viaversion.viaversion.libs.gson.JsonElement;
3232
import java.util.List;
3333

3434
/**
3535
* Safe to use before protocol loading
3636
*/
3737
public class RewindTypes {
3838

39-
public static final Type<String> SIGN_STRING = new StringType(384);
39+
public static final Type<JsonElement> SIGN_COMPONENT = new SignComponentType();
4040
public static final Type<int[]> INT_ARRAY = new IntArrayType(); // Integer array with byte as length indicator
4141

4242
public static final Type<BlockPosition> SHORT_POSITION = new PositionVarYType<>(Types.SHORT, value -> (short) value);
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* This file is part of ViaRewind - https://github.com/ViaVersion/ViaRewind
3+
* Copyright (C) 2018-2025 ViaVersion and contributors
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 3 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
17+
*/
18+
package com.viaversion.viarewind.api.type;
19+
20+
import com.viaversion.viaversion.api.Via;
21+
import com.viaversion.viaversion.api.type.Type;
22+
import com.viaversion.viaversion.api.type.types.ComponentType;
23+
import com.viaversion.viaversion.api.type.types.StringType;
24+
import com.viaversion.viaversion.libs.gson.JsonElement;
25+
import com.viaversion.viaversion.libs.gson.JsonParser;
26+
import com.viaversion.viaversion.libs.gson.JsonSyntaxException;
27+
import io.netty.buffer.ByteBuf;
28+
29+
public class SignComponentType extends ComponentType {
30+
31+
public static final Type<String> STRING = new StringType(384);
32+
33+
@Override
34+
public JsonElement read(final ByteBuf buffer) {
35+
final String string = STRING.read(buffer);
36+
try {
37+
return JsonParser.parseString(string);
38+
} catch (final JsonSyntaxException e) {
39+
if (Via.getManager().isDebug()) {
40+
Via.getPlatform().getLogger().severe("Error when trying to parse json: " + string);
41+
}
42+
throw e;
43+
}
44+
}
45+
46+
@Override
47+
public void write(final ByteBuf buffer, final JsonElement value) {
48+
STRING.write(buffer, value.toString());
49+
}
50+
51+
}

common/src/main/java/com/viaversion/viarewind/protocol/v1_9to1_8/rewriter/PlayerPacketRewriter1_9.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ public void register() {
444444
map(Types.BLOCK_POSITION1_8); // Position
445445
handler(wrapper -> {
446446
for (int i = 0; i < 4; i++) {
447-
final JsonElement json = JsonParser.parseString(wrapper.read(RewindTypes.SIGN_STRING));
447+
final JsonElement json = wrapper.read(RewindTypes.SIGN_COMPONENT);
448448
if (!json.isJsonPrimitive()) {
449449
throw new IllegalStateException("Invalid sign text: " + StringUtil.forLogging(json));
450450
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ org.gradle.configuration-cache=true
77
project_jvm_version=17
88

99
project_group=com.viaversion
10-
project_version=4.0.9
10+
project_version=4.0.10-SNAPSHOT
1111
project_description=ViaVersion addon to allow 1.8.x and 1.7.x clients on newer server versions.
1212

1313
publishing_dev_id=FlorianMichael

0 commit comments

Comments
 (0)