/
TownyCuboidProperties.java
106 lines (90 loc) · 3.31 KB
/
TownyCuboidProperties.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
package com.denizenscript.depenizen.bukkit.properties.towny;
import com.denizenscript.denizencore.objects.properties.Property;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.depenizen.bukkit.objects.towny.TownTag;
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
import com.palmergames.bukkit.towny.object.TownyUniverse;
import com.denizenscript.denizen.objects.CuboidTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.objects.core.ListTag;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.tags.Attribute;
import org.bukkit.Location;
import java.util.ArrayList;
import java.util.List;
public class TownyCuboidProperties implements Property {
@Override
public String getPropertyString() {
return null;
}
@Override
public String getPropertyId() {
return "TownyCuboid";
}
@Override
public void adjust(Mechanism mechanism) {
// None
}
public static boolean describes(ObjectTag object) {
return object instanceof CuboidTag;
}
public static TownyCuboidProperties getFrom(ObjectTag object) {
if (!describes(object)) {
return null;
}
else {
return new TownyCuboidProperties((CuboidTag) object);
}
}
public static final String[] handledTags = new String[] {
"has_town", "list_towns"
};
public static final String[] handledMechs = new String[] {
}; // None
private TownyCuboidProperties(CuboidTag cuboid) {
this.cuboid = cuboid;
}
CuboidTag cuboid = null;
@Override
public String getAttribute(Attribute attribute) {
// <--[tag]
// @attribute <CuboidTag.has_town>
// @returns ElementTag(Boolean)
// @description
// Returns whether the cuboid contains any town at all.
// @Plugin Depenizen, Towny
// -->
if (attribute.startsWith("has_town")) {
for (Location location : cuboid.getBlockLocationsUnfiltered()) {
if (TownyUniverse.getTownName(location) != null) {
return new ElementTag(true).getAttribute(attribute.fulfill(1));
}
}
return new ElementTag(false).getAttribute(attribute.fulfill(1));
}
// <--[tag]
// @attribute <CuboidTag.list_towns>
// @returns ListTag(dTown)
// @description
// Returns all the towns within the cuboid.
// @Plugin Depenizen, Towny
// -->
if (attribute.startsWith("list_towns")) {
ListTag list = new ListTag();
List<String> towns = new ArrayList<>();
try {
for (Location location : cuboid.getBlockLocationsUnfiltered()) {
String townName = TownyUniverse.getTownName(location);
if (townName != null && !towns.contains(townName)) {
list.add(new TownTag(TownyUniverse.getTownBlock(location).getTown()).identify());
towns.add(townName);
}
}
}
catch (NotRegisteredException e) {
}
return list.getAttribute(attribute.fulfill(1));
}
return null;
}
}