Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-09-08 22:02:50 +02:00
Use GSON instead, should fix memory leak issue with JSON. Also make sure that we use a copy of players for the bossbar.
Dieser Commit ist enthalten in:
Ursprung
d40c5851e9
Commit
11f3844d63
14
pom.xml
14
pom.xml
@ -101,6 +101,10 @@
|
|||||||
<pattern>org.spacehq.opennbt</pattern>
|
<pattern>org.spacehq.opennbt</pattern>
|
||||||
<shadedPattern>us.myles.viaversion.libs.opennbt</shadedPattern>
|
<shadedPattern>us.myles.viaversion.libs.opennbt</shadedPattern>
|
||||||
</relocation>
|
</relocation>
|
||||||
|
<relocation>
|
||||||
|
<pattern>com.google.gson</pattern>
|
||||||
|
<shadedPattern>us.myles.viaversion.libs.gson</shadedPattern>
|
||||||
|
</relocation>
|
||||||
</relocations>
|
</relocations>
|
||||||
</configuration>
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
@ -162,6 +166,15 @@
|
|||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<!-- GSON (JSON Library) -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
<version>2.6.2</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
<optional>true</optional>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
<!-- Netty (Network Library) -->
|
<!-- Netty (Network Library) -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.netty</groupId>
|
<groupId>io.netty</groupId>
|
||||||
@ -170,6 +183,7 @@
|
|||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<!-- Lombok -->
|
<!-- Lombok -->
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
|
@ -15,10 +15,7 @@ import us.myles.ViaVersion.packets.PacketType;
|
|||||||
import us.myles.ViaVersion.transformers.OutgoingTransformer;
|
import us.myles.ViaVersion.transformers.OutgoingTransformer;
|
||||||
import us.myles.ViaVersion.util.PacketUtil;
|
import us.myles.ViaVersion.util.PacketUtil;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
public class ViaBossBar implements BossBar {
|
public class ViaBossBar implements BossBar {
|
||||||
@ -142,7 +139,7 @@ public class ViaBossBar implements BossBar {
|
|||||||
|
|
||||||
private void sendPacket(UpdateAction action) {
|
private void sendPacket(UpdateAction action) {
|
||||||
ByteBuf buf = getPacket(action);
|
ByteBuf buf = getPacket(action);
|
||||||
for (UUID uuid : players)
|
for (UUID uuid : new ArrayList<>(players))
|
||||||
sendPacket(uuid, buf);
|
sendPacket(uuid, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
package us.myles.ViaVersion.transformers;
|
package us.myles.ViaVersion.transformers;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.GsonBuilder;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
import io.netty.buffer.ByteBuf;
|
import io.netty.buffer.ByteBuf;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.json.simple.JSONObject;
|
|
||||||
import org.json.simple.parser.JSONParser;
|
|
||||||
import org.json.simple.parser.ParseException;
|
|
||||||
import org.spacehq.opennbt.tag.builtin.CompoundTag;
|
import org.spacehq.opennbt.tag.builtin.CompoundTag;
|
||||||
import org.spacehq.opennbt.tag.builtin.StringTag;
|
import org.spacehq.opennbt.tag.builtin.StringTag;
|
||||||
import us.myles.ViaVersion.CancelException;
|
import us.myles.ViaVersion.CancelException;
|
||||||
@ -34,6 +34,7 @@ import static us.myles.ViaVersion.util.PacketUtil.*;
|
|||||||
|
|
||||||
|
|
||||||
public class OutgoingTransformer {
|
public class OutgoingTransformer {
|
||||||
|
private static Gson gson = new GsonBuilder().create();
|
||||||
|
|
||||||
private final ViaVersionPlugin plugin = (ViaVersionPlugin) ViaVersion.getInstance();
|
private final ViaVersionPlugin plugin = (ViaVersionPlugin) ViaVersion.getInstance();
|
||||||
|
|
||||||
@ -56,16 +57,16 @@ public class OutgoingTransformer {
|
|||||||
line = "{\"text\":\"\"}";
|
line = "{\"text\":\"\"}";
|
||||||
} else {
|
} else {
|
||||||
if ((!line.startsWith("\"") || !line.endsWith("\"")) && (!line.startsWith("{") || !line.endsWith("}"))) {
|
if ((!line.startsWith("\"") || !line.endsWith("\"")) && (!line.startsWith("{") || !line.endsWith("}"))) {
|
||||||
JSONObject obj = new JSONObject();
|
JsonObject jsonObject = new JsonObject();
|
||||||
obj.put("text", line);
|
jsonObject.addProperty("text", line);
|
||||||
return obj.toJSONString();
|
return gson.toJson(jsonObject);
|
||||||
}
|
}
|
||||||
if (line.startsWith("\"") && line.endsWith("\"")) {
|
if (line.startsWith("\"") && line.endsWith("\"")) {
|
||||||
line = "{\"text\":" + line + "}";
|
line = "{\"text\":" + line + "}";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
new JSONParser().parse(line);
|
gson.fromJson(line, JsonObject.class);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("Invalid JSON String: \"" + line + "\" Please report this issue to the ViaVersion Github: " + e.getMessage());
|
System.out.println("Invalid JSON String: \"" + line + "\" Please report this issue to the ViaVersion Github: " + e.getMessage());
|
||||||
return "{\"text\":\"\"}";
|
return "{\"text\":\"\"}";
|
||||||
@ -297,12 +298,12 @@ public class OutgoingTransformer {
|
|||||||
if (packet == PacketType.STATUS_RESPONSE) {
|
if (packet == PacketType.STATUS_RESPONSE) {
|
||||||
String originalStatus = PacketUtil.readString(input);
|
String originalStatus = PacketUtil.readString(input);
|
||||||
try {
|
try {
|
||||||
JSONObject json = (JSONObject) new JSONParser().parse(originalStatus);
|
JsonObject jsonObject = gson.fromJson(originalStatus, JsonObject.class);
|
||||||
JSONObject version = (JSONObject) json.get("version");
|
JsonObject version = jsonObject.get("version").getAsJsonObject();
|
||||||
if ((long) version.get("protocol") != 9999) //Fix ServerListPlus custom outdated message
|
if (version.get("protocol").getAsInt() != 9999) //Fix ServerListPlus custom outdated message
|
||||||
version.put("protocol", info.getProtocol());
|
version.addProperty("protocol", info.getProtocol());
|
||||||
PacketUtil.writeString(json.toJSONString(), output);
|
PacketUtil.writeString(gson.toJson(jsonObject), output);
|
||||||
} catch (ParseException e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren