mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-28 19:22:50 +01:00
094bb03a37
- Lots of itemstack cloning removed. Only clone if the item is actually moved - Return true when a plugin cancels inventory move item event instead of false, as false causes pulls to cycle through all items. However, pushes do not exhibit the same behavior, so this is not something plugins could of been relying on. - Add option (Default on) to cooldown hoppers when they fail to move an item due to full inventory - Skip subsequent InventoryMoveItemEvents if a plugin does not use the item after first event fire for an iteration
100 lines
3.6 KiB
Diff
100 lines
3.6 KiB
Diff
From 5a73d0282b24f09156533a66c32aa2f86ba00541 Mon Sep 17 00:00:00 2001
|
|
From: Aikar <aikar@aikar.co>
|
|
Date: Mon, 16 May 2016 20:47:41 -0400
|
|
Subject: [PATCH] Optimize UserCache / Thread Safe
|
|
|
|
Because Techable keeps complaining about how this isn't thread safe,
|
|
easier to do this than replace the entire thing.
|
|
|
|
Additionally, move Saving of the User cache to be done async, incase
|
|
the user never changed the default setting for Spigot's save on stop only.
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
index 45d3dbde2..ab7933079 100644
|
|
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
|
@@ -528,7 +528,7 @@ public abstract class MinecraftServer implements ICommandListener, Runnable, IAs
|
|
// Spigot start
|
|
if (org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly) {
|
|
LOGGER.info("Saving usercache.json");
|
|
- this.Y.c();
|
|
+ this.Y.c(false); // Paper
|
|
}
|
|
// Spigot end
|
|
}
|
|
diff --git a/src/main/java/net/minecraft/server/UserCache.java b/src/main/java/net/minecraft/server/UserCache.java
|
|
index 487fc11f1..924dc63a4 100644
|
|
--- a/src/main/java/net/minecraft/server/UserCache.java
|
|
+++ b/src/main/java/net/minecraft/server/UserCache.java
|
|
@@ -109,7 +109,7 @@ public class UserCache {
|
|
this.a(gameprofile, (Date) null);
|
|
}
|
|
|
|
- private void a(GameProfile gameprofile, Date date) {
|
|
+ private synchronized void a(GameProfile gameprofile, Date date) { // Paper - synchronize
|
|
UUID uuid = gameprofile.getId();
|
|
|
|
if (date == null) {
|
|
@@ -123,8 +123,9 @@ public class UserCache {
|
|
String s = gameprofile.getName().toLowerCase(Locale.ROOT);
|
|
UserCache.UserCacheEntry usercache_usercacheentry = new UserCache.UserCacheEntry(gameprofile, date, null);
|
|
|
|
- if (this.e.containsKey(uuid)) {
|
|
+ //if (this.e.containsKey(uuid)) { // Paper
|
|
UserCache.UserCacheEntry usercache_usercacheentry1 = (UserCache.UserCacheEntry) this.e.get(uuid);
|
|
+ if (usercache_usercacheentry1 != null) { // Paper
|
|
|
|
this.d.remove(usercache_usercacheentry1.a().getName().toLowerCase(Locale.ROOT));
|
|
this.f.remove(gameprofile);
|
|
@@ -137,7 +138,7 @@ public class UserCache {
|
|
}
|
|
|
|
@Nullable
|
|
- public GameProfile getProfile(String s) {
|
|
+ public synchronized GameProfile getProfile(String s) { // Paper - synchronize
|
|
String s1 = s.toLowerCase(Locale.ROOT);
|
|
UserCache.UserCacheEntry usercache_usercacheentry = (UserCache.UserCacheEntry) this.d.get(s1);
|
|
|
|
@@ -166,7 +167,7 @@ public class UserCache {
|
|
return usercache_usercacheentry == null ? null : usercache_usercacheentry.a();
|
|
}
|
|
|
|
- public String[] a() {
|
|
+ public synchronized String[] a() { // Paper - synchronize
|
|
ArrayList arraylist = Lists.newArrayList(this.d.keySet());
|
|
|
|
return (String[]) arraylist.toArray(new String[arraylist.size()]);
|
|
@@ -228,8 +229,15 @@ public class UserCache {
|
|
|
|
}
|
|
|
|
+ // Paper start
|
|
public void c() {
|
|
+ c(true);
|
|
+ }
|
|
+ public void c(boolean asyncSave) {
|
|
+ // Paper end
|
|
String s = this.b.toJson(this.a(org.spigotmc.SpigotConfig.userCacheCap));
|
|
+ Runnable save = () -> {
|
|
+
|
|
BufferedWriter bufferedwriter = null;
|
|
|
|
try {
|
|
@@ -243,6 +251,14 @@ public class UserCache {
|
|
} finally {
|
|
IOUtils.closeQuietly(bufferedwriter);
|
|
}
|
|
+ // Paper start
|
|
+ };
|
|
+ if (asyncSave) {
|
|
+ MCUtil.scheduleAsyncTask(save);
|
|
+ } else {
|
|
+ save.run();
|
|
+ }
|
|
+ // Paper end
|
|
|
|
}
|
|
|
|
--
|
|
2.16.1
|
|
|