mirror of
https://hub.spigotmc.org/stash/scm/spigot/spigot.git
synced 2025-09-18 21:33:01 +00:00
223 lines
9.5 KiB
Diff
223 lines
9.5 KiB
Diff
From b495e37c71f52cb8f29218aa87546dabf7a44281 Mon Sep 17 00:00:00 2001
|
|
From: Thinkofdeath <thethinkofdeath@gmail.com>
|
|
Date: Sun, 20 Apr 2014 13:18:55 +0100
|
|
Subject: [PATCH] Convert player skulls async
|
|
|
|
|
|
diff --git a/src/main/java/net/minecraft/server/ItemSkull.java b/src/main/java/net/minecraft/server/ItemSkull.java
|
|
index cbb902f50..ca33c9c13 100644
|
|
--- a/src/main/java/net/minecraft/server/ItemSkull.java
|
|
+++ b/src/main/java/net/minecraft/server/ItemSkull.java
|
|
@@ -124,13 +124,21 @@ public class ItemSkull extends Item {
|
|
return super.b(itemstack);
|
|
}
|
|
|
|
- public boolean a(NBTTagCompound nbttagcompound) {
|
|
+ public boolean a(final NBTTagCompound nbttagcompound) { // Spigot - make final
|
|
super.a(nbttagcompound);
|
|
if (nbttagcompound.hasKeyOfType("SkullOwner", 8) && !StringUtils.isBlank(nbttagcompound.getString("SkullOwner"))) {
|
|
GameProfile gameprofile = new GameProfile((UUID) null, nbttagcompound.getString("SkullOwner"));
|
|
|
|
- gameprofile = TileEntitySkull.b(gameprofile);
|
|
- nbttagcompound.set("SkullOwner", GameProfileSerializer.serialize(new NBTTagCompound(), gameprofile));
|
|
+ // Spigot start
|
|
+ TileEntitySkull.b(gameprofile, new com.google.common.base.Predicate<GameProfile>() {
|
|
+
|
|
+ @Override
|
|
+ public boolean apply(GameProfile gameprofile) {
|
|
+ nbttagcompound.set("SkullOwner", GameProfileSerializer.serialize(new NBTTagCompound(), gameprofile));
|
|
+ return false;
|
|
+ }
|
|
+ });
|
|
+ // Spigot end
|
|
return true;
|
|
} else {
|
|
// CraftBukkit start
|
|
diff --git a/src/main/java/net/minecraft/server/TileEntitySkull.java b/src/main/java/net/minecraft/server/TileEntitySkull.java
|
|
index 223e2ed2d..1e3c687d6 100644
|
|
--- a/src/main/java/net/minecraft/server/TileEntitySkull.java
|
|
+++ b/src/main/java/net/minecraft/server/TileEntitySkull.java
|
|
@@ -7,6 +7,23 @@ import com.mojang.authlib.properties.Property;
|
|
import java.util.UUID;
|
|
import javax.annotation.Nullable;
|
|
|
|
+// Spigot start
|
|
+import com.google.common.base.Predicate;
|
|
+import com.google.common.cache.LoadingCache;
|
|
+import com.google.common.cache.CacheBuilder;
|
|
+import com.google.common.cache.CacheLoader;
|
|
+import com.google.common.util.concurrent.Futures;
|
|
+import java.util.concurrent.Executors;
|
|
+import java.util.concurrent.ExecutorService;
|
|
+import java.util.concurrent.Future;
|
|
+import java.util.concurrent.TimeUnit;
|
|
+
|
|
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
|
|
+import com.mojang.authlib.Agent;
|
|
+import com.mojang.authlib.ProfileLookupCallback;
|
|
+import java.util.concurrent.Callable;
|
|
+// Spigot end
|
|
+
|
|
public class TileEntitySkull extends TileEntity implements ITickable {
|
|
|
|
private int a;
|
|
@@ -16,6 +33,58 @@ public class TileEntitySkull extends TileEntity implements ITickable {
|
|
private boolean i;
|
|
private static UserCache j;
|
|
private static MinecraftSessionService k;
|
|
+ // Spigot start
|
|
+ public static final ExecutorService executor = Executors.newFixedThreadPool(3,
|
|
+ new ThreadFactoryBuilder()
|
|
+ .setNameFormat("Head Conversion Thread - %1$d")
|
|
+ .build()
|
|
+ );
|
|
+ public static final LoadingCache<String, GameProfile> skinCache = CacheBuilder.newBuilder()
|
|
+ .maximumSize( 5000 )
|
|
+ .expireAfterAccess( 60, TimeUnit.MINUTES )
|
|
+ .build( new CacheLoader<String, GameProfile>()
|
|
+ {
|
|
+ @Override
|
|
+ public GameProfile load(String key) throws Exception
|
|
+ {
|
|
+ final GameProfile[] profiles = new GameProfile[1];
|
|
+ ProfileLookupCallback gameProfileLookup = new ProfileLookupCallback() {
|
|
+
|
|
+ @Override
|
|
+ public void onProfileLookupSucceeded(GameProfile gp) {
|
|
+ profiles[0] = gp;
|
|
+ }
|
|
+
|
|
+ @Override
|
|
+ public void onProfileLookupFailed(GameProfile gp, Exception excptn) {
|
|
+ profiles[0] = gp;
|
|
+ }
|
|
+ };
|
|
+
|
|
+ MinecraftServer.getServer().getGameProfileRepository().findProfilesByNames(new String[] { key }, Agent.MINECRAFT, gameProfileLookup);
|
|
+
|
|
+ GameProfile profile = profiles[ 0 ];
|
|
+ if (profile == null) {
|
|
+ UUID uuid = EntityHuman.a(new GameProfile(null, key));
|
|
+ profile = new GameProfile(uuid, key);
|
|
+
|
|
+ gameProfileLookup.onProfileLookupSucceeded(profile);
|
|
+ } else
|
|
+ {
|
|
+
|
|
+ Property property = Iterables.getFirst( profile.getProperties().get( "textures" ), null );
|
|
+
|
|
+ if ( property == null )
|
|
+ {
|
|
+ profile = MinecraftServer.getServer().az().fillProfileProperties( profile, true );
|
|
+ }
|
|
+ }
|
|
+
|
|
+
|
|
+ return profile;
|
|
+ }
|
|
+ } );
|
|
+ // Spigot end
|
|
|
|
public TileEntitySkull() {}
|
|
|
|
@@ -98,35 +167,65 @@ public class TileEntitySkull extends TileEntity implements ITickable {
|
|
}
|
|
|
|
private void i() {
|
|
- this.g = b(this.g);
|
|
- this.update();
|
|
+ // Spigot start
|
|
+ GameProfile profile = this.g;
|
|
+ setSkullType( 0 ); // Work around client bug
|
|
+ b(profile, new Predicate<GameProfile>() {
|
|
+
|
|
+ @Override
|
|
+ public boolean apply(GameProfile input) {
|
|
+ setSkullType(3); // Work around client bug
|
|
+ g = input;
|
|
+ update();
|
|
+ if (world != null) {
|
|
+ world.m(position); // PAIL: notify
|
|
+ }
|
|
+ return false;
|
|
+ }
|
|
+ });
|
|
+ // Spigot end
|
|
}
|
|
|
|
- public static GameProfile b(GameProfile gameprofile) {
|
|
+ // Spigot start - Support async lookups
|
|
+ public static Future<GameProfile> b(final GameProfile gameprofile, final Predicate<GameProfile> callback) {
|
|
if (gameprofile != null && !UtilColor.b(gameprofile.getName())) {
|
|
if (gameprofile.isComplete() && gameprofile.getProperties().containsKey("textures")) {
|
|
- return gameprofile;
|
|
- } else if (TileEntitySkull.j != null && TileEntitySkull.k != null) {
|
|
- GameProfile gameprofile1 = TileEntitySkull.j.getProfile(gameprofile.getName());
|
|
+ callback.apply(gameprofile);
|
|
+ } else if (MinecraftServer.getServer() == null) {
|
|
+ callback.apply(gameprofile);
|
|
+ } else {
|
|
+ GameProfile profile = skinCache.getIfPresent(gameprofile.getName().toLowerCase(java.util.Locale.ROOT));
|
|
+ if (profile != null && Iterables.getFirst(profile.getProperties().get("textures"), (Object) null) != null) {
|
|
+ callback.apply(profile);
|
|
|
|
- if (gameprofile1 == null) {
|
|
- return gameprofile;
|
|
+ return Futures.immediateFuture(profile);
|
|
} else {
|
|
- Property property = (Property) Iterables.getFirst(gameprofile1.getProperties().get("textures"), (Object) null);
|
|
-
|
|
- if (property == null) {
|
|
- gameprofile1 = TileEntitySkull.k.fillProfileProperties(gameprofile1, true);
|
|
- }
|
|
-
|
|
- return gameprofile1;
|
|
+ return executor.submit(new Callable<GameProfile>() {
|
|
+ @Override
|
|
+ public GameProfile call() {
|
|
+ final GameProfile profile = skinCache.getUnchecked(gameprofile.getName().toLowerCase(java.util.Locale.ROOT));
|
|
+ MinecraftServer.getServer().processQueue.add(new Runnable() {
|
|
+ @Override
|
|
+ public void run() {
|
|
+ if (profile == null) {
|
|
+ callback.apply(gameprofile);
|
|
+ } else {
|
|
+ callback.apply(profile);
|
|
+ }
|
|
+ }
|
|
+ });
|
|
+ return profile;
|
|
+ }
|
|
+ });
|
|
}
|
|
- } else {
|
|
- return gameprofile;
|
|
}
|
|
} else {
|
|
- return gameprofile;
|
|
+ callback.apply(gameprofile);
|
|
}
|
|
+
|
|
+ return Futures.immediateFuture(gameprofile);
|
|
}
|
|
+ // Spigot end
|
|
|
|
public int getSkullType() {
|
|
return this.a;
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java
|
|
index 8c5d3effc..8a58615f8 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSkull.java
|
|
@@ -77,7 +77,8 @@ class CraftMetaSkull extends CraftMetaItem implements SkullMeta {
|
|
|
|
if (profile != null) {
|
|
// Fill in textures
|
|
- profile = TileEntitySkull.b(profile);
|
|
+ // Must be done sync due to way client handles textures
|
|
+ profile = com.google.common.util.concurrent.Futures.getUnchecked(TileEntitySkull.b(profile, com.google.common.base.Predicates.alwaysTrue())); // Spigot
|
|
|
|
NBTTagCompound owner = new NBTTagCompound();
|
|
GameProfileSerializer.serialize(owner, profile);
|
|
--
|
|
2.14.1
|
|
|