GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
SummonCommand Class Reference

Public Member Functions

 __construct ($name)
 
 execute (CommandSender $sender, $currentAlias, array $args)
 
- Public Member Functions inherited from VanillaCommand
 __construct ($name, $description="", $usageMessage=null, array $aliases=[])
 
- Public Member Functions inherited from Command
 __construct ($name, $description="", $usageMessage=null, array $aliases=[])
 
 getDefaultCommandData ()
 
 generateCustomCommandData (Player $player)
 
 getOverloads ()
 
 execute (CommandSender $sender, $commandLabel, array $args)
 
 getName ()
 
 getPermission ()
 
 setPermission ($permission)
 
 testPermission (CommandSender $target)
 
 testPermissionSilent (CommandSender $target)
 
 getLabel ()
 
 setLabel ($name)
 
 register (CommandMap $commandMap)
 
 unregister (CommandMap $commandMap)
 
 isRegistered ()
 
 getAliases ()
 
 getPermissionMessage ()
 
 getDescription ()
 
 getUsage ()
 
 setAliases (array $aliases)
 
 setDescription ($description)
 
 setPermissionMessage ($permissionMessage)
 
 setUsage ($usage)
 
 __toString ()
 

Additional Inherited Members

- Static Public Member Functions inherited from Command
static generateDefaultData ()
 
static broadcastCommandMessage (CommandSender $source, $message, $sendToSource=true)
 
- Data Fields inherited from VanillaCommand
const MAX_COORD = 30000000
 
const MIN_COORD = -30000000
 
- Data Fields inherited from Command
 $timings
 
- Protected Member Functions inherited from VanillaCommand
 getInteger (CommandSender $sender, $value, $min=self::MIN_COORD, $max=self::MAX_COORD)
 
 getRelativeDouble ($original, CommandSender $sender, $input, $min=self::MIN_COORD, $max=self::MAX_COORD)
 
 getDouble (CommandSender $sender, $value, $min=self::MIN_COORD, $max=self::MAX_COORD)
 
- Protected Attributes inherited from Command
 $commandData = null
 
 $description = ""
 
 $usageMessage
 

Constructor & Destructor Documentation

◆ __construct()

__construct (   $name)

SummonCommand constructor.

Parameters
$name
42  {
43  parent::__construct(
44  $name,
45  "%pocketmine.command.summon.description",
46  "%pocketmine.command.summon.usage"
47  );
48  $this->setPermission("pocketmine.command.summon");
49  }

Member Function Documentation

◆ execute()

execute ( CommandSender  $sender,
  $currentAlias,
array  $args 
)
Parameters
CommandSender$sender
string$currentAlias
array$args
Returns
bool
58  {
59  if(!$this->testPermission($sender)){
60  return true;
61  }
62 
63  if(count($args) != 1 and count($args) != 4 and count($args) != 5){
64  $sender->sendMessage(new TranslationContainer("commands.generic.usage", [$this->usageMessage]));
65  return true;
66  }
67 
68  $x = 0;
69  $y = 0;
70  $z = 0;
71  if(count($args) == 4 or count($args) == 5){ //position is set
72  //TODO:simpilify them to one piece of code
73  //Code for setting $x
74  if(is_numeric($args[1])){ //x is given directly
75  $x = $args[1];
76  }elseif(strcmp($args[1], "~") >= 0){ //x is given with a "~"
77  $offset_x = trim($args[1], "~");
78  if($sender instanceof Player){ //using in-game
79  $x = is_numeric($offset_x) ? ($sender->x + $offset_x) : $sender->x;
80  }else{ //using in console
81  $sender->sendMessage(TextFormat::RED . "You must specify a position where the entity is spawned to when using in console");
82  return false;
83  }
84  }else{ //other circumstances
85  $sender->sendMessage(TextFormat::RED . "Argument error");
86  return false;
87  }
88 
89  //Code for setting $y
90  if(is_numeric($args[2])){ //y is given directly
91  $y = $args[2];
92  }elseif(strcmp($args[2], "~") >= 0){ //y is given with a "~"
93  $offset_y = trim($args[2], "~");
94  if($sender instanceof Player){ //using in-game
95  $y = is_numeric($offset_y) ? ($sender->y + $offset_y) : $sender->y;
96  $y = min(128, max(0, $y));
97  }else{ //using in console
98  $sender->sendMessage(TextFormat::RED . "You must specify a position where the entity is spawned to when using in console");
99  return false;
100  }
101  }else{ //other circumstances
102  $sender->sendMessage(TextFormat::RED . "Argument error");
103  return false;
104  }
105 
106  //Code for setting $z
107  if(is_numeric($args[3])){ //z is given directly
108  $z = $args[3];
109  }elseif(strcmp($args[3], "~") >= 0){ //z is given with a "~"
110  $offset_z = trim($args[3], "~");
111  if($sender instanceof Player){ //using in-game
112  $z = is_numeric($offset_z) ? ($sender->z + $offset_z) : $sender->z;
113  }else{ //using in console
114  $sender->sendMessage(TextFormat::RED . "You must specify a position where the entity is spawned to when using in console");
115  return false;
116  }
117  }else{ //other circumstances
118  $sender->sendMessage(TextFormat::RED . "Argument error");
119  return false;
120  }
121  } //finish setting the location
122 
123  if(count($args) == 1){
124  if($sender instanceof Player){
125  $x = $sender->x;
126  $y = $sender->y;
127  $z = $sender->z;
128  }else{
129  $sender->sendMessage(TextFormat::RED . "You must specify a position where the entity is spawned to when using in console");
130  return false;
131  }
132  } //finish setting the location
133 
134  $entity = null;
135  $type = $args[0];
136  $level = ($sender instanceof Player) ? $sender->getLevel() : $sender->getServer()->getDefaultLevel();
137  $nbt = new CompoundTag("", [
138  "Pos" => new ListTag("Pos", [
139  new DoubleTag("", $x),
140  new DoubleTag("", $y),
141  new DoubleTag("", $z)
142  ]),
143  "Motion" => new ListTag("Motion", [
144  new DoubleTag("", 0),
145  new DoubleTag("", 0),
146  new DoubleTag("", 0)
147  ]),
148  "Rotation" => new ListTag("Rotation", [
149  new FloatTag("", lcg_value() * 360),
150  new FloatTag("", 0)
151  ]),
152  ]);
153  if(count($args) == 5 and $args[4]{0} == "{"){//Tags are found
154  $nbtExtra = NBT::parseJSON($args[4]);
155  $nbt = NBT::combineCompoundTags($nbt, $nbtExtra, true);
156  }
157 
158  $entity = Entity::createEntity($type, $level, $nbt);
159  if($entity instanceof Entity){
160  $entity->spawnToAll();
161  $sender->sendMessage("Successfully spawned entity $type at ($x, $y, $z)");
162  return true;
163  }else{
164  $sender->sendMessage(TextFormat::RED . "An error occurred when spawning the entity $type");
165  return false;
166  }
167  }

The documentation for this class was generated from the following file: