From 5a33dbd4c6a88e86c2b0b2f4365429e615c26d3a Mon Sep 17 00:00:00 2001 From: Muqsit Date: Sun, 19 Apr 2020 18:27:37 +0100 Subject: [PATCH] Player: drop isAdmin from kick(), closes #3275 --- src/command/defaults/BanIpCommand.php | 2 +- src/command/defaults/KickCommand.php | 2 +- src/player/Player.php | 19 ++++++------------- 3 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/command/defaults/BanIpCommand.php b/src/command/defaults/BanIpCommand.php index 18f09efe3e..b70d1ff71b 100644 --- a/src/command/defaults/BanIpCommand.php +++ b/src/command/defaults/BanIpCommand.php @@ -81,7 +81,7 @@ class BanIpCommand extends VanillaCommand{ foreach($sender->getServer()->getOnlinePlayers() as $player){ if($player->getNetworkSession()->getIp() === $ip){ - $player->kick($reason !== "" ? $reason : "IP banned."); + $player->kick("Banned by admin. Reason: " . ($reason !== "" ? $reason : "IP banned.")); } } diff --git a/src/command/defaults/KickCommand.php b/src/command/defaults/KickCommand.php index 879a181602..f9cb617601 100644 --- a/src/command/defaults/KickCommand.php +++ b/src/command/defaults/KickCommand.php @@ -58,7 +58,7 @@ class KickCommand extends VanillaCommand{ $reason = trim(implode(" ", $args)); if(($player = $sender->getServer()->getPlayer($name)) instanceof Player){ - $player->kick($reason); + $player->kick("Kicked by admin." . ($reason !== "" ? "Reason: " . $reason : "")); if($reason !== ""){ Command::broadcastCommandMessage($sender, new TranslationContainer("commands.kick.success.reason", [$player->getName(), $reason])); }else{ diff --git a/src/player/Player.php b/src/player/Player.php index 97383d14d4..18c5aac294 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -1909,22 +1909,15 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, * * @param TranslationContainer|string $quitMessage */ - public function kick(string $reason = "", bool $isAdmin = true, $quitMessage = null) : bool{ + public function kick(string $reason = "", $quitMessage = null) : bool{ $ev = new PlayerKickEvent($this, $reason, $quitMessage ?? $this->getLeaveMessage()); $ev->call(); if(!$ev->isCancelled()){ $reason = $ev->getReason(); - $message = $reason; - if($isAdmin){ - if(!$this->isBanned()){ - $message = "Kicked by admin." . ($reason !== "" ? " Reason: " . $reason : ""); - } - }else{ - if($reason === ""){ - $message = "disconnectionScreen.noReason"; - } + if($reason === ""){ + $reason = "disconnectionScreen.noReason"; } - $this->disconnect($message, $ev->getQuitMessage()); + $this->disconnect($reason, $ev->getQuitMessage()); return true; } @@ -1936,8 +1929,8 @@ class Player extends Human implements CommandSender, ChunkLoader, ChunkListener, * Removes the player from the server. This cannot be cancelled. * This is used for remote disconnects and for uninterruptible disconnects (for example, when the server shuts down). * - * Note for plugin developers: Prefer kick() with the isAdmin flag set to kick without the "Kicked by admin" part - * instead of this method. This way other plugins can have a say in whether the player is removed or not. + * Note for plugin developers: Prefer kick() instead of this method. + * That way other plugins can have a say in whether the player is removed or not. * * @param string $reason Shown to the player, usually this will appear on their disconnect screen. * @param TranslationContainer|string $quitMessage Message to broadcast to online players (null will use default)