22declare(strict_types=1);
24namespace pocketmine\command\defaults;
71use
function microtime;
73use
function strtolower;
77 public function __construct(){
80 KnownTranslationFactory::pocketmine_command_particle_description(),
81 KnownTranslationFactory::pocketmine_command_particle_usage()
83 $this->setPermission(DefaultPermissionNames::COMMAND_PARTICLE);
91 if($sender instanceof
Player){
92 $senderPos = $sender->getPosition();
93 $world = $senderPos->getWorld();
95 $this->getRelativeDouble($senderPos->getX(), $sender, $args[1]),
96 $this->getRelativeDouble($senderPos->getY(), $sender, $args[2], World::Y_MIN, World::Y_MAX),
97 $this->getRelativeDouble($senderPos->getZ(), $sender, $args[3])
100 $world = $sender->getServer()->getWorldManager()->getDefaultWorld();
101 $pos =
new Vector3((
float) $args[1], (
float) $args[2], (
float) $args[3]);
104 $name = strtolower($args[0]);
106 $xd = (float) $args[4];
107 $yd = (float) $args[5];
108 $zd = (float) $args[6];
110 $count = isset($args[7]) ? max(1, (
int) $args[7]) : 1;
112 $data = $args[8] ??
null;
114 $particle = $this->getParticle($name, $data);
116 if($particle ===
null){
117 $sender->sendMessage(KnownTranslationFactory::commands_particle_notFound($name)->prefix(TextFormat::RED));
121 $sender->sendMessage(KnownTranslationFactory::commands_particle_success($name, (
string) $count));
123 $random =
new Random((
int) (microtime(
true) * 1000) + mt_rand());
125 for($i = 0; $i < $count; ++$i){
126 $world->addParticle($pos->add(
127 $random->nextSignedFloat() * $xd,
128 $random->nextSignedFloat() * $yd,
129 $random->nextSignedFloat() * $zd
136 private function getParticle(
string $name, ?
string $data =
null) : ?
Particle{
140 case "hugeexplosion":
142 case "hugeexplosionseed":
180 $item = StringToItemParser::getInstance()->parse($data);
181 if($item !==
null && !$item->isNull()){
188 $block = StringToItemParser::getInstance()->parse($data)?->getBlock();
189 if($block !==
null && $block->getTypeId() !== BlockTypeIds::AIR){
190 return new TerrainParticle($block);
195 return new HeartParticle((
int) ($data ?? 0));
197 return new InkParticle((
int) ($data ?? 0));
199 return new RainSplashParticle();
200 case "enchantmenttable":
201 return new EnchantmentTableParticle();
202 case "happyvillager":
203 return new HappyVillagerParticle();
204 case "angryvillager":
205 return new AngryVillagerParticle();
207 return new BlockForceFieldParticle((
int) ($data ?? 0));
209 return new EntityFlameParticle();
211 if($data !==
null && ($item = StringToItemParser::getInstance()->parse($data)) !==
null && !$item->isNull()){
212 return new ItemBreakParticle($item);
216 if($data !==
null && ($block = StringToItemParser::getInstance()->parse($data)?->getBlock()) !==
null && $block->getTypeId() !== BlockTypeIds::AIR){
217 return new TerrainParticle($block);
222 $d = explode(
"_", $data);
224 return new DustParticle(
new Color(
225 ((
int) $d[0]) & 0xff,
226 ((
int) $d[1]) & 0xff,
227 ((
int) $d[2]) & 0xff,
228 ((
int) ($d[3] ?? 255)) & 0xff
execute(CommandSender $sender, string $commandLabel, array $args)