Yatopia/patches/server/0032-Stop-wasting-resources-on-JsonList-get.patch
Simon Gardling d059af01b6
Updated Upstream and Sidestream(s) (Paper/Purpur/AirplaneLite) (#362)
* Updated Upstream and Sidestream(s) (Paper/Purpur/AirplaneLite)

Upstream/An Sidestream has released updates that appears to apply and compile correctly
This update has NOT been tested by YatopiaMC and as with ANY update, please do your own testing.

Paper Changes:
fc4c0bc42 Reset shield blocking on dimension change
1c8b6065e Skip distance map update when spawning is disabled
091e6700f Added PlayerStonecutterRecipeSelectEvent
fc885f966 Add toggle for always placing the dragon egg
b3a6da3a7 Updated Upstream (Bukkit/CraftBukkit)
18ccc062d [Auto] Updated Upstream (Spigot)

Purpur Changes:
df9bd08 Config to use infinity bows without arrows (#149)
9d537bc Fix PlayerEditBookEvent not saving new book
3f8816d [ci-skip] Oops
5508728 [ci-skip] Add granny to funding
4c7ab70 Updated Upstream (Paper)
5eefb52 [ci-skip] Update Gradle to 6.8.1

AirplaneLite Changes:
459bb20 Remove patch
515fec7 Remove streams
fc94d7b Correct launcher name
0b153bd Update gradle version

* add Remove-streams.patch from AirplaneLite
2021-01-25 13:22:51 -06:00

82 lines
4.2 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Ivan Pekov <ivan@mrivanplays.com>
Date: Fri, 4 Sep 2020 10:07:42 +0300
Subject: [PATCH] Stop wasting resources on JsonList#get
Previously, when a banned player attempted to join the server was removing all the stale entries.
This caused a resource waste, which was unnoticeable to users that use ban plugins which doesn't
use the ban list. Akarin's changes for saving it async lowered the pressure, however it was
still pretty high.
Our changes are the following:
1. Stop removing all stale entries when JsonList#get is called.
2. Only if a player joins and his ban has expired, remove his ban which triggers a save which then
triggers removing of all stale entries.
diff --git a/src/main/java/net/minecraft/server/JsonList.java b/src/main/java/net/minecraft/server/JsonList.java
index a674140b61547841a1a6060e9f36aa14d0a86ff9..99580abac1ff30c784b6792d69c9d4cad12c1b1f 100644
--- a/src/main/java/net/minecraft/server/JsonList.java
+++ b/src/main/java/net/minecraft/server/JsonList.java
@@ -71,9 +71,13 @@ public abstract class JsonList<K, V extends JsonListEntry<K>> {
// Paper start
// this.g();
// return (V) this.d.get(this.a(k0)); // CraftBukkit - fix decompile error
+ // Yatopia start - only remove if it expires and has been requested
+ return this.getBackingMap().get(this.getMappingKey(k0));
+ /*
return (V) this.getBackingMap().computeIfPresent(this.getMappingKey(k0), (k, v) -> {
return v.hasExpired() ? null : v;
});
+ */ // Yatopia end
// Paper end
}
@@ -154,12 +158,22 @@ public abstract class JsonList<K, V extends JsonListEntry<K>> {
this.removeStaleEntries(); // Paper - remove expired values before saving
JsonArray jsonarray = new JsonArray();
+ // Yatopia start - we're nuking streams wherever possible
+ /*
this.d.values().stream().map((jsonlistentry) -> {
JsonObject jsonobject = new JsonObject();
jsonlistentry.getClass();
return (JsonObject) SystemUtils.a(jsonobject, jsonlistentry::a); // CraftBukkit - decompile error
}).forEach(jsonarray::add);
+ */
+ for (V value : this.d.values()) {
+ JsonObject obj = new JsonObject();
+ // todo: obfhelper for this?
+ value.a(obj);
+ jsonarray.add(obj);
+ }
+ // Yatopia end
BufferedWriter bufferedwriter = Files.newWriter(this.c, StandardCharsets.UTF_8);
Throwable throwable = null;
diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java
index 14d8492c405db32e454bc363207a127167432a61..f354712e8e1cd359bc8fb0461f30214b8db24112 100644
--- a/src/main/java/net/minecraft/server/PlayerList.java
+++ b/src/main/java/net/minecraft/server/PlayerList.java
@@ -647,6 +647,7 @@ public abstract class PlayerList {
GameProfileBanEntry gameprofilebanentry;
if (getProfileBans().isBanned(gameprofile) && (gameprofilebanentry = getProfileBans().get(gameprofile)) != null) {
// Paper end
+ if (!gameprofilebanentry.hasExpired()) { // Yatopia
chatmessage = new ChatMessage("multiplayer.disconnect.banned.reason", new Object[]{gameprofilebanentry.getReason()});
if (gameprofilebanentry.getExpires() != null) {
@@ -654,7 +655,11 @@ public abstract class PlayerList {
}
// return chatmessage;
- if (!gameprofilebanentry.hasExpired()) event.disallow(PlayerLoginEvent.Result.KICK_BANNED, CraftChatMessage.fromComponent(chatmessage)); // Spigot
+ // Yatopia start
+ /* if (!gameprofilebanentry.hasExpired()) */ event.disallow(PlayerLoginEvent.Result.KICK_BANNED, CraftChatMessage.fromComponent(chatmessage)); // Spigot
+ } else {
+ getProfileBans().remove(gameprofile);
+ } // Yatopia end
} else if (!this.isWhitelisted(gameprofile, event)) { // Paper
chatmessage = new ChatMessage("multiplayer.disconnect.not_whitelisted");
//event.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, org.spigotmc.SpigotConfig.whitelistMessage); // Spigot // Paper - moved to isWhitelisted