aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-API-Patches/0092-Add-Ban-Methods-to-Player-Objects.patch
blob: 540eeb4d36d1514cb505c4b4870edefdb5f482fb (plain)
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Aikar <aikar@aikar.co>
Date: Sat, 28 Apr 2018 10:28:50 -0400
Subject: [PATCH] Add Ban Methods to Player Objects

Allows a more logical API for banning players.

player.banPlayer("Breaking the rules");

diff --git a/src/main/java/org/bukkit/OfflinePlayer.java b/src/main/java/org/bukkit/OfflinePlayer.java
index 58313929f81509030216a0e5e3869da63e11108e..6cf05fed701c67a2c797a4e0839c795802a238a1 100644
--- a/src/main/java/org/bukkit/OfflinePlayer.java
+++ b/src/main/java/org/bukkit/OfflinePlayer.java
@@ -45,6 +45,61 @@ public interface OfflinePlayer extends ServerOperator, AnimalTamer, Configuratio
      * @return true if banned, otherwise false
      */
     public boolean isBanned();
+    // Paper start
+
+    /**
+     * Permanently Bans this player from the server
+     *
+     * @param reason Reason for Ban
+     * @return Ban Entry
+     */
+    @NotNull
+    public default BanEntry banPlayer(@Nullable String reason) {
+        return banPlayer(reason, null, null);
+    }
+
+    /**
+     * Permanently Bans this player from the server
+     * @param reason Reason for Ban
+     * @param source Source of the ban, or null for default
+     * @return Ban Entry
+     */
+    @NotNull
+    public default BanEntry banPlayer(@Nullable String reason, @Nullable String source) {
+        return banPlayer(reason, null, source);
+    }
+
+    /**
+     * Bans this player from the server
+     * @param reason Reason for Ban
+     * @param expires When to expire the ban
+     * @return Ban Entry
+     */
+    @NotNull
+    public default BanEntry banPlayer(@Nullable String reason, @Nullable java.util.Date expires) {
+        return banPlayer(reason, expires, null);
+    }
+
+    /**
+     * Bans this player from the server
+     * @param reason Reason for Ban
+     * @param expires When to expire the ban
+     * @param source Source of the ban or null for default
+     * @return Ban Entry
+     */
+    @NotNull
+    public default BanEntry banPlayer(@Nullable String reason, @Nullable java.util.Date expires, @Nullable String source) {
+        return banPlayer(reason, expires, source, true);
+    }
+    @NotNull
+    public default BanEntry banPlayer(@Nullable String reason, @Nullable java.util.Date expires, @Nullable String source, boolean kickIfOnline) {
+        BanEntry banEntry = Bukkit.getServer().getBanList(BanList.Type.NAME).addBan(getName(), reason, expires, source);
+        if (kickIfOnline && isOnline()) {
+            getPlayer().kickPlayer(reason);
+        }
+        return banEntry;
+    }
+    // Paper end
 
     /**
      * Checks if this player is whitelisted or not
diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java
index 6769330f336afcd5f26c0f7286defa00bead543c..88fd4cdeaad4d27f414c6b268022cdedf73492e7 100644
--- a/src/main/java/org/bukkit/entity/Player.java
+++ b/src/main/java/org/bukkit/entity/Player.java
@@ -5,6 +5,10 @@ import java.util.UUID;
 import com.destroystokyo.paper.Title; // Paper
 import net.kyori.adventure.text.Component;
 import com.destroystokyo.paper.profile.PlayerProfile; // Paper
+import java.util.Date; // Paper
+import org.bukkit.BanEntry; // Paper
+import org.bukkit.BanList; // Paper
+import org.bukkit.Bukkit; // Paper
 import org.bukkit.DyeColor;
 import org.bukkit.Effect;
 import org.bukkit.GameMode;
@@ -618,6 +622,162 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
     public void sendMap(@NotNull MapView map);
 
     // Paper start
+    /**
+     * Permanently Bans the Profile and IP address currently used by the player.
+     *
+     * @param reason Reason for ban
+     * @return Ban Entry
+     */
+    // For reference, Bukkit defines this as nullable, while they impl isn't, we'll follow API.
+    @Nullable
+    public default BanEntry banPlayerFull(@Nullable String reason) {
+        return banPlayerFull(reason, null, null);
+    }
+
+    /**
+     * Permanently Bans the Profile and IP address currently used by the player.
+     *
+     * @param reason Reason for ban
+     * @param source Source of ban, or null for default
+     * @return Ban Entry
+     */
+    @Nullable
+    public default BanEntry banPlayerFull(@Nullable String reason, @Nullable String source) {
+        return banPlayerFull(reason, null, source);
+    }
+
+    /**
+     * Bans the Profile and IP address currently used by the player.
+     *
+     * @param reason Reason for Ban
+     * @param expires When to expire the ban
+     * @return Ban Entry
+     */
+    @Nullable
+    public default BanEntry banPlayerFull(@Nullable String reason, @Nullable Date expires) {
+        return banPlayerFull(reason, expires, null);
+    }
+
+    /**
+     * Bans the Profile and IP address currently used by the player.
+     *
+     * @param reason Reason for Ban
+     * @param expires When to expire the ban
+     * @param source Source of the ban, or null for default
+     * @return Ban Entry
+     */
+    @Nullable
+    public default BanEntry banPlayerFull(@Nullable String reason, @Nullable Date expires, @Nullable String source) {
+        banPlayer(reason, expires, source);
+        return banPlayerIP(reason, expires, source, true);
+    }
+
+    /**
+     * Permanently Bans the IP address currently used by the player.
+     * Does not ban the Profile, use {@link #banPlayerFull(String, Date, String)}
+     *
+     * @param reason Reason for ban
+     * @param kickPlayer Whether or not to kick the player afterwards
+     * @return Ban Entry
+     */
+    @Nullable
+    public default BanEntry banPlayerIP(@Nullable String reason, boolean kickPlayer) {
+        return banPlayerIP(reason, null, null, kickPlayer);
+    }
+
+    /**
+     * Permanently Bans the IP address currently used by the player.
+     * Does not ban the Profile, use {@link #banPlayerFull(String, Date, String)}
+     * @param reason Reason for ban
+     * @param source Source of ban, or null for default
+     * @param kickPlayer Whether or not to kick the player afterwards
+     * @return Ban Entry
+     */
+    @Nullable
+    public default BanEntry banPlayerIP(@Nullable String reason, @Nullable String source, boolean kickPlayer) {
+        return banPlayerIP(reason, null, source, kickPlayer);
+    }
+
+    /**
+     * Bans the IP address currently used by the player.
+     * Does not ban the Profile, use {@link #banPlayerFull(String, Date, String)}
+     * @param reason Reason for Ban
+     * @param expires When to expire the ban
+     * @param kickPlayer Whether or not to kick the player afterwards
+     * @return Ban Entry
+     */
+    @Nullable
+    public default BanEntry banPlayerIP(@Nullable String reason, @Nullable Date expires, boolean kickPlayer) {
+        return banPlayerIP(reason, expires, null, kickPlayer);
+    }
+
+    /**
+     * Permanently Bans the IP address currently used by the player.
+     * Does not ban the Profile, use {@link #banPlayerFull(String, Date, String)}
+     *
+     * @param reason Reason for ban
+     * @return Ban Entry
+     */
+    @Nullable
+    public default BanEntry banPlayerIP(@Nullable String reason) {
+        return banPlayerIP(reason, null, null);
+    }
+
+    /**
+     * Permanently Bans the IP address currently used by the player.
+     * Does not ban the Profile, use {@link #banPlayerFull(String, Date, String)}
+     * @param reason Reason for ban
+     * @param source Source of ban, or null for default
+     * @return Ban Entry
+     */
+    @Nullable
+    public default BanEntry banPlayerIP(@Nullable String reason, @Nullable String source) {
+        return banPlayerIP(reason, null, source);
+    }
+
+    /**
+     * Bans the IP address currently used by the player.
+     * Does not ban the Profile, use {@link #banPlayerFull(String, Date, String)}
+     * @param reason Reason for Ban
+     * @param expires When to expire the ban
+     * @return Ban Entry
+     */
+    @Nullable
+    public default BanEntry banPlayerIP(@Nullable String reason, @Nullable Date expires) {
+        return banPlayerIP(reason, expires, null);
+    }
+
+    /**
+     * Bans the IP address currently used by the player.
+     * Does not ban the Profile, use {@link #banPlayerFull(String, Date, String)}
+     * @param reason Reason for Ban
+     * @param expires When to expire the ban
+     * @param source Source of the banm or null for default
+     * @return Ban Entry
+     */
+    @Nullable
+    public default BanEntry banPlayerIP(@Nullable String reason, @Nullable Date expires, @Nullable String source) {
+        return banPlayerIP(reason, expires, source, true);
+    }
+
+    /**
+     * Bans the IP address currently used by the player.
+     * Does not ban the Profile, use {@link #banPlayerFull(String, Date, String)}
+     * @param reason Reason for Ban
+     * @param expires When to expire the ban
+     * @param source Source of the banm or null for default
+     * @param kickPlayer if the targeted player should be kicked
+     * @return Ban Entry
+     */
+    @Nullable
+    public default BanEntry banPlayerIP(@Nullable String reason, @Nullable Date expires, @Nullable String source, boolean kickPlayer) {
+        BanEntry banEntry = Bukkit.getServer().getBanList(BanList.Type.IP).addBan(getAddress().getAddress().getHostAddress(), reason, expires, source);
+        if (kickPlayer && isOnline()) {
+            getPlayer().kickPlayer(reason);
+        }
+
+        return banEntry;
+    }
 
     /**
      * Sends an Action Bar message to the client.