Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-12-29 01:20:15 +01:00
Share JsonParser instance
Dieser Commit ist enthalten in:
Ursprung
3a5a47aaa2
Commit
da2f153a43
@ -24,6 +24,7 @@ import us.myles.ViaVersion.protocols.protocol1_12to1_11_1.storage.EntityTracker1
|
|||||||
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type;
|
import us.myles.ViaVersion.protocols.protocol1_9_1_2to1_9_3_4.types.Chunk1_9_3_4Type;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
|
||||||
|
import us.myles.ViaVersion.util.GsonUtil;
|
||||||
|
|
||||||
public class Protocol1_12To1_11_1 extends Protocol {
|
public class Protocol1_12To1_11_1 extends Protocol {
|
||||||
|
|
||||||
@ -81,7 +82,7 @@ public class Protocol1_12To1_11_1 extends Protocol {
|
|||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
if (!Via.getConfig().is1_12NBTArrayFix()) return;
|
if (!Via.getConfig().is1_12NBTArrayFix()) return;
|
||||||
try {
|
try {
|
||||||
JsonElement obj = new JsonParser().parse(wrapper.get(Type.STRING, 0));
|
JsonElement obj = GsonUtil.getJsonParser().parse(wrapper.get(Type.STRING, 0));
|
||||||
if (!TranslateRewriter.toClient(obj, wrapper.user())) {
|
if (!TranslateRewriter.toClient(obj, wrapper.user())) {
|
||||||
wrapper.cancel();
|
wrapper.cancel();
|
||||||
return;
|
return;
|
||||||
|
@ -289,12 +289,12 @@ public class Protocol1_13To1_12_2 extends Protocol {
|
|||||||
int index;
|
int index;
|
||||||
int length;
|
int length;
|
||||||
// If no input or new word (then it's the start)
|
// If no input or new word (then it's the start)
|
||||||
if (input.endsWith(" ") || input.length() == 0) {
|
if (input.endsWith(" ") || input.isEmpty()) {
|
||||||
index = input.length();
|
index = input.length();
|
||||||
length = 0;
|
length = 0;
|
||||||
} else {
|
} else {
|
||||||
// Otherwise find the last space (+1 as we include it)
|
// Otherwise find the last space (+1 as we include it)
|
||||||
int lastSpace = input.lastIndexOf(" ") + 1;
|
int lastSpace = input.lastIndexOf(' ') + 1;
|
||||||
index = lastSpace;
|
index = lastSpace;
|
||||||
length = input.length() - lastSpace;
|
length = input.length() - lastSpace;
|
||||||
}
|
}
|
||||||
@ -1212,7 +1212,7 @@ public class Protocol1_13To1_12_2 extends Protocol {
|
|||||||
// The Display Name is just colours which overwrites the suffix
|
// The Display Name is just colours which overwrites the suffix
|
||||||
// It also overwrites for ANY colour in name but most plugins
|
// It also overwrites for ANY colour in name but most plugins
|
||||||
// will just send colour as 'invisible' character
|
// will just send colour as 'invisible' character
|
||||||
if (ChatColor.stripColor(name).length() == 0) {
|
if (ChatColor.stripColor(name).isEmpty()) {
|
||||||
StringBuilder newName = new StringBuilder();
|
StringBuilder newName = new StringBuilder();
|
||||||
for (int i = 1; i < name.length(); i += 2) {
|
for (int i = 1; i < name.length(); i += 2) {
|
||||||
char colorChar = name.charAt(i);
|
char colorChar = name.charAt(i);
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_16to1_15_2;
|
package us.myles.ViaVersion.protocols.protocol1_16to1_15_2;
|
||||||
|
|
||||||
import us.myles.ViaVersion.api.PacketWrapper;
|
|
||||||
import us.myles.ViaVersion.api.Via;
|
import us.myles.ViaVersion.api.Via;
|
||||||
import us.myles.ViaVersion.api.data.UserConnection;
|
import us.myles.ViaVersion.api.data.UserConnection;
|
||||||
import us.myles.ViaVersion.api.protocol.Protocol;
|
import us.myles.ViaVersion.api.protocol.Protocol;
|
||||||
@ -130,7 +129,7 @@ public class Protocol1_16To1_15_2 extends Protocol {
|
|||||||
|
|
||||||
|
|
||||||
cancelIncoming(State.PLAY, 0x0F); // Generate jisaw
|
cancelIncoming(State.PLAY, 0x0F); // Generate jisaw
|
||||||
cancelIncoming(State.PLAY, 0x28); // Jigsaw update
|
cancelIncoming(State.PLAY, 0x28); // Jigsaw update
|
||||||
|
|
||||||
registerIncoming(State.PLAY, 0x0F, 0x10);
|
registerIncoming(State.PLAY, 0x0F, 0x10);
|
||||||
registerIncoming(State.PLAY, 0x10, 0x11);
|
registerIncoming(State.PLAY, 0x10, 0x11);
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets;
|
package us.myles.ViaVersion.protocols.protocol1_9to1_8.packets;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
|
||||||
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.entities.Entity1_10Types;
|
import us.myles.ViaVersion.api.entities.Entity1_10Types;
|
||||||
@ -22,6 +21,7 @@ import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.CommandBlockProv
|
|||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MainHandProvider;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MainHandProvider;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.ClientChunks;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
|
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.EntityTracker1_9;
|
||||||
|
import us.myles.ViaVersion.util.GsonUtil;
|
||||||
|
|
||||||
public class PlayerPackets {
|
public class PlayerPackets {
|
||||||
public static void register(Protocol protocol) {
|
public static void register(Protocol protocol) {
|
||||||
@ -36,7 +36,7 @@ public class PlayerPackets {
|
|||||||
@Override
|
@Override
|
||||||
public void handle(PacketWrapper wrapper) throws Exception {
|
public void handle(PacketWrapper wrapper) throws Exception {
|
||||||
try {
|
try {
|
||||||
JsonObject obj = (JsonObject) new JsonParser().parse(wrapper.get(Type.STRING, 0));
|
JsonObject obj = (JsonObject) GsonUtil.getJsonParser().parse(wrapper.get(Type.STRING, 0));
|
||||||
ChatRewriter.toClient(obj, wrapper.user());
|
ChatRewriter.toClient(obj, wrapper.user());
|
||||||
wrapper.set(Type.STRING, 0, obj.toString());
|
wrapper.set(Type.STRING, 0, obj.toString());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -2,9 +2,11 @@ package us.myles.ViaVersion.util;
|
|||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
|
||||||
public final class GsonUtil {
|
public final class GsonUtil {
|
||||||
private static final Gson gson = getGsonBuilder().create();
|
private static final JsonParser JSON_PARSER = new JsonParser();
|
||||||
|
private static final Gson GSON = getGsonBuilder().create();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get google's Gson magic
|
* Get google's Gson magic
|
||||||
@ -12,7 +14,7 @@ public final class GsonUtil {
|
|||||||
* @return Gson instance
|
* @return Gson instance
|
||||||
*/
|
*/
|
||||||
public static Gson getGson() {
|
public static Gson getGson() {
|
||||||
return gson;
|
return GSON;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -23,4 +25,8 @@ public final class GsonUtil {
|
|||||||
public static GsonBuilder getGsonBuilder() {
|
public static GsonBuilder getGsonBuilder() {
|
||||||
return new GsonBuilder();
|
return new GsonBuilder();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static JsonParser getJsonParser() {
|
||||||
|
return JSON_PARSER;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren