2019-02-23 17:17:41 +00:00
|
|
|
From cbcd37fcba051f9148b24a33e042f21093ed9f2e Mon Sep 17 00:00:00 2001
|
2017-06-17 21:15:25 +00:00
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Sat, 17 Jun 2017 16:30:44 -0400
|
|
|
|
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/event/profile/LookupProfileEvent.java b/src/main/java/com/destroystokyo/paper/event/profile/LookupProfileEvent.java
|
|
|
|
new file mode 100644
|
2018-07-26 02:49:43 +00:00
|
|
|
index 00000000..160c98fe
|
2017-06-17 21:15:25 +00:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/event/profile/LookupProfileEvent.java
|
2018-07-26 02:49:43 +00:00
|
|
|
@@ -0,0 +1,44 @@
|
2017-06-17 21:15:25 +00:00
|
|
|
+package com.destroystokyo.paper.event.profile;
|
|
|
|
+
|
2018-01-19 05:03:09 +00:00
|
|
|
+import com.destroystokyo.paper.profile.PlayerProfile;
|
2017-06-17 21:15:25 +00:00
|
|
|
+import org.bukkit.Bukkit;
|
|
|
|
+import org.bukkit.event.Event;
|
|
|
|
+import org.bukkit.event.HandlerList;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Nonnull;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 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
|
|
|
|
+ * event.isAsync()
|
|
|
|
+ */
|
|
|
|
+public class LookupProfileEvent extends Event {
|
|
|
|
+
|
|
|
|
+ private static final HandlerList handlers = new HandlerList();
|
|
|
|
+
|
2018-01-19 05:03:09 +00:00
|
|
|
+ private final PlayerProfile profile;
|
|
|
|
+
|
|
|
|
+ public LookupProfileEvent(@Nonnull PlayerProfile profile) {
|
2017-06-17 21:15:25 +00:00
|
|
|
+ super(!Bukkit.isPrimaryThread());
|
|
|
|
+ this.profile = profile;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
2017-07-03 15:38:49 +00:00
|
|
|
+ * @return The profile that was recently looked up. This profile can be mutated
|
2018-01-19 05:03:09 +00:00
|
|
|
+ */
|
|
|
|
+ @Nonnull
|
|
|
|
+ public PlayerProfile getPlayerProfile() {
|
2017-06-17 21:15:25 +00:00
|
|
|
+ return profile;
|
|
|
|
+ }
|
|
|
|
+
|
2017-08-23 02:08:41 +00:00
|
|
|
+ @Override
|
2017-06-17 21:15:25 +00:00
|
|
|
+ public HandlerList getHandlers() {
|
|
|
|
+ return handlers;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public static HandlerList getHandlerList() {
|
|
|
|
+ return handlers;
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/event/profile/PreLookupProfileEvent.java b/src/main/java/com/destroystokyo/paper/event/profile/PreLookupProfileEvent.java
|
|
|
|
new file mode 100644
|
2018-07-26 02:49:43 +00:00
|
|
|
index 00000000..e5a5986a
|
2017-06-17 21:15:25 +00:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/event/profile/PreLookupProfileEvent.java
|
2018-07-26 02:49:43 +00:00
|
|
|
@@ -0,0 +1,105 @@
|
2017-06-17 21:15:25 +00:00
|
|
|
+package com.destroystokyo.paper.event.profile;
|
|
|
|
+
|
2018-01-19 05:03:09 +00:00
|
|
|
+import com.destroystokyo.paper.profile.PlayerProfile;
|
|
|
|
+import com.destroystokyo.paper.profile.ProfileProperty;
|
|
|
|
+import com.google.common.collect.ArrayListMultimap;
|
2017-06-17 21:15:25 +00:00
|
|
|
+import org.bukkit.Bukkit;
|
|
|
|
+import org.bukkit.event.Event;
|
|
|
|
+import org.bukkit.event.HandlerList;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Nonnull;
|
|
|
|
+import javax.annotation.Nullable;
|
2018-01-19 05:03:09 +00:00
|
|
|
+import java.util.HashSet;
|
2017-06-17 21:15:25 +00:00
|
|
|
+import java.util.Set;
|
|
|
|
+import java.util.UUID;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 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
|
|
|
|
+ * event.isAsync()
|
|
|
|
+ */
|
|
|
|
+public class PreLookupProfileEvent extends Event {
|
|
|
|
+
|
|
|
|
+ private static final HandlerList handlers = new HandlerList();
|
|
|
|
+ private final String name;
|
|
|
|
+ private UUID uuid;
|
2018-01-19 05:03:09 +00:00
|
|
|
+ private Set<ProfileProperty> properties = new HashSet<>();
|
2017-06-17 21:15:25 +00:00
|
|
|
+
|
|
|
|
+ public PreLookupProfileEvent(@Nonnull String name) {
|
|
|
|
+ super(!Bukkit.isPrimaryThread());
|
|
|
|
+ this.name = name;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
2017-07-03 15:38:49 +00:00
|
|
|
+ * @return Name of the profile
|
2017-06-17 21:15:25 +00:00
|
|
|
+ */
|
|
|
|
+ @Nonnull
|
|
|
|
+ public String getName() {
|
|
|
|
+ return name;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * If this value is left null by the completion of the event call, then the server will
|
|
|
|
+ * trigger a call to the Mojang API to look up the UUID (Network Request), and subsequently, fire a
|
|
|
|
+ * {@link LookupProfileEvent}
|
2017-08-23 02:08:41 +00:00
|
|
|
+ *
|
|
|
|
+ * @return The UUID of the profile if it has already been provided by a plugin
|
2017-06-17 21:15:25 +00:00
|
|
|
+ */
|
|
|
|
+ @Nullable
|
|
|
|
+ public UUID getUUID() {
|
|
|
|
+ return uuid;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Sets the UUID for this player name. This will skip the initial API call to find the players UUID.
|
|
|
|
+ *
|
2018-01-19 05:03:09 +00:00
|
|
|
+ * However, if Profile Properties are needed by the server, you must also set them or else an API call might still be made.
|
2017-07-03 15:38:49 +00:00
|
|
|
+ *
|
2018-01-19 05:03:09 +00:00
|
|
|
+ * @param uuid the UUID to set for the profile or null to reset
|
2017-06-17 21:15:25 +00:00
|
|
|
+ */
|
|
|
|
+ public void setUUID(@Nullable UUID uuid) {
|
|
|
|
+ this.uuid = uuid;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
2018-01-19 05:03:09 +00:00
|
|
|
+ * @return The currently pending prepopulated properties.
|
|
|
|
+ * Any property in this Set will be automatically prefilled on this Profile
|
|
|
|
+ */
|
|
|
|
+ public Set<ProfileProperty> getProfileProperties() {
|
|
|
|
+ return this.properties;
|
2017-06-17 21:15:25 +00:00
|
|
|
+ }
|
|
|
|
+
|
2017-08-23 02:08:41 +00:00
|
|
|
+ /**
|
2018-01-19 05:03:09 +00:00
|
|
|
+ * Clears any existing prepopulated properties and uses the supplied properties
|
|
|
|
+ * Any property in this Set will be automatically prefilled on this Profile
|
|
|
|
+ * @param properties The properties to add
|
2017-06-17 21:15:25 +00:00
|
|
|
+ */
|
2018-01-19 05:03:09 +00:00
|
|
|
+ public void setProfileProperties(Set<ProfileProperty> properties) {
|
|
|
|
+ this.properties = new HashSet<>();
|
|
|
|
+ this.properties.addAll(properties);
|
2017-06-17 21:15:25 +00:00
|
|
|
+ }
|
|
|
|
+
|
2017-08-23 02:08:41 +00:00
|
|
|
+ /**
|
2018-01-19 05:03:09 +00:00
|
|
|
+ * Adds any properties currently missing to the prepopulated properties set, replacing any that already were set.
|
|
|
|
+ * Any property in this Set will be automatically prefilled on this Profile
|
|
|
|
+ * @param properties The properties to add
|
2017-08-23 02:08:41 +00:00
|
|
|
+ */
|
2018-01-19 05:03:09 +00:00
|
|
|
+ public void addProfileProperties(Set<ProfileProperty> properties) {
|
|
|
|
+ this.properties.addAll(properties);
|
|
|
|
+ }
|
2017-06-17 21:15:25 +00:00
|
|
|
+
|
2018-01-19 05:03:09 +00:00
|
|
|
+ @Override
|
|
|
|
+ public HandlerList getHandlers() {
|
|
|
|
+ return handlers;
|
|
|
|
+ }
|
2017-06-17 21:15:25 +00:00
|
|
|
+
|
2018-01-19 05:03:09 +00:00
|
|
|
+ public static HandlerList getHandlerList() {
|
|
|
|
+ return handlers;
|
2017-06-17 21:15:25 +00:00
|
|
|
+ }
|
2018-01-19 05:03:09 +00:00
|
|
|
+
|
2017-06-17 21:15:25 +00:00
|
|
|
+}
|
|
|
|
--
|
2019-02-23 17:17:41 +00:00
|
|
|
2.20.1
|
2017-06-17 21:15:25 +00:00
|
|
|
|