-
-
Notifications
You must be signed in to change notification settings - Fork 103
/
EntityBeamTarget.java
96 lines (82 loc) · 3 KB
/
EntityBeamTarget.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
package com.denizenscript.denizen.objects.properties.entity;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizen.objects.LocationTag;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import org.bukkit.Location;
import org.bukkit.entity.EnderCrystal;
public class EntityBeamTarget implements Property {
public static boolean describes(ObjectTag entity) {
return entity instanceof EntityTag
&& ((EntityTag) entity).getBukkitEntity() instanceof EnderCrystal;
}
public static EntityBeamTarget getFrom(ObjectTag entity) {
if (!describes(entity)) {
return null;
}
else {
return new EntityBeamTarget((EntityTag) entity);
}
}
public static final String[] handledMechs = new String[] {
"beam_target"
};
private EntityBeamTarget(EntityTag entity) {
dentity = entity;
}
EntityTag dentity;
@Override
public String getPropertyString() {
Location beamTarget = getCrystal().getBeamTarget();
return beamTarget != null ? new LocationTag(beamTarget).identify() : null;
}
@Override
public String getPropertyId() {
return "beam_target";
}
public EnderCrystal getCrystal() {
return (EnderCrystal) dentity.getBukkitEntity();
}
public static void registerTags() {
// <--[tag]
// @attribute <EntityTag.beam_target>
// @returns LocationTag
// @mechanism EntityTag.beam_target
// @group properties
// @description
// Returns the target location of the ender crystal's beam, if any.
// -->
PropertyParser.registerTag(EntityBeamTarget.class, LocationTag.class, "beam_target", (attribute, object) -> {
Location beamTarget = object.getCrystal().getBeamTarget();
if (beamTarget != null) {
return new LocationTag(beamTarget);
}
return null;
});
}
@Override
public void adjust(Mechanism mechanism) {
// <--[mechanism]
// @object EntityTag
// @name beam_target
// @input LocationTag
// @description
// Sets a new target location for the ender crystal's beam.
// Provide no input to remove the beam.
// @tags
// <EntityTag.beam_target>
// -->
if (mechanism.matches("beam_target")) {
if (mechanism.hasValue()) {
if (mechanism.requireObject(LocationTag.class)) {
getCrystal().setBeamTarget(mechanism.valueAsType(LocationTag.class));
}
}
else {
getCrystal().setBeamTarget(null);
}
}
}
}