mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-16 03:51:37 +00:00
This PR started out as an effort to decouple Command and CommandMap, but it's turned into a bit more than that. A summary of changes: ## UX - Added `cmdalias create`, `cmdalias delete` and `cmdalias list` commands - `/help` now shows prefixed names such as `pocketmine:help` - Prefixed command name (e.g. `pocketmine:help`) are now visible to Minecraft clients - Permission denied messages are now able to show more useful context when e.g. checking subcommand permissions - Multiple commands claiming an alias make the alias unusable (an error will be shown when used telling the user to pick from the namespaced names), instead of whichever plugin loaded last getting lucky ## API - Added `CommandAliasMap`, which handles mapping of aliases to namespaced command IDs - Added `CommandSender->getCommandAliasMap()` for user-specific aliases - Added `CommandMap->getAliasMap()` for global fallback aliases - `Command` no longer tracks its own registered aliases (now the job of `CommandMap`), breaking circular dependency - Aliases must now be provided to `CommandMap->register()` - Aliases can now be individually registered and unregistered without re-registering/unregistering the whole command using `CommandAliasMap` APIs - Aliases are no longer namespaced, only the main command name (e.g. `pocketmine:?` is now gone while `pocketmine:help` still exists) - `Command` now requires a `$namespace` parameter, which replaces the old `$fallbackPrefix` parameter of `register()`. It should be set to the name of the plugin. Relevant issues - #6508 - #3371 - this PR doesn't implement storage, but allows configuration of per-user aliases during server runtime
62 lines
1.9 KiB
PHP
62 lines
1.9 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\lang\KnownTranslationFactory;
|
|
use pocketmine\permission\DefaultPermissionNames;
|
|
use function count;
|
|
use function inet_pton;
|
|
|
|
class PardonIpCommand extends VanillaCommand{
|
|
|
|
public function __construct(string $namespace, string $name){
|
|
parent::__construct(
|
|
$namespace,
|
|
$name,
|
|
KnownTranslationFactory::pocketmine_command_unban_ip_description(),
|
|
KnownTranslationFactory::commands_unbanip_usage()
|
|
);
|
|
$this->setPermission(DefaultPermissionNames::COMMAND_UNBAN_IP);
|
|
}
|
|
|
|
public function execute(CommandSender $sender, string $commandLabel, array $args){
|
|
if(count($args) !== 1){
|
|
throw new InvalidCommandSyntaxException();
|
|
}
|
|
|
|
if(inet_pton($args[0]) !== false){
|
|
$sender->getServer()->getIPBans()->remove($args[0]);
|
|
$sender->getServer()->getNetwork()->unblockAddress($args[0]);
|
|
Command::broadcastCommandMessage($sender, KnownTranslationFactory::commands_unbanip_success($args[0]));
|
|
}else{
|
|
$sender->sendMessage(KnownTranslationFactory::commands_unbanip_invalid());
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|