/
Denizen.java
744 lines (629 loc) · 28.4 KB
/
Denizen.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
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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
package net.aufdemrand.denizen;
import java.io.File;
import java.io.IOException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.aufdemrand.denizen.events.EventManager;
import net.aufdemrand.denizen.events.bukkit.SavesReloadEvent;
import net.aufdemrand.denizen.events.bukkit.ScriptReloadEvent;
import net.aufdemrand.denizen.flags.FlagManager;
import net.aufdemrand.denizen.scripts.commands.BukkitCommandRegistry;
import net.aufdemrand.denizen.scripts.queues.ScriptQueue;
import net.aufdemrand.denizen.utilities.*;
import net.aufdemrand.denizencore.interfaces.dExternal;
import net.aufdemrand.denizen.listeners.ListenerRegistry;
import net.aufdemrand.denizen.npc.dNPCRegistry;
import net.aufdemrand.denizen.npc.speech.DenizenChat;
import net.aufdemrand.denizen.npc.traits.*;
import net.aufdemrand.denizen.objects.*;
import net.aufdemrand.denizen.objects.notable.NotableManager;
import net.aufdemrand.denizen.objects.properties.PropertyParser;
import net.aufdemrand.denizen.scripts.*;
import net.aufdemrand.denizen.scripts.containers.core.*;
import net.aufdemrand.denizen.scripts.queues.ScriptEngine;
import net.aufdemrand.denizen.scripts.queues.core.InstantQueue;
import net.aufdemrand.denizen.scripts.requirements.RequirementRegistry;
import net.aufdemrand.denizen.scripts.triggers.TriggerRegistry;
import net.aufdemrand.denizen.tags.TagManager;
import net.aufdemrand.denizen.utilities.command.CommandManager;
import net.aufdemrand.denizen.utilities.command.Injector;
import net.aufdemrand.denizen.utilities.command.messaging.Messaging;
import net.aufdemrand.denizen.utilities.debugging.dB;
import net.aufdemrand.denizen.utilities.depends.Depends;
import net.aufdemrand.denizencore.DenizenCore;
import net.aufdemrand.denizencore.DenizenImplementation;
import net.aufdemrand.denizencore.scripts.ScriptHelper;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.trait.TraitInfo;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.OfflinePlayer;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.java.JavaPlugin;
public class Denizen extends JavaPlugin implements DenizenImplementation {
public final static int configVersion = 7;
public static String versionTag = null;
private boolean startedSuccessful = false;
private CommandManager commandManager;
public CommandManager getCommandManager() {
return commandManager;
}
/*
* Denizen Engines
*/
private ScriptEngine scriptEngine = new ScriptEngine(this);
public ScriptEngine getScriptEngine() {
return scriptEngine;
}
/*
* Denizen Registries
*/
private BukkitCommandRegistry commandRegistry = new BukkitCommandRegistry();
private TriggerRegistry triggerRegistry = new TriggerRegistry();
private RequirementRegistry requirementRegistry = new RequirementRegistry(this);
private ListenerRegistry listenerRegistry = new ListenerRegistry();
private dNPCRegistry dNPCRegistry;
public BukkitCommandRegistry getCommandRegistry() {
return commandRegistry;
}
public dNPCRegistry getNPCRegistry() {
return dNPCRegistry;
}
public ListenerRegistry getListenerRegistry() {
return listenerRegistry;
}
public RequirementRegistry getRequirementRegistry() {
return requirementRegistry;
}
public TriggerRegistry getTriggerRegistry() {
return triggerRegistry;
}
/*
* Denizen Property Parser
*/
private PropertyParser propertyParser;
public PropertyParser getPropertyParser() {
return propertyParser;
}
/*
* Denizen Managers
*/
private FlagManager flagManager = new FlagManager(this);
private TagManager tagManager = new TagManager(this);
private NotableManager notableManager = new NotableManager();
private EventManager eventManager;
public EventManager eventManager() {
return eventManager;
}
public FlagManager flagManager() {
return flagManager;
}
public TagManager tagManager() {
return tagManager;
}
public NotableManager notableManager() {
return notableManager;
}
public Depends depends = new Depends();
public RuntimeCompiler runtimeCompiler;
private WorldScriptHelper ws_helper;
public final static long startTime = System.currentTimeMillis();
/*
* Sets up Denizen on start of the CraftBukkit server.
*/
@Override
public void onEnable() {
try {
net.minecraft.server.v1_8_R1.Block.getById(0);
}
catch (NoClassDefFoundError e) {
getLogger().warning("-------------------------------------");
getLogger().warning("This Denizen version is not compatible with this CraftBukkit version! Deactivating Denizen!");
getLogger().warning("-------------------------------------");
getServer().getPluginManager().disablePlugin(this);
startedSuccessful = false;
return;
}
try {
versionTag = this.getDescription().getVersion();
// Load Denizen's core
DenizenCore.init(this);
// Activate dependencies
depends.initialize();
if(Depends.citizens == null || !Depends.citizens.isEnabled()) {
getLogger().warning("Citizens does not seem to be activated! Denizen will have greatly reduced functionality!");
//getServer().getPluginManager().disablePlugin(this);
//return;
}
startedSuccessful = true;
// Startup procedure
dB.log(ChatColor.LIGHT_PURPLE + "+-------------------------+");
dB.log(ChatColor.YELLOW + " _/_ _ ._ _ _ ");
dB.log(ChatColor.YELLOW + "(/(-/ )/ /_(-/ ) " + ChatColor.GRAY + " scriptable minecraft");
dB.log("");
dB.log(ChatColor.GRAY + "by: " + ChatColor.WHITE + "aufdemrand");
dB.log(ChatColor.GRAY + "version: "+ ChatColor.WHITE + versionTag);
dB.log(ChatColor.LIGHT_PURPLE + "+-------------------------+");
}
catch (Exception e) {
dB.echoError(e);
}
try {
MetricsLite metrics = new MetricsLite(this);
metrics.start();
}
catch (Exception e) {
dB.echoError(e);
}
try {
// Create the dNPC Registry
dNPCRegistry = new dNPCRegistry(this);
// Create our CommandManager to handle '/denizen' commands
commandManager = new CommandManager();
commandManager.setInjector(new Injector(this));
commandManager.register(DenizenCommandHandler.class);
// If Citizens is enabled, let it handle '/npc' commands
if (Depends.citizens != null) {
Depends.citizens.registerCommandClass(NPCCommandHandler.class);
}
// Track all player names for quick dPlayer matching
for (OfflinePlayer player: Bukkit.getOfflinePlayers()) {
dPlayer.notePlayer(player);
}
}
catch (Exception e) {
dB.echoError(e);
}
try {
DenizenCore.setCommandRegistry(getCommandRegistry());
getCommandRegistry().registerCoreMembers();
}
catch (Exception e) {
dB.echoError(e);
}
try {
// Register script-container types
ScriptRegistry._registerCoreTypes();
// Populate config.yml if it doesn't yet exist.
saveDefaultConfig();
reloadConfig();
}
catch (Exception e) {
dB.echoError(e);
}
try {
// Ensure the Scripts and Midi folder exist
new File(getDataFolder() + "/scripts").mkdirs();
new File(getDataFolder() + "/midi").mkdirs();
new File(getDataFolder() + "/schematics").mkdirs();
// Ensure the example Denizen.mid sound file is available
if (!new File(getDataFolder() + "/midi/Denizen.mid").exists()) {
String sourceFile = URLDecoder.decode(Denizen.class.getProtectionDomain().getCodeSource().getLocation().getFile());
dB.log("Denizen.mid not found, extracting from " + sourceFile);
Utilities.extractFile(new File(sourceFile), "Denizen.mid", getDataFolder() + "/midi/");
}
}
catch (Exception e) {
dB.echoError(e);
}
try {
// Warn if configuration is outdated / too new
if (!getConfig().isSet("Config.Version") ||
getConfig().getInt("Config.Version", 0) != configVersion) {
dB.echoError("Your Denizen config file is from a different version. " +
"Some settings will not be available unless you generate a new one. " +
"This is easily done by stopping the server, deleting the current config.yml file in the Denizen folder " +
"and restarting the server.");
}
// Create the command script handler for listener
ws_helper = new WorldScriptHelper();
ItemScriptHelper is_helper = new ItemScriptHelper();
InventoryScriptHelper in_helper = new InventoryScriptHelper();
EntityScriptHelper es_helper = new EntityScriptHelper();
CommandScriptHelper cs_helper = new CommandScriptHelper();
}
catch (Exception e) {
dB.echoError(e);
}
try {
if (Depends.citizens != null) {
// Register traits
// TODO: should this be a separate function?
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(TriggerTrait.class).withName("triggers"));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(PushableTrait.class).withName("pushable"));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(AssignmentTrait.class).withName("assignment"));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(NicknameTrait.class).withName("nickname"));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(HealthTrait.class).withName("health"));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(ConstantsTrait.class).withName("constants"));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(HungerTrait.class).withName("hunger"));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(SittingTrait.class).withName("sitting"));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(FishingTrait.class).withName("fishing"));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(SleepingTrait.class).withName("sleeping"));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(ParticlesTrait.class).withName("particles"));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(SneakingTrait.class).withName("sneaking"));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(InvisibleTrait.class).withName("invisible"));
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(MobproxTrait.class).withName("mobprox"));
// Register Speech AI
CitizensAPI.getSpeechFactory().register(DenizenChat.class, "denizen_chat");
}
// If Program AB, used for reading Artificial Intelligence Markup Language
// 2.0, is included as a dependency at Denizen/lib/Ab.jar, register the
// ChatbotTrait
if (Depends.hasProgramAB)
CitizensAPI.getTraitFactory().registerTrait(TraitInfo.create(ChatbotTrait.class).withName("chatbot"));
// Compile and load Denizen externals
runtimeCompiler = new RuntimeCompiler(this);
runtimeCompiler.loader();
}
catch (Exception e) {
dB.echoError(e);
}
// Register Core Members in the Denizen Registries
try {
if (Depends.citizens != null)
getTriggerRegistry().registerCoreMembers();
getRequirementRegistry().registerCoreMembers();
getListenerRegistry().registerCoreMembers();
}
catch (Exception e) {
dB.echoError(e);
}
try {
tagManager().registerCoreTags();
eventManager = new EventManager();
eventManager().registerCoreMembers();
// Register Core dObjects with the ObjectFetcher
ObjectFetcher._registerCoreObjects();
}
catch (Exception e) {
dB.echoError(e);
}
try {
// Initialize non-standard dMaterials
dMaterial._initialize();
// Initialize Property Parser
propertyParser = new PropertyParser();
}
catch (Exception e) {
dB.echoError(e);
}
// Run everything else on the first server tick
getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
@Override
public void run() {
try {
DenizenCore.loadScripts();
// Reload notables from notables.yml into memory
notableManager.reloadNotables();
// Load the saves.yml into memory
reloadSaves();
dB.log(ChatColor.LIGHT_PURPLE + "+-------------------------+");
// Fire the 'on Server Start' world event
ws_helper.serverStartEvent();
}
catch (Exception e) {
dB.echoError(e);
}
}
}, 1);
}
/*
* Unloads Denizen on shutdown of the craftbukkit server.
*/
@Override
public void onDisable() {
if(!startedSuccessful) return;
// Save notables
notableManager.saveNotables();
// Save scoreboards
ScoreboardHelper._saveScoreboards();
// Save entities
EntityScriptHelper.saveEntities();
// Save offline player inventories
InventoryScriptHelper._savePlayerInventories();
// Deconstruct listeners (server shutdown seems not to be triggering a PlayerQuitEvent)
for (Player player : this.getServer().getOnlinePlayers())
getListenerRegistry().deconstructPlayer(dPlayer.mirrorBukkitPlayer(player));
for (OfflinePlayer player : this.getServer().getOfflinePlayers()) {
try {
getListenerRegistry().deconstructPlayer(dPlayer.mirrorBukkitPlayer(player)); } catch (Exception e) {
if (player == null) dB.echoError("Tell aufdemrand ASAP about this error! ERR: OPN");
else dB.echoError("'" + player.getName() + "' is having trouble deconstructing! " +
"You might have a corrupt player file!");
}
}
// Unload loaded dExternals
for (dExternal external : RuntimeCompiler.loadedExternals)
external.unload();
RuntimeCompiler.loadedExternals.clear();
//Disable core members
getCommandRegistry().disableCoreMembers();
getLogger().log(Level.INFO, " v" + getDescription().getVersion() + " disabled.");
Bukkit.getServer().getScheduler().cancelTasks(this);
HandlerList.unregisterAll(this);
saveSaves();
}
/*
* Reloads, retrieves and saves progress information in
* Denizen/saves.yml and Denizen/scoreboards.yml
*/
private FileConfiguration savesConfig = null;
private File savesConfigFile = null;
private FileConfiguration scoreboardsConfig = null;
private File scoreboardsConfigFile = null;
private FileConfiguration entityConfig = null;
private File entityConfigFile = null;
public void reloadSaves() {
if (savesConfigFile == null) {
savesConfigFile = new File(getDataFolder(), "saves.yml");
}
savesConfig = YamlConfiguration.loadConfiguration(savesConfigFile);
// Reload dLocations from saves.yml, load them into NotableManager // TODO: probably remove this
dLocation._recallLocations();
// Update saves from name to UUID
updateSaves();
if (scoreboardsConfigFile == null) {
scoreboardsConfigFile = new File(getDataFolder(), "scoreboards.yml");
}
scoreboardsConfig = YamlConfiguration.loadConfiguration(scoreboardsConfigFile);
// Reload scoreboards from scoreboards.yml
ScoreboardHelper._recallScoreboards();
if (entityConfigFile == null) {
entityConfigFile = new File(getDataFolder(), "entities.yml");
}
entityConfig = YamlConfiguration.loadConfiguration(entityConfigFile);
// Load entities from entities.yml
EntityScriptHelper.reloadEntities();
Bukkit.getServer().getPluginManager().callEvent(new SavesReloadEvent());
}
public void updateSaves() {
int saves_version = 1;
if (savesConfig.contains("a_saves.version"))
saves_version = savesConfig.getInt("a_saves.version");
if (saves_version == 1) {
dB.log("Updating saves from v1 to v2...");
ConfigurationSection section = savesConfig.getConfigurationSection("Players");
if (section != null) {
ArrayList<String> keyList = new ArrayList<String>(section.getKeys(false));
// Remove UPPERCASE cooldown saves from the list - handled manually
for (int i = 0; i < keyList.size(); i++) {
String key = keyList.get(i);
if (!key.equals(key.toUpperCase()) && keyList.contains(key.toUpperCase())) {
keyList.remove(key.toUpperCase());
}
}
// Handle all actual player saves
for (int i = 0; i < keyList.size(); i++) {
String key = keyList.get(i);
try {
// Flags
ConfigurationSection playerSection = savesConfig.getConfigurationSection("Players." + key);
if (playerSection == null) {
dB.echoError("Can't update saves for player '" + key + "' - broken YAML section!");
continue;
}
Map<String, Object> keys = playerSection.getValues(true);
if (!key.equals(key.toUpperCase()) && savesConfig.contains("Players." + key.toUpperCase())) {
// Cooldowns
keys.putAll(savesConfig.getConfigurationSection("Players." + key.toUpperCase()).getValues(true));
savesConfig.set("Players." + key.toUpperCase(), null);
}
dPlayer player = dPlayer.valueOf(key);
if (player == null) {
dB.echoError("Can't update saves for player '" + key + "' - invalid name!");
savesConfig.createSection("PlayersBACKUP." + key, keys);
// TODO: READ FROM BACKUP AT LOG IN
}
else {
savesConfig.createSection("Players." + player.getSaveName(), keys);
}
savesConfig.set("Players." + key, null);
}
catch (Exception ex) {
dB.echoError(ex);
}
}
}
section = savesConfig.getConfigurationSection("Listeners");
if (section != null) {
for (String key: section.getKeys(false)) {
try {
dPlayer player = dPlayer.valueOf(key);
if (player == null)
dB.log("Warning: can't update listeners for player '" + key + "' - invalid name!");
else // Listeners
savesConfig.createSection("Listeners." + player.getSaveName(), savesConfig.getConfigurationSection("Listeners." + key).getValues(true));
savesConfig.set("Listeners." + key, null);
}
catch (Exception ex) {
dB.echoError(ex);
}
}
}
savesConfig.set("a_saves.version", "2");
dB.log("Done!");
}
}
public FileConfiguration getSaves() {
if (savesConfig == null) {
reloadSaves();
}
return savesConfig;
}
public FileConfiguration getScoreboards() {
if (scoreboardsConfig == null) {
reloadSaves();
}
return scoreboardsConfig;
}
public FileConfiguration getEntities() {
if (entityConfig == null) {
reloadSaves();
}
return entityConfig;
}
public void saveSaves() {
if (savesConfig == null || savesConfigFile == null) {
return;
}
// Save notables
notableManager.saveNotables();
// Save scoreboards to scoreboards.yml
ScoreboardHelper._saveScoreboards();
// Save entities to entities.yml
EntityScriptHelper.saveEntities();
try {
savesConfig.save(savesConfigFile);
} catch (IOException ex) {
Logger.getLogger(JavaPlugin.class.getName()).log(Level.SEVERE, "Could not save to " + savesConfigFile, ex);
}
try {
scoreboardsConfig.save(scoreboardsConfigFile);
} catch (IOException ex) {
Logger.getLogger(JavaPlugin.class.getName()).log(Level.SEVERE, "Could not save to " + scoreboardsConfigFile, ex);
}
try {
entityConfig.save(entityConfigFile);
} catch (IOException ex) {
Logger.getLogger(JavaPlugin.class.getName()).log(Level.SEVERE, "Could not save to " + entityConfigFile, ex);
}
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String cmdName, String[] args) {
// <--[language]
// @name /ex command
// @group Console Commands
// @description
// The '/ex' command is an easy way to run a single denizen script command in-game. Its syntax,
// aside from '/ex' is exactly the same as any other command. When running a command, some context
// is also supplied, such as '<player>' if being run by a player (versus the console), as well as
// '<npc>' if a NPC is selected by using the '/npc sel' command.
//
// Examples:
// /ex flag <player> test_flag:!
// /ex run 's@npc walk script' as:<npc>
//
// Need to '/ex' a command as a different player or NPC? No problem. Just use the 'npc' and 'player'
// value arguments, or utilize the object fetcher.
//
// Examples:
// /ex narrate player:p@NLBlackEagle 'Your health is <player.health.formatted>.'
// /ex walk npc:n@fred <player.location.cursor_on>
// -->
// ...except this one :) /ex command
if (cmdName.equalsIgnoreCase("ex")) {
List<String> entries = new ArrayList<String>();
String entry = "";
for (String arg : args)
entry = entry + arg + " ";
if (entry.length() < 2) {
sender.sendMessage("/ex <dCommand> (arguments)");
return true;
}
if (Settings.showExHelp()) {
if (dB.showDebug)
sender.sendMessage(ChatColor.YELLOW + "Executing dCommand... check the console for debug output!");
else
sender.sendMessage(ChatColor.YELLOW + "Executing dCommand... to see debug, use /denizen debug");
}
entries.add(entry);
InstantQueue queue = InstantQueue.getQueue(ScriptQueue.getNextId("EXCOMMAND"));
dNPC npc = null;
if (Depends.citizens != null && Depends.citizens.getNPCSelector().getSelected(sender) != null)
npc = new dNPC(Depends.citizens.getNPCSelector().getSelected(sender));
List<ScriptEntry> scriptEntries = ScriptBuilder.buildScriptEntries(entries, null,
(sender instanceof Player)?dPlayer.mirrorBukkitPlayer((Player) sender):null, npc);
queue.addEntries(scriptEntries);
queue.start();
return true;
}
//if (Depends.citizens != null)
// return citizens.onCommand(sender, cmd, cmdName, args);
String modifier = args.length > 0 ? args[0] : "";
if (!commandManager.hasCommand(cmd, modifier) && !modifier.isEmpty()) {
return suggestClosestModifier(sender, cmd.getName(), modifier);
}
Object[] methodArgs = { sender };
return commandManager.executeSafe(cmd, args, sender, methodArgs);
}
private boolean suggestClosestModifier(CommandSender sender, String command, String modifier) {
String closest = commandManager.getClosestCommandModifier(command, modifier);
if (!closest.isEmpty()) {
Messaging.send(sender, "<7>Unknown command. Did you mean:");
Messaging.send(sender, " /" + command + " " + closest);
return true;
}
return false;
}
@Override
public File getScriptFolder() {
File file = null;
// Get the script directory
if (Settings.useDefaultScriptPath())
file = new File(DenizenAPI.getCurrentInstance()
.getDataFolder() + File.separator + "scripts");
else
file = new File(Settings.getAlternateScriptPath().replace("/", File.separator));
return file;
}
@Override
public String getImplementationVersion() {
return versionTag;
}
@Override
public void debugMessage(String message) {
dB.log(message);
}
@Override
public void debugException(Throwable ex) {
dB.echoError(ex);
}
@Override
public void debugError(String error) {
dB.echoError(error);
}
@Override
public void debugApproval(String message) {
dB.echoApproval(message);
}
@Override
public String getImplementationName() {
return "Bukkit";
}
@Override
public void preScriptReload() {
// Remove all recipes added by Denizen item scripts
ItemScriptHelper.removeDenizenRecipes();
// Remove all registered commands added by Denizen command scripts
CommandScriptHelper.removeDenizenCommands();
}
@Override
public void onScriptReload() {
Bukkit.getServer().getPluginManager().callEvent(new ScriptReloadEvent());
}
@Override
public void buildCoreContainers(net.aufdemrand.denizencore.utilities.YamlConfiguration config) {
ScriptRegistry._buildCoreYamlScriptContainers(config);
}
@Override
public List<net.aufdemrand.denizencore.utilities.YamlConfiguration> getOutsideScripts() {
List<net.aufdemrand.denizencore.utilities.YamlConfiguration> files = new ArrayList<net.aufdemrand.denizencore.utilities.YamlConfiguration>();
try {
files.add(ScriptHelper.loadConfig("Denizen.jar/util.dscript", getResource("util.dscript")));
}
catch (IOException e) {
dB.echoError(e);
}
return files;
}
}