PocketMine-MP  1.4 - API 1.10.0
 All Classes Namespaces Functions Variables Pages
VanillaCommand.php
1 <?php
2 
3 /*
4  *
5  * ____ _ _ __ __ _ __ __ ____
6  * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7  * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8  * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9  * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10  *
11  * This program is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License as published by
13  * the Free Software Foundation, either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * @author PocketMine Team
17  * @link http://www.pocketmine.net/
18  *
19  *
20 */
21 
22 namespace pocketmine\command\defaults;
23 
26 
27 abstract class VanillaCommand extends Command{
28  const MAX_COORD = 30000000;
29  const MIN_COORD = -30000000;
30 
31  public function __construct($name, $description = "", $usageMessage = null, array $aliases = []){
32  parent::__construct($name, $description, $usageMessage, $aliases);
33  }
34 
35  protected function getInteger(CommandSender $sender, $value, $min = self::MIN_COORD, $max = self::MAX_COORD){
36  $i = (int) $value;
37 
38  if($i < $min){
39  $i = $min;
40  }elseif($i > $max){
41  $i = $max;
42  }
43 
44  return $i;
45  }
46 
47  protected function getRelativeDouble($original, CommandSender $sender, $input, $min = self::MIN_COORD, $max = self::MAX_COORD){
48  if($input{0} === "~"){
49  $value = $this->getDouble($sender, substr($input, 1));
50 
51  return $original + $value;
52  }
53 
54  return $this->getDouble($sender, $input, $min, $max);
55  }
56 
57  protected function getDouble(CommandSender $sender, $value, $min = self::MIN_COORD, $max = self::MAX_COORD){
58  $i = (double) $value;
59 
60  if($i < $min){
61  $i = $min;
62  }elseif($i > $max){
63  $i = $max;
64  }
65 
66  return $i;
67  }
68 }