From 71b180df27698d5032be98a8f4793b538af47ae4 Mon Sep 17 00:00:00 2001 From: Sotr Date: Sun, 24 Mar 2019 04:58:06 +0800 Subject: [PATCH] Hotfix - initalise hidden players w/ refactor user cache system --- .../server/core/AkarinGlobalConfig.java | 5 + .../paper/profile/CraftPlayerProfile.java | 34 ++- .../net/minecraft/server/AkarinUserCache.java | 276 ++++++++++++++++++ .../net/minecraft/server/DedicatedServer.java | 2 +- .../java/net/minecraft/server/MCUtil.java | 2 +- .../net/minecraft/server/MinecraftServer.java | 10 +- .../server/NameReferencingFileConverter.java | 10 +- .../java/net/minecraft/server/PlayerList.java | 7 +- .../java/net/minecraft/server/UserCache.java | 16 +- .../java/net/minecraft/server/Village.java | 37 ++- .../craftbukkit/CraftProfileBanList.java | 52 +++- .../org/bukkit/craftbukkit/CraftServer.java | 4 +- .../bukkit/craftbukkit/block/CraftSkull.java | 20 +- .../craftbukkit/entity/CraftPlayer.java | 4 +- 14 files changed, 438 insertions(+), 41 deletions(-) create mode 100644 src/main/java/net/minecraft/server/AkarinUserCache.java diff --git a/src/api/main/java/io/akarin/server/core/AkarinGlobalConfig.java b/src/api/main/java/io/akarin/server/core/AkarinGlobalConfig.java index 312aceaee..8d97de55c 100644 --- a/src/api/main/java/io/akarin/server/core/AkarinGlobalConfig.java +++ b/src/api/main/java/io/akarin/server/core/AkarinGlobalConfig.java @@ -170,4 +170,9 @@ public class AkarinGlobalConfig { private static void lazyThreadAssertion() { lazyThreadAssertion = getBoolean("core.lazy-thread-assertion", lazyThreadAssertion); } + + public static int userCacheExpireDays = 30; + private static void userCacheExpireDays() { + userCacheExpireDays = getSeconds(getString("core.user-cache-expire-time", "30d")); + } } \ No newline at end of file diff --git a/src/main/java/com/destroystokyo/paper/profile/CraftPlayerProfile.java b/src/main/java/com/destroystokyo/paper/profile/CraftPlayerProfile.java index b151a13c1..7924eae34 100644 --- a/src/main/java/com/destroystokyo/paper/profile/CraftPlayerProfile.java +++ b/src/main/java/com/destroystokyo/paper/profile/CraftPlayerProfile.java @@ -3,8 +3,12 @@ package com.destroystokyo.paper.profile; import com.destroystokyo.paper.PaperConfig; import com.google.common.base.Charsets; import com.mojang.authlib.GameProfile; +import com.mojang.authlib.ProfileLookupCallback; import com.mojang.authlib.properties.Property; import com.mojang.authlib.properties.PropertyMap; + +import net.minecraft.server.AkarinUserCache; +import net.minecraft.server.EntityHuman; import net.minecraft.server.MinecraftServer; import net.minecraft.server.UserCache; import org.bukkit.craftbukkit.entity.CraftPlayer; @@ -143,7 +147,9 @@ public class CraftPlayerProfile implements PlayerProfile { } MinecraftServer server = MinecraftServer.getServer(); String name = profile.getName(); - UserCache userCache = server.getUserCache(); + // Akarin start + AkarinUserCache userCache = server.getModernUserCache(); + /* if (profile.getId() == null) { final GameProfile profile; boolean isOnlineMode = server.getOnlineMode() || (SpigotConfig.bungee && PaperConfig.bungeeOnlineMode); @@ -165,7 +171,31 @@ public class CraftPlayerProfile implements PlayerProfile { this.profile = profile; } } - return this.profile.isComplete(); + */ + ProfileLookupCallback callback = new ProfileLookupCallback() { + @Override + public void onProfileLookupSucceeded(GameProfile gameprofile) { + profile = gameprofile; + } + + @Override + public void onProfileLookupFailed(GameProfile gameprofile, Exception ex) { + ; + } + }; + + if (lookupName) { + userCache.acquire(name, callback, true); + } else { + GameProfile peeked = userCache.peek(name); + if (peeked.getName() == null) { + userCache.acquire(name, callback, true); + } else { + this.profile = peeked; + } + } + return true; + // Akarin end } public boolean complete(boolean textures) { diff --git a/src/main/java/net/minecraft/server/AkarinUserCache.java b/src/main/java/net/minecraft/server/AkarinUserCache.java new file mode 100644 index 000000000..e1db70c17 --- /dev/null +++ b/src/main/java/net/minecraft/server/AkarinUserCache.java @@ -0,0 +1,276 @@ +package net.minecraft.server; + +import java.io.BufferedReader; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.Locale; +import java.util.concurrent.TimeUnit; + +import javax.annotation.Nullable; + +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.spigotmc.SpigotConfig; + +import com.destroystokyo.paper.PaperConfig; +import com.github.benmanes.caffeine.cache.Cache; +import com.github.benmanes.caffeine.cache.Caffeine; +import com.google.common.base.Charsets; +import com.google.common.collect.Lists; +import com.google.common.io.Files; +import com.google.gson.Gson; +import com.google.gson.JsonParseException; +import com.google.gson.JsonSyntaxException; +import com.mojang.authlib.Agent; +import com.mojang.authlib.GameProfile; +import com.mojang.authlib.GameProfileRepository; +import com.mojang.authlib.ProfileLookupCallback; +import io.akarin.server.core.AkarinGlobalConfig; +import net.minecraft.server.UserCache.UserCacheEntry; + +public class AkarinUserCache { + private final static Logger LOGGER = LogManager.getLogger("Akarin"); + public static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z"); + + // Used to reduce date create + private final static long RECREATE_DATE_INTERVAL = TimeUnit.MILLISECONDS.convert(10, TimeUnit.MINUTES); + private static long lastWarpExpireDate; + private static Date lastExpireDate; + + /** + * All user caches, Username -> Entry(profile and expire date included) + */ + private final Cache profiles = Caffeine.newBuilder().maximumSize(SpigotConfig.userCacheCap).build(); + + private final GameProfileRepository profileHandler; + protected final Gson gson; + private final File userCacheFile; + + public static boolean isOnlineMode() { + return UserCache.isOnlineMode() || (SpigotConfig.bungee && PaperConfig.bungeeOnlineMode); + } + + public static Date createExpireDate(boolean force) { + long now = System.currentTimeMillis(); + if (force || (now - lastWarpExpireDate) > RECREATE_DATE_INTERVAL) { + lastWarpExpireDate = now; + Calendar calendar = Calendar.getInstance(); + + calendar.setTimeInMillis(now); + calendar.add(Calendar.DAY_OF_YEAR, AkarinGlobalConfig.userCacheExpireDays); + return lastExpireDate = calendar.getTime(); + } + + return lastExpireDate; + } + + public static boolean isExpired(UserCacheEntry entry) { + return System.currentTimeMillis() >= entry.getExpireDate().getTime(); + } + + public static UserCacheEntry refreshExpireDate(UserCacheEntry entry) { + return new UserCacheEntry(entry.getProfile(), createExpireDate(true)); + } + + public static GameProfile lookup(GameProfileRepository profileRepo, String keyUsername, ProfileLookupCallback callback, boolean async) { + if (!isOnlineMode()) + callback.onProfileLookupSucceeded(new GameProfile(EntityHuman.getOfflineUUID(keyUsername.toLowerCase(Locale.ROOT)), keyUsername)); + + GameProfile[] gameProfile = new GameProfile[1]; + ProfileLookupCallback callbackHandler = new ProfileLookupCallback() { + @Override + public void onProfileLookupSucceeded(GameProfile gameprofile) { + if (async) + callback.onProfileLookupSucceeded(gameprofile); + else + gameProfile[0] = gameprofile; + } + + @Override + public void onProfileLookupFailed(GameProfile gameprofile, Exception ex) { + LOGGER.warn("Failed to lookup player {}, using local UUID.", gameprofile.getName()); + if (async) + callback.onProfileLookupSucceeded(new GameProfile(EntityHuman.getOfflineUUID(keyUsername), keyUsername)); + else + gameProfile[0] = new GameProfile(EntityHuman.getOfflineUUID(keyUsername), keyUsername); + } + }; + + Runnable find = () -> profileRepo.findProfilesByNames(new String[] { keyUsername }, Agent.MINECRAFT, callbackHandler); + if (async) { + MCUtil.scheduleAsyncTask(find); + return null; // TODO: future + } else { + find.run(); + return gameProfile[0]; + } + } + + public AkarinUserCache(GameProfileRepository repo, File file, Gson gson) { + lastExpireDate = createExpireDate(true); + + this.profileHandler = repo; + this.userCacheFile = file; + this.gson = gson; + + this.load(); + } + + GameProfile lookupAndCache(String keyUsername, ProfileLookupCallback callback, boolean async) { + return lookupAndCache(keyUsername, callback, createExpireDate(false), async); + } + + GameProfile lookupAndCache(String keyUsername, ProfileLookupCallback callback, Date date, boolean async) { + ProfileLookupCallback callbackHandler = new ProfileLookupCallback() { + @Override + public void onProfileLookupSucceeded(GameProfile gameprofile) { + profiles.put(keyUsername, new UserCacheEntry(gameprofile, date)); + if (async) + callback.onProfileLookupSucceeded(gameprofile); + + if(!org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly) + save(); + } + + @Override + public void onProfileLookupFailed(GameProfile gameprofile, Exception ex) { + ; + } + }; + + return lookup(profileHandler, keyUsername, callbackHandler, async); + } + + public GameProfile acquire(String username) { + return acquire(username, null, false); + } + + public GameProfile acquire(String username, ProfileLookupCallback callback) { + return acquire(username, callback, true); + } + + public GameProfile acquire(String username, ProfileLookupCallback callback, boolean async) { + if (StringUtils.isBlank(username)) + return null; + + String keyUsername = isOnlineMode() ? username : username.toLowerCase(Locale.ROOT); + UserCacheEntry entry = profiles.getIfPresent(keyUsername); + + if (entry != null) { + if (isExpired(entry)) { + profiles.invalidate(keyUsername); + return lookupAndCache(keyUsername, callback, async); + } else { + if (async) { + callback.onProfileLookupSucceeded(entry.getProfile()); + return null; + } else { + return entry.getProfile(); + } + } + } + return lookupAndCache(keyUsername, callback, async); + } + + @Nullable + public GameProfile peek(String username) { + String keyUsername = isOnlineMode() ? username : username.toLowerCase(Locale.ROOT); + UserCacheEntry entry = profiles.getIfPresent(keyUsername); + return entry == null ? null : entry.getProfile(); + } + + void offer(GameProfile profile) { + offer(profile, createExpireDate(false)); + } + + void offer(GameProfile profile, Date date) { + String keyUsername = isOnlineMode() ? profile.getName() : profile.getName().toLowerCase(Locale.ROOT); + UserCacheEntry entry = profiles.getIfPresent(keyUsername); + + if (entry != null) { + // The offered profile may has an raw case, this only happened on offline servers with old caches, + // so replace with an lower-case profile. + if (!UserCache.isOnlineMode() && !entry.getProfile().getName().equals(profile.getName())) + entry = new UserCacheEntry(new GameProfile(entry.getProfile().getId(), keyUsername), date); + else + entry = refreshExpireDate(entry); + } else { + entry = new UserCacheEntry(profile, date); + } + + profiles.put(keyUsername, entry); + if (!SpigotConfig.saveUserCacheOnStopOnly) + this.save(); + } + + void offer(UserCacheEntry entry) { + if (!isExpired(entry)) + profiles.put(isOnlineMode() ? entry.getProfile().getName() : entry.getProfile().getName().toLowerCase(Locale.ROOT), entry); + } + + String[] usernames() { + return profiles.asMap().keySet().toArray(new String[profiles.asMap().size()]); + } + + protected void load() { + BufferedReader reader = null; + + try { + reader = Files.newReader(userCacheFile, Charsets.UTF_8); + List entries = this.gson.fromJson(reader, UserCache.PARAMETERIZED_TYPE); + profiles.invalidateAll(); + + if (entries != null && !entries.isEmpty()) + Lists.reverse(entries).forEach(this::offer); + } catch (FileNotFoundException e) { + ; + } catch (JsonSyntaxException e) { + LOGGER.warn("Usercache.json is corrupted or has bad formatting. Deleting it to prevent further issues."); + this.userCacheFile.delete(); + } catch (JsonParseException e) { + ; + } finally { + IOUtils.closeQuietly(reader); + } + } + + public void save() { + save(true); + } + + public void save(boolean async) { + Runnable save = () -> { + String jsonString = this.gson.toJson(this.entries()); + BufferedWriter writer = null; + + try { + writer = Files.newWriter(this.userCacheFile, Charsets.UTF_8); + writer.write(jsonString); + return; + } catch (FileNotFoundException e) { + return; + } catch (IOException io) { + ; + } finally { + IOUtils.closeQuietly(writer); + } + }; + + if (async) + MCUtil.scheduleAsyncTask(save); + else + save.run(); + } + + List entries() { + return Lists.newArrayList(profiles.asMap().values()); + } +} \ No newline at end of file diff --git a/src/main/java/net/minecraft/server/DedicatedServer.java b/src/main/java/net/minecraft/server/DedicatedServer.java index 21a05b2b2..92fd8bb1f 100644 --- a/src/main/java/net/minecraft/server/DedicatedServer.java +++ b/src/main/java/net/minecraft/server/DedicatedServer.java @@ -251,7 +251,7 @@ public class DedicatedServer extends MinecraftServer implements IMinecraftServer } if (this.aX()) { - this.getUserCache().c(); + this.getModernUserCache().load(); // Akarin } if (!NameReferencingFileConverter.a(this.propertyManager)) { diff --git a/src/main/java/net/minecraft/server/MCUtil.java b/src/main/java/net/minecraft/server/MCUtil.java index 2e060b516..1880f2dc2 100644 --- a/src/main/java/net/minecraft/server/MCUtil.java +++ b/src/main/java/net/minecraft/server/MCUtil.java @@ -27,7 +27,7 @@ import java.util.concurrent.TimeoutException; import java.util.function.Supplier; public final class MCUtil { - private static final Executor asyncExecutor = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("Paper Async Task Handler Thread - %1$d").build()); + private static final Executor asyncExecutor = Executors.newSingleThreadExecutor(new ThreadFactoryBuilder().setNameFormat("Akarin Async Task Handler Thread - %1$d").build()); // Akarin private MCUtil() {} diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java index b9036043d..6d5352fe7 100644 --- a/src/main/java/net/minecraft/server/MinecraftServer.java +++ b/src/main/java/net/minecraft/server/MinecraftServer.java @@ -180,6 +180,7 @@ public abstract class MinecraftServer implements IAsyncTaskHandler, IMojangStati this.V = minecraftsessionservice; this.W = gameprofilerepository; this.X = usercache; + this.userCache = new AkarinUserCache(gameprofilerepository, usercache.file(), usercache.gson()); // Akarin // this.universe = file; // CraftBukkit // this.serverConnection = new ServerConnection(this); // CraftBukkit // Spigot // this.convertable = file == null ? null : new WorldLoaderServer(file.toPath(), file.toPath().resolve("../backups"), datafixer); // CraftBukkit - moved to DedicatedServer.init @@ -693,7 +694,7 @@ public abstract class MinecraftServer implements IAsyncTaskHandler, IMojangStati // Spigot start if (org.spigotmc.SpigotConfig.saveUserCacheOnStopOnly) { LOGGER.info("Saving usercache.json"); - this.getUserCache().c(false); // Paper + this.getModernUserCache().save(false); // Paper // Akarin } // Spigot end } @@ -1666,6 +1667,13 @@ public abstract class MinecraftServer implements IAsyncTaskHandler, IMojangStati public UserCache getUserCache() { return this.X; } + // Akarin start + private final AkarinUserCache userCache; + + public AkarinUserCache getModernUserCache() { + return userCache; + } + // Akarin end public ServerPing getServerPing() { return this.m; diff --git a/src/main/java/net/minecraft/server/NameReferencingFileConverter.java b/src/main/java/net/minecraft/server/NameReferencingFileConverter.java index dcaba3c40..f387e3ae6 100644 --- a/src/main/java/net/minecraft/server/NameReferencingFileConverter.java +++ b/src/main/java/net/minecraft/server/NameReferencingFileConverter.java @@ -95,7 +95,7 @@ public class NameReferencingFileConverter { a(NameReferencingFileConverter.b, (Map) map); ProfileLookupCallback profilelookupcallback = new ProfileLookupCallback() { public void onProfileLookupSucceeded(GameProfile gameprofile) { - minecraftserver.getUserCache().a(gameprofile); + minecraftserver.getModernUserCache().offer(gameprofile); // Akarin String[] astring = (String[]) map.get(gameprofile.getName().toLowerCase(Locale.ROOT)); if (astring == null) { @@ -194,7 +194,7 @@ public class NameReferencingFileConverter { List list = Files.readLines(NameReferencingFileConverter.c, StandardCharsets.UTF_8); ProfileLookupCallback profilelookupcallback = new ProfileLookupCallback() { public void onProfileLookupSucceeded(GameProfile gameprofile) { - minecraftserver.getUserCache().a(gameprofile); + minecraftserver.getModernUserCache().offer(gameprofile); // Akarin oplist.add(new OpListEntry(gameprofile, minecraftserver.j(), false)); } @@ -239,7 +239,7 @@ public class NameReferencingFileConverter { List list = Files.readLines(NameReferencingFileConverter.d, StandardCharsets.UTF_8); ProfileLookupCallback profilelookupcallback = new ProfileLookupCallback() { public void onProfileLookupSucceeded(GameProfile gameprofile) { - minecraftserver.getUserCache().a(gameprofile); + minecraftserver.getModernUserCache().offer(gameprofile); // Akarin whitelist.add(new WhiteListEntry(gameprofile)); } @@ -277,7 +277,7 @@ public class NameReferencingFileConverter { final List list = Lists.newArrayList(); ProfileLookupCallback profilelookupcallback = new ProfileLookupCallback() { public void onProfileLookupSucceeded(GameProfile gameprofile1) { - minecraftserver.getUserCache().a(gameprofile1); + minecraftserver.getModernUserCache().offer(gameprofile1); // Akarin list.add(gameprofile1); } @@ -324,7 +324,7 @@ public class NameReferencingFileConverter { final String[] astring = (String[]) list.toArray(new String[list.size()]); ProfileLookupCallback profilelookupcallback = new ProfileLookupCallback() { public void onProfileLookupSucceeded(GameProfile gameprofile) { - dedicatedserver.getUserCache().a(gameprofile); + dedicatedserver.getModernUserCache().offer(gameprofile); // Akarin UUID uuid = gameprofile.getId(); if (uuid == null) { diff --git a/src/main/java/net/minecraft/server/PlayerList.java b/src/main/java/net/minecraft/server/PlayerList.java index f3eee29eb..de9be3548 100644 --- a/src/main/java/net/minecraft/server/PlayerList.java +++ b/src/main/java/net/minecraft/server/PlayerList.java @@ -97,11 +97,10 @@ public abstract class PlayerList { public void a(NetworkManager networkmanager, EntityPlayer entityplayer) { entityplayer.loginTime = System.currentTimeMillis(); // Paper GameProfile gameprofile = entityplayer.getProfile(); - UserCache usercache = this.server.getUserCache(); - GameProfile gameprofile1 = usercache.a(gameprofile.getId()); + AkarinUserCache usercache = this.server.getModernUserCache(); // Akarin + GameProfile gameprofile1 = usercache.peek(gameprofile.getName()); // Akarin String s = gameprofile1 == null ? gameprofile.getName() : gameprofile1.getName(); - - usercache.a(gameprofile); + usercache.offer(gameprofile); // Akarin NBTTagCompound nbttagcompound = this.a(entityplayer); // CraftBukkit start - Better rename detection if (nbttagcompound != null && nbttagcompound.hasKey("bukkit")) { diff --git a/src/main/java/net/minecraft/server/UserCache.java b/src/main/java/net/minecraft/server/UserCache.java index 059665836..65bb03952 100644 --- a/src/main/java/net/minecraft/server/UserCache.java +++ b/src/main/java/net/minecraft/server/UserCache.java @@ -47,8 +47,8 @@ public class UserCache { private final Map e = Maps.newHashMap(); private final Deque f = new java.util.concurrent.LinkedBlockingDeque(); // CraftBukkit private final GameProfileRepository g; - protected final Gson b; - private final File h; + protected final Gson b; protected Gson gson() { return this.b; } // Akarin - OBFHELPER + private final File h; File file() { return this.h; } // Akarin - OBFHELPER private static final ParameterizedType i = new ParameterizedType() { public Type[] getActualTypeArguments() { return new Type[] { UserCache.UserCacheEntry.class}; @@ -62,6 +62,7 @@ public class UserCache { return null; } }; + static final ParameterizedType PARAMETERIZED_TYPE = i; // Akarin - OBFHELPER public UserCache(GameProfileRepository gameprofilerepository, File file) { this.g = gameprofilerepository; @@ -100,6 +101,7 @@ public class UserCache { UserCache.c = flag; } + static boolean isOnlineMode() { return d(); } // Akarin - OBFHELPER private static boolean d() { return UserCache.c; } @@ -279,12 +281,12 @@ public class UserCache { return list; } - class UserCacheEntry { + static class UserCacheEntry { // Akarin - static private final GameProfile b;public GameProfile getProfile() { return b; } // Paper - OBFHELPER - private final Date c; + private final Date c; public Date getExpireDate() { return c; } // Akarin - OBFHELPER - private UserCacheEntry(GameProfile gameprofile, Date date) { + UserCacheEntry(GameProfile gameprofile, Date date) { // Akarin - package this.b = gameprofile; this.c = date; } @@ -298,7 +300,7 @@ public class UserCache { } } - class BanEntrySerializer implements JsonDeserializer, JsonSerializer { + static class BanEntrySerializer implements JsonDeserializer, JsonSerializer { // Akarin - static private BanEntrySerializer() {} @@ -342,7 +344,7 @@ public class UserCache { return null; } - return UserCache.this.new UserCacheEntry(new GameProfile(uuid, s1), date); + return new UserCacheEntry(new GameProfile(uuid, s1), date); // Akarin - static } else { return null; } diff --git a/src/main/java/net/minecraft/server/Village.java b/src/main/java/net/minecraft/server/Village.java index 1363c53ff..a32b6d664 100644 --- a/src/main/java/net/minecraft/server/Village.java +++ b/src/main/java/net/minecraft/server/Village.java @@ -3,6 +3,10 @@ package net.minecraft.server; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import com.mojang.authlib.GameProfile; +import com.mojang.authlib.ProfileLookupCallback; + +import net.minecraft.server.UserCache.UserCacheEntry; + import java.util.Iterator; import java.util.List; import java.util.Map; @@ -394,8 +398,8 @@ public class Village { NBTTagCompound nbttagcompound2 = nbttaglist1.getCompound(j); if (nbttagcompound2.hasKey("UUID") && this.a != null && this.a.getMinecraftServer() != null) { - UserCache usercache = this.a.getMinecraftServer().getUserCache(); - GameProfile gameprofile = usercache.a(UUID.fromString(nbttagcompound2.getString("UUID"))); + AkarinUserCache usercache = this.a.getMinecraftServer().getModernUserCache(); // Akarin + GameProfile gameprofile = usercache.peek(nbttagcompound2.getString("Name")); // Akarin if (gameprofile != null) { this.j.put(gameprofile.getName(), nbttagcompound2.getInt("S")); @@ -443,16 +447,31 @@ public class Village { while (iterator1.hasNext()) { String s = (String) iterator1.next(); NBTTagCompound nbttagcompound2 = new NBTTagCompound(); - UserCache usercache = this.a.getMinecraftServer().getUserCache(); + AkarinUserCache usercache = this.a.getMinecraftServer().getModernUserCache(); // Akarin try { - GameProfile gameprofile = usercache.getProfile(s); + // Akarin start + ProfileLookupCallback callback = new ProfileLookupCallback() { + @Override + public void onProfileLookupSucceeded(GameProfile gameprofile) { + nbttagcompound2.setString("UUID", gameprofile.getId().toString()); + nbttagcompound2.setInt("S", (Integer) j.get(s)); + nbttaglist1.add((NBTBase) nbttagcompound2); + } - if (gameprofile != null) { - nbttagcompound2.setString("UUID", gameprofile.getId().toString()); - nbttagcompound2.setInt("S", (Integer) this.j.get(s)); - nbttaglist1.add((NBTBase) nbttagcompound2); - } + @Override + public void onProfileLookupFailed(GameProfile gameprofile, Exception ex) { + ; + } + }; + usercache.acquire(s, callback); + + //if (gameprofile != null) { + // nbttagcompound2.setString("UUID", gameprofile.getId().toString()); + // nbttagcompound2.setInt("S", (Integer) this.j.get(s)); + // nbttaglist1.add((NBTBase) nbttagcompound2); + //} + // Akarin end } catch (RuntimeException runtimeexception) { ; } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftProfileBanList.java b/src/main/java/org/bukkit/craftbukkit/CraftProfileBanList.java index 84a1f9c86..f3060c869 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftProfileBanList.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftProfileBanList.java @@ -14,6 +14,8 @@ import org.apache.commons.lang.Validate; import com.google.common.collect.ImmutableSet; import com.mojang.authlib.GameProfile; +import com.mojang.authlib.ProfileLookupCallback; + import java.util.logging.Level; import org.bukkit.Bukkit; @@ -28,7 +30,7 @@ public class CraftProfileBanList implements org.bukkit.BanList { public org.bukkit.BanEntry getBanEntry(String target) { Validate.notNull(target, "Target cannot be null"); - GameProfile profile = MinecraftServer.getServer().getUserCache().getProfile(target); + GameProfile profile = MinecraftServer.getServer().getModernUserCache().acquire(target); if (profile == null) { return null; } @@ -45,7 +47,30 @@ public class CraftProfileBanList implements org.bukkit.BanList { public org.bukkit.BanEntry addBan(String target, String reason, Date expires, String source) { Validate.notNull(target, "Ban target cannot be null"); - GameProfile profile = MinecraftServer.getServer().getUserCache().getProfile(target); + // Akarin start + ProfileLookupCallback callback = new ProfileLookupCallback() { + @Override + public void onProfileLookupSucceeded(GameProfile profile) { + GameProfileBanEntry entry = new GameProfileBanEntry(profile, new Date(), + StringUtils.isBlank(source) ? null : source, expires, + StringUtils.isBlank(reason) ? null : reason); + + list.add(entry); + + try { + list.save(); + } catch (IOException ex) { + Bukkit.getLogger().log(Level.SEVERE, "Failed to save banned-players.json, {0}", ex.getMessage()); + } + } + + @Override + public void onProfileLookupFailed(GameProfile gameprofile, Exception ex) { + ; + } + }; + MinecraftServer.getServer().getModernUserCache().acquire(target, callback); + /* if (profile == null) { return null; } @@ -61,8 +86,10 @@ public class CraftProfileBanList implements org.bukkit.BanList { } catch (IOException ex) { Bukkit.getLogger().log(Level.SEVERE, "Failed to save banned-players.json, {0}", ex.getMessage()); } + */ - return new CraftProfileBanEntry(profile, entry, list); + return null; + // Akarin end } @Override @@ -81,7 +108,7 @@ public class CraftProfileBanList implements org.bukkit.BanList { public boolean isBanned(String target) { Validate.notNull(target, "Target cannot be null"); - GameProfile profile = MinecraftServer.getServer().getUserCache().getProfile(target); + GameProfile profile = MinecraftServer.getServer().getModernUserCache().acquire(target);// Akarin if (profile == null) { return false; } @@ -93,7 +120,20 @@ public class CraftProfileBanList implements org.bukkit.BanList { public void pardon(String target) { Validate.notNull(target, "Target cannot be null"); - GameProfile profile = MinecraftServer.getServer().getUserCache().getProfile(target); - list.remove(profile); + // Akarin start + ProfileLookupCallback callback = new ProfileLookupCallback() { + @Override + public void onProfileLookupSucceeded(GameProfile profile) { + list.remove(profile); + } + + @Override + public void onProfileLookupFailed(GameProfile gameprofile, Exception ex) { + ; + } + }; + GameProfile profile = MinecraftServer.getServer().getModernUserCache().acquire(target, callback); + //list.remove(profile); + // Akarin end } } diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java index 5b12fd20b..9b4ce2f31 100644 --- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java +++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java @@ -1434,7 +1434,7 @@ public final class CraftServer implements Server { // Only fetch an online UUID in online mode if (MinecraftServer.getServer().getOnlineMode() || (org.spigotmc.SpigotConfig.bungee && com.destroystokyo.paper.PaperConfig.bungeeOnlineMode)) { - profile = console.getUserCache().getProfile( name ); + profile = console.getModernUserCache().acquire( name ); // Akarin } else { // Make an OfflinePlayer using an offline mode UUID since the name has no profile profile = new GameProfile(UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8)), name); @@ -1457,7 +1457,7 @@ public final class CraftServer implements Server { if ( MinecraftServer.getServer().getOnlineMode() || com.destroystokyo.paper.PaperConfig.isProxyOnlineMode()) // Paper - Handle via setting { - profile = console.getUserCache().getProfile( name ); + profile = console.getModernUserCache().acquire( name ); // Akarin } // Spigot end if (profile == null) { diff --git a/src/main/java/org/bukkit/craftbukkit/block/CraftSkull.java b/src/main/java/org/bukkit/craftbukkit/block/CraftSkull.java index c260af11c..253cfb6b1 100644 --- a/src/main/java/org/bukkit/craftbukkit/block/CraftSkull.java +++ b/src/main/java/org/bukkit/craftbukkit/block/CraftSkull.java @@ -4,8 +4,11 @@ import com.destroystokyo.paper.profile.CraftPlayerProfile; import com.destroystokyo.paper.profile.PlayerProfile; import com.google.common.base.Preconditions; import com.mojang.authlib.GameProfile; +import com.mojang.authlib.ProfileLookupCallback; + import net.minecraft.server.MinecraftServer; import net.minecraft.server.TileEntitySkull; + import org.bukkit.Bukkit; import org.bukkit.Material; import org.bukkit.OfflinePlayer; @@ -74,12 +77,25 @@ public class CraftSkull extends CraftBlockEntityState implement return false; } - GameProfile profile = MinecraftServer.getServer().getUserCache().getProfile(name); + // Akarin start + ProfileLookupCallback callback = new ProfileLookupCallback() { + @Override + public void onProfileLookupSucceeded(GameProfile gameprofile) { + profile = gameprofile; + } + + @Override + public void onProfileLookupFailed(GameProfile gameprofile, Exception ex) { + ; + } + }; + GameProfile profile = MinecraftServer.getServer().getModernUserCache().acquire(name, callback); if (profile == null) { return false; } - this.profile = profile; + //this.profile = profile; + // Akarin end return true; } diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index 75ec5886a..b216a22db 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -5,6 +5,7 @@ import com.destroystokyo.paper.profile.CraftPlayerProfile; import com.destroystokyo.paper.profile.PlayerProfile; import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; +import com.google.common.collect.Sets; import com.google.common.io.BaseEncoding; import com.koloboke.collect.map.hash.HashObjObjMap; import com.koloboke.collect.map.hash.HashObjObjMaps; @@ -18,6 +19,7 @@ import java.net.InetSocketAddress; import java.net.SocketAddress; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; @@ -124,7 +126,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player { private boolean hasPlayedBefore = false; private final ConversationTracker conversationTracker = new ConversationTracker(); private final Set channels = new HashSet(); - private Map>> hiddenPlayers; // Akarin + private Map>> hiddenPlayers = Collections.emptyMap(); // Akarin private static final WeakHashMap> pluginWeakReferences = new WeakHashMap<>(); private int hash = 0; private double health = 20;