mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-23 02:55:47 +01:00
efd47e3a68
* Updated Upstream (Bukkit/CraftBukkit/Spigot) Upstream has released updates that appear 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: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices ecfa559a PR-849: Add InventoryView#setTitle 653d7edb SPIGOT-519: Add TNTPrimeEvent 22fccc09 PR-846: Add method to get chunk load level a070a52c PR-844: Add methods to convert Vector to and from JOML vectors cc7111fe PR-276: Add accessors to Wither's invulnerability ticks 777d24e9 SPIGOT-7209: Accessors and events for player's exp cooldown ccb2d01b SPIGOT-6308: Deprecate the location name property of map items cd04a31b PR-780: Add PlayerSpawnChangeEvent 7d1f5b64 SPIGOT-6780: Improve documentation for World#spawnFallingBlock 5696668a SPIGOT-6885: Add test and easier to debug code for reference in yaml configuration comments 2e13cff7 PR-589: Expand the FishHook API 2c7d3da5 PR-279: Minor edits to various Javadocs CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices a7cfc778f PR-1176: Add InventoryView#setTitle 563d42226 SPIGOT-519: Add TNTPrimeEvent ccbc6abca Add test for Chunk.LoadLevel mirroring 2926e0513 PR-1171: Add method to get chunk load level 63cad7f84 PR-375: Add accessors to Wither's invulnerability ticks bfd8b1ac8 SPIGOT-7209: Accessors and events for player's exp cooldown f92a41c39 PR-1181: Consolidate Location conversion code 10f866759 SPIGOT-6308: Deprecate the location name property of map items 82f7b658a PR-1095: Add PlayerSpawnChangeEvent b421af7e4 PR-808: Expand the FishHook API 598ad7b3f Increase outdated build delay Spigot Changes: d1bd3bd2 Rebuild patches e4265cc8 SPIGOT-7297: Entity Tracking Range option for Display entities * Work around javac bug * Call PlayerSpawnChangeEvent * Updated Upstream (Bukkit/CraftBukkit/Spigot) Upstream has released updates that appear 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: 2fcba9b2 SPIGOT-7347: Add missing documentation and details to ShapedRecipe c278419d PR-854: Move getHighestBlockYAt methods from World to RegionAccessor 201399fb PR-853: Add API for directly setting Display transformation matrices CraftBukkit Changes: 01b2e1af4 SPIGOT-7346: Disallow players from executing commands after disconnecting 7fe5ee022 PR-1186: Move getHighestBlockYAt methods from World to RegionAccessor bcc85ef67 PR-1185: Add API for directly setting Display transformation matrices Spigot Changes: 7da74dae Rebuild patches
141 lines
6.9 KiB
Diff
141 lines
6.9 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
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
index bfc81327f0c64ef3bd2e8ba218f6a4970553a309..952e0735bf1e66a812c90f283203c4f73e3905a5 100644
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -642,7 +642,7 @@ public abstract class PlayerList {
|
|
} 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
|
|
- } else if (this.getIpBans().isBanned(socketaddress) && !this.getIpBans().get(socketaddress).hasExpired()) {
|
|
+ } else if (this.getIpBans().isBanned(socketaddress) && getIpBans().get(socketaddress) != null && !this.getIpBans().get(socketaddress).hasExpired()) { // Paper - fix NPE with temp ip bans
|
|
IpBanListEntry ipbanentry = this.ipBans.get(socketaddress);
|
|
|
|
ichatmutablecomponent = Component.translatable("multiplayer.disconnect.banned_ip.reason", ipbanentry.getReason());
|
|
diff --git a/src/main/java/net/minecraft/server/players/StoredUserList.java b/src/main/java/net/minecraft/server/players/StoredUserList.java
|
|
index 097a25fd4ae5438161158a1018c707886cfbb959..91899909abd83611ac63633fef701be542cf64bf 100644
|
|
--- a/src/main/java/net/minecraft/server/players/StoredUserList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/StoredUserList.java
|
|
@@ -13,6 +13,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;
|
|
@@ -30,7 +32,22 @@ public abstract class StoredUserList<K, V extends StoredUserEntry<K>> {
|
|
private static final Logger LOGGER = LogUtils.getLogger();
|
|
private static final Gson GSON = (new GsonBuilder()).setPrettyPrinting().create();
|
|
private final File file;
|
|
- private final Map<String, V> map = Maps.newHashMap();
|
|
+ // Paper - replace HashMap is ConcurrentHashMap
|
|
+ private final Map<String, V> map = Maps.newConcurrentMap();
|
|
+ private boolean e = true;
|
|
+ private static final ParameterizedType f = new ParameterizedType() {
|
|
+ public Type[] getActualTypeArguments() {
|
|
+ return new Type[]{StoredUserEntry.class};
|
|
+ }
|
|
+
|
|
+ public Type getRawType() {
|
|
+ return List.class;
|
|
+ }
|
|
+
|
|
+ public Type getOwnerType() {
|
|
+ return null;
|
|
+ }
|
|
+ };
|
|
|
|
public StoredUserList(File file) {
|
|
this.file = file;
|
|
@@ -53,8 +70,13 @@ public abstract class StoredUserList<K, V extends StoredUserEntry<K>> {
|
|
|
|
@Nullable
|
|
public V get(K key) {
|
|
- this.removeExpired();
|
|
- return (V) this.map.get(this.getKeyForUser(key)); // CraftBukkit - fix decompile error
|
|
+ // 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) -> {
|
|
+ return v.hasExpired() ? null : v;
|
|
+ });
|
|
+ // Paper end
|
|
}
|
|
|
|
public void remove(K key) {
|
|
@@ -83,7 +105,8 @@ public abstract class StoredUserList<K, V extends StoredUserEntry<K>> {
|
|
// CraftBukkit end
|
|
|
|
public boolean isEmpty() {
|
|
- return this.map.size() < 1;
|
|
+ // return this.d.size() < 1; // Paper
|
|
+ return this.map.isEmpty(); // Paper - readability is the goal. As an aside, isEmpty() uses only sumCount() and a comparison. size() uses sumCount(), casts, and boolean logic
|
|
}
|
|
|
|
protected String getKeyForUser(K profile) {
|
|
@@ -95,14 +118,14 @@ public abstract class StoredUserList<K, V extends StoredUserEntry<K>> {
|
|
}
|
|
|
|
private void removeExpired() {
|
|
- List<K> list = Lists.newArrayList();
|
|
- Iterator iterator = this.map.values().iterator();
|
|
+ /*List<K> list = Lists.newArrayList();
|
|
+ Iterator iterator = this.d.values().iterator();
|
|
|
|
while (iterator.hasNext()) {
|
|
V v0 = (V) iterator.next(); // CraftBukkit - decompile error
|
|
|
|
if (v0.hasExpired()) {
|
|
- list.add(v0.getUser());
|
|
+ list.add(v0.getKey());
|
|
}
|
|
}
|
|
|
|
@@ -111,9 +134,11 @@ public abstract class StoredUserList<K, V extends StoredUserEntry<K>> {
|
|
while (iterator.hasNext()) {
|
|
K k0 = (K) iterator.next(); // CraftBukkit - decompile error
|
|
|
|
- this.map.remove(this.getKeyForUser(k0));
|
|
- }
|
|
+ this.d.remove(this.a(k0));
|
|
+ }*/
|
|
|
|
+ this.map.values().removeIf(StoredUserEntry::hasExpired);
|
|
+ // Paper end
|
|
}
|
|
|
|
protected abstract StoredUserEntry<K> createEntry(JsonObject json);
|
|
@@ -123,6 +148,7 @@ 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
|
|
JsonObject jsonobject = new JsonObject();
|