/
TabCompleteHelper.java
85 lines (78 loc) · 3.49 KB
/
TabCompleteHelper.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
package com.denizenscript.denizen.utilities.command;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizen.objects.ItemTag;
import com.denizenscript.denizen.objects.MaterialTag;
import com.denizenscript.denizen.scripts.containers.core.EntityScriptHelper;
import com.denizenscript.denizen.scripts.containers.core.ItemScriptHelper;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.properties.PropertyParser;
import com.denizenscript.denizencore.scripts.commands.AbstractCommand;
import com.denizenscript.denizencore.utilities.CoreUtilities;
import org.bukkit.Material;
import org.bukkit.entity.EntityType;
import java.util.Map;
public class TabCompleteHelper {
public static void tabCompleteItems(AbstractCommand.TabCompletionsBuilder tab) {
int bracket = tab.arg.indexOf('[');
if (bracket == -1) {
for (Material material : Material.values()) {
if (material.isItem()) {
tab.add(material.name());
}
}
tab.add(ItemScriptHelper.item_scripts.keySet());
return;
}
String material = tab.arg.substring(0, bracket);
ItemTag item = ItemTag.valueOf(material, CoreUtilities.noDebugContext);
tabCompletePropertiesFor(tab, bracket, item);
}
public static void tabCompleteBlockMaterials(AbstractCommand.TabCompletionsBuilder tab) {
int bracket = tab.arg.indexOf('[');
if (bracket == -1) {
for (Material material : Material.values()) {
if (material.isBlock()) {
tab.add(material.name());
}
}
return;
}
String material = tab.arg.substring(0, bracket);
MaterialTag mat = MaterialTag.valueOf(material, CoreUtilities.noDebugContext);
tabCompletePropertiesFor(tab, bracket, mat);
}
public static void tabCompleteEntityTypes(AbstractCommand.TabCompletionsBuilder tab) {
int bracket = tab.arg.indexOf('[');
if (bracket == -1) {
tab.add(EntityType.values());
tab.add(EntityScriptHelper.scripts.keySet());
return;
}
String type = tab.arg.substring(0, bracket);
EntityTag entity = EntityTag.valueOf(type, CoreUtilities.noDebugContext);
if (entity == null || entity.isUnique()) {
return;
}
tabCompletePropertiesFor(tab, bracket, entity);
}
public static void tabCompletePropertiesFor(AbstractCommand.TabCompletionsBuilder tab, int bracket, ObjectTag object) {
if (object == null) {
return;
}
int lastSemicolon = tab.arg.lastIndexOf(';');
if (lastSemicolon == -1) {
lastSemicolon = bracket;
}
String propertyPart = tab.arg.substring(lastSemicolon + 1);
if (propertyPart.indexOf('=') != -1) {
return;
}
String prefixPart = tab.arg.substring(0, lastSemicolon + 1);
PropertyParser.ClassPropertiesInfo properties = PropertyParser.propertiesByClass.get(object.getObjectTagClass());
for (Map.Entry<String, PropertyParser.PropertyGetter> property : properties.propertiesByMechanism.entrySet()) {
if (property.getKey().startsWith(propertyPart) && property.getValue().get(object) != null) {
tab.add(prefixPart + property.getKey());
}
}
}
}