2021-06-11 14:02:28 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
|
From: Aikar <aikar@aikar.co>
|
|
|
|
Date: Mon, 3 Jul 2017 18:11:34 -0500
|
|
|
|
Subject: [PATCH] ProfileWhitelistVerifyEvent
|
|
|
|
|
|
|
|
Fires when the server is validating if a player is whitelisted.
|
|
|
|
|
|
|
|
Allows you to do dynamic whitelisting and change of kick message
|
|
|
|
|
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/event/profile/ProfileWhitelistVerifyEvent.java b/src/main/java/com/destroystokyo/paper/event/profile/ProfileWhitelistVerifyEvent.java
|
|
|
|
new file mode 100644
|
2024-02-01 10:15:57 +01:00
|
|
|
index 0000000000000000000000000000000000000000..52959c2d19c5b73ccd85afce6b2ab8133478f7c6
|
2021-06-11 14:02:28 +02:00
|
|
|
--- /dev/null
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/event/profile/ProfileWhitelistVerifyEvent.java
|
2024-02-01 10:15:57 +01:00
|
|
|
@@ -0,0 +1,147 @@
|
2021-06-11 14:02:28 +02:00
|
|
|
+/*
|
|
|
|
+ * Copyright (c) 2017 - Daniel Ennis (Aikar) - MIT License
|
|
|
|
+ *
|
|
|
|
+ * Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
+ * a copy of this software and associated documentation files (the
|
|
|
|
+ * "Software"), to deal in the Software without restriction, including
|
|
|
|
+ * without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
+ * distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
+ * permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
+ * the following conditions:
|
|
|
|
+ *
|
|
|
|
+ * The above copyright notice and this permission notice shall be
|
|
|
|
+ * included in all copies or substantial portions of the Software.
|
|
|
|
+ *
|
|
|
|
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+package com.destroystokyo.paper.event.profile;
|
|
|
|
+
|
|
|
|
+import com.destroystokyo.paper.profile.PlayerProfile;
|
|
|
|
+import net.kyori.adventure.text.Component;
|
2022-05-26 21:12:14 +02:00
|
|
|
+import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
2021-06-11 14:02:28 +02:00
|
|
|
+import org.bukkit.event.Event;
|
|
|
|
+import org.bukkit.event.HandlerList;
|
2024-02-01 10:15:57 +01:00
|
|
|
+import org.jetbrains.annotations.ApiStatus;
|
2021-06-11 14:02:28 +02:00
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
|
+import org.jetbrains.annotations.Nullable;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Fires when the server needs to verify if a player is whitelisted.
|
2024-02-01 10:15:57 +01:00
|
|
|
+ * <p>
|
2021-06-11 14:02:28 +02:00
|
|
|
+ * Plugins may override/control the servers whitelist with this event,
|
|
|
|
+ * and dynamically change the kick message.
|
|
|
|
+ */
|
|
|
|
+public class ProfileWhitelistVerifyEvent extends Event {
|
2024-02-01 10:15:57 +01:00
|
|
|
+
|
|
|
|
+ private static final HandlerList HANDLER_LIST = new HandlerList();
|
|
|
|
+
|
2021-06-11 14:02:28 +02:00
|
|
|
+ @NotNull private final PlayerProfile profile;
|
|
|
|
+ private final boolean whitelistEnabled;
|
|
|
|
+ private final boolean isOp;
|
2024-02-01 10:15:57 +01:00
|
|
|
+ private boolean whitelisted;
|
2021-06-11 14:02:28 +02:00
|
|
|
+ @Nullable private Component kickMessage;
|
|
|
|
+
|
|
|
|
+ @Deprecated
|
2024-02-01 10:15:57 +01:00
|
|
|
+ @ApiStatus.Internal
|
2021-06-11 14:02:28 +02:00
|
|
|
+ public ProfileWhitelistVerifyEvent(@NotNull final PlayerProfile profile, boolean whitelistEnabled, boolean whitelisted, boolean isOp, @Nullable String kickMessage) {
|
2022-05-26 21:12:14 +02:00
|
|
|
+ this(profile, whitelistEnabled, whitelisted, isOp, kickMessage == null ? null : LegacyComponentSerializer.legacySection().deserialize(kickMessage));
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+
|
2024-02-01 10:15:57 +01:00
|
|
|
+ @ApiStatus.Internal
|
2021-06-11 14:02:28 +02:00
|
|
|
+ public ProfileWhitelistVerifyEvent(@NotNull final PlayerProfile profile, boolean whitelistEnabled, boolean whitelisted, boolean isOp, @Nullable Component kickMessage) {
|
|
|
|
+ this.profile = profile;
|
|
|
|
+ this.whitelistEnabled = whitelistEnabled;
|
|
|
|
+ this.whitelisted = whitelisted;
|
|
|
|
+ this.isOp = isOp;
|
|
|
|
+ this.kickMessage = kickMessage;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @return the currently planned message to send to the user if they are not whitelisted
|
|
|
|
+ * @deprecated use {@link #kickMessage()}
|
|
|
|
+ */
|
|
|
|
+ @Deprecated
|
|
|
|
+ @Nullable
|
|
|
|
+ public String getKickMessage() {
|
2024-02-01 10:15:57 +01:00
|
|
|
+ return this.kickMessage == null ? null : LegacyComponentSerializer.legacySection().serialize(this.kickMessage);
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
2024-02-01 10:15:57 +01:00
|
|
|
+ * @param kickMessage The message to send to the player on kick if not whitelisted. May set to {@code null} to use the server configured default
|
2021-06-11 14:02:28 +02:00
|
|
|
+ * @deprecated Use {@link #kickMessage(Component)}
|
|
|
|
+ */
|
|
|
|
+ @Deprecated
|
|
|
|
+ public void setKickMessage(@Nullable String kickMessage) {
|
2022-05-26 21:12:14 +02:00
|
|
|
+ this.kickMessage(kickMessage == null ? null : LegacyComponentSerializer.legacySection().deserialize(kickMessage));
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @return the currently planned message to send to the user if they are not whitelisted
|
|
|
|
+ */
|
|
|
|
+ @Nullable
|
|
|
|
+ public Component kickMessage() {
|
|
|
|
+ return this.kickMessage;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
2024-02-01 10:15:57 +01:00
|
|
|
+ * @param kickMessage The message to send to the player on kick if not whitelisted. May set to {@code null} to use the server configured default
|
2021-06-11 14:02:28 +02:00
|
|
|
+ */
|
|
|
|
+ public void kickMessage(@Nullable Component kickMessage) {
|
|
|
|
+ this.kickMessage = kickMessage;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @return The profile of the player trying to connect
|
|
|
|
+ */
|
|
|
|
+ @NotNull
|
|
|
|
+ public PlayerProfile getPlayerProfile() {
|
2024-02-01 10:15:57 +01:00
|
|
|
+ return this.profile;
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @return Whether the player is whitelisted to play on this server (whitelist may be off is why its true)
|
|
|
|
+ */
|
|
|
|
+ public boolean isWhitelisted() {
|
2024-02-01 10:15:57 +01:00
|
|
|
+ return this.whitelisted;
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
2024-02-01 10:15:57 +01:00
|
|
|
+ * Changes the players whitelisted state. {@code false} will deny the login
|
2021-06-11 14:02:28 +02:00
|
|
|
+ * @param whitelisted The new whitelisted state
|
|
|
|
+ */
|
|
|
|
+ public void setWhitelisted(boolean whitelisted) {
|
|
|
|
+ this.whitelisted = whitelisted;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @return if the player obtained whitelist status by having op
|
|
|
|
+ */
|
|
|
|
+ public boolean isOp() {
|
2024-02-01 10:15:57 +01:00
|
|
|
+ return this.isOp;
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * @return if the server even has whitelist on
|
|
|
|
+ */
|
|
|
|
+ public boolean isWhitelistEnabled() {
|
2024-02-01 10:15:57 +01:00
|
|
|
+ return this.whitelistEnabled;
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @NotNull
|
|
|
|
+ @Override
|
|
|
|
+ public HandlerList getHandlers() {
|
2024-02-01 10:15:57 +01:00
|
|
|
+ return HANDLER_LIST;
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @NotNull
|
|
|
|
+ public static HandlerList getHandlerList() {
|
2024-02-01 10:15:57 +01:00
|
|
|
+ return HANDLER_LIST;
|
2021-06-11 14:02:28 +02:00
|
|
|
+ }
|
|
|
|
+}
|