diff --git a/paper-api/src/main/java/com/destroystokyo/paper/event/profile/LookupProfileEvent.java b/paper-api/src/main/java/com/destroystokyo/paper/event/profile/LookupProfileEvent.java new file mode 100644 index 0000000000..9e8ae0ab13 --- /dev/null +++ b/paper-api/src/main/java/com/destroystokyo/paper/event/profile/LookupProfileEvent.java @@ -0,0 +1,45 @@ +package com.destroystokyo.paper.event.profile; + +import com.destroystokyo.paper.profile.PlayerProfile; +import org.bukkit.Bukkit; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.ApiStatus; +import org.jspecify.annotations.NullMarked; + +/** + * Allows a plugin to be notified anytime AFTER a Profile has been looked up from the Mojang API + * This is an opportunity to view the response and potentially cache things. + *
+ * No guarantees are made about thread execution context for this event. If you need to know, check + * {@link Event#isAsynchronous()} + */ +@NullMarked +public class LookupProfileEvent extends Event { + + private static final HandlerList HANDLER_LIST = new HandlerList(); + + private final PlayerProfile profile; + + @ApiStatus.Internal + public LookupProfileEvent(final PlayerProfile profile) { + super(!Bukkit.isPrimaryThread()); + this.profile = profile; + } + + /** + * @return The profile that was recently looked up. This profile can be mutated + */ + public PlayerProfile getPlayerProfile() { + return this.profile; + } + + @Override + public HandlerList getHandlers() { + return HANDLER_LIST; + } + + public static HandlerList getHandlerList() { + return HANDLER_LIST; + } +} diff --git a/paper-api/src/main/java/com/destroystokyo/paper/event/profile/PreLookupProfileEvent.java b/paper-api/src/main/java/com/destroystokyo/paper/event/profile/PreLookupProfileEvent.java new file mode 100644 index 0000000000..07416cc9e2 --- /dev/null +++ b/paper-api/src/main/java/com/destroystokyo/paper/event/profile/PreLookupProfileEvent.java @@ -0,0 +1,107 @@ +package com.destroystokyo.paper.event.profile; + +import com.destroystokyo.paper.profile.ProfileProperty; +import java.util.HashSet; +import java.util.Set; +import java.util.UUID; +import org.bukkit.Bukkit; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.ApiStatus; +import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.Nullable; + +/** + * Allows a plugin to intercept a Profile Lookup for a Profile by name + *
+ * At the point of event fire, the UUID and properties are unset. + *
+ * If a plugin sets the UUID, and optionally the properties, the API call to look up the profile may be skipped. + *
+ * No guarantees are made about thread execution context for this event. If you need to know, check
+ * {@link Event#isAsynchronous()}
+ */
+@NullMarked
+public class PreLookupProfileEvent extends Event {
+
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+
+ private final String name;
+
+ private @Nullable UUID uuid;
+ private Set
+ * However, if Profile Properties are needed by the server, you must also set them or else an API call might still be made.
+ *
+ * @param uuid the UUID to set for the profile or {@code null} to reset
+ */
+ public void setUUID(final @Nullable UUID uuid) {
+ this.uuid = uuid;
+ }
+
+ /**
+ * @return The currently pending pre-populated properties.
+ * Any property in this Set will be automatically prefilled on this Profile
+ */
+ public Set