-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathShows.java
More file actions
353 lines (301 loc) · 12.2 KB
/
Shows.java
File metadata and controls
353 lines (301 loc) · 12.2 KB
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
package us.mcparks.showscript;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.stream.Collectors;
import cloud.commandframework.annotations.Argument;
import cloud.commandframework.annotations.CommandMethod;
import cloud.commandframework.annotations.CommandPermission;
import cloud.commandframework.annotations.Flag;
import cloud.commandframework.annotations.parsers.Parser;
import cloud.commandframework.annotations.suggestions.Suggestions;
import cloud.commandframework.context.CommandContext;
import cloud.commandframework.execution.preprocessor.CommandPreprocessingContext;
import cloud.commandframework.execution.preprocessor.CommandPreprocessor;
import us.mcparks.showscript.showscript.framework.ShowArgs;
import us.mcparks.showscript.showscript.framework.schedulers.ShowScheduler;
/* // <INTERNAL>
import us.mcparks.showscript.showscript.toaster.ShowSched;
// </INTERNAL> */
import us.mcparks.showscript.util.DebugLogger;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.BlockCommandSender;
import org.bukkit.command.CommandSender;
import org.bukkit.command.ConsoleCommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.checkerframework.checker.nullness.qual.NonNull;
public class Shows {
public static Plugin plugin;
public static Main main;
public Shows(Plugin pl, Main m) {
Shows.plugin = pl;
Shows.main = m;
Main.cloudCommandManager.registerCommandPreProcessor(new LegacyLogActionsArgumentPreprocessor<>());
}
@CommandMethod("show toggledebug")
@CommandPermission("castmember")
public void toggleDebug(CommandSender sender) {
DebugLogger.toggleLogging();
sender.sendMessage("Console debug has been set to: " + DebugLogger.isEnabled());
}
@CommandMethod("show stopall")
@CommandPermission("castmember")
public void stopAllShows(CommandSender sender) {
if (sender instanceof Player) {
int count = main.cancelAllShows();
sender.sendMessage(ChatColor.AQUA + "" + count + ChatColor.GREEN
+ " shows stopped.");
}
}
@CommandMethod("show stop <showName>")
@CommandPermission("castmember")
public void stopShow(CommandSender sender, @Argument(value = "showName", suggestions = "runningShows") String showName) {
int count = main.cancelShowByName(showName);
sender.sendMessage(ChatColor.AQUA + "" + count + ChatColor.GREEN
+ " instances of show " + ChatColor.AQUA + showName + ChatColor.GREEN
+ " cancelled.");
}
@CommandMethod("show list")
@CommandPermission("castmember")
public void listShows(CommandSender sender,
@Flag(value="path", suggestions = "showDirectoryNames") String path) {
List<ShowScheduler> shows = main.getActiveShows();
List<ShowScheduler> filteredShows = shows;
// Filter by path if provided
if (path != null) {
filteredShows = shows.stream()
.filter(show -> show.getName().startsWith(path))
.collect(Collectors.toList());
}
// Build message with filter info if applicable
StringBuilder message = new StringBuilder(ChatColor.AQUA)
.append(filteredShows.size())
.append(ChatColor.GREEN)
.append(" shows")
.append(path != null ? " (filtered by path: " + path + ")" : "")
.append(": ");
sender.sendMessage(message.toString());
// Display shows
for (ShowScheduler show : filteredShows) {
sender.sendMessage(ChatColor.AQUA + show.getName() + ChatColor.GRAY + " - " + ChatColor.GREEN + "Syntax Version: " + show.getSyntaxVersion());
}
}
@CommandMethod("show start <showName>")
@CommandPermission("castmember")
public void startShowCommand(CommandSender sender,
@Flag(value = "log") boolean logActions,
@Flag(value="async") boolean async,
@Flag(value="startAt") Integer startAt,
@Flag(value="args", parserName = "showArguments") String args,
@Argument(value = "showName", suggestions = "showNames") String showName) {
if (startAt == null) {
startAt = 0;
}
startShow(showName, sender, logActions, async, startAt, new ShowArgs(args));
}
@CommandMethod("show startasync <showName> [logActions]")
@CommandPermission("castmember")
public void startShowAsyncCommand(CommandSender sender,
@Argument(value = "showName", suggestions = "showNames") String showName,
@Argument(value = "logActions", defaultValue = "false") boolean logActions) {
startShow(showName, sender, logActions, true, 0, null);
}
@CommandMethod("show startat <showName> <logActions> <startAt>")
@CommandPermission("castmember")
public void startShowAtCommand(CommandSender sender,
@Argument(value = "showName", suggestions = "showNames") String showName,
@Argument("logActions") boolean logActions,
@Argument("startAt") int startAt) {
startShow(showName, sender, logActions, false, startAt, null);
}
/**
* Command auto-completion for all show names
* @param sender
* @param input
* @return
*/
@Suggestions("showNames")
public List<String> showNames(CommandContext<CommandSender> sender, String input) {
if (input.isEmpty()) {
return new ArrayList<>();
}
return main.showFileNames.get().stream().filter(s -> s.startsWith(input)).collect(Collectors.toList());
}
@Suggestions("showDirectoryNames")
public List<String> showDirectories(CommandContext<CommandSender> sender, String input) {
if (input.isEmpty()) {
return new ArrayList<>();
}
return main.showFileNames.get().stream().map(path -> path.lastIndexOf("/") == -1 ? path : path.substring(0, path.lastIndexOf("/"))).distinct().filter(s -> s.startsWith(input)).collect(Collectors.toList());
}
public static String getShowNameFromAbsolutePath(String absolutePath) {
return absolutePath.substring(Main.getPlugin(Main.class).fs.getAbsolutePath().toString().length()+1);
}
@Parser(name = "showArguments")
public String parseShowArguments(CommandContext<CommandSender> sender, Queue<String> input) {
StringBuilder sb = new StringBuilder();
while (!input.isEmpty()) {
sb.append(input.poll());
sb.append(" ");
}
return sb.toString().trim();
}
/**
* For compatibility with legacy command syntax `/show start <showName> <logActions>`, convert
* `/show start <showName> true` to `/show start <showName> --log`
* and `/show start <showName> false` to `/show start <showName>`
* @param <C>
*/
static class LegacyLogActionsArgumentPreprocessor<C> implements CommandPreprocessor<C> {
@Override
public void accept(@NonNull CommandPreprocessingContext<C> context) {
List<String> input = context.getInputQueue();
if (input.size() == 4) {
if (input.get(0).equalsIgnoreCase("show") && input.get(1).equalsIgnoreCase("start")) {
if (input.get(3).equalsIgnoreCase("true")) {
input.set(3, "--log");
} else if (input.get(3).equalsIgnoreCase("false")) {
input.remove(3);
}
}
}
}
}
/**
* Command auto-completion for running shows
* @param sender
* @param input
* @return
*/
@Suggestions("runningShows")
public List<String> runningShows(CommandContext<CommandSender> sender, String input) {
return main.getActiveShows().stream().map(ShowScheduler::getName).filter(s -> s.startsWith(input)).collect(Collectors.toList());
}
public void startShow(String name, CommandSender p, boolean display, boolean async, int timecode, ShowArgs args) {
String log = "";
if (p instanceof Player) {
log += "Player " + p.getName() + " ";
} else if (p instanceof BlockCommandSender) {
BlockCommandSender b = (BlockCommandSender) p;
log += "CommandBlock at " + b.getBlock().getX() + ", " + b.getBlock().getY() + ", " + b.getBlock().getZ() + " ";
} else if (p instanceof ConsoleCommandSender) {
log += "Console ";
}
log += "is starting show " + name;
if (async) {
log += " asynchronously";
}
if (timecode > 0) {
log += " at timecode " + timecode;
}
Bukkit.getLogger().info(log);
File groovyFile = new File(main.fs, name + ".groovy");
File yamlFile = new File(main.fs, name + ".yml");
if (groovyFile.exists() || yamlFile.exists()) {
main.timecodeExecutor.startShowAt(name, p, display, 0, timecode, async, args);
} else {
startToasterShow(name, p, display);
}
}
// In our internal version of ShowScript, this method is used to invoke the parser for a reaaaally old format of show
// files that MCParks used while we were partnered with mcamusement. This old show plugin was built by mr_toaster111,
// so the file extension is .toaster!
private void startToasterShow(String name, CommandSender p, boolean display) {
File file = new File(main.fs, name + ".toaster");
FileConfiguration filez;
if (!file.exists()) {
p.sendMessage(ChatColor.RED + "ERROR:\n");
p.sendMessage("File does not exist!");
return;
}
try {
filez = YamlConfiguration.loadConfiguration(file);
} catch (Exception x) {
p.sendMessage(ChatColor.RED + "ERROR:\n");
p.sendMessage(x.getMessage());
return;
}
Queue<String> showContents;
showContents = new LinkedList<String>();
for (String str : filez.getKeys(false)) {
if (str.equals("counter")) {
//
} else {
showContents.add(str);
}
}
/* // <INTERNAL>
ShowSched ss = new ShowSched(plugin, main, showContents, name, display, p);
ss.runTaskTimer(plugin, 1, 1);
// </INTERNAL> */
}
/* // <INTERNAL>
public void convertShow(String name) {
FileConfiguration filez;
FileConfiguration newFilez;
File file = new File(main.fs, name + ".toaster");
File newFile = new File(main.fs, name + ".yml");
if (!newFile.exists()) {
try {
newFile.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
filez = YamlConfiguration.loadConfiguration(file);
newFilez = YamlConfiguration.loadConfiguration(newFile);
} catch (Exception x) {
x.printStackTrace();
return;
}
int tick = 0;
for (String str : filez.getKeys(false)) {
if (!str.equals("counter")) {
String actionType = str.replaceAll("\\d", "");
Map<String, Object> action = new HashMap<>();
if (actionType.equalsIgnoreCase("cmd")) {
action.put("item", "cmd");
action.put("cmd", filez.getString(str + ".cmd"));
} else if (actionType.equalsIgnoreCase("build")) {
action.put("item", "rebuild");
action.put("name", filez.getString(str + ".name"));
} else if (actionType.equalsIgnoreCase("text")) {
action.put("item", "text");
action.put("text", filez.getString(str + ".text"));
action.put("x", Double.parseDouble(filez.getString(str + ".x")));
action.put("y", Double.parseDouble(filez.getString(str + ".y")));
action.put("z", Double.parseDouble(filez.getString(str + ".z")));
action.put("range", Double.parseDouble(filez.getString(str + ".range")));
action.put("world", filez.getString(str + ".world"));
}
if (actionType.equalsIgnoreCase("wait")) {
tick+=Integer.parseInt(filez.getString(str));
} else {
tick++;
}
List<Map<String, Object>> list = new ArrayList<>();
list.add(action);
if (action.size() > 0) {
newFilez.set("time" + tick, list);
}
}
}
try {
newFilez.save(newFile);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
// </INTERNAL> */
}