mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-16 10:34:49 +00:00
71 lines
2.1 KiB
Diff
71 lines
2.1 KiB
Diff
--- a/net/minecraft/network/ServerStatusResponse.java
|
|
+++ b/net/minecraft/network/ServerStatusResponse.java
|
|
@@ -26,6 +26,7 @@
|
|
|
|
public void setServerDescription(ITextComponent descriptionIn) {
|
|
this.description = descriptionIn;
|
|
+ invalidateJson();
|
|
}
|
|
|
|
public ServerStatusResponse.Players getPlayers() {
|
|
@@ -34,6 +35,7 @@
|
|
|
|
public void setPlayers(ServerStatusResponse.Players playersIn) {
|
|
this.players = playersIn;
|
|
+ invalidateJson();
|
|
}
|
|
|
|
public ServerStatusResponse.Version getVersion() {
|
|
@@ -42,16 +44,51 @@
|
|
|
|
public void setVersion(ServerStatusResponse.Version versionIn) {
|
|
this.version = versionIn;
|
|
+ invalidateJson();
|
|
}
|
|
|
|
public void setFavicon(String faviconBlob) {
|
|
this.favicon = faviconBlob;
|
|
+ invalidateJson();
|
|
}
|
|
|
|
public String getFavicon() {
|
|
return this.favicon;
|
|
}
|
|
|
|
+ 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.GSON.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 maxPlayers;
|
|
private final int onlinePlayerCount;
|