-
-
Notifications
You must be signed in to change notification settings - Fork 104
/
NPCTag.java
1779 lines (1618 loc) · 65.6 KB
/
NPCTag.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.denizenscript.denizen.objects;
import com.denizenscript.denizen.Denizen;
import com.denizenscript.denizen.npc.traits.*;
import com.denizenscript.denizen.scripts.commands.npc.EngageCommand;
import com.denizenscript.denizen.scripts.containers.core.InteractScriptContainer;
import com.denizenscript.denizen.scripts.containers.core.InteractScriptHelper;
import com.denizenscript.denizen.scripts.triggers.AbstractTrigger;
import com.denizenscript.denizencore.flags.AbstractFlagTracker;
import com.denizenscript.denizencore.flags.FlaggableObject;
import com.denizenscript.denizencore.tags.ObjectTagProcessor;
import com.denizenscript.denizencore.tags.TagRunnable;
import com.denizenscript.denizencore.utilities.Deprecations;
import com.denizenscript.denizencore.utilities.debugging.Debug;
import com.denizenscript.denizencore.objects.*;
import com.denizenscript.denizen.npc.DenizenNPCHelper;
import com.denizenscript.denizen.tags.core.NPCTagBase;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.core.ListTag;
import com.denizenscript.denizencore.objects.core.ScriptTag;
import com.denizenscript.denizencore.tags.Attribute;
import com.denizenscript.denizencore.tags.TagContext;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.ai.Navigator;
import net.citizensnpcs.api.ai.TeleportStuckAction;
import net.citizensnpcs.api.event.DespawnReason;
import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.npc.NPCRegistry;
import net.citizensnpcs.api.trait.Trait;
import net.citizensnpcs.api.trait.trait.Equipment;
import net.citizensnpcs.api.trait.trait.Owner;
import net.citizensnpcs.api.util.DataKey;
import net.citizensnpcs.api.util.MemoryDataKey;
import net.citizensnpcs.npc.ai.NPCHolder;
import net.citizensnpcs.npc.skin.SkinnableEntity;
import net.citizensnpcs.trait.*;
import net.citizensnpcs.trait.waypoint.*;
import net.citizensnpcs.util.Anchor;
import net.citizensnpcs.util.Pose;
import org.bukkit.*;
import org.bukkit.entity.*;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import java.util.*;
public class NPCTag implements ObjectTag, Adjustable, InventoryHolder, EntityFormObject, FlaggableObject {
// <--[ObjectType]
// @name NPCTag
// @prefix n
// @base EntityTag
// @implements FlaggableObject
// @format
// The identity format for NPCs is the NPC's id number.
// For example, 'n@5'.
// Or, an NPC's id number, followed by a comma, followed by a custom registry name.
// For example 'n@12,specialnpcs'
//
// @description
// An NPCTag represents an NPC configured through Citizens.
//
// This object type is flaggable.
// Flags on this object type will be stored in the Citizens saves.yml file, under the 'denizen_flags' trait.
//
// -->
public static NPCRegistry getRegistryByName(String name) {
NPCRegistry registry = CitizensAPI.getNamedNPCRegistry(name);
if (registry != null) {
return registry;
}
for (NPCRegistry possible : CitizensAPI.getNPCRegistries()) {
if (possible.getName().equals(name)) {
return possible;
}
}
return null;
}
public static NPCTag fromEntity(Entity entity) {
return new NPCTag(((NPCHolder) entity).getNPC());
}
@Deprecated
public static NPCTag valueOf(String string) {
return valueOf(string, null);
}
@Fetchable("n")
public static NPCTag valueOf(String string, TagContext context) {
if (string == null) {
return null;
}
if (string.startsWith("n@")) {
string = string.substring("n@".length());
}
NPCRegistry registry;
int commaIndex = string.indexOf(',');
String idText = string;
if (commaIndex == -1) {
registry = CitizensAPI.getNPCRegistry();
}
else {
registry = getRegistryByName(string.substring(commaIndex + 1));
if (registry == null) {
if (context == null || context.showErrors()) {
Debug.echoError("Unknown NPC registry for '" + string + "'.");
}
return null;
}
idText = string.substring(0, commaIndex);
}
if (ArgumentHelper.matchesInteger(idText)) {
int id = Integer.parseInt(idText);
NPC npc = registry.getById(id);
if (npc != null) {
return new NPCTag(npc);
}
else if (context == null || context.showErrors()) {
Debug.echoError("NPC '" + id + "' does not exist in " + registry.getName() + ".");
}
}
return null;
}
public static boolean matches(String string) {
if (CoreUtilities.toLowerCase(string).startsWith("n@")) {
return true;
}
if (valueOf(string, CoreUtilities.noDebugContext) != null) {
return true;
}
return false;
}
public boolean isValid() {
return npc != null && npc.getOwningRegistry().getById(npc.getId()) != null;
}
@Override
public AbstractFlagTracker getFlagTracker() {
return npc.getOrAddTrait(DenizenFlagsTrait.class).fullFlagData;
}
public boolean hasFlag(String flag) {
DenizenFlagsTrait flagTrait = npc.getTraitNullable(DenizenFlagsTrait.class);
if (flagTrait == null) {
return false;
}
return flagTrait.fullFlagData.hasFlag(flag);
}
@Override
public void reapplyTracker(AbstractFlagTracker tracker) {
// Nothing to do.
}
public NPC npc;
public NPCTag(NPC citizensNPC) {
this.npc = citizensNPC;
}
public NPC getCitizen() {
return npc;
}
public Entity getEntity() {
try {
return getCitizen().getEntity();
}
catch (NullPointerException ex) {
Debug.echoError("Uh oh! Denizen has encountered a NPE while trying to fetch an NPC entity. " +
"Has this NPC been removed?");
if (Debug.verbose) {
Debug.echoError(ex);
}
return null;
}
}
public LivingEntity getLivingEntity() {
try {
if (getCitizen().getEntity() instanceof LivingEntity) {
return (LivingEntity) getCitizen().getEntity();
}
else {
Debug.log("Uh oh! Tried to get the living entity of a non-living NPC!");
return null;
}
}
catch (NullPointerException ex) {
Debug.echoError("Uh oh! Denizen has encountered a NPE while trying to fetch an NPC livingEntity. " +
"Has this NPC been removed?");
if (Debug.verbose) {
Debug.echoError(ex);
}
return null;
}
}
@Override
public EntityTag getDenizenEntity() {
try {
return new EntityTag(getCitizen().getEntity());
}
catch (NullPointerException ex) {
Debug.echoError("Uh oh! Denizen has encountered a NPE while trying to fetch an NPC EntityTag. " +
"Has this NPC been removed?");
if (Debug.verbose) {
Debug.echoError(ex);
}
return null;
}
}
@Override
public Inventory getInventory() {
return DenizenNPCHelper.getInventory(getCitizen());
}
public InventoryTag getDenizenInventory() {
return new InventoryTag(getInventory(), this);
}
public EntityType getEntityType() {
return getCitizen().getEntity().getType();
}
public Navigator getNavigator() {
return getCitizen().getNavigator();
}
public int getId() {
return npc.getId();
}
public String getName() {
return getCitizen().getName();
}
public InteractScriptContainer getInteractScript() {
return InteractScriptHelper.getInteractScript(this);
}
public InteractScriptContainer getInteractScript(PlayerTag player, Class<? extends AbstractTrigger> triggerType) {
return InteractScriptHelper.getInteractScript(this, player, true, triggerType);
}
public InteractScriptContainer getInteractScriptQuietly(PlayerTag player, Class<? extends AbstractTrigger> triggerType) {
return InteractScriptHelper.getInteractScript(this, player, false, triggerType);
}
public void destroy() {
getCitizen().destroy();
}
@Override
public LocationTag getLocation() {
if (isSpawned()) {
return new LocationTag(getEntity().getLocation());
}
else {
return new LocationTag(getCitizen().getStoredLocation());
}
}
public LocationTag getEyeLocation() {
if (isSpawned() && getCitizen().getEntity() instanceof LivingEntity) {
return new LocationTag(((LivingEntity) getCitizen().getEntity()).getEyeLocation());
}
else if (isSpawned()) {
return new LocationTag(getEntity().getLocation());
}
else {
return new LocationTag(getCitizen().getStoredLocation());
}
}
public World getWorld() {
if (isSpawned()) {
return getEntity().getWorld();
}
else {
return null;
}
}
@Override
public String toString() {
return identify();
}
public boolean isEngaged() {
return EngageCommand.getEngaged(getCitizen());
}
public boolean isSpawned() {
return npc.isSpawned();
}
public UUID getOwner() {
return getCitizen().getOrAddTrait(Owner.class).getOwnerId();
}
public AssignmentTrait getAssignmentTrait() {
return getCitizen().getOrAddTrait(AssignmentTrait.class);
}
public Equipment getEquipmentTrait() {
return getCitizen().getOrAddTrait(Equipment.class);
}
public NicknameTrait getNicknameTrait() {
return getCitizen().getOrAddTrait(NicknameTrait.class);
}
public FishingTrait getFishingTrait() {
return getCitizen().getOrAddTrait(FishingTrait.class);
}
public net.citizensnpcs.api.trait.trait.Inventory getInventoryTrait() {
return getCitizen().getOrAddTrait(net.citizensnpcs.api.trait.trait.Inventory.class);
}
public PushableTrait getPushableTrait() {
return getCitizen().getOrAddTrait(PushableTrait.class);
}
public LookClose getLookCloseTrait() {
return getCitizen().getOrAddTrait(LookClose.class);
}
public TriggerTrait getTriggerTrait() {
return getCitizen().getOrAddTrait(TriggerTrait.class);
}
public String action(String actionName, PlayerTag player, Map<String, ObjectTag> context) {
if (getCitizen() != null) {
if (getCitizen().hasTrait(AssignmentTrait.class)) {
return Denizen.getInstance().npcHelper.getActionHandler().doAction(actionName, this, player, getAssignmentTrait().getAssignment(), context);
}
}
return "none";
}
public String action(String actionName, PlayerTag player) {
return action(actionName, player, null);
}
private String prefix = "npc";
@Override
public String getPrefix() {
return prefix;
}
@Override
public String debuggable() {
if (npc.getOwningRegistry() == CitizensAPI.getNPCRegistry()) {
return "n@" + npc.getId() + "<GR> (" + getName() + "<GR>)";
}
else {
return "n@" + npc.getId() + "<G>," + npc.getOwningRegistry().getName() + "<GR> (" + getName() + "<GR>)";
}
}
@Override
public boolean isUnique() {
return true;
}
@Override
public String getObjectType() {
return "NPC";
}
@Override
public String identify() {
if (npc.getOwningRegistry() == CitizensAPI.getNPCRegistry()) {
return "n@" + npc.getId();
}
else {
return "n@" + npc.getId() + "," + npc.getOwningRegistry().getName();
}
}
@Override
public String identifySimple() {
return identify();
}
@Override
public NPCTag setPrefix(String prefix) {
this.prefix = prefix;
return this;
}
@Override
public boolean equals(Object o) {
if (o == null) {
return false;
}
if (!(o instanceof NPCTag)) {
return false;
}
return getId() == ((NPCTag) o).getId();
}
@Override
public int hashCode() {
return getId();
}
public static void registerTags() {
AbstractFlagTracker.registerFlagHandlers(tagProcessor);
// Defined in EntityTag
tagProcessor.registerTag(ElementTag.class, "is_npc", (attribute, object) -> {
return new ElementTag(true);
});
// Defined in EntityTag
tagProcessor.registerTag(ObjectTag.class, "location", (attribute, object) -> {
if (attribute.startsWith("previous_location", 2)) {
attribute.fulfill(1);
Deprecations.npcPreviousLocationTag.warn(attribute.context);
return NPCTagBase.previousLocations.get(object.getId());
}
if (object.isSpawned()) {
return new EntityTag(object).getObjectAttribute(attribute);
}
return object.getLocation();
});
// <--[tag]
// @attribute <NPCTag.previous_location>
// @returns LocationTag
// @description
// Returns the NPC's previous navigated location.
// -->
tagProcessor.registerTag(LocationTag.class, "previous_location", (attribute, object) -> {
return NPCTagBase.previousLocations.get(object.getId());
});
// Defined in EntityTag
tagProcessor.registerTag(LocationTag.class, "eye_location", (attribute, object) -> {
return object.getEyeLocation();
});
// <--[tag]
// @attribute <NPCTag.has_nickname>
// @returns ElementTag(Boolean)
// @description
// Returns true if the NPC has a nickname.
// -->
tagProcessor.registerTag(ElementTag.class, "has_nickname", (attribute, object) -> {
NPC citizen = object.getCitizen();
return new ElementTag(citizen.hasTrait(NicknameTrait.class) && citizen.getOrAddTrait(NicknameTrait.class).hasNickname());
});
// <--[tag]
// @attribute <NPCTag.is_sitting>
// @returns ElementTag(Boolean)
// @description
// Returns true if the NPC is sitting. Relates to <@link command sit>.
// -->
tagProcessor.registerTag(ElementTag.class, "is_sitting", (attribute, object) -> {
NPC citizen = object.getCitizen();
return new ElementTag(citizen.hasTrait(SittingTrait.class) && citizen.getOrAddTrait(SittingTrait.class).isSitting());
});
// <--[tag]
// @attribute <NPCTag.is_sleeping>
// @returns ElementTag(Boolean)
// @description
// Returns true if the NPC is sleeping. Relates to <@link command sleep>.
// -->
tagProcessor.registerTag(ElementTag.class, "is_sleeping", (attribute, object) -> {
NPC citizen = object.getCitizen();
return new ElementTag(citizen.hasTrait(SleepingTrait.class) && citizen.getOrAddTrait(SleepingTrait.class).isSleeping());
});
// <--[tag]
// @attribute <NPCTag.nickname>
// @returns ElementTag
// @description
// Returns the NPC's display name, as set by the Nickname trait (or the default NPC name).
// -->
tagProcessor.registerTag(ElementTag.class, "nickname", (attribute, object) -> {
return new ElementTag(object.getCitizen().hasTrait(NicknameTrait.class) ? object.getCitizen().getOrAddTrait(NicknameTrait.class)
.getNickname() : object.getName());
});
// Documented in EntityTag
tagProcessor.registerTag(ElementTag.class, "name", (attribute, object) -> {
if (attribute.startsWith("nickname", 2)) {
Deprecations.npcNicknameTag.warn(attribute.context);
attribute.fulfill(1);
return new ElementTag(object.getCitizen().hasTrait(NicknameTrait.class) ? object.getCitizen().getOrAddTrait(NicknameTrait.class)
.getNickname() : object.getName());
}
return new ElementTag(object.getName());
});
// <--[tag]
// @attribute <NPCTag.traits>
// @returns ListTag
// @description
// Returns a list of all of the NPC's traits.
// -->
tagProcessor.registerTag(ListTag.class, "traits", (attribute, object) -> {
List<String> list = new ArrayList<>();
for (Trait trait : object.getCitizen().getTraits()) {
list.add(trait.getName());
}
return new ListTag(list);
}, "list_traits");
// <--[tag]
// @attribute <NPCTag.has_trait[<trait>]>
// @returns ElementTag(Boolean)
// @description
// Returns whether the NPC has a specified trait.
// -->
tagProcessor.registerTag(ElementTag.class, "has_trait", (attribute, object) -> {
if (attribute.hasContext(1)) {
Class<? extends Trait> trait = CitizensAPI.getTraitFactory().getTraitClass(attribute.getContext(1));
if (trait != null) {
return new ElementTag(object.getCitizen().hasTrait(trait));
}
}
return null;
});
// <--[tag]
// @attribute <NPCTag.pushable>
// @returns ElementTag(Boolean)
// @description
// Returns whether the NPC is pushable.
// -->
tagProcessor.registerTag(ElementTag.class, "pushable", (attribute, object) -> {
return new ElementTag(object.getPushableTrait().isPushable());
}, "is_pushable");
// <--[tag]
// @attribute <NPCTag.has_trigger[<trigger>]>
// @returns ElementTag(Boolean)
// @description
// Returns whether the NPC has a specified trigger.
// -->
tagProcessor.registerTag(ElementTag.class, "has_trigger", (attribute, object) -> {
if (!attribute.hasContext(1)) {
return null;
}
if (!object.getCitizen().hasTrait(TriggerTrait.class)) {
return new ElementTag(false);
}
TriggerTrait trait = object.getCitizen().getOrAddTrait(TriggerTrait.class);
return new ElementTag(trait.hasTrigger(attribute.getContext(1)));
});
// <--[tag]
// @attribute <NPCTag.has_anchors>
// @returns ElementTag(Boolean)
// @description
// Returns whether the NPC has anchors assigned.
// -->
tagProcessor.registerTag(ElementTag.class, "has_anchors", (attribute, object) -> {
return (new ElementTag(object.getCitizen().getOrAddTrait(Anchors.class).getAnchors().size() > 0));
});
// <--[tag]
// @attribute <NPCTag.list_anchors>
// @returns ListTag
// @description
// Returns a list of anchor names currently assigned to the NPC.
// -->
tagProcessor.registerTag(ListTag.class, "list_anchors", (attribute, object) -> {
ListTag list = new ListTag();
for (Anchor anchor : object.getCitizen().getOrAddTrait(Anchors.class).getAnchors()) {
list.add(anchor.getName());
}
return list;
});
// <--[tag]
// @attribute <NPCTag.anchor[<name>]>
// @returns LocationTag
// @description
// Returns the location associated with the specified anchor, or null if it doesn't exist.
// -->
tagProcessor.registerTag(ObjectTag.class, "anchor", (attribute, object) -> {
Anchors trait = object.getCitizen().getOrAddTrait(Anchors.class);
if (attribute.hasContext(1)) {
Anchor anchor = trait.getAnchor(attribute.getContext(1));
if (anchor != null) {
return new LocationTag(anchor.getLocation());
}
else {
attribute.echoError("NPC Anchor '" + attribute.getContext(1) + "' is not defined.");
return null;
}
}
else if (attribute.startsWith("list", 2)) {
attribute.fulfill(1);
Deprecations.npcAnchorListTag.warn(attribute.context);
ListTag list = new ListTag();
for (Anchor anchor : trait.getAnchors()) {
list.add(anchor.getName());
}
return list;
}
else {
attribute.echoError("npc.anchor[...] tag must have an input.");
}
return null;
}, "anchors");
// <--[tag]
// @attribute <NPCTag.constant[<constant_name>]>
// @returns ElementTag
// @description
// Returns the specified constant from the NPC.
// -->
tagProcessor.registerTag(ElementTag.class, "constant", (attribute, object) -> {
if (attribute.hasContext(1)) {
if (object.getCitizen().hasTrait(ConstantsTrait.class)
&& object.getCitizen().getOrAddTrait(ConstantsTrait.class).getConstant(attribute.getContext(1)) != null) {
return new ElementTag(object.getCitizen().getOrAddTrait(ConstantsTrait.class)
.getConstant(attribute.getContext(1)));
}
else {
return null;
}
}
return null;
});
// <--[tag]
// @attribute <NPCTag.has_pose[<name>]>
// @returns ElementTag(Boolean)
// @description
// Returns true if the NPC has the specified pose, otherwise returns false.
// -->
tagProcessor.registerTag(ElementTag.class, "has_pose", (attribute, object) -> {
if (attribute.hasContext(1)) {
return new ElementTag(object.getCitizen().getOrAddTrait(Poses.class).hasPose(attribute.getContext(1)));
}
else {
return null;
}
});
// <--[tag]
// @attribute <NPCTag.pose[<name>]>
// @returns LocationTag
// @description
// Returns the pose as a LocationTag with x, y, and z set to 0, and the world set to the first
// possible available world Bukkit knows about.
// -->
tagProcessor.registerTag(LocationTag.class, "pose", (attribute, object) -> {
if (attribute.hasContext(1)) {
Pose pose = object.getCitizen().getOrAddTrait(Poses.class).getPose(attribute.getContext(1));
return new LocationTag(org.bukkit.Bukkit.getWorlds().get(0), 0, 0, 0, pose.getYaw(), pose.getPitch());
}
else {
return null;
}
}, "get_pose");
// <--[tag]
// @attribute <NPCTag.name_hologram_npc>
// @returns NPCTag
// @description
// Returns the NPCTag of a hologram attached to this NPC as its nameplate (if any).
// Note that this can regenerate at any time.
// -->
tagProcessor.registerTag(ObjectTag.class, "name_hologram_npc", (attribute, object) -> {
if (!object.getCitizen().hasTrait(HologramTrait.class)) {
return null;
}
HologramTrait hologram = object.getCitizen().getTraitNullable(HologramTrait.class);
Entity entity = hologram.getNameEntity();
if (entity == null) {
return null;
}
return new EntityTag(entity).getDenizenObject();
});
// <--[tag]
// @attribute <NPCTag.hologram_npcs>
// @returns ListTag(NPCTag)
// @description
// Returns the list of hologram NPCs attached to an NPC (if any).
// Note that these can regenerate at any time.
// -->
tagProcessor.registerTag(ListTag.class, "hologram_npcs", (attribute, object) -> {
if (!object.getCitizen().hasTrait(HologramTrait.class)) {
return null;
}
HologramTrait hologram = object.getCitizen().getTraitNullable(HologramTrait.class);
Collection<ArmorStand> stands = hologram.getHologramEntities();
if (stands == null || stands.isEmpty()) {
return null;
}
ListTag output = new ListTag();
for (ArmorStand stand : stands) {
output.addObject(new EntityTag(stand).getDenizenObject());
}
return output;
});
// <--[tag]
// @attribute <NPCTag.hologram_lines>
// @returns ListTag
// @mechanism NPCTag.hologram_lines
// @description
// Returns the list of hologram lines attached to an NPC.
// -->
tagProcessor.registerTag(ListTag.class, "hologram_lines", (attribute, object) -> {
if (!object.getCitizen().hasTrait(HologramTrait.class)) {
return null;
}
HologramTrait hologram = object.getCitizen().getTraitNullable(HologramTrait.class);
return new ListTag(hologram.getLines());
});
// <--[tag]
// @attribute <NPCTag.hologram_direction>
// @returns ElementTag
// @mechanism NPCTag.hologram_direction
// @description
// Returns the direction of an NPC's hologram as "BOTTOM_UP" or "TOP_DOWN".
// -->
tagProcessor.registerTag(ElementTag.class, "hologram_direction", (attribute, object) -> {
if (!object.getCitizen().hasTrait(HologramTrait.class)) {
return null;
}
HologramTrait hologram = object.getCitizen().getTraitNullable(HologramTrait.class);
return new ElementTag(hologram.getDirection().name());
});
// <--[tag]
// @attribute <NPCTag.hologram_line_height>
// @returns ElementTag(Decimal)
// @mechanism NPCTag.hologram_line_height
// @description
// Returns the line height for an NPC's hologram. Can be -1, indicating a default value should be used.
// -->
tagProcessor.registerTag(ElementTag.class, "hologram_line_height", (attribute, object) -> {
if (!object.getCitizen().hasTrait(HologramTrait.class)) {
return null;
}
HologramTrait hologram = object.getCitizen().getTraitNullable(HologramTrait.class);
return new ElementTag(hologram.getLineHeight());
});
// <--[tag]
// @attribute <NPCTag.is_sneaking>
// @returns ElementTag(Boolean)
// @description
// Returns whether the NPC is currently sneaking. Only works for player-type NPCs.
// -->
tagProcessor.registerTag(ElementTag.class, "is_sneaking", (attribute, object) -> {
if (!object.isSpawned() && object.getEntity() instanceof Player) {
return null;
}
return new ElementTag(((Player) object.getEntity()).isSneaking());
});
// <--[tag]
// @attribute <NPCTag.engaged>
// @returns ElementTag(Boolean)
// @description
// Returns whether the NPC is currently engaged.
// See <@link command engage>
// -->
tagProcessor.registerTag(ElementTag.class, "engaged", (attribute, object) -> {
return new ElementTag(object.isEngaged());
}, "is_engaged");
// <--[tag]
// @attribute <NPCTag.invulnerable>
// @returns ElementTag(Boolean)
// @description
// Returns whether the NPC is currently invulnerable.
// See <@link command vulnerable>
// -->
tagProcessor.registerTag(ElementTag.class, "invulnerable", (attribute, object) -> {
return new ElementTag(object.getCitizen().data().get(NPC.DEFAULT_PROTECTED_METADATA, true));
}, "vulnerable");
// <--[tag]
// @attribute <NPCTag.id>
// @returns ElementTag(Number)
// @description
// Returns the NPC's ID number.
// -->
tagProcessor.registerTag(ElementTag.class, "id", (attribute, object) -> {
return new ElementTag(object.getId());
});
// <--[tag]
// @attribute <NPCTag.owner>
// @returns PlayerTag
// @mechanism NPCTag.owner
// @description
// Returns the owner of the NPC as a PlayerTag, if any.
// -->
tagProcessor.registerTag(ObjectTag.class, "owner", (attribute, object) -> {
UUID owner = object.getOwner();
if (owner == null) {
return null;
}
OfflinePlayer player = Bukkit.getOfflinePlayer(owner);
if (player.hasPlayedBefore()) {
return new PlayerTag(player);
}
return null;
});
// <--[tag]
// @attribute <NPCTag.has_skin>
// @returns ElementTag(Boolean)
// @mechanism NPCTag.skin
// @description
// Returns whether the NPC has a custom skin.
// -->
tagProcessor.registerTag(ElementTag.class, "has_skin", (attribute, object) -> {
return new ElementTag(object.getCitizen().hasTrait(SkinTrait.class) && object.getCitizen().getOrAddTrait(SkinTrait.class).getSkinName() != null);
});
// <--[tag]
// @attribute <NPCTag.skin_blob>
// @returns ElementTag
// @mechanism NPCTag.skin_blob
// @description
// Returns the NPC's custom skin blob, if any.
// In the format: "texture;signature" (two values separated by a semicolon).
// See also <@link language Player Entity Skins (Skin Blobs)>.
// -->
tagProcessor.registerTag(ElementTag.class, "skin_blob", (attribute, object) -> {
if (object.getCitizen().hasTrait(SkinTrait.class)) {
SkinTrait skin = object.getCitizen().getOrAddTrait(SkinTrait.class);
String tex = skin.getTexture();
String sign = "";
if (skin.getSignature() != null) {
sign = ";" + skin.getSignature();
}
return new ElementTag(tex + sign);
}
return null;
});
// <--[tag]
// @attribute <NPCTag.skull_skin>
// @returns ElementTag
// @description
// Returns the NPC's current skin blob, formatted for input to a Player Skull item.
// In the format: "UUID|Texture" (two values separated by pipes).
// See also <@link language Player Entity Skins (Skin Blobs)>.
// -->
tagProcessor.registerTag(ElementTag.class, "skull_skin", (attribute, object) -> {
if (!object.getCitizen().hasTrait(SkinTrait.class)) {
return null;
}
SkinTrait skin = object.getCitizen().getOrAddTrait(SkinTrait.class);
return new ElementTag(skin.getSkinName() + "|" + skin.getTexture());
});
// <--[tag]
// @attribute <NPCTag.skin>
// @returns ElementTag
// @mechanism NPCTag.skin
// @description
// Returns the NPC's custom skin, if any.
// -->
tagProcessor.registerTag(ElementTag.class, "skin", (attribute, object) -> {
if (object.getCitizen().hasTrait(SkinTrait.class)) {
return new ElementTag(object.getCitizen().getOrAddTrait(SkinTrait.class).getSkinName());
}
return null;
});
// <--[tag]
// @attribute <NPCTag.auto_update_skin>
// @returns ElementTag(Boolean)
// @mechanism NPCTag.auto_update_skin
// @description
// Returns whether the NPC is set to automatically update skins from name.
// -->
tagProcessor.registerTag(ElementTag.class, "auto_update_skin", (attribute, object) -> {
if (object.getCitizen().hasTrait(SkinTrait.class)) {
return new ElementTag(object.getCitizen().getOrAddTrait(SkinTrait.class).shouldUpdateSkins());
}
return null;
});
// <--[tag]
// @attribute <NPCTag.inventory>
// @returns InventoryTag
// @description
// Returns the InventoryTag of the NPC.
// -->
tagProcessor.registerTag(InventoryTag.class, "inventory", (attribute, object) -> {
return object.getDenizenInventory();
});
// <--[tag]
// @attribute <NPCTag.is_spawned>
// @returns ElementTag(Boolean)
// @description
// Returns whether the NPC is spawned.
// -->
tagProcessor.registerTag(ElementTag.class, "is_spawned", (attribute, object) -> {
return new ElementTag(object.isSpawned());
});
// <--[tag]
// @attribute <NPCTag.is_protected>
// @returns ElementTag(Boolean)
// @description
// Returns whether the NPC is protected.
// -->
tagProcessor.registerTag(ElementTag.class, "is_protected", (attribute, object) -> {
return new ElementTag(object.getCitizen().isProtected());
});
// <--[tag]
// @attribute <NPCTag.lookclose>
// @returns ElementTag(Boolean)
// @mechanism NPCTag.lookclose
// @description
// Returns whether the NPC has lookclose enabled.
// -->
tagProcessor.registerTag(ElementTag.class, "lookclose", (attribute, object) -> {
NPC citizen = object.getCitizen();
if (citizen.hasTrait(LookClose.class)) {
// There is no method to check if the NPC has LookClose enabled...
// LookClose.toString() returns "LookClose{" + enabled + "}"
String lookclose = citizen.getOrAddTrait(LookClose.class).toString();
lookclose = lookclose.substring(10, lookclose.length() - 1);
return new ElementTag(Boolean.valueOf(lookclose));
}
return new ElementTag(false);
});
// <--[tag]
// @attribute <NPCTag.controllable>
// @returns ElementTag(Boolean)
// @mechanism NPCTag.controllable
// @description
// Returns whether the NPC has controllable enabled.
// -->
tagProcessor.registerTag(ElementTag.class, "controllable", (attribute, object) -> {
if (object.getCitizen().hasTrait(Controllable.class)) {
return new ElementTag(object.getCitizen().getOrAddTrait(Controllable.class).isEnabled());
}
return new ElementTag(false);
});
// <--[tag]
// @attribute <NPCTag.targetable>
// @returns ElementTag(Boolean)
// @mechanism NPCTag.targetable
// @description
// Returns whether the NPC is targetable.
// -->
tagProcessor.registerTag(ElementTag.class, "targetable", (attribute, object) -> {
boolean targetable = object.getCitizen().data().get(NPC.TARGETABLE_METADATA, object.getCitizen().data().get(NPC.DEFAULT_PROTECTED_METADATA, true));
return new ElementTag(targetable);
});
// <--[tag]
// @attribute <NPCTag.teleport_on_stuck>
// @returns ElementTag(Boolean)
// @mechanism NPCTag.teleport_on_stuck
// @description
// Returns whether the NPC teleports when it is stuck.
// -->
tagProcessor.registerTag(ElementTag.class, "teleport_on_stuck", (attribute, object) -> {
return new ElementTag(object.getNavigator().getDefaultParameters().stuckAction() == TeleportStuckAction.INSTANCE);
});
tagProcessor.registerTag(ElementTag.class, "has_script", (attribute, object) -> {
Deprecations.hasScriptTags.warn(attribute.context);
NPC citizen = object.getCitizen();
return new ElementTag(citizen.hasTrait(AssignmentTrait.class) && citizen.getOrAddTrait(AssignmentTrait.class).hasAssignment());
});
// <--[tag]
// @attribute <NPCTag.script>
// @returns ScriptTag
// @description
// Returns the NPC's assigned script.
// -->