/
CommonRegistries.java
147 lines (141 loc) · 8.5 KB
/
CommonRegistries.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
package com.denizenscript.denizen.utilities;
import com.denizenscript.denizen.objects.*;
import com.denizenscript.denizen.tags.core.*;
import com.denizenscript.denizen.utilities.debugging.Debug;
import com.denizenscript.denizen.utilities.depends.Depends;
import com.denizenscript.denizencore.objects.ObjectFetcher;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import com.denizenscript.denizencore.utilities.CoreUtilities;
public class CommonRegistries {
// <--[language]
// @name ObjectTags
// @group Object System
// @description
// ObjectTags are a system put into place by Denizen that make working with things, or 'objects',
// in Minecraft and Denizen easier. Many parts of scripts will require some kind of object as an
// argument, identifier/type, or such as in world events, part of an event name. The ObjectTags notation
// system helps both you and Denizen know what type of objects are being referenced and worked with.
//
// So when should you use ObjectTags? In arguments, event names, replaceable tags, configs, flags, and
// more! If you're just a beginner, you've probably been using them without even realizing it!
//
// ObjectTag is a broader term for a 'type' of object that more specifically represents something,
// such as a LocationTag or ScriptTag, often times just referred to as a 'location' or 'script'. Denizen
// employs many object types that you should be familiar with. You'll notice that many times objects
// are referenced with their 'ObjectTag notation' which is in the format of 'x@', the x being the specific
// notation of an object type. Example: player objects use the p@ notation, and locations use l@.
// This notation is automatically generated when directly displaying objects, or saving them into data files.
// It should never be manually typed into a script.
//
// Let's take the tag system, for example. It uses the ObjectTags system pretty heavily. For instance,
// every time you use <player.name> or <npc.id>, you're using a ObjectTag, which brings us to a simple
// clarification: Why <player.name> and not <PlayerTag.name>? That's because Denizen allows Players,
// NPCs and other 'in-context objects' to be linked to certain scripts. In short, <player> already
// contains a reference to a specific player, such as the player that died in a world event 'on player dies'.
// <PlayerTag.name> is instead the format for documentation, with "PlayerTag" simply indicating 'any player object here'.
//
// ObjectTags can be used to CREATE new instances of objects, too! Though not all types allow 'new'
// objects to be created, many do, such as ItemTags. With the use of tags, it's easy to reference a specific
// item, say -- an item in the Player's hand -- items are also able to use a constructor to make a new item,
// and say, drop it in the world. Take the case of the command/usage '- drop diamond_ore'. The item object
// used is a brand new diamond_ore, which is then dropped by the command to a location of your choice -- just
// specify an additional location argument.
//
// There's a great deal more to learn about ObjectTags, so be sure to check out each object type for more
// specific information. While all ObjectTags share some features, many contain goodies on top of that!
// -->
// <--[language]
// @name Tick
// @group Common Terminology
// @description
// A 'tick' is usually referred to as 1/20th of a second, the speed at which Minecraft servers update
// and process everything on them.
// -->
public static void registerMainTagHandlers() {
// Objects
new BiomeTagBase();
new ChunkTagBase();
new ColorTagBase();
new CuboidTagBase();
new EllipsoidTagBase();
new EntityTagBase();
new InventoryTagBase();
new ItemTagBase();
new LocationTagBase();
new MaterialTagBase();
if (Depends.citizens != null) {
new NPCTagBase();
}
new PlayerTagBase();
new PluginTagBase();
new TradeTagBase();
new WorldTagBase();
// Other bases
new ServerTagBase();
new TextTagBase();
new ParseTagBase();
}
public static void registerMainObjects() {
ObjectFetcher.registerWithObjectFetcher(BiomeTag.class, BiomeTag.tagProcessor); // b@
ObjectFetcher.registerWithObjectFetcher(ChunkTag.class, ChunkTag.tagProcessor); // ch@
ObjectFetcher.registerWithObjectFetcher(ColorTag.class, ColorTag.tagProcessor); // co@
ObjectFetcher.registerWithObjectFetcher(CuboidTag.class, CuboidTag.tagProcessor); // cu@
ObjectFetcher.registerWithObjectFetcher(EllipsoidTag.class, EllipsoidTag.tagProcessor); // ellipsoid@
ObjectFetcher.registerWithObjectFetcher(EntityTag.class, EntityTag.tagProcessor); // e@
ObjectFetcher.registerWithObjectFetcher(InventoryTag.class, InventoryTag.tagProcessor); // in@
ObjectFetcher.registerWithObjectFetcher(ItemTag.class, ItemTag.tagProcessor); // i@
ObjectFetcher.registerWithObjectFetcher(LocationTag.class, LocationTag.tagProcessor); // l@
ObjectFetcher.registerWithObjectFetcher(MaterialTag.class, MaterialTag.tagProcessor); // m@
if (Depends.citizens != null) {
ObjectFetcher.registerWithObjectFetcher(NPCTag.class, NPCTag.tagProcessor); // n@
}
ObjectFetcher.registerWithObjectFetcher(PlayerTag.class, PlayerTag.tagProcessor); // p@
ObjectFetcher.registerWithObjectFetcher(PluginTag.class, PluginTag.tagProcessor); // pl@
ObjectFetcher.registerWithObjectFetcher(TradeTag.class, TradeTag.tagProcessor); // trade@
ObjectFetcher.registerWithObjectFetcher(WorldTag.class, WorldTag.tagProcessor); // w@
StringBuilder debug = new StringBuilder(256);
for (ObjectFetcher.ObjectType<?> objectType : ObjectFetcher.objectsByPrefix.values()) {
debug.append(objectType.clazz.getSimpleName()).append(" as ").append(objectType.prefix).append(", ");
}
CoreUtilities.registerTypeAsNoOtherTypeCode(BiomeTag.class, "b");
CoreUtilities.registerTypeAsNoOtherTypeCode(ChunkTag.class, "ch");
CoreUtilities.registerTypeAsNoOtherTypeCode(ColorTag.class, "co");
CoreUtilities.registerTypeAsNoOtherTypeCode(CuboidTag.class, "cu");
CoreUtilities.registerTypeAsNoOtherTypeCode(EllipsoidTag.class, "ellipsoid");
CoreUtilities.typeCheckers.put(EntityTag.class, new CoreUtilities.TypeComparisonRunnable() { // This is adapted 'no other type code' but for e@, p@, and n@
@Override
public boolean canBecome(ObjectTag inp) {
if (inp == null) {
return false;
}
Class<? extends ObjectTag> inpType = inp.getObjectTagClass();
if (inpType == EntityTag.class || inpType == PlayerTag.class || inpType == NPCTag.class) {
return true;
}
else if (inpType == ElementTag.class) {
String simple = inp.identifySimple();
int atIndex = simple.indexOf('@');
if (atIndex != -1) {
String code = simple.substring(0, atIndex);
if (!code.equals("e") && !code.equals("p") && !code.equals("n") && !code.equals("el")) {
return false;
}
}
return true;
}
return false;
}
});
CoreUtilities.registerTypeAsNoOtherTypeCode(InventoryTag.class, "in");
CoreUtilities.registerTypeAsNoOtherTypeCode(ItemTag.class, "i");
CoreUtilities.registerTypeAsNoOtherTypeCode(LocationTag.class, "l");
CoreUtilities.registerTypeAsNoOtherTypeCode(MaterialTag.class, "m");
CoreUtilities.registerTypeAsNoOtherTypeCode(NPCTag.class, "n");
CoreUtilities.registerTypeAsNoOtherTypeCode(PlayerTag.class, "p");
CoreUtilities.registerTypeAsNoOtherTypeCode(PluginTag.class, "pl");
CoreUtilities.registerTypeAsNoOtherTypeCode(TradeTag.class, "trade");
CoreUtilities.registerTypeAsNoOtherTypeCode(WorldTag.class, "w");
Debug.echoApproval("Loaded core object types: [" + debug.substring(0, debug.length() - 2) + "]");
}
}