This repository has been archived by the owner on Nov 5, 2019. It is now read-only.
/
ParticleEffect.java
1612 lines (1524 loc) · 58.4 KB
/
ParticleEffect.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package com.massivecraft.massivecore.particleeffect;
import com.massivecraft.massivecore.particleeffect.ReflectionUtils.PackageType;
import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.util.ReflectionUtil;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
/**
* <b>ParticleEffect Library</b>
* <p>
* This library was created by @DarkBlade12 and allows you to display all Minecraft particle effects on a Bukkit server
* <p>
* You are welcome to use it, modify it and redistribute it under the following conditions:
* <ul>
* <li>Don't claim this class as your own
* <li>Don't remove this disclaimer
* </ul>
* <p>
* Special thanks:
* <ul>
* <li>@microgeek (original idea, names and packet parameters)
* <li>@ShadyPotato (1.8 names, ids and packet parameters)
* <li>@RingOfStorms (particle behavior)
* <li>@Cybermaxke (particle behavior)
* </ul>
* <p>
* <i>It would be nice if you provide credit to me if you use this class in a published project</i>
*
* @author DarkBlade12
* @version 1.7
*/
public enum ParticleEffect {
/**
* A particle effect which is displayed by exploding tnt and creepers:
* <ul>
* <li>It looks like a white cloud
* <li>The speed value influences the velocity at which the particle flies off
* </ul>
*/
EXPLOSION_NORMAL("explode", 0, -1, ParticleProperty.DIRECTIONAL),
/**
* A particle effect which is displayed by exploding ghast fireballs and wither skulls:
* <ul>
* <li>It looks like a gray ball which is fading away
* <li>The speed value slightly influences the size of this particle effect
* </ul>
*/
EXPLOSION_LARGE("largeexplode", 1, -1),
/**
* A particle effect which is displayed by exploding tnt and creepers:
* <ul>
* <li>It looks like a crowd of gray balls which are fading away
* <li>The speed value has no influence on this particle effect
* </ul>
*/
EXPLOSION_HUGE("hugeexplosion", 2, -1),
/**
* A particle effect which is displayed by launching fireworks:
* <ul>
* <li>It looks like a white star which is sparkling
* <li>The speed value influences the velocity at which the particle flies off
* </ul>
*/
FIREWORKS_SPARK("fireworksSpark", 3, -1, ParticleProperty.DIRECTIONAL),
/**
* A particle effect which is displayed by swimming entities and arrows in water:
* <ul>
* <li>It looks like a bubble
* <li>The speed value influences the velocity at which the particle flies off
* </ul>
*/
WATER_BUBBLE("bubble", 4, -1, ParticleProperty.DIRECTIONAL, ParticleProperty.REQUIRES_WATER),
/**
* A particle effect which is displayed by swimming entities and shaking wolves:
* <ul>
* <li>It looks like a blue drop
* <li>The speed value has no influence on this particle effect
* </ul>
*/
WATER_SPLASH("splash", 5, -1, ParticleProperty.DIRECTIONAL),
/**
* A particle effect which is displayed on water when fishing:
* <ul>
* <li>It looks like a blue droplet
* <li>The speed value influences the velocity at which the particle flies off
* </ul>
*/
WATER_WAKE("wake", 6, 7, ParticleProperty.DIRECTIONAL),
/**
* A particle effect which is displayed by water:
* <ul>
* <li>It looks like a tiny blue square
* <li>The speed value has no influence on this particle effect
* </ul>
*/
SUSPENDED("suspended", 7, -1, ParticleProperty.REQUIRES_WATER),
/**
* A particle effect which is displayed by air when close to bedrock and the in the void:
* <ul>
* <li>It looks like a tiny gray square
* <li>The speed value has no influence on this particle effect
* </ul>
*/
SUSPENDED_DEPTH("depthSuspend", 8, -1, ParticleProperty.DIRECTIONAL),
/**
* A particle effect which is displayed when landing a critical hit and by arrows:
* <ul>
* <li>It looks like a light brown cross
* <li>The speed value influences the velocity at which the particle flies off
* </ul>
*/
CRIT("crit", 9, -1, ParticleProperty.DIRECTIONAL),
/**
* A particle effect which is displayed when landing a hit with an enchanted weapon:
* <ul>
* <li>It looks like a cyan star
* <li>The speed value influences the velocity at which the particle flies off
* </ul>
*/
CRIT_MAGIC("magicCrit", 10, -1, ParticleProperty.DIRECTIONAL),
/**
* A particle effect which is displayed by primed tnt, torches, droppers, dispensers, end portals, brewing stands and monster spawners:
* <ul>
* <li>It looks like a little gray cloud
* <li>The speed value influences the velocity at which the particle flies off
* </ul>
*/
SMOKE_NORMAL("smoke", 11, -1, ParticleProperty.DIRECTIONAL),
/**
* A particle effect which is displayed by fire, minecarts with furnace and blazes:
* <ul>
* <li>It looks like a large gray cloud
* <li>The speed value influences the velocity at which the particle flies off
* </ul>
*/
SMOKE_LARGE("largesmoke", 12, -1, ParticleProperty.DIRECTIONAL),
/**
* A particle effect which is displayed when splash potions or bottles o' enchanting hit something:
* <ul>
* <li>It looks like a white swirl
* <li>The speed value causes the particle to only move upwards when set to 0
* <li>Only the motion on the y-axis can be controlled, the motion on the x- and z-axis are multiplied by 0.1 when setting the values to 0
* </ul>
*/
SPELL("spell", 13, -1),
/**
* A particle effect which is displayed when instant splash potions hit something:
* <ul>
* <li>It looks like a white cross
* <li>The speed value causes the particle to only move upwards when set to 0
* <li>Only the motion on the y-axis can be controlled, the motion on the x- and z-axis are multiplied by 0.1 when setting the values to 0
* </ul>
*/
SPELL_INSTANT("instantSpell", 14, -1),
/**
* A particle effect which is displayed by entities with active potion effects:
* <ul>
* <li>It looks like a colored swirl
* <li>The speed value causes the particle to be colored black when set to 0
* <li>The particle color gets lighter when increasing the speed and darker when decreasing the speed
* </ul>
*/
SPELL_MOB("mobSpell", 15, -1, ParticleProperty.COLORABLE),
/**
* A particle effect which is displayed by entities with active potion effects applied through a beacon:
* <ul>
* <li>It looks like a transparent colored swirl
* <li>The speed value causes the particle to be always colored black when set to 0
* <li>The particle color gets lighter when increasing the speed and darker when decreasing the speed
* </ul>
*/
SPELL_MOB_AMBIENT("mobSpellAmbient", 16, -1, ParticleProperty.COLORABLE),
/**
* A particle effect which is displayed by witches:
* <ul>
* <li>It looks like a purple cross
* <li>The speed value causes the particle to only move upwards when set to 0
* <li>Only the motion on the y-axis can be controlled, the motion on the x- and z-axis are multiplied by 0.1 when setting the values to 0
* </ul>
*/
SPELL_WITCH("witchMagic", 17, -1),
/**
* A particle effect which is displayed by blocks beneath a water source:
* <ul>
* <li>It looks like a blue drip
* <li>The speed value has no influence on this particle effect
* </ul>
*/
DRIP_WATER("dripWater", 18, -1),
/**
* A particle effect which is displayed by blocks beneath a lava source:
* <ul>
* <li>It looks like an orange drip
* <li>The speed value has no influence on this particle effect
* </ul>
*/
DRIP_LAVA("dripLava", 19, -1),
/**
* A particle effect which is displayed when attacking a villager in a village:
* <ul>
* <li>It looks like a cracked gray heart
* <li>The speed value has no influence on this particle effect
* </ul>
*/
VILLAGER_ANGRY("angryVillager", 20, -1),
/**
* A particle effect which is displayed when using bone meal and trading with a villager in a village:
* <ul>
* <li>It looks like a green star
* <li>The speed value has no influence on this particle effect
* </ul>
*/
VILLAGER_HAPPY("happyVillager", 21, -1, ParticleProperty.DIRECTIONAL),
/**
* A particle effect which is displayed by mycelium:
* <ul>
* <li>It looks like a tiny gray square
* <li>The speed value has no influence on this particle effect
* </ul>
*/
TOWN_AURA("townaura", 22, -1, ParticleProperty.DIRECTIONAL),
/**
* A particle effect which is displayed by note blocks:
* <ul>
* <li>It looks like a colored note
* <li>The speed value causes the particle to be colored green when set to 0
* </ul>
*/
NOTE("note", 23, -1, ParticleProperty.COLORABLE),
/**
* A particle effect which is displayed by nether portals, endermen, ender pearls, eyes of ender, ender chests and dragon eggs:
* <ul>
* <li>It looks like a purple cloud
* <li>The speed value influences the spread of this particle effect
* </ul>
*/
PORTAL("portal", 24, -1, ParticleProperty.DIRECTIONAL),
/**
* A particle effect which is displayed by enchantment tables which are nearby bookshelves:
* <ul>
* <li>It looks like a cryptic white letter
* <li>The speed value influences the spread of this particle effect
* </ul>
*/
ENCHANTMENT_TABLE("enchantmenttable", 25, -1, ParticleProperty.DIRECTIONAL),
/**
* A particle effect which is displayed by torches, active furnaces, magma cubes and monster spawners:
* <ul>
* <li>It looks like a tiny flame
* <li>The speed value influences the velocity at which the particle flies off
* </ul>
*/
FLAME("flame", 26, -1, ParticleProperty.DIRECTIONAL),
/**
* A particle effect which is displayed by lava:
* <ul>
* <li>It looks like a spark
* <li>The speed value has no influence on this particle effect
* </ul>
*/
LAVA("lava", 27, -1),
/**
* A particle effect which is currently unused:
* <ul>
* <li>It looks like a transparent gray square
* <li>The speed value has no influence on this particle effect
* </ul>
*/
FOOTSTEP("footstep", 28, -1),
/**
* A particle effect which is displayed when a mob dies:
* <ul>
* <li>It looks like a large white cloud
* <li>The speed value influences the velocity at which the particle flies off
* </ul>
*/
CLOUD("cloud", 29, -1, ParticleProperty.DIRECTIONAL),
/**
* A particle effect which is displayed by redstone ore, powered redstone, redstone torches and redstone repeaters:
* <ul>
* <li>It looks like a tiny colored cloud
* <li>The speed value causes the particle to be colored red when set to 0
* </ul>
*/
REDSTONE("reddust", 30, -1, ParticleProperty.COLORABLE),
/**
* A particle effect which is displayed when snowballs hit a block:
* <ul>
* <li>It looks like a little piece with the snowball texture
* <li>The speed value has no influence on this particle effect
* </ul>
*/
SNOWBALL("snowballpoof", 31, -1),
/**
* A particle effect which is currently unused:
* <ul>
* <li>It looks like a tiny white cloud
* <li>The speed value influences the velocity at which the particle flies off
* </ul>
*/
SNOW_SHOVEL("snowshovel", 32, -1, ParticleProperty.DIRECTIONAL),
/**
* A particle effect which is displayed by slimes:
* <ul>
* <li>It looks like a tiny part of the slimeball icon
* <li>The speed value has no influence on this particle effect
* </ul>
*/
SLIME("slime", 33, -1),
/**
* A particle effect which is displayed when breeding and taming animals:
* <ul>
* <li>It looks like a red heart
* <li>The speed value has no influence on this particle effect
* </ul>
*/
HEART("heart", 34, -1),
/**
* A particle effect which is displayed by barriers:
* <ul>
* <li>It looks like a red box with a slash through it
* <li>The speed value has no influence on this particle effect
* </ul>
*/
BARRIER("barrier", 35, 8),
/**
* A particle effect which is displayed when breaking a tool or eggs hit a block:
* <ul>
* <li>It looks like a little piece with an item texture
* </ul>
*/
ITEM_CRACK("iconcrack", 36, -1, ParticleProperty.DIRECTIONAL, ParticleProperty.REQUIRES_DATA),
/**
* A particle effect which is displayed when breaking blocks or sprinting:
* <ul>
* <li>It looks like a little piece with a block texture
* <li>The speed value has no influence on this particle effect
* </ul>
*/
BLOCK_CRACK("blockcrack", 37, -1, ParticleProperty.DIRECTIONAL, ParticleProperty.REQUIRES_DATA),
/**
* A particle effect which is displayed when falling:
* <ul>
* <li>It looks like a little piece with a block texture
* </ul>
*/
BLOCK_DUST("blockdust", 38, 7, ParticleProperty.DIRECTIONAL, ParticleProperty.REQUIRES_DATA),
/**
* A particle effect which is displayed when rain hits the ground:
* <ul>
* <li>It looks like a blue droplet
* <li>The speed value has no influence on this particle effect
* </ul>
*/
WATER_DROP("droplet", 39, 8),
/**
* A particle effect which is currently unused:
* <ul>
* <li>It has no visual effect
* </ul>
*/
ITEM_TAKE("take", 40, 8),
/**
* A particle effect which is displayed by elder guardians:
* <ul>
* <li>It looks like the shape of the elder guardian
* <li>The speed value has no influence on this particle effect
* <li>The offset values have no influence on this particle effect
* </ul>
*/
MOB_APPEARANCE("mobappearance", 41, 8);
private static final Map<String, ParticleEffect> NAME_MAP = new HashMap<>();
private static final Map<Integer, ParticleEffect> ID_MAP = new HashMap<>();
private final String name;
private final int id;
private final int requiredVersion;
private final List<ParticleProperty> properties;
// Initialize map for quick name and id lookup
static {
for (ParticleEffect effect : values()) {
NAME_MAP.put(effect.name, effect);
ID_MAP.put(effect.id, effect);
}
}
/**
* Construct a new particle effect
*
* @param name Name of this particle effect
* @param id Id of this particle effect
* @param requiredVersion Version which is required (1.x)
* @param properties Properties of this particle effect
*/
ParticleEffect(String name, int id, int requiredVersion, ParticleProperty... properties) {
this.name = name;
this.id = id;
this.requiredVersion = requiredVersion;
this.properties = Arrays.asList(properties);
}
/**
* Returns the name of this particle effect
*
* @return The name
*/
public String getName() {
return name;
}
/**
* Returns the id of this particle effect
*
* @return The id
*/
public int getId() {
return id;
}
/**
* Returns the required version for this particle effect (1.x)
*
* @return The required version
*/
public int getRequiredVersion() {
return requiredVersion;
}
/**
* Determine if this particle effect has a specific property
*
* @return Whether it has the property or not
*/
public boolean hasProperty(ParticleProperty property) {
return properties.contains(property);
}
/**
* Determine if this particle effect is supported by your current server version
*
* @return Whether the particle effect is supported or not
*/
public boolean isSupported() {
if (requiredVersion == -1) {
return true;
}
return ParticlePacket.getVersion() >= requiredVersion;
}
/**
* Returns the particle effect with the given name
*
* @param name Name of the particle effect
* @return The particle effect
*/
public static ParticleEffect fromName(String name) {
for (Entry<String, ParticleEffect> entry : NAME_MAP.entrySet()) {
if (!entry.getKey().equalsIgnoreCase(name)) {
continue;
}
return entry.getValue();
}
return null;
}
/**
* Returns the particle effect with the given id
*
* @param id Id of the particle effect
* @return The particle effect
*/
public static ParticleEffect fromId(int id) {
for (Entry<Integer, ParticleEffect> entry : ID_MAP.entrySet()) {
if (entry.getKey() != id) {
continue;
}
return entry.getValue();
}
return null;
}
/**
* Determine if water is at a certain location
*
* @param location Location to check
* @return Whether water is at this location or not
*/
private static boolean isWater(Location location) {
Material material = location.getBlock().getType();
return material == Material.WATER || material == Material.STATIONARY_WATER;
}
/**
* Determine if the distance between @param location and one of the players exceeds 256
*
* @param location Location to check
* @return Whether the distance exceeds 256 or not
*/
private static boolean isLongDistance(Location location, List<Player> players) {
for (Player player : players) {
if (player.getLocation().distanceSquared(location) < 65536) {
continue;
}
return true;
}
return false;
}
/**
* Determine if the data type for a particle effect is correct
*
* @param effect Particle effect
* @param data Particle data
* @return Whether the data type is correct or not
*/
private static boolean isDataCorrect(ParticleEffect effect, ParticleData data) {
return ((effect == BLOCK_CRACK || effect == BLOCK_DUST) && data instanceof BlockData) || (effect == ITEM_CRACK && data instanceof ItemData);
}
/**
* Determine if the color type for a particle effect is correct
*
* @param effect Particle effect
* @param color Particle color
* @return Whether the color type is correct or not
*/
private static boolean isColorCorrect(ParticleEffect effect, ParticleColor color) {
return ((effect == SPELL_MOB || effect == SPELL_MOB_AMBIENT || effect == REDSTONE) && color instanceof OrdinaryColor) || (effect == NOTE && color instanceof NoteColor);
}
/**
* Displays a particle effect which is only visible for all players within a certain range in the world of @param center
*
* @param offsetX Maximum distance particles can fly away from the center on the x-axis
* @param offsetY Maximum distance particles can fly away from the center on the y-axis
* @param offsetZ Maximum distance particles can fly away from the center on the z-axis
* @param speed Display speed of the particles
* @param amount Amount of particles
* @param center Center location of the effect
* @param range Range of the visibility
* @throws ParticleVersionException If the particle effect is not supported by the server version
* @throws ParticleDataException If the particle effect requires additional data
* @throws IllegalArgumentException If the particle effect requires water and none is at the center location
* @see ParticlePacket
* @see ParticlePacket#sendTo(Location, double)
*/
public void display(float offsetX, float offsetY, float offsetZ, float speed, int amount, Location center, double range) throws ParticleVersionException, ParticleDataException, IllegalArgumentException {
if (!isSupported()) {
throw new ParticleVersionException("This particle effect is not supported by your server version");
}
if (hasProperty(ParticleProperty.REQUIRES_DATA)) {
throw new ParticleDataException("This particle effect requires additional data");
}
if (hasProperty(ParticleProperty.REQUIRES_WATER) && !isWater(center)) {
throw new IllegalArgumentException("There is no water at the center location");
}
new ParticlePacket(this, offsetX, offsetY, offsetZ, speed, amount, range > 256, null).sendTo(center, range);
}
/**
* Displays a particle effect which is only visible for the specified players
*
* @param offsetX Maximum distance particles can fly away from the center on the x-axis
* @param offsetY Maximum distance particles can fly away from the center on the y-axis
* @param offsetZ Maximum distance particles can fly away from the center on the z-axis
* @param speed Display speed of the particles
* @param amount Amount of particles
* @param center Center location of the effect
* @param players Receivers of the effect
* @throws ParticleVersionException If the particle effect is not supported by the server version
* @throws ParticleDataException If the particle effect requires additional data
* @throws IllegalArgumentException If the particle effect requires water and none is at the center location
* @see ParticlePacket
* @see ParticlePacket#sendTo(Location, List)
*/
public void display(float offsetX, float offsetY, float offsetZ, float speed, int amount, Location center, List<Player> players) throws ParticleVersionException, ParticleDataException, IllegalArgumentException {
if (!isSupported()) {
throw new ParticleVersionException("This particle effect is not supported by your server version");
}
if (hasProperty(ParticleProperty.REQUIRES_DATA)) {
throw new ParticleDataException("This particle effect requires additional data");
}
if (hasProperty(ParticleProperty.REQUIRES_WATER) && !isWater(center)) {
throw new IllegalArgumentException("There is no water at the center location");
}
new ParticlePacket(this, offsetX, offsetY, offsetZ, speed, amount, isLongDistance(center, players), null).sendTo(center, players);
}
/**
* Displays a particle effect which is only visible for the specified players
*
* @param offsetX Maximum distance particles can fly away from the center on the x-axis
* @param offsetY Maximum distance particles can fly away from the center on the y-axis
* @param offsetZ Maximum distance particles can fly away from the center on the z-axis
* @param speed Display speed of the particles
* @param amount Amount of particles
* @param center Center location of the effect
* @param players Receivers of the effect
* @throws ParticleVersionException If the particle effect is not supported by the server version
* @throws ParticleDataException If the particle effect requires additional data
* @throws IllegalArgumentException If the particle effect requires water and none is at the center location
* @see #display(float, float, float, float, int, Location, List)
*/
public void display(float offsetX, float offsetY, float offsetZ, float speed, int amount, Location center, Player... players) throws ParticleVersionException, ParticleDataException, IllegalArgumentException {
display(offsetX, offsetY, offsetZ, speed, amount, center, Arrays.asList(players));
}
/**
* Displays a single particle which flies into a determined direction and is only visible for all players within a certain range in the world of @param center
*
* @param direction Direction of the particle
* @param speed Display speed of the particle
* @param center Center location of the effect
* @param range Range of the visibility
* @throws ParticleVersionException If the particle effect is not supported by the server version
* @throws ParticleDataException If the particle effect requires additional data
* @throws IllegalArgumentException If the particle effect is not directional or if it requires water and none is at the center location
* @see ParticlePacket#ParticlePacket(ParticleEffect, Vector, float, boolean, ParticleData)
* @see ParticlePacket#sendTo(Location, double)
*/
public void display(Vector direction, float speed, Location center, double range) throws ParticleVersionException, ParticleDataException, IllegalArgumentException {
if (!isSupported()) {
throw new ParticleVersionException("This particle effect is not supported by your server version");
}
if (hasProperty(ParticleProperty.REQUIRES_DATA)) {
throw new ParticleDataException("This particle effect requires additional data");
}
if (!hasProperty(ParticleProperty.DIRECTIONAL)) {
throw new IllegalArgumentException("This particle effect is not directional");
}
if (hasProperty(ParticleProperty.REQUIRES_WATER) && !isWater(center)) {
throw new IllegalArgumentException("There is no water at the center location");
}
new ParticlePacket(this, direction, speed, range > 256, null).sendTo(center, range);
}
/**
* Displays a single particle which flies into a determined direction and is only visible for the specified players
*
* @param direction Direction of the particle
* @param speed Display speed of the particle
* @param center Center location of the effect
* @param players Receivers of the effect
* @throws ParticleVersionException If the particle effect is not supported by the server version
* @throws ParticleDataException If the particle effect requires additional data
* @throws IllegalArgumentException If the particle effect is not directional or if it requires water and none is at the center location
* @see ParticlePacket#ParticlePacket(ParticleEffect, Vector, float, boolean, ParticleData)
* @see ParticlePacket#sendTo(Location, List)
*/
public void display(Vector direction, float speed, Location center, List<Player> players) throws ParticleVersionException, ParticleDataException, IllegalArgumentException {
if (!isSupported()) {
throw new ParticleVersionException("This particle effect is not supported by your server version");
}
if (hasProperty(ParticleProperty.REQUIRES_DATA)) {
throw new ParticleDataException("This particle effect requires additional data");
}
if (!hasProperty(ParticleProperty.DIRECTIONAL)) {
throw new IllegalArgumentException("This particle effect is not directional");
}
if (hasProperty(ParticleProperty.REQUIRES_WATER) && !isWater(center)) {
throw new IllegalArgumentException("There is no water at the center location");
}
new ParticlePacket(this, direction, speed, isLongDistance(center, players), null).sendTo(center, players);
}
/**
* Displays a single particle which flies into a determined direction and is only visible for the specified players
*
* @param direction Direction of the particle
* @param speed Display speed of the particle
* @param center Center location of the effect
* @param players Receivers of the effect
* @throws ParticleVersionException If the particle effect is not supported by the server version
* @throws ParticleDataException If the particle effect requires additional data
* @throws IllegalArgumentException If the particle effect is not directional or if it requires water and none is at the center location
* @see #display(Vector, float, Location, List)
*/
public void display(Vector direction, float speed, Location center, Player... players) throws ParticleVersionException, ParticleDataException, IllegalArgumentException {
display(direction, speed, center, Arrays.asList(players));
}
/**
* Displays a single particle which is colored and only visible for all players within a certain range in the world of @param center
*
* @param color Color of the particle
* @param center Center location of the effect
* @param range Range of the visibility
* @throws ParticleVersionException If the particle effect is not supported by the server version
* @throws ParticleColorException If the particle effect is not colorable or the color type is incorrect
* @see ParticlePacket#ParticlePacket(ParticleEffect, ParticleColor, boolean)
* @see ParticlePacket#sendTo(Location, double)
*/
public void display(ParticleColor color, Location center, double range) throws ParticleVersionException, ParticleColorException {
if (!isSupported()) {
throw new ParticleVersionException("This particle effect is not supported by your server version");
}
if (!hasProperty(ParticleProperty.COLORABLE)) {
throw new ParticleColorException("This particle effect is not colorable");
}
if (!isColorCorrect(this, color)) {
throw new ParticleColorException("The particle color type is incorrect");
}
new ParticlePacket(this, color, range > 256).sendTo(center, range);
}
/**
* Displays a single particle which is colored and only visible for the specified players
*
* @param color Color of the particle
* @param center Center location of the effect
* @param players Receivers of the effect
* @throws ParticleVersionException If the particle effect is not supported by the server version
* @throws ParticleColorException If the particle effect is not colorable or the color type is incorrect
* @see ParticlePacket#ParticlePacket(ParticleEffect, ParticleColor, boolean)
* @see ParticlePacket#sendTo(Location, List)
*/
public void display(ParticleColor color, Location center, List<Player> players) throws ParticleVersionException, ParticleColorException {
if (!isSupported()) {
throw new ParticleVersionException("This particle effect is not supported by your server version");
}
if (!hasProperty(ParticleProperty.COLORABLE)) {
throw new ParticleColorException("This particle effect is not colorable");
}
if (!isColorCorrect(this, color)) {
throw new ParticleColorException("The particle color type is incorrect");
}
new ParticlePacket(this, color, isLongDistance(center, players)).sendTo(center, players);
}
/**
* Displays a single particle which is colored and only visible for the specified players
*
* @param color Color of the particle
* @param center Center location of the effect
* @param players Receivers of the effect
* @throws ParticleVersionException If the particle effect is not supported by the server version
* @throws ParticleColorException If the particle effect is not colorable or the color type is incorrect
* @see #display(ParticleColor, Location, List)
*/
public void display(ParticleColor color, Location center, Player... players) throws ParticleVersionException, ParticleColorException {
display(color, center, Arrays.asList(players));
}
/**
* Displays a particle effect which requires additional data and is only visible for all players within a certain range in the world of @param center
*
* @param data Data of the effect
* @param offsetX Maximum distance particles can fly away from the center on the x-axis
* @param offsetY Maximum distance particles can fly away from the center on the y-axis
* @param offsetZ Maximum distance particles can fly away from the center on the z-axis
* @param speed Display speed of the particles
* @param amount Amount of particles
* @param center Center location of the effect
* @param range Range of the visibility
* @throws ParticleVersionException If the particle effect is not supported by the server version
* @throws ParticleDataException If the particle effect does not require additional data or if the data type is incorrect
* @see ParticlePacket
* @see ParticlePacket#sendTo(Location, double)
*/
public void display(ParticleData data, float offsetX, float offsetY, float offsetZ, float speed, int amount, Location center, double range) throws ParticleVersionException, ParticleDataException {
if (!isSupported()) {
throw new ParticleVersionException("This particle effect is not supported by your server version");
}
if (!hasProperty(ParticleProperty.REQUIRES_DATA)) {
throw new ParticleDataException("This particle effect does not require additional data");
}
if (!isDataCorrect(this, data)) {
throw new ParticleDataException("The particle data type is incorrect");
}
new ParticlePacket(this, offsetX, offsetY, offsetZ, speed, amount, range > 256, data).sendTo(center, range);
}
/**
* Displays a particle effect which requires additional data and is only visible for the specified players
*
* @param data Data of the effect
* @param offsetX Maximum distance particles can fly away from the center on the x-axis
* @param offsetY Maximum distance particles can fly away from the center on the y-axis
* @param offsetZ Maximum distance particles can fly away from the center on the z-axis
* @param speed Display speed of the particles
* @param amount Amount of particles
* @param center Center location of the effect
* @param players Receivers of the effect
* @throws ParticleVersionException If the particle effect is not supported by the server version
* @throws ParticleDataException If the particle effect does not require additional data or if the data type is incorrect
* @see ParticlePacket
* @see ParticlePacket#sendTo(Location, List)
*/
public void display(ParticleData data, float offsetX, float offsetY, float offsetZ, float speed, int amount, Location center, List<Player> players) throws ParticleVersionException, ParticleDataException {
if (!isSupported()) {
throw new ParticleVersionException("This particle effect is not supported by your server version");
}
if (!hasProperty(ParticleProperty.REQUIRES_DATA)) {
throw new ParticleDataException("This particle effect does not require additional data");
}
if (!isDataCorrect(this, data)) {
throw new ParticleDataException("The particle data type is incorrect");
}
new ParticlePacket(this, offsetX, offsetY, offsetZ, speed, amount, isLongDistance(center, players), data).sendTo(center, players);
}
/**
* Displays a particle effect which requires additional data and is only visible for the specified players
*
* @param data Data of the effect
* @param offsetX Maximum distance particles can fly away from the center on the x-axis
* @param offsetY Maximum distance particles can fly away from the center on the y-axis
* @param offsetZ Maximum distance particles can fly away from the center on the z-axis
* @param speed Display speed of the particles
* @param amount Amount of particles
* @param center Center location of the effect
* @param players Receivers of the effect
* @throws ParticleVersionException If the particle effect is not supported by the server version
* @throws ParticleDataException If the particle effect does not require additional data or if the data type is incorrect
* @see #display(ParticleData, float, float, float, float, int, Location, List)
*/
public void display(ParticleData data, float offsetX, float offsetY, float offsetZ, float speed, int amount, Location center, Player... players) throws ParticleVersionException, ParticleDataException {
display(data, offsetX, offsetY, offsetZ, speed, amount, center, Arrays.asList(players));
}
/**
* Displays a single particle which requires additional data that flies into a determined direction and is only visible for all players within a certain range in the world of @param center
*
* @param data Data of the effect
* @param direction Direction of the particle
* @param speed Display speed of the particles
* @param center Center location of the effect
* @param range Range of the visibility
* @throws ParticleVersionException If the particle effect is not supported by the server version
* @throws ParticleDataException If the particle effect does not require additional data or if the data type is incorrect
* @see ParticlePacket
* @see ParticlePacket#sendTo(Location, double)
*/
public void display(ParticleData data, Vector direction, float speed, Location center, double range) throws ParticleVersionException, ParticleDataException {
if (!isSupported()) {
throw new ParticleVersionException("This particle effect is not supported by your server version");
}
if (!hasProperty(ParticleProperty.REQUIRES_DATA)) {
throw new ParticleDataException("This particle effect does not require additional data");
}
if (!isDataCorrect(this, data)) {
throw new ParticleDataException("The particle data type is incorrect");
}
new ParticlePacket(this, direction, speed, range > 256, data).sendTo(center, range);
}
/**
* Displays a single particle which requires additional data that flies into a determined direction and is only visible for the specified players
*
* @param data Data of the effect
* @param direction Direction of the particle
* @param speed Display speed of the particles
* @param center Center location of the effect
* @param players Receivers of the effect
* @throws ParticleVersionException If the particle effect is not supported by the server version
* @throws ParticleDataException If the particle effect does not require additional data or if the data type is incorrect
* @see ParticlePacket
* @see ParticlePacket#sendTo(Location, List)
*/
public void display(ParticleData data, Vector direction, float speed, Location center, List<Player> players) throws ParticleVersionException, ParticleDataException {
if (!isSupported()) {
throw new ParticleVersionException("This particle effect is not supported by your server version");
}
if (!hasProperty(ParticleProperty.REQUIRES_DATA)) {
throw new ParticleDataException("This particle effect does not require additional data");
}
if (!isDataCorrect(this, data)) {
throw new ParticleDataException("The particle data type is incorrect");
}
new ParticlePacket(this, direction, speed, isLongDistance(center, players), data).sendTo(center, players);
}
/**
* Displays a single particle which requires additional data that flies into a determined direction and is only visible for the specified players
*
* @param data Data of the effect
* @param direction Direction of the particle
* @param speed Display speed of the particles
* @param center Center location of the effect
* @param players Receivers of the effect
* @throws ParticleVersionException If the particle effect is not supported by the server version
* @throws ParticleDataException If the particle effect does not require additional data or if the data type is incorrect
* @see #display(ParticleData, Vector, float, Location, List)
*/
public void display(ParticleData data, Vector direction, float speed, Location center, Player... players) throws ParticleVersionException, ParticleDataException {
display(data, direction, speed, center, Arrays.asList(players));
}
/**
* Represents the property of a particle effect
* <p>
* This class is part of the <b>ParticleEffect Library</b> and follows the same usage conditions
*
* @author DarkBlade12
* @since 1.7
*/
public enum ParticleProperty {
/**
* The particle effect requires water to be displayed
*/
REQUIRES_WATER,
/**
* The particle effect requires block or item data to be displayed
*/
REQUIRES_DATA,
/**
* The particle effect uses the offsets as direction values
*/
DIRECTIONAL,
/**
* The particle effect uses the offsets as color values
*/
COLORABLE
}
/**
* Represents the particle data for effects like {@link ParticleEffect#ITEM_CRACK}, {@link ParticleEffect#BLOCK_CRACK} and {@link ParticleEffect#BLOCK_DUST}
* <p>
* This class is part of the <b>ParticleEffect Library</b> and follows the same usage conditions
*
* @author DarkBlade12
* @since 1.6
*/
public static abstract class ParticleData {
private final Material material;
private final byte data;
private final int[] packetData;
/**
* Construct a new particle data
*
* @param material Material of the item/block
* @param data Data value of the item/block
*/
@SuppressWarnings("deprecation")
public ParticleData(Material material, byte data) {
this.material = material;
this.data = data;
this.packetData = new int[] { material.getId(), data };
}
/**
* Returns the material of this data
*
* @return The material
*/
public Material getMaterial() {
return material;
}
/**
* Returns the data value of this data
*
* @return The data value
*/
public byte getData() {
return data;
}
/**
* Returns the data as an int array for packet construction
*
* @return The data for the packet
*/
public int[] getPacketData() {
return packetData;
}
/**
* Returns the data as a string for pre 1.8 versions
*
* @return The data string for the packet
*/
public String getPacketDataString() {
return "_" + packetData[0] + "_" + packetData[1];
}
}
/**
* Represents the item data for the {@link ParticleEffect#ITEM_CRACK} effect
* <p>
* This class is part of the <b>ParticleEffect Library</b> and follows the same usage conditions
*
* @author DarkBlade12
* @since 1.6
*/
public static final class ItemData extends ParticleData {