Paper/patches/api/0096-Add-Ban-Methods-to-Player-Objects.patch
Jake Potrebic 0b20f94297
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#9953)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
96340858 PR-938: Various Sound API improvements
cbfe0ff0 PR-937: Minor improvements to World#rayTrace documentation
e979ee95 PR-935: Change Consumer and Predicates to super
27ae46dc SPIGOT-3641, SPIGOT-7479, PR-931: Add missing values to EntityEffect
0616ec8b Add eclipse .factorypath file to .gitignore

CraftBukkit Changes:
8e162d008 PR-1301: Various Sound API improvements
eeb7dfc2d SPIGOT-7520: Attribute LootTableSeed missing for generated containers with attached LootTable
d433f086d PR-1297: Change Consumer and Predicates to super
864f616da SPIGOT-7518: Fix NullPointerException when calling Block#applyBoneMeal()
5a2d905af Add eclipse .factorypath file to .gitignore
7c6bf15d4 Fix SkullMeta configuration serialization / deserialization with note block sound

Spigot Changes:
7de1049b Rebuild patches
2023-11-25 14:34:42 -08:00

243 lines
9.3 KiB
Diff

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 12349910297a75c00e64f6ccc7981aeeeb43ecd3..8f2f3e0ac5266f571b62a754921422bb07d61984 100644
--- a/src/main/java/org/bukkit/OfflinePlayer.java
+++ b/src/main/java/org/bukkit/OfflinePlayer.java
@@ -67,6 +67,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
/**
* Adds this user to the {@link ProfileBanList}. If a previous ban exists, this will
diff --git a/src/main/java/org/bukkit/entity/Player.java b/src/main/java/org/bukkit/entity/Player.java
index 67d253239b86a120162e7fcc56a345b5ebb88ba9..e13d09c5d4c62d47f6f4e057a23caea3ed18496a 100644
--- a/src/main/java/org/bukkit/entity/Player.java
+++ b/src/main/java/org/bukkit/entity/Player.java
@@ -1103,6 +1103,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 org.bukkit.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 org.bukkit.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 org.bukkit.BanEntry banPlayerFull(@Nullable String reason, @Nullable java.util.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 org.bukkit.BanEntry banPlayerFull(@Nullable String reason, @Nullable java.util.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, java.util.Date, String)}
+ *
+ * @param reason Reason for ban
+ * @param kickPlayer Whether or not to kick the player afterwards
+ * @return Ban Entry
+ */
+ @Nullable
+ public default org.bukkit.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, java.util.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 org.bukkit.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, java.util.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 org.bukkit.BanEntry banPlayerIP(@Nullable String reason, @Nullable java.util.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, java.util.Date, String)}
+ *
+ * @param reason Reason for ban
+ * @return Ban Entry
+ */
+ @Nullable
+ public default org.bukkit.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, java.util.Date, String)}
+ * @param reason Reason for ban
+ * @param source Source of ban, or null for default
+ * @return Ban Entry
+ */
+ @Nullable
+ public default org.bukkit.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, java.util.Date, String)}
+ * @param reason Reason for Ban
+ * @param expires When to expire the ban
+ * @return Ban Entry
+ */
+ @Nullable
+ public default org.bukkit.BanEntry banPlayerIP(@Nullable String reason, @Nullable java.util.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, java.util.Date, String)}
+ * @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 org.bukkit.BanEntry banPlayerIP(@Nullable String reason, @Nullable java.util.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, java.util.Date, String)}
+ * @param reason Reason for Ban
+ * @param expires When to expire the ban
+ * @param source Source of the ban or null for default
+ * @param kickPlayer if the targeted player should be kicked
+ * @return Ban Entry
+ */
+ @Nullable
+ public default org.bukkit.BanEntry banPlayerIP(@Nullable String reason, @Nullable java.util.Date expires, @Nullable String source, boolean kickPlayer) {
+ org.bukkit.BanEntry banEntry = org.bukkit.Bukkit.getServer().getBanList(org.bukkit.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.