geforkt von Mirrors/Paper
c0d07c1b67
Upstream has released updates that appears to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Bukkit Changes: f009c3dd SPIGOT-5810, SPIGOT-5835: 'Better' handling of Player.isOnGround e677c370 Update ECJ version 5058a35d SPIGOT-5860: Item.setItemStack should be NotNull CraftBukkit Changes:d77f4d9b
SPIGOT-5810, SPIGOT-5835: 'Better' handling of Player.isOnGround53c95627
SPIGOT-5865: Piglin does not trigger EntityPickupItemEvent2ab04d24
Update ECJ version7884e079
SPIGOT-5868: Blocks do not tick in custom nether / end2a848286
SPIGOT-5863: Don't check colour in scoreboard length validationf2cbce30
SPIGOT-5866: Beehive unknown TargetReason Spigot Changes: ad703da0 SPIGOT-5870: /plugins "website" field shows "version" 1a27cfd8 #98: Improve output of /plugins command using text components 732d5bab Disable checkstyle in Spigot blocks 0199a9a6 #97: Add Memory Usage to Ticks Per Second Command. 33ea98fc SPIGOT-5858: NPE: Joining the server with an invalid dimension
137 Zeilen
6.4 KiB
Diff
137 Zeilen
6.4 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: egg82 <phantom_zero@ymail.com>
|
|
Date: Tue, 7 Aug 2018 01:24:23 -0600
|
|
Subject: [PATCH] Use ConcurrentHashMap in JsonList
|
|
|
|
This is specifically aimed at fixing #471
|
|
|
|
Using a ConcurrentHashMap because thread safety
|
|
The performance benefit of Map over ConcurrentMap is negligabe at best in this scenaio, as most operations will be get and not add or remove
|
|
Even without considering the use-case the benefits are still negligable
|
|
|
|
Original ideas for the system included an expiration policy and/or handler
|
|
The simpler solution was to use a computeIfPresent in the get method
|
|
This will simultaneously have an O(1) lookup time and automatically expire any values
|
|
Since the get method (nor other similar methods) don't seem to have a critical need to flush the map to disk at any of these points further processing is simply wasteful
|
|
Meaning the original function expired values unrelated to the current value without actually having any explicit need to
|
|
|
|
The h method was heavily modified to be much more efficient in its processing
|
|
Also instead of being called on every get, it's now called just before a save
|
|
This will eliminate stale values being flushed to disk
|
|
|
|
Modified isEmpty to use the isEmpty() method instead of the slightly confusing size() < 1
|
|
The point of this is readability, but does have a side-benefit of a small microptimization
|
|
|
|
Finally, added a couple obfhelpers for the modified code
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/JsonList.java b/src/main/java/net/minecraft/server/JsonList.java
|
|
index 5b01e4edb3c0f8bc785b70128cbe31b14356e4fb..9213bfb78e92b838189161045e3945588251b486 100644
|
|
--- a/src/main/java/net/minecraft/server/JsonList.java
|
|
+++ b/src/main/java/net/minecraft/server/JsonList.java
|
|
@@ -12,6 +12,8 @@ import java.io.BufferedReader;
|
|
import java.io.BufferedWriter;
|
|
import java.io.File;
|
|
import java.io.IOException;
|
|
+import java.lang.reflect.ParameterizedType; // Paper
|
|
+import java.lang.reflect.Type; // Paper
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.util.Collection;
|
|
import java.util.Iterator;
|
|
@@ -26,7 +28,22 @@ public abstract class JsonList<K, V extends JsonListEntry<K>> {
|
|
protected static final Logger LOGGER = LogManager.getLogger();
|
|
private static final Gson b = (new GsonBuilder()).setPrettyPrinting().create();
|
|
private final File c;
|
|
- private final Map<String, V> d = Maps.newHashMap();
|
|
+ // Paper - replace HashMap is ConcurrentHashMap
|
|
+ private final Map<String, V> d = Maps.newConcurrentMap(); private final Map<String, V> getBackingMap() { return this.d; } // Paper - OBFHELPER
|
|
+ private boolean e = true;
|
|
+ private static final ParameterizedType f = new ParameterizedType() {
|
|
+ public Type[] getActualTypeArguments() {
|
|
+ return new Type[]{JsonListEntry.class};
|
|
+ }
|
|
+
|
|
+ public Type getRawType() {
|
|
+ return List.class;
|
|
+ }
|
|
+
|
|
+ public Type getOwnerType() {
|
|
+ return null;
|
|
+ }
|
|
+ };
|
|
|
|
public JsonList(File file) {
|
|
this.c = file;
|
|
@@ -49,8 +66,13 @@ public abstract class JsonList<K, V extends JsonListEntry<K>> {
|
|
|
|
@Nullable
|
|
public V get(K k0) {
|
|
- this.g();
|
|
- return (V) this.d.get(this.a(k0)); // CraftBukkit - fix decompile error
|
|
+ // Paper start
|
|
+ // this.g();
|
|
+ // return (V) this.d.get(this.a(k0)); // CraftBukkit - fix decompile error
|
|
+ return (V) this.getBackingMap().computeIfPresent(this.getMappingKey(k0), (k, v) -> {
|
|
+ return v.hasExpired() ? null : v;
|
|
+ });
|
|
+ // Paper end
|
|
}
|
|
|
|
public void remove(K k0) {
|
|
@@ -79,9 +101,11 @@ public abstract class JsonList<K, V extends JsonListEntry<K>> {
|
|
// CraftBukkit end
|
|
|
|
public boolean isEmpty() {
|
|
- return this.d.size() < 1;
|
|
+ // return this.d.size() < 1; // Paper
|
|
+ return this.getBackingMap().isEmpty(); // Paper - readability is the goal. As an aside, isEmpty() uses only sumCount() and a comparison. size() uses sumCount(), casts, and boolean logic
|
|
}
|
|
|
|
+ protected final String getMappingKey(K k0) { return a(k0); } // Paper - OBFHELPER
|
|
protected String a(K k0) {
|
|
return k0.toString();
|
|
}
|
|
@@ -90,8 +114,9 @@ public abstract class JsonList<K, V extends JsonListEntry<K>> {
|
|
return this.d.containsKey(this.a(k0));
|
|
}
|
|
|
|
+ private void removeStaleEntries() { g(); } // Paper - OBFHELPER
|
|
private void g() {
|
|
- List<K> list = Lists.newArrayList();
|
|
+ /*List<K> list = Lists.newArrayList();
|
|
Iterator iterator = this.d.values().iterator();
|
|
|
|
while (iterator.hasNext()) {
|
|
@@ -108,8 +133,10 @@ public abstract class JsonList<K, V extends JsonListEntry<K>> {
|
|
K k0 = (K) iterator.next(); // CraftBukkit - decompile error
|
|
|
|
this.d.remove(this.a(k0));
|
|
- }
|
|
+ }*/
|
|
|
|
+ this.getBackingMap().values().removeIf(JsonListEntry::hasExpired);
|
|
+ // Paper end
|
|
}
|
|
|
|
protected abstract JsonListEntry<K> a(JsonObject jsonobject);
|
|
@@ -119,6 +146,7 @@ public abstract class JsonList<K, V extends JsonListEntry<K>> {
|
|
}
|
|
|
|
public void save() throws IOException {
|
|
+ this.removeStaleEntries(); // Paper - remove expired values before saving
|
|
JsonArray jsonarray = new JsonArray();
|
|
|
|
this.d.values().stream().map((jsonlistentry) -> {
|
|
diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java
|
|
index 509451c73892147419ef4cf23b449c61d21cf279..7c88e370c19554652d4a580252e657747180047d 100644
|
|
--- a/src/main/java/net/minecraft/server/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/PlayerList.java
|
|
@@ -543,7 +543,7 @@ public abstract class PlayerList {
|
|
} else if (!this.isWhitelisted(gameprofile)) {
|
|
chatmessage = new ChatMessage("multiplayer.disconnect.not_whitelisted");
|
|
//event.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, org.spigotmc.SpigotConfig.whitelistMessage); // Spigot // Paper - moved to isWhitelisted
|
|
- } else if (getIPBans().isBanned(socketaddress) && !getIPBans().get(socketaddress).hasExpired()) {
|
|
+ } else if (getIPBans().isBanned(socketaddress) && getIPBans().get(socketaddress) != null && !getIPBans().get(socketaddress).hasExpired()) { // Paper - fix NPE with temp ip bans
|
|
IpBanEntry ipbanentry = this.l.get(socketaddress);
|
|
|
|
chatmessage = new ChatMessage("multiplayer.disconnect.banned_ip.reason", new Object[]{ipbanentry.getReason()});
|