JsonList#get optimization && Global Eula file
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Etil <81570777+etil2jz@users.noreply.github.com>
|
||||
Date: Sun, 19 Sep 2021 16:26:16 +0200
|
||||
Subject: [PATCH] (Sugarcane) Stop wasting resources on JsonList#get
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
||||
index 9dea6afb7fd90ff58970a5fe130fb14d2cdc991d..e61c9b789583382612b4b0fd56084ebe2e9adbda 100644
|
||||
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
||||
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
||||
@@ -753,14 +753,20 @@ public abstract class PlayerList {
|
||||
if (getBans().isBanned(gameprofile) && (gameprofilebanentry = getBans().get(gameprofile)) != null) {
|
||||
// Paper end
|
||||
|
||||
- chatmessage = new TranslatableComponent("multiplayer.disconnect.banned.reason", new Object[]{gameprofilebanentry.getReason()});
|
||||
+ if (!gameprofilebanentry.hasExpired()) { // Sugarcane
|
||||
+ chatmessage = new TranslatableComponent("multiplayer.disconnect.banned.reason", new Object[]{gameprofilebanentry.getReason()});
|
||||
if (gameprofilebanentry.getExpires() != null) {
|
||||
chatmessage.append(new TranslatableComponent("multiplayer.disconnect.banned.expiration", new Object[]{PlayerList.BAN_DATE_FORMAT.format(gameprofilebanentry.getExpires())}));
|
||||
}
|
||||
|
||||
// return chatmessage;
|
||||
+ // Sugarcane start
|
||||
event.disallow(PlayerLoginEvent.Result.KICK_BANNED, PaperAdventure.asAdventure(chatmessage)); // Paper - Adventure
|
||||
- } else if (!this.isWhitelisted(gameprofile, event)) { // Paper
|
||||
+ } else {
|
||||
+ getBans().remove(gameprofile);
|
||||
+ }
|
||||
+ // Sugarcane end
|
||||
+ } else if (!this.isWhitelisted(gameprofile, event)) { // Paper
|
||||
//chatmessage = new ChatMessage("multiplayer.disconnect.not_whitelisted"); // Paper
|
||||
//event.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, org.spigotmc.SpigotConfig.whitelistMessage); // Spigot // Paper - moved to isWhitelisted
|
||||
} else if (this.getIpBans().isBanned(socketaddress) && getIpBans().get(socketaddress) != null && !this.getIpBans().get(socketaddress).hasExpired()) { // Paper - fix NPE with temp ip bans
|
||||
diff --git a/src/main/java/net/minecraft/server/players/StoredUserList.java b/src/main/java/net/minecraft/server/players/StoredUserList.java
|
||||
index 9152c6c9e7e5c8fdb9183c2b4f088a810621b333..6f5cb7091ae9772264d16564d4831dde6ff82ba0 100644
|
||||
--- a/src/main/java/net/minecraft/server/players/StoredUserList.java
|
||||
+++ b/src/main/java/net/minecraft/server/players/StoredUserList.java
|
||||
@@ -73,9 +73,14 @@ 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
|
||||
+ // Sugarcane start - only remove if it expires and has been requested
|
||||
+ return this.map.get(this.getKeyForUser(key));
|
||||
+ /*
|
||||
return (V) this.map.computeIfPresent(this.getKeyForUser(key), (k, v) -> {
|
||||
return v.hasExpired() ? null : v;
|
||||
});
|
||||
+ */
|
||||
+ // Sugarcane end
|
||||
// Paper end
|
||||
}
|
||||
|
||||
@@ -150,6 +155,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();
|
||||
+ // Sugarcane start - we're nuking streams wherever possible
|
||||
+ /*
|
||||
Stream<JsonObject> stream = this.map.values().stream().map((jsonlistentry) -> { // CraftBukkit - decompile error
|
||||
JsonObject jsonobject = new JsonObject();
|
||||
|
||||
@@ -159,6 +166,13 @@ public abstract class StoredUserList<K, V extends StoredUserEntry<K>> {
|
||||
|
||||
Objects.requireNonNull(jsonarray);
|
||||
stream.forEach(jsonarray::add);
|
||||
+ */
|
||||
+ for (V value : this.map.values()) {
|
||||
+ JsonObject obj = new JsonObject();
|
||||
+ value.serialize(obj);
|
||||
+ jsonarray.add(obj);
|
||||
+ }
|
||||
+ // Sugarcane end
|
||||
BufferedWriter bufferedwriter = Files.newWriter(this.file, StandardCharsets.UTF_8);
|
||||
|
||||
try {
|
||||
40
patches/server/0028-Yatopia-Global-Eula-file.patch
Normal file
40
patches/server/0028-Yatopia-Global-Eula-file.patch
Normal file
@@ -0,0 +1,40 @@
|
||||
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
||||
From: Etil <81570777+etil2jz@users.noreply.github.com>
|
||||
Date: Sun, 19 Sep 2021 16:32:38 +0200
|
||||
Subject: [PATCH] (Yatopia) Global Eula file
|
||||
|
||||
|
||||
diff --git a/src/main/java/net/minecraft/server/Eula.java b/src/main/java/net/minecraft/server/Eula.java
|
||||
index a1d5c0f8fe2adb2ee56f3217e089211ec7c61eb0..00008b0dc478cccd710b1d82f5158f02f6271f03 100644
|
||||
--- a/src/main/java/net/minecraft/server/Eula.java
|
||||
+++ b/src/main/java/net/minecraft/server/Eula.java
|
||||
@@ -16,12 +16,26 @@ public class Eula {
|
||||
|
||||
public Eula(Path eulaFile) {
|
||||
this.file = eulaFile;
|
||||
- this.agreed = SharedConstants.IS_RUNNING_IN_IDE || this.readFile();
|
||||
+ this.agreed = SharedConstants.IS_RUNNING_IN_IDE || globalEula() || this.readFile(eulaFile);
|
||||
}
|
||||
|
||||
- private boolean readFile() {
|
||||
+ // Sugarcane start - global eula file
|
||||
+ private boolean globalEula() {
|
||||
+ java.io.File globalEula = new java.io.File(System.getProperty("user.home"), "eula.txt");
|
||||
+
|
||||
+ if (globalEula.exists()) {
|
||||
+ System.out.println("Loaded global eula file from " + globalEula.getAbsolutePath());
|
||||
+ return readFile(globalEula.toPath());
|
||||
+ } else {
|
||||
+ System.out.println("No global eula file found at " + globalEula.getAbsolutePath());
|
||||
+ }
|
||||
+ return false;
|
||||
+ }
|
||||
+ // Sugarcane end
|
||||
+
|
||||
+ private boolean readFile(java.nio.file.Path path) {
|
||||
try {
|
||||
- InputStream inputStream = Files.newInputStream(this.file);
|
||||
+ InputStream inputStream = Files.newInputStream(path);
|
||||
|
||||
boolean var3;
|
||||
try {
|
||||
Reference in New Issue
Block a user