mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-12-27 11:37:42 +01:00
Move commands around
This commit is contained in:
parent
5f953764c4
commit
f36097c6c7
@ -24,6 +24,7 @@ import net.citizensnpcs.command.command.AdminCommands;
|
|||||||
import net.citizensnpcs.command.command.EditorCommands;
|
import net.citizensnpcs.command.command.EditorCommands;
|
||||||
import net.citizensnpcs.command.command.HelpCommands;
|
import net.citizensnpcs.command.command.HelpCommands;
|
||||||
import net.citizensnpcs.command.command.NPCCommands;
|
import net.citizensnpcs.command.command.NPCCommands;
|
||||||
|
import net.citizensnpcs.command.command.ScriptCommands;
|
||||||
import net.citizensnpcs.command.exception.CommandException;
|
import net.citizensnpcs.command.exception.CommandException;
|
||||||
import net.citizensnpcs.command.exception.CommandUsageException;
|
import net.citizensnpcs.command.exception.CommandUsageException;
|
||||||
import net.citizensnpcs.command.exception.ServerCommandException;
|
import net.citizensnpcs.command.exception.ServerCommandException;
|
||||||
@ -131,6 +132,7 @@ public class Citizens extends JavaPlugin {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
|
Messaging.log(System.getProperty("java.class.path"));
|
||||||
// Disable if the server is not using the compatible Minecraft version
|
// Disable if the server is not using the compatible Minecraft version
|
||||||
String mcVersion = ((CraftServer) getServer()).getServer().getVersion();
|
String mcVersion = ((CraftServer) getServer()).getServer().getVersion();
|
||||||
compatible = mcVersion.startsWith(COMPATIBLE_MC_VERSION);
|
compatible = mcVersion.startsWith(COMPATIBLE_MC_VERSION);
|
||||||
@ -225,11 +227,6 @@ public class Citizens extends JavaPlugin {
|
|||||||
}.start();
|
}.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerScriptHelpers() {
|
|
||||||
ScriptCompiler compiler = CitizensAPI.getScriptCompiler();
|
|
||||||
compiler.registerGlobalContextProvider(new EventRegistrar(this));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void registerCommands() {
|
private void registerCommands() {
|
||||||
commands.setInjector(new Injector(this));
|
commands.setInjector(new Injector(this));
|
||||||
|
|
||||||
@ -238,6 +235,12 @@ public class Citizens extends JavaPlugin {
|
|||||||
commands.register(EditorCommands.class);
|
commands.register(EditorCommands.class);
|
||||||
commands.register(HelpCommands.class);
|
commands.register(HelpCommands.class);
|
||||||
commands.register(NPCCommands.class);
|
commands.register(NPCCommands.class);
|
||||||
|
commands.register(ScriptCommands.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void registerScriptHelpers() {
|
||||||
|
ScriptCompiler compiler = CitizensAPI.getScriptCompiler();
|
||||||
|
compiler.registerGlobalContextProvider(new EventRegistrar(this));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reload() throws NPCLoadException {
|
public void reload() throws NPCLoadException {
|
||||||
|
@ -47,11 +47,11 @@ public class Settings {
|
|||||||
SELECTION_ITEM("npc.selection.item", "280"),
|
SELECTION_ITEM("npc.selection.item", "280"),
|
||||||
SELECTION_MESSAGE("npc.selection.message", "<b>You selected <a><npc><b>!"),
|
SELECTION_MESSAGE("npc.selection.message", "<b>You selected <a><npc><b>!"),
|
||||||
SERVER_OWNS_NPCS("npc.server-ownership", false),
|
SERVER_OWNS_NPCS("npc.server-ownership", false),
|
||||||
|
STORAGE_FILE("storage.file", "saves.yml"),
|
||||||
|
STORAGE_TYPE("storage.type", "yaml"),
|
||||||
TALK_CLOSE_MAXIMUM_COOLDOWN("npc.text.max-talk-cooldown", 60),
|
TALK_CLOSE_MAXIMUM_COOLDOWN("npc.text.max-talk-cooldown", 60),
|
||||||
TALK_CLOSE_MINIMUM_COOLDOWN("npc.text.min-talk-cooldown", 30),
|
TALK_CLOSE_MINIMUM_COOLDOWN("npc.text.min-talk-cooldown", 30),
|
||||||
TALK_ITEM("npc.text.talk-item", "340"),
|
TALK_ITEM("npc.text.talk-item", "340");
|
||||||
STORAGE_TYPE("storage.type", "yaml"),
|
|
||||||
STORAGE_FILE("storage.file", "saves.yml");
|
|
||||||
|
|
||||||
private String path;
|
private String path;
|
||||||
private Object value;
|
private Object value;
|
||||||
|
@ -235,11 +235,10 @@ public class CommandManager {
|
|||||||
boolean isStatic = Modifier.isStatic(method.getModifiers());
|
boolean isStatic = Modifier.isStatic(method.getModifiers());
|
||||||
|
|
||||||
Command cmd = method.getAnnotation(Command.class);
|
Command cmd = method.getAnnotation(Command.class);
|
||||||
String[] modifiers = cmd.modifiers();
|
|
||||||
|
|
||||||
// Cache the aliases too
|
// Cache the aliases too
|
||||||
for (String alias : cmd.aliases()) {
|
for (String alias : cmd.aliases()) {
|
||||||
for (String modifier : modifiers) {
|
for (String modifier : cmd.modifiers()) {
|
||||||
commands.put(alias + " " + modifier, method);
|
commands.put(alias + " " + modifier, method);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,8 @@
|
|||||||
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;
|
||||||
@ -17,7 +12,6 @@ import net.citizensnpcs.util.Messaging;
|
|||||||
import net.citizensnpcs.util.StringHelper;
|
import net.citizensnpcs.util.StringHelper;
|
||||||
|
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
|
||||||
|
|
||||||
@Requirements
|
@Requirements
|
||||||
public class AdminCommands {
|
public class AdminCommands {
|
||||||
@ -27,32 +21,9 @@ 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 = "script.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("The file '" + args.getString(1) + "' doesn't exist!");
|
|
||||||
Messaging.send(
|
|
||||||
sender,
|
|
||||||
"Could put into queue? "
|
|
||||||
+ CitizensAPI.getScriptCompiler().compile(file).withCallback(new CompileCallback() {
|
|
||||||
@Override
|
|
||||||
public void onScriptCompiled(ScriptFactory script) {
|
|
||||||
script.newInstance();
|
|
||||||
Messaging.send(sender, "<a>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) {
|
@ServerCommand
|
||||||
|
public void citizens(CommandContext args, CommandSender player, NPC npc) {
|
||||||
Messaging.send(player,
|
Messaging.send(player,
|
||||||
" " + StringHelper.wrapHeader("<e>Citizens v" + plugin.getDescription().getVersion()));
|
" " + StringHelper.wrapHeader("<e>Citizens v" + plugin.getDescription().getVersion()));
|
||||||
Messaging.send(player, " <7>-- <c>Written by fullwall and aPunch");
|
Messaging.send(player, " <7>-- <c>Written by fullwall and aPunch");
|
||||||
@ -61,13 +32,13 @@ public class AdminCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "citizens" },
|
aliases = { "citizens" },
|
||||||
usage = "reload",
|
usage = "reload",
|
||||||
desc = "Reload Citizens",
|
desc = "Reload Citizens",
|
||||||
modifiers = { "reload" },
|
modifiers = { "reload" },
|
||||||
min = 1,
|
min = 1,
|
||||||
max = 1,
|
max = 1,
|
||||||
permission = "admin")
|
permission = "admin")
|
||||||
@ServerCommand
|
@ServerCommand
|
||||||
public void reload(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
public void reload(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||||
Messaging.send(sender, "<e>Reloading Citizens...");
|
Messaging.send(sender, "<e>Reloading Citizens...");
|
||||||
@ -81,13 +52,13 @@ public class AdminCommands {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "citizens" },
|
aliases = { "citizens" },
|
||||||
usage = "save",
|
usage = "save",
|
||||||
desc = "Save NPCs",
|
desc = "Save NPCs",
|
||||||
modifiers = { "save" },
|
modifiers = { "save" },
|
||||||
min = 1,
|
min = 1,
|
||||||
max = 1,
|
max = 1,
|
||||||
permission = "admin")
|
permission = "admin")
|
||||||
@ServerCommand
|
@ServerCommand
|
||||||
public void save(CommandContext args, CommandSender sender, NPC npc) {
|
public void save(CommandContext args, CommandSender sender, NPC npc) {
|
||||||
Messaging.send(sender, "<e>Saving Citizens...");
|
Messaging.send(sender, "<e>Saving Citizens...");
|
||||||
|
@ -62,6 +62,25 @@ public class HelpCommands {
|
|||||||
return lines;
|
return lines;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Command(
|
||||||
|
aliases = { "script" },
|
||||||
|
usage = "help (page)",
|
||||||
|
desc = "Script help menu",
|
||||||
|
modifiers = { "help" },
|
||||||
|
min = 1,
|
||||||
|
max = 2,
|
||||||
|
permission = "script.help")
|
||||||
|
@Requirements
|
||||||
|
@ServerCommand
|
||||||
|
public void scriptHelp(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
||||||
|
int page = args.argsLength() == 2 ? args.getInteger(1) : 1;
|
||||||
|
Paginator paginator = new Paginator().header("Script Help");
|
||||||
|
for (String line : getLines(sender, "script"))
|
||||||
|
paginator.addLine(line);
|
||||||
|
if (!paginator.sendPage(sender, page))
|
||||||
|
throw new CommandException("The page '" + page + "' does not exist.");
|
||||||
|
}
|
||||||
|
|
||||||
@Command(
|
@Command(
|
||||||
aliases = { "npc" },
|
aliases = { "npc" },
|
||||||
usage = "help (page)",
|
usage = "help (page)",
|
||||||
|
@ -0,0 +1,63 @@
|
|||||||
|
package net.citizensnpcs.command.command;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import net.citizensnpcs.Citizens;
|
||||||
|
import net.citizensnpcs.api.CitizensAPI;
|
||||||
|
import net.citizensnpcs.api.npc.NPC;
|
||||||
|
import net.citizensnpcs.api.scripting.CompileCallback;
|
||||||
|
import net.citizensnpcs.api.scripting.Script;
|
||||||
|
import net.citizensnpcs.api.scripting.ScriptFactory;
|
||||||
|
import net.citizensnpcs.command.Command;
|
||||||
|
import net.citizensnpcs.command.CommandContext;
|
||||||
|
import net.citizensnpcs.command.ServerCommand;
|
||||||
|
import net.citizensnpcs.command.exception.CommandException;
|
||||||
|
import net.citizensnpcs.util.Messaging;
|
||||||
|
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import com.google.common.base.Splitter;
|
||||||
|
|
||||||
|
public class ScriptCommands {
|
||||||
|
private final Citizens plugin;
|
||||||
|
|
||||||
|
public ScriptCommands(Citizens plugin) {
|
||||||
|
this.plugin = plugin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Command(
|
||||||
|
aliases = { "script" },
|
||||||
|
modifiers = { "compile", "run" },
|
||||||
|
usage = "compile|run [file]",
|
||||||
|
desc = "compile and run a script",
|
||||||
|
min = 2,
|
||||||
|
max = 2,
|
||||||
|
permission = "script.compile")
|
||||||
|
@ServerCommand
|
||||||
|
public void runScript(final CommandContext args, final CommandSender sender, NPC npc) throws CommandException {
|
||||||
|
File file = new File(plugin.getDataFolder(), args.getString(1));
|
||||||
|
if (!file.exists())
|
||||||
|
throw new CommandException("The file '" + args.getString(1) + "' doesn't exist!");
|
||||||
|
boolean success = CitizensAPI.getScriptCompiler().compile(file).withCallback(new CompileCallback() {
|
||||||
|
@Override
|
||||||
|
public void onScriptCompiled(ScriptFactory script) {
|
||||||
|
Script s = script.newInstance();
|
||||||
|
if (args.hasValueFlag("i")) {
|
||||||
|
for (String m : Splitter.on(',').split(args.getFlag("i"))) {
|
||||||
|
try {
|
||||||
|
s.invoke(m, new Object[] {});
|
||||||
|
} catch (NoSuchMethodException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Messaging.send(sender, "<a>Done.");
|
||||||
|
}
|
||||||
|
}).begin();
|
||||||
|
if (success) {
|
||||||
|
sender.sendMessage("Compiling...");
|
||||||
|
} else {
|
||||||
|
sender.sendMessage("Could not schedule compilation.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -4,6 +4,8 @@ version: 2.0
|
|||||||
main: net.citizensnpcs.Citizens
|
main: net.citizensnpcs.Citizens
|
||||||
website: http://www.citizensnpcs.net
|
website: http://www.citizensnpcs.net
|
||||||
commands:
|
commands:
|
||||||
|
script:
|
||||||
|
description: Scripting commands
|
||||||
citizens:
|
citizens:
|
||||||
description: Administration commands
|
description: Administration commands
|
||||||
npc:
|
npc:
|
||||||
@ -14,30 +16,23 @@ permissions:
|
|||||||
children:
|
children:
|
||||||
citizens.admin: true
|
citizens.admin: true
|
||||||
citizens.help: true
|
citizens.help: true
|
||||||
|
citizens.script.*:
|
||||||
|
children:
|
||||||
|
citizens.script.compile: true
|
||||||
citizens.npc.*:
|
citizens.npc.*:
|
||||||
children:
|
children:
|
||||||
citizens.npc.age: true
|
|
||||||
citizens.npc.character.*: true
|
citizens.npc.character.*: true
|
||||||
citizens.npc.create: true
|
citizens.npc.create: true
|
||||||
citizens.npc.despawn: true
|
citizens.npc.despawn: true
|
||||||
citizens.npc.edit.*:
|
citizens.npc.equip: true
|
||||||
children:
|
|
||||||
citizens.npc.edit.equip: true
|
|
||||||
citizens.npc.edit.path: true
|
|
||||||
citizens.npc.edit.text: true
|
|
||||||
citizens.npc.help: true
|
citizens.npc.help: true
|
||||||
citizens.npc.list: true
|
citizens.npc.path: true
|
||||||
citizens.npc.owner: true
|
|
||||||
citizens.npc.power: true
|
|
||||||
citizens.npc.remove: true
|
citizens.npc.remove: true
|
||||||
citizens.npc.remove.all: true
|
citizens.npc.remove.all: true
|
||||||
citizens.npc.rename: true
|
citizens.npc.rename: true
|
||||||
citizens.npc.select: true
|
citizens.npc.select: true
|
||||||
citizens.npc.spawn: true
|
citizens.npc.spawn: true
|
||||||
citizens.npc.talk: true
|
citizens.npc.text: true
|
||||||
citizens.npc.tp: true
|
citizens.npc.tp: true
|
||||||
citizens.npc.tphere: true
|
citizens.npc.tphere: true
|
||||||
citizens.npc.lookclose: true
|
citizens.npc.lookclose: true
|
||||||
citizens.script.*:
|
|
||||||
children:
|
|
||||||
citizens.script.run: true
|
|
Loading…
Reference in New Issue
Block a user