aboutsummaryrefslogtreecommitdiffhomepage
path: root/patches/server/0172-Fill-Profile-Property-Events.patch
blob: ef1f330999a119d41c9adee9d59fce3f0f09a970 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Tue, 2 Jan 2018 00:31:26 -0500
Subject: [PATCH] Fill Profile Property Events

Allows plugins to populate profile properties from local sources to avoid calls out to Mojang API
to fill in textures for example.

If Mojang API does need to be hit, event fire so you can get the results.

This is useful for implementing a ProfileCache for Player Skulls

diff --git a/src/main/java/com/destroystokyo/paper/profile/PaperMinecraftSessionService.java b/src/main/java/com/destroystokyo/paper/profile/PaperMinecraftSessionService.java
index 985e6fc43a0946943847e0c283426242ef594a26..d577384797bb381eb57437f57b726ea8e4feb80b 100644
--- a/src/main/java/com/destroystokyo/paper/profile/PaperMinecraftSessionService.java
+++ b/src/main/java/com/destroystokyo/paper/profile/PaperMinecraftSessionService.java
@@ -1,6 +1,7 @@
 package com.destroystokyo.paper.profile;
 
 import com.mojang.authlib.Environment;
+import com.mojang.authlib.GameProfile;
 import com.mojang.authlib.yggdrasil.ProfileResult;
 import com.mojang.authlib.yggdrasil.ServicesKeySet;
 import com.mojang.authlib.yggdrasil.YggdrasilMinecraftSessionService;
@@ -15,7 +16,21 @@ public class PaperMinecraftSessionService extends YggdrasilMinecraftSessionServi
         super(servicesKeySet, proxy, environment);
     }
 
-    @Override
+    public @Nullable ProfileResult fetchProfile(GameProfile profile, final boolean requireSecure) {
+        CraftPlayerProfile playerProfile = (CraftPlayerProfile) CraftPlayerProfile.asBukkitMirror(profile);
+        new com.destroystokyo.paper.event.profile.PreFillProfileEvent(playerProfile).callEvent();
+        profile = playerProfile.getGameProfile();
+        if (profile.getProperties().containsKey("textures")) {
+            return new ProfileResult(profile, java.util.Collections.emptySet());
+        }
+        ProfileResult result = super.fetchProfile(profile.getId(), requireSecure);
+        if (result != null) {
+            new com.destroystokyo.paper.event.profile.FillProfileEvent(CraftPlayerProfile.asBukkitMirror(result.profile())).callEvent();
+        }
+        return result;
+    }
+
+    @Override @io.papermc.paper.annotation.DoNotUse @Deprecated
     public @Nullable ProfileResult fetchProfile(final UUID profileId, final boolean requireSecure) {
         return super.fetchProfile(profileId, requireSecure);
     }
diff --git a/src/main/java/net/minecraft/world/item/component/ResolvableProfile.java b/src/main/java/net/minecraft/world/item/component/ResolvableProfile.java
index d8ed3404e8c3c61b2daff110ef32ef890a77a461..78863e72239a0f3535bc85758479da84d58c11c1 100644
--- a/src/main/java/net/minecraft/world/item/component/ResolvableProfile.java
+++ b/src/main/java/net/minecraft/world/item/component/ResolvableProfile.java
@@ -49,7 +49,7 @@ public record ResolvableProfile(Optional<String> name, Optional<UUID> id, Proper
         if (this.isResolved()) {
             return CompletableFuture.completedFuture(this);
         } else {
-            return this.id.isPresent() ? SkullBlockEntity.fetchGameProfile(this.id.get()).thenApply(optional -> {
+            return this.id.isPresent() ? SkullBlockEntity.fetchGameProfile(this.id.get(), this.name.orElse(null)).thenApply(optional -> { // Paper - player profile events
                 GameProfile gameProfile = optional.orElseGet(() -> new GameProfile(this.id.get(), this.name.orElse("")));
                 return new ResolvableProfile(gameProfile);
             }) : SkullBlockEntity.fetchGameProfile(this.name.orElseThrow()).thenApply(profile -> {
diff --git a/src/main/java/net/minecraft/world/level/block/entity/SkullBlockEntity.java b/src/main/java/net/minecraft/world/level/block/entity/SkullBlockEntity.java
index ebba6bc5b337d19e32be5a78294501ed8300f2bd..81d9a4e6bc1bc4f992ecb77b176daf89d645bbf2 100644
--- a/src/main/java/net/minecraft/world/level/block/entity/SkullBlockEntity.java
+++ b/src/main/java/net/minecraft/world/level/block/entity/SkullBlockEntity.java
@@ -41,7 +41,7 @@ public class SkullBlockEntity extends BlockEntity {
     @Nullable
     private static LoadingCache<String, CompletableFuture<Optional<GameProfile>>> profileCacheByName;
     @Nullable
-    private static LoadingCache<UUID, CompletableFuture<Optional<GameProfile>>> profileCacheById;
+    private static LoadingCache<com.mojang.datafixers.util.Pair<java.util.UUID,  @org.jetbrains.annotations.Nullable GameProfile>, CompletableFuture<Optional<GameProfile>>> profileCacheById; // Paper - player profile events
     public static final Executor CHECKED_MAIN_THREAD_EXECUTOR = runnable -> {
         Executor executor = mainThreadExecutor;
         if (executor != null) {
@@ -76,9 +76,9 @@ public class SkullBlockEntity extends BlockEntity {
         profileCacheById = CacheBuilder.newBuilder()
             .expireAfterAccess(Duration.ofMinutes(10L))
             .maximumSize(256L)
-            .build(new CacheLoader<UUID, CompletableFuture<Optional<GameProfile>>>() {
+            .build(new CacheLoader<>() { // Paper - player profile events
                 @Override
-                public CompletableFuture<Optional<GameProfile>> load(UUID uUID) {
+                public CompletableFuture<Optional<GameProfile>> load(com.mojang.datafixers.util.Pair<java.util.UUID, @org.jetbrains.annotations.Nullable GameProfile> uUID) { // Paper - player profile events
                     return SkullBlockEntity.fetchProfileById(uUID, apiServices, booleanSupplier);
                 }
             });
@@ -89,20 +89,26 @@ public class SkullBlockEntity extends BlockEntity {
             .getAsync(name)
             .thenCompose(
                 optional -> {
-                    LoadingCache<UUID, CompletableFuture<Optional<GameProfile>>> loadingCache = profileCacheById;
+                    LoadingCache<com.mojang.datafixers.util.Pair<java.util.UUID, @org.jetbrains.annotations.Nullable GameProfile>, CompletableFuture<Optional<GameProfile>>> loadingCache = profileCacheById; // Paper - player profile events
                     return loadingCache != null && !optional.isEmpty()
-                        ? loadingCache.getUnchecked(optional.get().getId()).thenApply(optional2 -> optional2.or(() -> optional))
+                        ? loadingCache.getUnchecked(new com.mojang.datafixers.util.Pair<>(optional.get().getId(), optional.get())).thenApply(optional2 -> optional2.or(() -> optional)) // Paper - player profile events
                         : CompletableFuture.completedFuture(Optional.empty());
                 }
             );
     }
 
-    static CompletableFuture<Optional<GameProfile>> fetchProfileById(UUID uuid, Services apiServices, BooleanSupplier booleanSupplier) {
+    static CompletableFuture<Optional<GameProfile>> fetchProfileById(com.mojang.datafixers.util.Pair<java.util.UUID, @org.jetbrains.annotations.Nullable GameProfile> pair, Services apiServices, BooleanSupplier booleanSupplier) { // Paper
         return CompletableFuture.supplyAsync(() -> {
             if (booleanSupplier.getAsBoolean()) {
                 return Optional.empty();
             } else {
-                ProfileResult profileResult = apiServices.sessionService().fetchProfile(uuid, true);
+                // Paper start - fill player profile events
+                if (apiServices.sessionService() instanceof com.destroystokyo.paper.profile.PaperMinecraftSessionService paperService) {
+                    final GameProfile profile = pair.getSecond() != null ? pair.getSecond() : new com.mojang.authlib.GameProfile(pair.getFirst(), "");
+                    return Optional.ofNullable(paperService.fetchProfile(profile, true)).map(ProfileResult::profile);
+                }
+                ProfileResult profileResult = apiServices.sessionService().fetchProfile(pair.getFirst(), true);
+                // Paper end - fill player profile events
                 return Optional.ofNullable(profileResult).map(ProfileResult::profile);
             }
         }, Util.PROFILE_EXECUTOR); // Paper - don't submit BLOCKING PROFILE LOOKUPS to the world gen thread
@@ -210,9 +216,11 @@ public class SkullBlockEntity extends BlockEntity {
             : CompletableFuture.completedFuture(Optional.empty());
     }
 
-    public static CompletableFuture<Optional<GameProfile>> fetchGameProfile(UUID uuid) {
-        LoadingCache<UUID, CompletableFuture<Optional<GameProfile>>> loadingCache = profileCacheById;
-        return loadingCache != null ? loadingCache.getUnchecked(uuid) : CompletableFuture.completedFuture(Optional.empty());
+    // Paper start - player profile events
+    public static CompletableFuture<Optional<GameProfile>> fetchGameProfile(UUID uuid, @Nullable String name) {
+        LoadingCache<com.mojang.datafixers.util.Pair<java.util.UUID,  @org.jetbrains.annotations.Nullable GameProfile>, CompletableFuture<Optional<GameProfile>>> loadingCache = profileCacheById;
+        return loadingCache != null ? loadingCache.getUnchecked(new com.mojang.datafixers.util.Pair<>(uuid, name != null ? new com.mojang.authlib.GameProfile(uuid, name) : null)) : CompletableFuture.completedFuture(Optional.empty());
+        // Paper end - player profile events
     }
 
     @Override