Archiviert
13
0

Add Setters for ID/Name and add completeByCache for Profile API

Dieser Commit ist enthalten in:
Aikar 2018-03-25 21:50:46 -04:00
Ursprung 9b12f54b69
Commit 658eca0c22
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 401ADFC9891FAAFE
2 geänderte Dateien mit 117 neuen und 29 gelöschten Zeilen

Datei anzeigen

@ -1,4 +1,4 @@
From 15f696b679672e955cf4f3186130eb9afa2e0df6 Mon Sep 17 00:00:00 2001
From 8a79fb272338e01bf067f3a27797b26311e25815 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Mon, 15 Jan 2018 21:46:46 -0500
Subject: [PATCH] Basic PlayerProfile API
@ -7,10 +7,10 @@ Provides basic elements of a PlayerProfile to be used by future API/events
diff --git a/src/main/java/com/destroystokyo/paper/profile/PlayerProfile.java b/src/main/java/com/destroystokyo/paper/profile/PlayerProfile.java
new file mode 100644
index 00000000..404fb468
index 00000000..e060c38a
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/profile/PlayerProfile.java
@@ -0,0 +1,125 @@
@@ -0,0 +1,149 @@
+package com.destroystokyo.paper.profile;
+
+import com.mojang.authlib.GameProfile;
@ -32,11 +32,27 @@ index 00000000..404fb468
+ @Nullable String getName();
+
+ /**
+ * Sets this profiles Name
+ *
+ * @param name The new Name
+ * @return The previous Name
+ */
+ String setName(@Nullable String name);
+
+ /**
+ * @return The players unique identifier, if set
+ */
+ @Nullable UUID getId();
+
+ /**
+ * Sets this profiles UUID
+ *
+ * @param uuid The new UUID
+ * @return The previous UUID
+ */
+ UUID setId(@Nullable UUID uuid);
+
+ /**
+ * @return A Mutable set of this players properties, such as textures.
+ * Values specified here are subject to implementation details.
+ */
@ -98,16 +114,24 @@ index 00000000..404fb468
+ void clearProperties();
+
+ /**
+ * @return Does this profile have Name, UUID and Textures filled in
+ * @return If the profile is now complete (has UUID and Name)
+ */
+ boolean isComplete();
+
+ /**
+ * Like {@link #complete(boolean)} but will try only from cache, and not make network calls
+ * Does not account for textures.
+ *
+ * @return If the profile is now complete (has UUID and Name)
+ */
+ boolean completeFromCache();
+
+ /**
+ * If this profile is not complete, then make the API call to complete it.
+ * This is a blocking operation and should be done asynchronously.
+ *
+ * This will also complete textures. If you do not want to load textures, use {{@link #complete(boolean)}}
+ * @return if the profile is now complete (if you get rate limited, this operation may fail)
+ * @return If the profile is now complete (has UUID and Name) (if you get rate limited, this operation may fail)
+ */
+ default boolean complete() {
+ return complete(true);
@ -118,7 +142,7 @@ index 00000000..404fb468
+ * This is a blocking operation and should be done asynchronously.
+ *
+ * Optionally will also fill textures.
+ * @return if the profile is now complete (if you get rate limited, this operation may fail)
+ * @return If the profile is now complete (has UUID and Name) (if you get rate limited, this operation may fail)
+ */
+ boolean complete(boolean textures);
+

Datei anzeigen

@ -1,4 +1,4 @@
From 66eb52192232cadf9810fdb683fe6c8294ee5a74 Mon Sep 17 00:00:00 2001
From dcdadafa3574152be245d8ebdad7d666a12006c1 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Mon, 15 Jan 2018 22:11:48 -0500
Subject: [PATCH] Basic PlayerProfile API
@ -6,10 +6,10 @@ Subject: [PATCH] Basic PlayerProfile API
diff --git a/src/main/java/com/destroystokyo/paper/profile/CraftPlayerProfile.java b/src/main/java/com/destroystokyo/paper/profile/CraftPlayerProfile.java
new file mode 100644
index 000000000..bb9d3fb8d
index 000000000..8cc85be8f
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/profile/CraftPlayerProfile.java
@@ -0,0 +1,248 @@
@@ -0,0 +1,276 @@
+package com.destroystokyo.paper.profile;
+
+import com.destroystokyo.paper.PaperConfig;
@ -18,6 +18,7 @@ index 000000000..bb9d3fb8d
+import com.mojang.authlib.properties.Property;
+import com.mojang.authlib.properties.PropertyMap;
+import net.minecraft.server.MinecraftServer;
+import net.minecraft.server.UserCache;
+import org.bukkit.craftbukkit.entity.CraftPlayer;
+import org.spigotmc.SpigotConfig;
+
@ -70,12 +71,28 @@ index 000000000..bb9d3fb8d
+ return profile.getId();
+ }
+
+ @Override
+ public UUID setId(@Nullable UUID uuid) {
+ GameProfile prev = this.profile;
+ this.profile = new GameProfile(uuid, prev.getName());
+ copyProfileProperties(prev, this.profile);
+ return prev.getId();
+ }
+
+ @Nullable
+ @Override
+ public String getName() {
+ return profile.getName();
+ }
+
+ @Override
+ public String setName(@Nullable String name) {
+ GameProfile prev = this.profile;
+ this.profile = new GameProfile(prev.getId(), name);
+ copyProfileProperties(prev, this.profile);
+ return prev.getName();
+ }
+
+ @Nonnull
+ @Override
+ public Set<ProfileProperty> getProperties() {
@ -127,25 +144,44 @@ index 000000000..bb9d3fb8d
+ return profile.isComplete();
+ }
+
+ public boolean complete(boolean textures) {
+ @Override
+ public boolean completeFromCache() {
+ return completeFromCache(false);
+ }
+
+ public boolean completeFromCache(boolean lookupName) {
+ MinecraftServer server = MinecraftServer.getServer();
+ String name = profile.getName();
+ UserCache userCache = server.getUserCache();
+ if (profile.getId() == null) {
+ GameProfile profile = getProfileByName(name);
+ final GameProfile profile;
+ boolean isOnlineMode = server.getOnlineMode() || (SpigotConfig.bungee && PaperConfig.bungeeOnlineMode);
+ if (isOnlineMode) {
+ profile = lookupName ? userCache.getProfile(name) : userCache.getProfileIfCached(name);
+ } 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);
+ }
+ if (profile == null) {
+ throw new NullPointerException("Could not get UUID for Player " + name);
+ }
+ this.profile = profile;
+ }
+ boolean needsTextures = textures && !hasTextures();
+ if (profile.getName() == null && !needsTextures) {
+
+ if (profile.getName() == null) {
+ // If we need textures, skip this check, as we will get it below anyways.
+ GameProfile profile = MinecraftServer.getServer().getUserCache().getProfile(this.profile.getId());
+ GameProfile profile = userCache.getProfile(this.profile.getId());
+ if (profile != null) {
+ this.profile = profile;
+ }
+ }
+ if (!profile.isComplete() || needsTextures) {
+ return this.profile.isComplete();
+ }
+
+ public boolean complete(boolean textures) {
+ MinecraftServer server = MinecraftServer.getServer();
+
+ if (!this.completeFromCache(true) || textures && !hasTextures()) {
+ GameProfile result = server.getSessionService().fillProfileProperties(profile, true);
+ if (result != null) {
+ this.profile = result;
@ -154,23 +190,15 @@ index 000000000..bb9d3fb8d
+ return profile.isComplete() && (!textures || hasTextures());
+ }
+
+ private static GameProfile getProfileByName(String name) {
+ final GameProfile profile;
+ final MinecraftServer server = MinecraftServer.getServer();
+ boolean isOnlineMode = server.getOnlineMode() || (SpigotConfig.bungee && PaperConfig.bungeeOnlineMode);
+ if (isOnlineMode) {
+ profile = server.getUserCache().getProfile(name);
+ } 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);
+ }
+ return profile;
+ }
+
+ private static void copyProfileProperties(GameProfile source, GameProfile target) {
+ PropertyMap sourceProperties = source.getProperties();
+ if (sourceProperties.isEmpty()) {
+ return;
+ }
+ PropertyMap properties = target.getProperties();
+ properties.clear();
+ for (Property property : source.getProperties().values()) {
+
+ for (Property property : sourceProperties.values()) {
+ properties.put(property.getName(), property);
+ }
+ }
@ -295,6 +323,42 @@ index e8bddc171..3b01ebd96 100644
public MinecraftSessionService az() {
return this.W;
}
diff --git a/src/main/java/net/minecraft/server/UserCache.java b/src/main/java/net/minecraft/server/UserCache.java
index 7ce08eb8b..6a750c25e 100644
--- a/src/main/java/net/minecraft/server/UserCache.java
+++ b/src/main/java/net/minecraft/server/UserCache.java
@@ -44,7 +44,7 @@ public class UserCache {
public static final SimpleDateFormat a = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z");
private static boolean c;
- private final Map<String, UserCache.UserCacheEntry> d = Maps.newHashMap();
+ private final Map<String, UserCache.UserCacheEntry> d = Maps.newHashMap();private final Map<String, UserCache.UserCacheEntry> nameCache = d; // Paper - OBFHELPER
private final Map<UUID, UserCache.UserCacheEntry> e = Maps.newHashMap();
private final Deque<GameProfile> f = new java.util.concurrent.LinkedBlockingDeque<GameProfile>(); // CraftBukkit
private final GameProfileRepository g;
@@ -173,6 +173,13 @@ public class UserCache {
return (String[]) arraylist.toArray(new String[arraylist.size()]);
}
+ // Paper start
+ @Nullable public GameProfile getProfileIfCached(String name) {
+ UserCache.UserCacheEntry entry = this.nameCache.get(name.toLowerCase(Locale.ROOT));
+ return entry == null ? null : entry.getProfile();
+ }
+ // Paper end
+
@Nullable public GameProfile getProfile(UUID uuid) { return a(uuid); } // Paper - OBFHELPER
@Nullable
public synchronized GameProfile a(UUID uuid) { // Paper - synchronize
@@ -282,7 +289,7 @@ public class UserCache {
class UserCacheEntry {
- private final GameProfile b;
+ private final GameProfile b;public GameProfile getProfile() { return b; } // Paper - OBFHELPER
private final Date c;
private UserCacheEntry(GameProfile gameprofile, Date date) {
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
index 77c16fe2c..2dd7ed96a 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java