mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-13 15:05:33 +00:00
closes #3910 the existing naming was misleading, and many plugin devs assumed that it returns an exact match. However, this is not guaranteed, and it's possible for two different players to match the same prefix. - There is no defined behaviour for what happens when multiple players can equally match a prefix (e.g. 'fr' could match 'fred' or 'frog' equally, because the name lengths are the same) - A prefix might match a different player at a different time (e.g. 'fr' could match 'freddie' before 'fred' joins, after which it will match 'fred' instead) With these flaws in mind, it's better to break compatibility on this to make the intent more clear, and to make plugin developers reassess their usages of this method. In most non-command use cases, they should likely be using getPlayerExact() instead.
91 lines
2.7 KiB
PHP
91 lines
2.7 KiB
PHP
<?php
|
|
|
|
/*
|
|
*
|
|
* ____ _ _ __ __ _ __ __ ____
|
|
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
|
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
|
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
|
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
|
*
|
|
* This program is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Lesser General Public License as published by
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* @author PocketMine Team
|
|
* @link http://www.pocketmine.net/
|
|
*
|
|
*
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace pocketmine\command\defaults;
|
|
|
|
use pocketmine\command\Command;
|
|
use pocketmine\command\CommandSender;
|
|
use pocketmine\command\utils\InvalidCommandSyntaxException;
|
|
use pocketmine\event\entity\EntityDamageEvent;
|
|
use pocketmine\lang\TranslationContainer;
|
|
use pocketmine\player\Player;
|
|
use pocketmine\utils\TextFormat;
|
|
use function count;
|
|
|
|
class KillCommand extends VanillaCommand{
|
|
|
|
public function __construct(string $name){
|
|
parent::__construct(
|
|
$name,
|
|
"%pocketmine.command.kill.description",
|
|
"%pocketmine.command.kill.usage",
|
|
["suicide"]
|
|
);
|
|
$this->setPermission("pocketmine.command.kill.self;pocketmine.command.kill.other");
|
|
}
|
|
|
|
public function execute(CommandSender $sender, string $commandLabel, array $args){
|
|
if(!$this->testPermission($sender)){
|
|
return true;
|
|
}
|
|
|
|
if(count($args) >= 2){
|
|
throw new InvalidCommandSyntaxException();
|
|
}
|
|
|
|
if(count($args) === 1){
|
|
if(!$sender->hasPermission("pocketmine.command.kill.other")){
|
|
$sender->sendMessage($sender->getLanguage()->translateString(TextFormat::RED . "%commands.generic.permission"));
|
|
|
|
return true;
|
|
}
|
|
|
|
$player = $sender->getServer()->getPlayerByPrefix($args[0]);
|
|
|
|
if($player instanceof Player){
|
|
$player->attack(new EntityDamageEvent($player, EntityDamageEvent::CAUSE_SUICIDE, 1000));
|
|
Command::broadcastCommandMessage($sender, new TranslationContainer("commands.kill.successful", [$player->getName()]));
|
|
}else{
|
|
$sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.player.notFound"));
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
if($sender instanceof Player){
|
|
if(!$sender->hasPermission("pocketmine.command.kill.self")){
|
|
$sender->sendMessage($sender->getLanguage()->translateString(TextFormat::RED . "%commands.generic.permission"));
|
|
|
|
return true;
|
|
}
|
|
|
|
$sender->attack(new EntityDamageEvent($sender, EntityDamageEvent::CAUSE_SUICIDE, 1000));
|
|
$sender->sendMessage(new TranslationContainer("commands.kill.successful", [$sender->getName()]));
|
|
}else{
|
|
throw new InvalidCommandSyntaxException();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|