mirror of
https://github.com/BX-Team/DivineMC.git
synced 2025-12-19 14:59:25 +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 c0c14766adaac855112f85a203a6163b8adfdded..d4e3bc6dc71740d2f989e87f9b5cc48ac96ba8d5 100644
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -702,13 +702,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 4fd709a550bf8da1e996894a1ca6b91206c31e9e..bf959b19b068a7cfbb9bed72448a4139b7d50095 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 {
|