aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0226-Fill-Profile-Property-Events.patch
blob: d2684ddb9f4a2c21142237b7371fa7cbb5818f47 (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
From e0ef1c07627248d2d678a1f2e78bd60b763dc9e6 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 4b2a67423f..61cfdf73c8 100644
--- a/src/main/java/com/destroystokyo/paper/profile/PaperMinecraftSessionService.java
+++ b/src/main/java/com/destroystokyo/paper/profile/PaperMinecraftSessionService.java
@@ -1,5 +1,7 @@
 package com.destroystokyo.paper.profile;
 
+import com.destroystokyo.paper.event.profile.FillProfileEvent;
+import com.destroystokyo.paper.event.profile.PreFillProfileEvent;
 import com.mojang.authlib.GameProfile;
 import com.mojang.authlib.minecraft.MinecraftProfileTexture;
 import com.mojang.authlib.yggdrasil.YggdrasilAuthenticationService;
@@ -19,7 +21,15 @@ public class PaperMinecraftSessionService extends YggdrasilMinecraftSessionServi
 
     @Override
     public GameProfile fillProfileProperties(GameProfile profile, boolean requireSecure) {
-        return super.fillProfileProperties(profile, requireSecure);
+        CraftPlayerProfile playerProfile = (CraftPlayerProfile) CraftPlayerProfile.asBukkitMirror(profile);
+        new PreFillProfileEvent(playerProfile).callEvent();
+        profile = playerProfile.getGameProfile();
+        if (profile.isComplete() && profile.getProperties().containsKey("textures")) {
+            return profile;
+        }
+        GameProfile gameProfile = super.fillProfileProperties(profile, requireSecure);
+        new FillProfileEvent(CraftPlayerProfile.asBukkitMirror(gameProfile)).callEvent();
+        return gameProfile;
     }
 
     @Override
-- 
2.21.0