Use components properly in ProfileWhitelistVerifyEvent (#11456)

This commit is contained in:
Jake Potrebic 2024-10-02 05:32:05 -07:00
parent 8d3c6e1052
commit ec8b5b419f
2 changed files with 7 additions and 4 deletions

View file

@ -44,6 +44,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+import org.bukkit.event.Event;
+import org.bukkit.event.HandlerList;
+import org.jetbrains.annotations.ApiStatus;
+import org.jetbrains.annotations.Contract;
+import org.jspecify.annotations.NullMarked;
+import org.jspecify.annotations.Nullable;
+
@ -100,6 +101,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
+ /**
+ * @return the currently planned message to send to the user if they are not whitelisted
+ */
+ @Contract(pure = true)
+ public @Nullable Component kickMessage() {
+ return this.kickMessage;
+ }

View file

@ -27,18 +27,19 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
public boolean isWhiteListed(GameProfile profile) {
- return !this.doWhiteList || this.ops.contains(profile) || this.whitelist.contains(profile);
+ // Paper start - ProfileWhitelistVerifyEvent
+ return isWhiteListed(profile, null);
+ return this.isWhiteListed(profile, null);
+ }
+ public boolean isWhiteListed(GameProfile gameprofile, org.bukkit.event.player.PlayerLoginEvent loginEvent) {
+ public boolean isWhiteListed(GameProfile gameprofile, @Nullable org.bukkit.event.player.PlayerLoginEvent loginEvent) {
+ boolean isOp = this.ops.contains(gameprofile);
+ boolean isWhitelisted = !this.doWhiteList || isOp || this.whitelist.contains(gameprofile);
+ final com.destroystokyo.paper.event.profile.ProfileWhitelistVerifyEvent event;
+
+ event = new com.destroystokyo.paper.event.profile.ProfileWhitelistVerifyEvent(com.destroystokyo.paper.profile.CraftPlayerProfile.asBukkitMirror(gameprofile), this.doWhiteList, isWhitelisted, isOp, org.spigotmc.SpigotConfig.whitelistMessage);
+ final net.kyori.adventure.text.Component configuredMessage = net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(org.spigotmc.SpigotConfig.whitelistMessage);
+ event = new com.destroystokyo.paper.event.profile.ProfileWhitelistVerifyEvent(com.destroystokyo.paper.profile.CraftPlayerProfile.asBukkitMirror(gameprofile), this.doWhiteList, isWhitelisted, isOp, configuredMessage);
+ event.callEvent();
+ if (!event.isWhitelisted()) {
+ if (loginEvent != null) {
+ loginEvent.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer.legacySection().deserialize(event.getKickMessage() == null ? org.spigotmc.SpigotConfig.whitelistMessage : event.getKickMessage()));
+ loginEvent.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, event.kickMessage() == null ? configuredMessage : event.kickMessage());
+ }
+ return false;
+ }