2020-09-04 09:24:27 +02:00
|
|
|
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
|
2020-10-02 16:54:16 +02:00
|
|
|
index 4094ef76b7b05de1bfcc28aa0ef13033abadeb7e..0224a6d0e47e836fa485b39e7b4ce5b83ea554bf 100644
|
2020-09-04 09:24:27 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/JsonList.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/JsonList.java
|
2020-10-02 16:54:16 +02:00
|
|
|
@@ -71,9 +71,13 @@ public abstract class JsonList<K, V extends JsonListEntry<K>> {
|
2020-09-04 09:24:27 +02:00
|
|
|
// 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
|
|
|
|
}
|
|
|
|
|
2020-10-02 16:54:16 +02:00
|
|
|
@@ -154,12 +158,22 @@ public abstract class JsonList<K, V extends JsonListEntry<K>> {
|
2020-09-04 09:24:27 +02:00
|
|
|
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
|
2020-10-02 16:54:16 +02:00
|
|
|
BufferedWriter bufferedwriter = Files.newWriter(this.c, StandardCharsets.UTF_8);
|
2020-09-04 09:24:27 +02:00
|
|
|
Throwable throwable = null;
|
|
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java
|
2020-12-02 07:35:11 +01:00
|
|
|
index b679a6ee7ee2fb00293fb02b3537eddf5580e596..e54706b9c65f0a15bd5ff0e0f227bb881fc172b3 100644
|
2020-09-04 09:24:27 +02:00
|
|
|
--- a/src/main/java/net/minecraft/server/PlayerList.java
|
|
|
|
+++ b/src/main/java/net/minecraft/server/PlayerList.java
|
2020-10-06 16:26:45 +02:00
|
|
|
@@ -636,6 +636,7 @@ public abstract class PlayerList {
|
2020-09-04 09:24:27 +02:00
|
|
|
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) {
|
2020-10-06 16:26:45 +02:00
|
|
|
@@ -643,7 +644,11 @@ public abstract class PlayerList {
|
2020-09-04 09:24:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|