2020-04-02 23:07:06 +02:00
|
|
|
From ee60b16c81cd7ad8564d94a908c93eae2263973e Mon Sep 17 00:00:00 2001
|
2017-06-17 23:15:25 +02: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
|
2020-04-02 23:07:06 +02:00
|
|
|
index 000000000..8df37c07c
|
2017-06-17 23:15:25 +02:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/event/profile/LookupProfileEvent.java
|
2019-03-20 01:28:15 +01:00
|
|
|
@@ -0,0 +1,46 @@
|
2017-06-17 23:15:25 +02:00
|
|
|
+package com.destroystokyo.paper.event.profile;
|
|
|
|
+
|
2018-01-19 06:03:09 +01:00
|
|
|
+import com.destroystokyo.paper.profile.PlayerProfile;
|
2017-06-17 23:15:25 +02:00
|
|
|
+import org.bukkit.Bukkit;
|
|
|
|
+import org.bukkit.event.Event;
|
|
|
|
+import org.bukkit.event.HandlerList;
|
|
|
|
+
|
2019-03-20 01:28:15 +01:00
|
|
|
+import org.jetbrains.annotations.NotNull;
|
2017-06-17 23:15:25 +02:00
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 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();
|
|
|
|
+
|
2019-03-20 01:28:15 +01:00
|
|
|
+ @NotNull private final PlayerProfile profile;
|
2018-01-19 06:03:09 +01:00
|
|
|
+
|
2019-03-20 01:28:15 +01:00
|
|
|
+ public LookupProfileEvent(@NotNull PlayerProfile profile) {
|
2017-06-17 23:15:25 +02:00
|
|
|
+ super(!Bukkit.isPrimaryThread());
|
|
|
|
+ this.profile = profile;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
2017-07-03 17:38:49 +02:00
|
|
|
+ * @return The profile that was recently looked up. This profile can be mutated
|
2018-01-19 06:03:09 +01:00
|
|
|
+ */
|
2019-03-20 01:28:15 +01:00
|
|
|
+ @NotNull
|
2018-01-19 06:03:09 +01:00
|
|
|
+ public PlayerProfile getPlayerProfile() {
|
2017-06-17 23:15:25 +02:00
|
|
|
+ return profile;
|
|
|
|
+ }
|
|
|
|
+
|
2019-03-20 01:28:15 +01:00
|
|
|
+ @NotNull
|
2017-08-23 04:08:41 +02:00
|
|
|
+ @Override
|
2017-06-17 23:15:25 +02:00
|
|
|
+ public HandlerList getHandlers() {
|
|
|
|
+ return handlers;
|
|
|
|
+ }
|
|
|
|
+
|
2019-03-20 01:28:15 +01:00
|
|
|
+ @NotNull
|
2017-06-17 23:15:25 +02:00
|
|
|
+ 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
|
2020-04-02 23:07:06 +02:00
|
|
|
index 000000000..4dcf6242c
|
2017-06-17 23:15:25 +02:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/event/profile/PreLookupProfileEvent.java
|
2019-03-20 01:28:15 +01:00
|
|
|
@@ -0,0 +1,108 @@
|
2017-06-17 23:15:25 +02:00
|
|
|
+package com.destroystokyo.paper.event.profile;
|
|
|
|
+
|
2018-01-19 06:03:09 +01:00
|
|
|
+import com.destroystokyo.paper.profile.PlayerProfile;
|
|
|
|
+import com.destroystokyo.paper.profile.ProfileProperty;
|
|
|
|
+import com.google.common.collect.ArrayListMultimap;
|
2017-06-17 23:15:25 +02:00
|
|
|
+import org.bukkit.Bukkit;
|
|
|
|
+import org.bukkit.event.Event;
|
|
|
|
+import org.bukkit.event.HandlerList;
|
|
|
|
+
|
2018-01-19 06:03:09 +01:00
|
|
|
+import java.util.HashSet;
|
2017-06-17 23:15:25 +02:00
|
|
|
+import java.util.Set;
|
|
|
|
+import java.util.UUID;
|
2019-03-20 01:28:15 +01:00
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
|
+import org.jetbrains.annotations.Nullable;
|
2017-06-17 23:15:25 +02:00
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * 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();
|
2019-03-20 01:28:15 +01:00
|
|
|
+ @NotNull private final String name;
|
2017-06-17 23:15:25 +02:00
|
|
|
+ private UUID uuid;
|
2019-03-20 01:28:15 +01:00
|
|
|
+ @NotNull private Set<ProfileProperty> properties = new HashSet<>();
|
2017-06-17 23:15:25 +02:00
|
|
|
+
|
2019-03-20 01:28:15 +01:00
|
|
|
+ public PreLookupProfileEvent(@NotNull String name) {
|
2017-06-17 23:15:25 +02:00
|
|
|
+ super(!Bukkit.isPrimaryThread());
|
|
|
|
+ this.name = name;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
2017-07-03 17:38:49 +02:00
|
|
|
+ * @return Name of the profile
|
2017-06-17 23:15:25 +02:00
|
|
|
+ */
|
2019-03-20 01:28:15 +01:00
|
|
|
+ @NotNull
|
2017-06-17 23:15:25 +02:00
|
|
|
+ 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 04:08:41 +02:00
|
|
|
+ *
|
|
|
|
+ * @return The UUID of the profile if it has already been provided by a plugin
|
2017-06-17 23:15:25 +02: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 06:03:09 +01: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 17:38:49 +02:00
|
|
|
+ *
|
2018-01-19 06:03:09 +01:00
|
|
|
+ * @param uuid the UUID to set for the profile or null to reset
|
2017-06-17 23:15:25 +02:00
|
|
|
+ */
|
|
|
|
+ public void setUUID(@Nullable UUID uuid) {
|
|
|
|
+ this.uuid = uuid;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
2018-01-19 06:03:09 +01:00
|
|
|
+ * @return The currently pending prepopulated properties.
|
|
|
|
+ * Any property in this Set will be automatically prefilled on this Profile
|
|
|
|
+ */
|
2019-03-20 01:28:15 +01:00
|
|
|
+ @NotNull
|
2018-01-19 06:03:09 +01:00
|
|
|
+ public Set<ProfileProperty> getProfileProperties() {
|
|
|
|
+ return this.properties;
|
2017-06-17 23:15:25 +02:00
|
|
|
+ }
|
|
|
|
+
|
2017-08-23 04:08:41 +02:00
|
|
|
+ /**
|
2018-01-19 06:03:09 +01: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 23:15:25 +02:00
|
|
|
+ */
|
2019-03-20 01:28:15 +01:00
|
|
|
+ public void setProfileProperties(@NotNull Set<ProfileProperty> properties) {
|
2018-01-19 06:03:09 +01:00
|
|
|
+ this.properties = new HashSet<>();
|
|
|
|
+ this.properties.addAll(properties);
|
2017-06-17 23:15:25 +02:00
|
|
|
+ }
|
|
|
|
+
|
2017-08-23 04:08:41 +02:00
|
|
|
+ /**
|
2018-01-19 06:03:09 +01: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 04:08:41 +02:00
|
|
|
+ */
|
2019-03-20 01:28:15 +01:00
|
|
|
+ public void addProfileProperties(@NotNull Set<ProfileProperty> properties) {
|
2018-01-19 06:03:09 +01:00
|
|
|
+ this.properties.addAll(properties);
|
|
|
|
+ }
|
2017-06-17 23:15:25 +02:00
|
|
|
+
|
2019-03-20 01:28:15 +01:00
|
|
|
+ @NotNull
|
2018-01-19 06:03:09 +01:00
|
|
|
+ @Override
|
|
|
|
+ public HandlerList getHandlers() {
|
|
|
|
+ return handlers;
|
|
|
|
+ }
|
2017-06-17 23:15:25 +02:00
|
|
|
+
|
2019-03-20 01:28:15 +01:00
|
|
|
+ @NotNull
|
2018-01-19 06:03:09 +01:00
|
|
|
+ public static HandlerList getHandlerList() {
|
|
|
|
+ return handlers;
|
2017-06-17 23:15:25 +02:00
|
|
|
+ }
|
2018-01-19 06:03:09 +01:00
|
|
|
+
|
2017-06-17 23:15:25 +02:00
|
|
|
+}
|
|
|
|
--
|
2020-04-02 23:07:06 +02:00
|
|
|
2.25.1
|
2017-06-17 23:15:25 +02:00
|
|
|
|