23
23
24
24
namespace pocketmine \command \defaults ;
25
25
26
- use pocketmine \block \BlockFactory ;
26
+ use pocketmine \block \BlockLegacyIds ;
27
27
use pocketmine \color \Color ;
28
28
use pocketmine \command \CommandSender ;
29
29
use pocketmine \command \utils \InvalidCommandSyntaxException ;
30
- use pocketmine \item \ItemFactory ;
30
+ use pocketmine \item \StringToItemParser ;
31
31
use pocketmine \item \VanillaItems ;
32
32
use pocketmine \lang \KnownTranslationFactory ;
33
33
use pocketmine \math \Vector3 ;
70
70
use function max ;
71
71
use function microtime ;
72
72
use function mt_rand ;
73
- use function strpos ;
74
73
use function strtolower ;
75
74
76
75
class ParticleCommand extends VanillaCommand{
@@ -114,7 +113,7 @@ public function execute(CommandSender $sender, string $commandLabel, array $args
114
113
115
114
$ count = isset ($ args [7 ]) ? max (1 , (int ) $ args [7 ]) : 1 ;
116
115
117
- $ data = isset ( $ args [8 ]) ? ( int ) $ args [ 8 ] : null ;
116
+ $ data = $ args [8 ] ?? null ;
118
117
119
118
$ particle = $ this ->getParticle ($ name , $ data );
120
119
@@ -138,7 +137,7 @@ public function execute(CommandSender $sender, string $commandLabel, array $args
138
137
return true ;
139
138
}
140
139
141
- private function getParticle (string $ name , ?int $ data = null ) : ?Particle {
140
+ private function getParticle (string $ name , ?string $ data = null ) : ?Particle {
142
141
switch ($ name ){
143
142
case "explode " :
144
143
return new ExplodeParticle ();
@@ -156,7 +155,7 @@ private function getParticle(string $name, ?int $data = null) : ?Particle{
156
155
case "crit " :
157
156
return new CriticalParticle ();
158
157
case "smoke " :
159
- return new SmokeParticle ($ data ?? 0 );
158
+ return new SmokeParticle (( int ) ( $ data ?? 0 ) );
160
159
case "spell " :
161
160
return new EnchantParticle (new Color (0 , 0 , 0 , 255 )); //TODO: colour support
162
161
case "instantspell " :
@@ -175,25 +174,31 @@ private function getParticle(string $name, ?int $data = null) : ?Particle{
175
174
case "lava " :
176
175
return new LavaParticle ();
177
176
case "reddust " :
178
- return new RedstoneParticle ($ data ?? 1 );
177
+ return new RedstoneParticle (( int ) ( $ data ?? 1 ) );
179
178
case "snowballpoof " :
180
179
return new ItemBreakParticle (VanillaItems::SNOWBALL ());
181
180
case "slime " :
182
181
return new ItemBreakParticle (VanillaItems::SLIMEBALL ());
183
182
case "itembreak " :
184
- if ($ data !== null && $ data !== 0 ){
185
- return new ItemBreakParticle (ItemFactory::getInstance ()->get ($ data ));
183
+ if ($ data !== null ){
184
+ $ item = StringToItemParser::getInstance ()->parse ($ data );
185
+ if ($ item !== null && !$ item ->isNull ()){
186
+ return new ItemBreakParticle ($ item );
187
+ }
186
188
}
187
189
break ;
188
190
case "terrain " :
189
- if ($ data !== null && $ data !== 0 ){
190
- return new TerrainParticle (BlockFactory::getInstance ()->get ($ data , 0 ));
191
+ if ($ data !== null ){
192
+ $ block = StringToItemParser::getInstance ()->parse ($ data )?->getBlock();
193
+ if ($ block !== null && $ block ->getId () !== BlockLegacyIds::AIR ){
194
+ return new TerrainParticle ($ block );
195
+ }
191
196
}
192
197
break ;
193
198
case "heart " :
194
- return new HeartParticle ($ data ?? 0 );
199
+ return new HeartParticle (( int ) ( $ data ?? 0 ) );
195
200
case "ink " :
196
- return new InkParticle ($ data ?? 0 );
201
+ return new InkParticle (( int ) ( $ data ?? 0 ) );
197
202
case "droplet " :
198
203
return new RainSplashParticle ();
199
204
case "enchantmenttable " :
@@ -203,26 +208,32 @@ private function getParticle(string $name, ?int $data = null) : ?Particle{
203
208
case "angryvillager " :
204
209
return new AngryVillagerParticle ();
205
210
case "forcefield " :
206
- return new BlockForceFieldParticle ($ data ?? 0 );
211
+ return new BlockForceFieldParticle (( int ) ( $ data ?? 0 ) );
207
212
case "mobflame " :
208
213
return new EntityFlameParticle ();
209
- }
210
-
211
- if (strpos ($ name , "iconcrack_ " ) === 0 ){
212
- $ d = explode ("_ " , $ name );
213
- if (count ($ d ) === 3 ){
214
- return new ItemBreakParticle (ItemFactory::getInstance ()->get ((int ) $ d [1 ], (int ) $ d [2 ]));
215
- }
216
- }elseif (strpos ($ name , "blockcrack_ " ) === 0 ){
217
- $ d = explode ("_ " , $ name );
218
- if (count ($ d ) === 2 ){
219
- return new TerrainParticle (BlockFactory::getInstance ()->get (((int ) $ d [1 ]) & 0xff , ((int ) $ d [1 ]) >> 12 ));
220
- }
221
- }elseif (strpos ($ name , "blockdust_ " ) === 0 ){
222
- $ d = explode ("_ " , $ name );
223
- if (count ($ d ) >= 4 ){
224
- return new DustParticle (new Color (((int ) $ d [1 ]) & 0xff , ((int ) $ d [2 ]) & 0xff , ((int ) $ d [3 ]) & 0xff , isset ($ d [4 ]) ? ((int ) $ d [4 ]) & 0xff : 255 ));
225
- }
214
+ case "iconcrack " :
215
+ if ($ data !== null && ($ item = StringToItemParser::getInstance ()->parse ($ data )) !== null && !$ item ->isNull ()){
216
+ return new ItemBreakParticle ($ item );
217
+ }
218
+ break ;
219
+ case "blockcrack " :
220
+ if ($ data !== null && ($ block = StringToItemParser::getInstance ()->parse ($ data )?->getBlock()) !== null && $ block ->getId () !== BlockLegacyIds::AIR ){
221
+ return new TerrainParticle ($ block );
222
+ }
223
+ break ;
224
+ case "blockdust " :
225
+ if ($ data !== null ){
226
+ $ d = explode ("_ " , $ data );
227
+ if (count ($ d ) >= 3 ){
228
+ return new DustParticle (new Color (
229
+ ((int ) $ d [0 ]) & 0xff ,
230
+ ((int ) $ d [1 ]) & 0xff ,
231
+ ((int ) $ d [2 ]) & 0xff ,
232
+ ((int ) ($ d [3 ] ?? 255 )) & 0xff
233
+ ));
234
+ }
235
+ }
236
+ break ;
226
237
}
227
238
228
239
return null ;
0 commit comments