forked from electronicboy/Paper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
0068-ProfileWhitelistVerifyEvent.patch
157 lines (154 loc) · 5.83 KB
/
0068-ProfileWhitelistVerifyEvent.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <[email protected]>
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
index 0000000000000000000000000000000000000000..c6f5e2b5459368ad1e4db9929ca14568a25793fa
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/profile/ProfileWhitelistVerifyEvent.java
@@ -0,0 +1,142 @@
+/*
+ * 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;
+import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
+import org.bukkit.event.Event;
+import org.bukkit.event.HandlerList;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Fires when the server needs to verify if a player is whitelisted.
+ *
+ * Plugins may override/control the servers whitelist with this event,
+ * and dynamically change the kick message.
+ */
+public class ProfileWhitelistVerifyEvent extends Event {
+ private static final HandlerList handlers = new HandlerList();
+ @NotNull private final PlayerProfile profile;
+ private final boolean whitelistEnabled;
+ private boolean whitelisted;
+ private final boolean isOp;
+ @Nullable private Component kickMessage;
+
+ @Deprecated
+ public ProfileWhitelistVerifyEvent(@NotNull final PlayerProfile profile, boolean whitelistEnabled, boolean whitelisted, boolean isOp, @Nullable String kickMessage) {
+ this(profile, whitelistEnabled, whitelisted, isOp, kickMessage == null ? null : LegacyComponentSerializer.legacySection().deserialize(kickMessage));
+ }
+
+ 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() {
+ return this.kickMessage == null ? null : LegacyComponentSerializer.legacySection().serialize(kickMessage);
+ }
+
+ /**
+ * @param kickMessage The message to send to the player on kick if not whitelisted. May set to null to use the server configured default
+ * @deprecated Use {@link #kickMessage(Component)}
+ */
+ @Deprecated
+ public void setKickMessage(@Nullable String kickMessage) {
+ this.kickMessage(kickMessage == null ? null : LegacyComponentSerializer.legacySection().deserialize(kickMessage));
+ }
+
+ /**
+ * @return the currently planned message to send to the user if they are not whitelisted
+ */
+ @Nullable
+ public Component kickMessage() {
+ return this.kickMessage;
+ }
+
+ /**
+ * @param kickMessage The message to send to the player on kick if not whitelisted. May set to null to use the server configured default
+ */
+ public void kickMessage(@Nullable Component kickMessage) {
+ this.kickMessage = kickMessage;
+ }
+
+ /**
+ * @return The profile of the player trying to connect
+ */
+ @NotNull
+ public PlayerProfile getPlayerProfile() {
+ return profile;
+ }
+
+ /**
+ * @return Whether the player is whitelisted to play on this server (whitelist may be off is why its true)
+ */
+ public boolean isWhitelisted() {
+ return whitelisted;
+ }
+
+ /**
+ * Changes the players whitelisted state. false will deny the login
+ * @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() {
+ return isOp;
+ }
+
+ /**
+ * @return if the server even has whitelist on
+ */
+ public boolean isWhitelistEnabled() {
+ return whitelistEnabled;
+ }
+
+ @NotNull
+ @Override
+ public HandlerList getHandlers() {
+ return handlers;
+ }
+
+ @NotNull
+ public static HandlerList getHandlerList() {
+ return handlers;
+ }
+}