ForgePatch/patches/minecraft/net/minecraft/network/ServerStatusResponse.java.p...

71 lines
2.1 KiB
Diff

--- a/net/minecraft/network/ServerStatusResponse.java
+++ b/net/minecraft/network/ServerStatusResponse.java
@@ -26,6 +26,7 @@
public void func_151315_a(ITextComponent p_151315_1_) {
this.field_151326_a = p_151315_1_;
+ invalidateJson();
}
public ServerStatusResponse.Players func_151318_b() {
@@ -34,6 +35,7 @@
public void func_151319_a(ServerStatusResponse.Players p_151319_1_) {
this.field_151324_b = p_151319_1_;
+ invalidateJson();
}
public ServerStatusResponse.Version func_151322_c() {
@@ -42,16 +44,51 @@
public void func_151321_a(ServerStatusResponse.Version p_151321_1_) {
this.field_151325_c = p_151321_1_;
+ invalidateJson();
}
public void func_151320_a(String p_151320_1_) {
this.field_151323_d = p_151320_1_;
+ invalidateJson();
}
public String func_151316_d() {
return this.field_151323_d;
}
+ private java.util.concurrent.Semaphore mutex = new java.util.concurrent.Semaphore(1);
+ private String json = null;
+ /**
+ * Returns this object as a Json string.
+ * Converting to JSON if a cached version is not available.
+ *
+ * Also to prevent potentially large memory allocations on the server
+ * this is moved from the SPacketServerInfo writePacket function
+ *
+ * As this method is called from the network threads so thread safety is important!
+ */
+ public String getJson() {
+ String ret = this.json;
+ if (ret == null) {
+ mutex.acquireUninterruptibly();
+ ret = this.json;
+ if (ret == null) {
+ ret = net.minecraft.network.status.server.SPacketServerInfo.field_149297_a.toJson(this);
+ this.json = ret;
+ }
+ mutex.release();
+ }
+ return ret;
+ }
+
+ /**
+ * Invalidates the cached json, causing the next call to getJson to rebuild it.
+ * This is needed externally because PlayerCountData.setPlayer's is public.
+ */
+ public void invalidateJson() {
+ this.json = null;
+ }
+
public static class Players {
private final int field_151336_a;
private final int field_151334_b;