Update Profile Lookup Events to use new PlayerProfile API
This commit is contained in:
@@ -4,11 +4,11 @@ Date: Mon, 15 Jan 2018 22:11:48 -0500
|
||||
Subject: [PATCH] Basic PlayerProfile API
|
||||
|
||||
|
||||
diff --git a/src/main/java/com/destroystokyo/paper/profile/CraftGameProfile.java b/src/main/java/com/destroystokyo/paper/profile/CraftGameProfile.java
|
||||
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..9891d8f06
|
||||
index 000000000..6e9a6a2e6
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/com/destroystokyo/paper/profile/CraftGameProfile.java
|
||||
+++ b/src/main/java/com/destroystokyo/paper/profile/CraftPlayerProfile.java
|
||||
@@ -0,0 +0,0 @@
|
||||
+package com.destroystokyo.paper.profile;
|
||||
+
|
||||
@@ -23,7 +23,7 @@ index 000000000..9891d8f06
|
||||
+import java.util.UUID;
|
||||
+import java.util.stream.Collectors;
|
||||
+
|
||||
+public class CraftGameProfile implements PlayerProfile {
|
||||
+public class CraftPlayerProfile implements PlayerProfile {
|
||||
+
|
||||
+ private final GameProfile profile;
|
||||
+
|
||||
@@ -36,7 +36,7 @@ index 000000000..9891d8f06
|
||||
+ * @param name Display name of the profile
|
||||
+ * @throws IllegalArgumentException Both ID and name are either null or empty
|
||||
+ */
|
||||
+ public CraftGameProfile(UUID id, String name) {
|
||||
+ public CraftPlayerProfile(UUID id, String name) {
|
||||
+ this.profile = new GameProfile(id, name);
|
||||
+ }
|
||||
+
|
||||
@@ -53,7 +53,7 @@ index 000000000..9891d8f06
|
||||
+ @Nonnull
|
||||
+ @Override
|
||||
+ public Set<ProfileProperty> getProperties() {
|
||||
+ return profile.getProperties().values().stream().map(this::toBukkit).collect(Collectors.toSet());
|
||||
+ return profile.getProperties().values().stream().map(CraftPlayerProfile::toBukkit).collect(Collectors.toSet());
|
||||
+ }
|
||||
+
|
||||
+ @Nullable
|
||||
@@ -105,12 +105,22 @@ index 000000000..9891d8f06
|
||||
+ return profile.isComplete();
|
||||
+ }
|
||||
+
|
||||
+ private ProfileProperty toBukkit(Property property) {
|
||||
+ private static ProfileProperty toBukkit(Property property) {
|
||||
+ return new ProfileProperty(property.getName(), property.getValue(), property.getSignature());
|
||||
+ }
|
||||
+
|
||||
+ public static PlayerProfile from(GameProfile gameProfile) {
|
||||
+ PlayerProfile profile = new CraftPlayerProfile(gameProfile.getId(), gameProfile.getName());
|
||||
+ gameProfile.getProperties().values().forEach(property -> profile.setProperty(toBukkit(property)));
|
||||
+ return profile;
|
||||
+ }
|
||||
+
|
||||
+ public static Property asAuthlib(ProfileProperty property) {
|
||||
+ return new Property(property.getName(), property.getValue(), property.getSignature());
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftServer.java b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
index 8d0a9e8ca..7d26531d8 100644
|
||||
index 8d0a9e8ca..f0ae65f08 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/CraftServer.java
|
||||
@@ -0,0 +0,0 @@ import org.bukkit.craftbukkit.util.CraftNamespacedKey;
|
||||
@@ -138,7 +148,7 @@ index 8d0a9e8ca..7d26531d8 100644
|
||||
+ }
|
||||
+
|
||||
+ public com.destroystokyo.paper.profile.PlayerProfile createProfile(@Nullable UUID uuid, @Nullable String name) {
|
||||
+ return new com.destroystokyo.paper.profile.CraftGameProfile(uuid, name);
|
||||
+ return new com.destroystokyo.paper.profile.CraftPlayerProfile(uuid, name);
|
||||
+ }
|
||||
// Paper end
|
||||
}
|
||||
|
||||
@@ -6,15 +6,91 @@ Subject: [PATCH] Profile Lookup Events
|
||||
Adds a Pre Lookup Event and a Post Lookup Event so that plugins may prefill in profile data, and cache the responses from
|
||||
profiles that had to be looked up.
|
||||
|
||||
diff --git a/src/main/java/com/destroystokyo/paper/profile/WrappedGameProfileRepository.java b/src/main/java/com/destroystokyo/paper/profile/WrappedGameProfileRepository.java
|
||||
new file mode 100644
|
||||
index 000000000..950fa930d
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/com/destroystokyo/paper/profile/WrappedGameProfileRepository.java
|
||||
@@ -0,0 +0,0 @@
|
||||
+package com.destroystokyo.paper.profile;
|
||||
+
|
||||
+import com.destroystokyo.paper.event.profile.LookupProfileEvent;
|
||||
+import com.destroystokyo.paper.event.profile.PreLookupProfileEvent;
|
||||
+import com.google.common.collect.Sets;
|
||||
+import com.mojang.authlib.Agent;
|
||||
+import com.mojang.authlib.GameProfile;
|
||||
+import com.mojang.authlib.GameProfileRepository;
|
||||
+import com.mojang.authlib.ProfileLookupCallback;
|
||||
+import com.mojang.authlib.properties.Property;
|
||||
+
|
||||
+import javax.annotation.Nonnull;
|
||||
+import java.util.Set;
|
||||
+
|
||||
+public class WrappedGameProfileRepository implements GameProfileRepository {
|
||||
+
|
||||
+ private final GameProfileRepository orig;
|
||||
+ public WrappedGameProfileRepository(@Nonnull GameProfileRepository orig) {
|
||||
+ this.orig = orig;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void findProfilesByNames(String[] names, Agent agent, ProfileLookupCallback callback) {
|
||||
+ Set<String> unfoundNames = Sets.newHashSet();
|
||||
+ for (String name : names) {
|
||||
+ PreLookupProfileEvent event = new PreLookupProfileEvent(name);
|
||||
+ event.callEvent();
|
||||
+ if (event.getUUID() != null) {
|
||||
+ // Plugin provided UUI, we can skip network call.
|
||||
+ GameProfile gameprofile = new GameProfile(event.getUUID(), name);
|
||||
+ // We might even have properties!
|
||||
+ Set<ProfileProperty> profileProperties = event.getProfileProperties();
|
||||
+ if (!profileProperties.isEmpty()) {
|
||||
+ for (ProfileProperty property : profileProperties) {
|
||||
+ gameprofile.getProperties().put(property.getName(), CraftPlayerProfile.asAuthlib(property));
|
||||
+ }
|
||||
+ }
|
||||
+ callback.onProfileLookupSucceeded(gameprofile);
|
||||
+ } else {
|
||||
+ unfoundNames.add(name);
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ // Some things were not found.... Proceed to look up.
|
||||
+ if (!unfoundNames.isEmpty()) {
|
||||
+ String[] namesArr = unfoundNames.toArray(new String[unfoundNames.size()]);
|
||||
+ orig.findProfilesByNames(namesArr, agent, new PreProfileLookupCallback(callback));
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+ private static class PreProfileLookupCallback implements ProfileLookupCallback {
|
||||
+ private final ProfileLookupCallback callback;
|
||||
+
|
||||
+ PreProfileLookupCallback(ProfileLookupCallback callback) {
|
||||
+ this.callback = callback;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void onProfileLookupSucceeded(GameProfile gameProfile) {
|
||||
+ PlayerProfile from = CraftPlayerProfile.from(gameProfile);
|
||||
+ new LookupProfileEvent(from).callEvent();
|
||||
+ callback.onProfileLookupSucceeded(gameProfile);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void onProfileLookupFailed(GameProfile gameProfile, Exception e) {
|
||||
+ callback.onProfileLookupFailed(gameProfile, e);
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
diff --git a/src/main/java/net/minecraft/server/MinecraftServer.java b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
index e8bddc171..0e255861d 100644
|
||||
index e8bddc171..6159cf4c0 100644
|
||||
--- a/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
+++ b/src/main/java/net/minecraft/server/MinecraftServer.java
|
||||
@@ -0,0 +0,0 @@ public abstract class MinecraftServer implements ICommandListener, Runnable, IAs
|
||||
YggdrasilAuthenticationService yggdrasilauthenticationservice = new YggdrasilAuthenticationService(Proxy.NO_PROXY, UUID.randomUUID().toString());
|
||||
MinecraftSessionService minecraftsessionservice = yggdrasilauthenticationservice.createMinecraftSessionService();
|
||||
GameProfileRepository gameprofilerepository = yggdrasilauthenticationservice.createProfileRepository();
|
||||
+ gameprofilerepository = com.destroystokyo.paper.event.profile.PreLookupProfileEvent.wrapProfileRepository(gameprofilerepository); // Paper
|
||||
+ gameprofilerepository = new com.destroystokyo.paper.profile.WrappedGameProfileRepository(gameprofilerepository); // Paper
|
||||
UserCache usercache = new UserCache(gameprofilerepository, new File(s1, MinecraftServer.a.getName()));
|
||||
final DedicatedServer dedicatedserver = new DedicatedServer(options, DataConverterRegistry.a(), yggdrasilauthenticationservice, minecraftsessionservice, gameprofilerepository, usercache);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user