mirror of
https://github.com/BX-Team/DivineMC.git
synced 2025-12-23 16:59:24 +00:00
83 lines
4.9 KiB
Diff
83 lines
4.9 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
|
|
|
|
Original code by YatopiaMC, licensed under MIT
|
|
You can find the original code on https://github.com/YatopiaMC/Yatopia
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
index 3fc95b7d7b41e078e1d219e29ada27aeab1320bf..faaf13f46bc7bf0ffc1fe61f45e9f11cb9c8b4d5 100644
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -758,13 +758,19 @@ public abstract class PlayerList {
|
|
if (getBans().isBanned(gameprofile) && (gameprofilebanentry = getBans().get(gameprofile)) != null) {
|
|
// Paper end
|
|
|
|
- ichatmutablecomponent = Component.translatable("multiplayer.disconnect.banned.reason", gameprofilebanentry.getReason());
|
|
- if (gameprofilebanentry.getExpires() != null) {
|
|
- ichatmutablecomponent.append((Component) Component.translatable("multiplayer.disconnect.banned.expiration", PlayerList.BAN_DATE_FORMAT.format(gameprofilebanentry.getExpires())));
|
|
- }
|
|
+ // Yatopia start - Stop wasting resources on JsonList#get
|
|
+ if (!gameprofilebanentry.hasExpired()) {
|
|
+ ichatmutablecomponent = Component.translatable("multiplayer.disconnect.banned.reason", gameprofilebanentry.getReason());
|
|
+ if (gameprofilebanentry.getExpires() != null) {
|
|
+ ichatmutablecomponent.append((Component) Component.translatable("multiplayer.disconnect.banned.expiration", PlayerList.BAN_DATE_FORMAT.format(gameprofilebanentry.getExpires())));
|
|
+ }
|
|
|
|
- // return chatmessage;
|
|
- event.disallow(PlayerLoginEvent.Result.KICK_BANNED, PaperAdventure.asAdventure(ichatmutablecomponent)); // Paper - Adventure
|
|
+ // return chatmessage;
|
|
+ event.disallow(PlayerLoginEvent.Result.KICK_BANNED, PaperAdventure.asAdventure(ichatmutablecomponent)); // Paper - Adventure
|
|
+ } else {
|
|
+ getBans().remove(gameprofile);
|
|
+ }
|
|
+ // Yatopia end
|
|
} else if (!this.isWhiteListed(gameprofile, event)) { // Paper
|
|
//ichatmutablecomponent = Component.translatable("multiplayer.disconnect.not_whitelisted"); // Paper
|
|
//event.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(org.spigotmc.SpigotConfig.whitelistMessage)); // Spigot // Paper - Adventure - moved to isWhitelisted
|
|
diff --git a/src/main/java/net/minecraft/server/players/StoredUserList.java b/src/main/java/net/minecraft/server/players/StoredUserList.java
|
|
index 63c0fe30ff035b6b5c1b4b35d3ad6c649d94e421..109e08e098a6c1ca1ba3dc2a9a293eaf9d5d7cb7 100644
|
|
--- a/src/main/java/net/minecraft/server/players/StoredUserList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/StoredUserList.java
|
|
@@ -73,9 +73,12 @@ public abstract class StoredUserList<K, V extends StoredUserEntry<K>> {
|
|
// Paper start
|
|
// this.g();
|
|
// return (V) this.d.get(this.a(k0)); // CraftBukkit - fix decompile error
|
|
- return (V) this.map.computeIfPresent(this.getKeyForUser(key), (k, v) -> {
|
|
+ // Yatopia start - Stop wasting resources on JsonList#get
|
|
+ return this.map.get(this.getKeyForUser(key));
|
|
+ /*return (V) this.map.computeIfPresent(this.getKeyForUser(key), (k, v) -> {
|
|
return v.hasExpired() ? null : v;
|
|
- });
|
|
+ });*/
|
|
+ // Yatopia end
|
|
// Paper end
|
|
}
|
|
|
|
@@ -150,7 +153,8 @@ public abstract class StoredUserList<K, V extends StoredUserEntry<K>> {
|
|
public void save() throws IOException {
|
|
this.removeExpired(); // Paper - remove expired values before saving
|
|
JsonArray jsonarray = new JsonArray();
|
|
- Stream<JsonObject> stream = this.map.values().stream().map((jsonlistentry) -> { // CraftBukkit - decompile error
|
|
+ // Yatopia start - Stop wasting resources on JsonList#get
|
|
+ /*Stream<JsonObject> stream = this.map.values().stream().map((jsonlistentry) -> { // CraftBukkit - decompile error
|
|
JsonObject jsonobject = new JsonObject();
|
|
|
|
Objects.requireNonNull(jsonlistentry);
|
|
@@ -158,7 +162,13 @@ public abstract class StoredUserList<K, V extends StoredUserEntry<K>> {
|
|
});
|
|
|
|
Objects.requireNonNull(jsonarray);
|
|
- stream.forEach(jsonarray::add);
|
|
+ stream.forEach(jsonarray::add);*/
|
|
+ for (V value : this.map.values()) {
|
|
+ JsonObject obj = new JsonObject();
|
|
+ value.serialize(obj);
|
|
+ jsonarray.add(obj);
|
|
+ }
|
|
+ // Yatopia end
|
|
BufferedWriter bufferedwriter = Files.newWriter(this.file, StandardCharsets.UTF_8);
|
|
|
|
try {
|