mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-12 16:59:44 +00:00
68 lines
1.8 KiB
PHP
68 lines
1.8 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/
|
|
*
|
|
*
|
|
*/
|
|
|
|
namespace pocketmine\command\defaults;
|
|
|
|
use pocketmine\command\Command;
|
|
use pocketmine\command\CommandSender;
|
|
|
|
abstract class VanillaCommand extends Command{
|
|
const MAX_COORD = 30000000;
|
|
const MIN_COORD = -30000000;
|
|
|
|
public function __construct($name, $description = "", $usageMessage = null, array $aliases = []){
|
|
parent::__construct($name, $description, $usageMessage, $aliases);
|
|
}
|
|
|
|
protected function getInteger(CommandSender $sender, $value, $min = self::MIN_COORD, $max = self::MAX_COORD){
|
|
$i = (int) $value;
|
|
|
|
if($i < $min){
|
|
$i = $min;
|
|
}elseif($i > $max){
|
|
$i = $max;
|
|
}
|
|
|
|
return $i;
|
|
}
|
|
|
|
protected function getRelativeDouble($original, CommandSender $sender, $input, $min = self::MIN_COORD, $max = self::MAX_COORD){
|
|
if($input{0} === "~"){
|
|
$value = $this->getDouble($sender, substr($input, 1));
|
|
|
|
return $original + $value;
|
|
}
|
|
|
|
return $this->getDouble($sender, $input, $min, $max);
|
|
}
|
|
|
|
protected function getDouble(CommandSender $sender, $value, $min = self::MIN_COORD, $max = self::MAX_COORD){
|
|
$i = (double) $value;
|
|
|
|
if($i < $min){
|
|
$i = $min;
|
|
}elseif($i > $max){
|
|
$i = $max;
|
|
}
|
|
|
|
return $i;
|
|
}
|
|
} |