Add script compile command

This commit is contained in:
fullwall 2012-04-12 23:30:01 +08:00
parent 9ab17fdf13
commit 29e268b699

View File

@ -1,8 +1,13 @@
package net.citizensnpcs.command.command; package net.citizensnpcs.command.command;
import java.io.File;
import net.citizensnpcs.Citizens; import net.citizensnpcs.Citizens;
import net.citizensnpcs.api.CitizensAPI;
import net.citizensnpcs.api.exception.NPCLoadException; import net.citizensnpcs.api.exception.NPCLoadException;
import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.npc.NPC;
import net.citizensnpcs.api.scripting.CompileCallback;
import net.citizensnpcs.api.scripting.ScriptFactory;
import net.citizensnpcs.command.Command; import net.citizensnpcs.command.Command;
import net.citizensnpcs.command.CommandContext; import net.citizensnpcs.command.CommandContext;
import net.citizensnpcs.command.Requirements; import net.citizensnpcs.command.Requirements;
@ -22,6 +27,28 @@ public class AdminCommands {
this.plugin = plugin; this.plugin = plugin;
} }
@Command(
aliases = "citizens",
modifiers = "script",
desc = "compile and run a script",
min = 2,
max = 2,
permission = "scripts.run")
@ServerCommand
public void runScript(CommandContext args, final CommandSender sender, NPC npc) throws CommandException {
File file = new File(args.getString(1));
if (!file.exists())
throw new CommandException("file doesn't exist!");
sender.sendMessage("Could put into queue? "
+ CitizensAPI.getScriptCompiler().compile(file).withCallback(new CompileCallback() {
@Override
public void onScriptCompiled(ScriptFactory script) {
script.newInstance();
sender.sendMessage("Script compiled.");
}
}).begin());
}
@Command(aliases = { "citizens" }, desc = "Show basic plugin information", max = 0, permission = "admin") @Command(aliases = { "citizens" }, desc = "Show basic plugin information", max = 0, permission = "admin")
public void citizens(CommandContext args, Player player, NPC npc) { public void citizens(CommandContext args, Player player, NPC npc) {
Messaging.send(player, Messaging.send(player,