/
Convertor.java
267 lines (222 loc) · 6.74 KB
/
Convertor.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
package com.laytonsmith.abstraction;
import com.laytonsmith.PureUtilities.DaemonManager;
import com.laytonsmith.abstraction.blocks.MCMaterial;
import com.laytonsmith.abstraction.enums.MCDyeColor;
import com.laytonsmith.abstraction.enums.MCPatternShape;
import com.laytonsmith.abstraction.enums.MCPotionType;
import com.laytonsmith.abstraction.enums.MCRecipeType;
import com.laytonsmith.abstraction.enums.MCTone;
import com.laytonsmith.commandhelper.CommandHelperPlugin;
import com.laytonsmith.core.constructs.Target;
import com.laytonsmith.core.environments.Environment;
import com.laytonsmith.core.exceptions.CRE.CREFormatException;
import java.util.List;
import java.util.concurrent.Callable;
/**
* This should be implemented once for each server type. It mostly wraps static methods, but also provides methods for
* getting other server specific things. You can get an instance of the current Convertor by looking for the
* <code>@convert</code> tag. StaticLayer wraps all the functionality for you however.
*/
public interface Convertor {
MCLocation GetLocation(MCWorld w, double x, double y, double z, float yaw, float pitch);
Class GetServerEventMixin();
MCEnchantment[] GetEnchantmentValues();
/**
* Returns the enchantment, given an enchantment name (or a string'd number). Returns null if no such enchantment
* exists.
*
* @param name
* @return
*/
MCEnchantment GetEnchantmentByName(String name);
MCServer GetServer();
MCItemStack GetItemStack(MCMaterial type, int qty);
MCItemStack GetItemStack(String type, int qty);
MCPotionData GetPotionData(MCPotionType type, boolean extended, boolean upgraded);
void Startup(CommandHelperPlugin chp);
MCMaterial[] GetMaterialValues();
MCMaterial GetMaterialFromLegacy(String name, int data);
MCMaterial GetMaterialFromLegacy(int id, int data);
MCMaterial GetMaterial(String name);
MCMetadataValue GetMetadataValue(Object value, MCPlugin plugin);
/**
* A future runnable is run on a server accessible thread at roughly the time specified in the future. This is no
* guarantee however, as the particular server implementation may make this hard to do. The value returned is
*
* @param dm
* @param ms
* @param r
* @return
*/
int SetFutureRunnable(DaemonManager dm, long ms, Runnable r);
/**
* Clears all future runnables, but does not interrupt existing ones.
*/
void ClearAllRunnables();
/**
* Clears a future runnable task by id.
*
* @param id
*/
void ClearFutureRunnable(int id);
/**
* Adds a future repeater
*
* @param dm
* @param ms
* @param initialDelay
* @param r
* @return
*/
int SetFutureRepeater(DaemonManager dm, long ms, long initialDelay, Runnable r);
MCEntity GetCorrectEntity(MCEntity e);
MCItemMeta GetCorrectMeta(MCItemMeta im);
/**
* Returns the entities at the specified location, or null if no entities are in this location.
*
* @param loc
* @return
*/
List<MCEntity> GetEntitiesAt(MCLocation loc, double radius);
/**
* Gets the inventory of the specified entity, or null if the entity id is invalid
*
* @param entity
* @return
*/
MCInventory GetEntityInventory(MCEntity entity);
/**
* Returns the inventory of the block at the specified location, if it is an inventory type block, or null if
* otherwise invalid.
*
* @param location
* @return
*/
MCInventory GetLocationInventory(MCLocation location);
MCInventoryHolder CreateInventoryHolder(String id);
/**
* Run whenever the server is shutting down (or restarting). There is no guarantee provided as to what thread the
* runnables actually run on, so you should ensure that the runnable executes it's actions on the appropriate thread
* yourself.
*
* @param r
*/
void addShutdownHook(Runnable r);
/**
* Runs all the registered shutdown hooks. This should only be called by the shutdown mechanism. After running, each
* Runnable will be removed from the queue.
*/
void runShutdownHooks();
/**
* Runs some task on the "main" thread, possibly now, possibly in the future, and possibly even on this thread.
* However, if the platform needs some critical action to happen on one thread, (for instance, UI updates on the UI
* thread) those actions will occur here.
*
* @param dm
* @param r
*/
void runOnMainThreadLater(DaemonManager dm, Runnable r);
/**
* Works like runOnMainThreadLater, but waits for the task to finish.
*
* @param <T>
* @param callable
* @return
* @throws java.lang.Exception
*/
<T> T runOnMainThreadAndWait(Callable<T> callable) throws Exception;
/**
* Returns a MCWorldCreator object for the given world name.
*
* @param worldName
* @return
*/
MCWorldCreator getWorldCreator(String worldName);
/**
* Gets a note object, which can be used to play a sound
*
* @param octave May be 0-2
* @param tone
* @param sharp If the note should be a sharp (only applies to some tones)
* @return
*/
MCNote GetNote(int octave, MCTone tone, boolean sharp);
/**
* Returns a color object for this server.
*
* @param red
* @param green
* @param blue
* @return
*/
MCColor GetColor(int red, int green, int blue);
/**
* Returns a color object given the color name. The color name must come from the standard color types, or a
* FormatException is thrown.
*
* @param colorName
* @param t
* @return
*/
MCColor GetColor(String colorName, Target t) throws CREFormatException;
/**
* Returns a pattern object
*
* @param color
* @param shape
*/
MCPattern GetPattern(MCDyeColor color, MCPatternShape shape);
/**
* Returns an MCFirework which can be built.
*
* @return
*/
MCFireworkBuilder GetFireworkBuilder();
MCPluginMeta GetPluginMeta();
/**
* Creates a new properly typed recipe instance
*
* @param type the type of recipe
* @param result the itemstack the recipe will result in
* @return
*/
MCRecipe GetNewRecipe(String key, MCRecipeType type, MCItemStack result);
/**
* Used to convert a generic recipe into the correct type
*
* @param unspecific type
* @return specific type
*/
MCRecipe GetRecipe(MCRecipe unspecific);
/**
*
* @param name
* @return a new MCCommand instance
*/
MCCommand getNewCommand(String name);
/**
*
* @param unspecific an ambiguous MCCommandSender
* @return a properly typed MCCommandSender
*/
MCCommandSender GetCorrectSender(MCCommandSender unspecific);
/**
* Returns the name of CommandHelper by parsing the plugin.yml file.
*
* @return
*/
String GetPluginName();
/**
* Returns a MCPlugin instance of CommandHelper.
*
* @return
*/
MCPlugin GetPlugin();
/**
* Returns the name of the current user, or null if this doesn't make sense in the given platform.
*
* @param env The runtime environment, in case the convertor needs it
* @return The username
*/
String GetUser(Environment env);
}