mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-08 04:38:35 +00:00
VanillaCommand: added getBoundedInt()
This commit is contained in:
parent
c20b16a0fe
commit
773f760fff
@ -86,13 +86,9 @@ class EffectCommand extends VanillaCommand{
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(count($args) >= 4){
|
if(count($args) >= 4){
|
||||||
$amplification = (int) $args[3];
|
$amplification = $this->getBoundedInt($sender, $args[3], 0, 255);
|
||||||
if($amplification > 255){
|
if($amplification === null){
|
||||||
$sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.num.tooBig", [(string) $args[3], "255"]));
|
return false;
|
||||||
return true;
|
|
||||||
}elseif($amplification < 0){
|
|
||||||
$sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.num.tooSmall", [(string) $args[3], "0"]));
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,9 @@ namespace pocketmine\command\defaults;
|
|||||||
|
|
||||||
use pocketmine\command\Command;
|
use pocketmine\command\Command;
|
||||||
use pocketmine\command\CommandSender;
|
use pocketmine\command\CommandSender;
|
||||||
|
use pocketmine\command\utils\InvalidCommandSyntaxException;
|
||||||
|
use pocketmine\lang\TranslationContainer;
|
||||||
|
use pocketmine\utils\TextFormat;
|
||||||
|
|
||||||
abstract class VanillaCommand extends Command{
|
abstract class VanillaCommand extends Command{
|
||||||
public const MAX_COORD = 30000000;
|
public const MAX_COORD = 30000000;
|
||||||
@ -88,4 +91,22 @@ abstract class VanillaCommand extends Command{
|
|||||||
|
|
||||||
return $i;
|
return $i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function getBoundedInt(CommandSender $sender, string $input, int $min, int $max) : ?int{
|
||||||
|
if(!is_numeric($input)){
|
||||||
|
throw new InvalidCommandSyntaxException();
|
||||||
|
}
|
||||||
|
|
||||||
|
$v = (int) $input;
|
||||||
|
if($v > $max){
|
||||||
|
$sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.num.tooBig", [$input, (string) $max]));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if($v < $min){
|
||||||
|
$sender->sendMessage(new TranslationContainer(TextFormat::RED . "%commands.generic.num.tooSmall", [$input, (string) $min]));
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $v;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user