add permissions to commands

This commit is contained in:
dfsek 2021-12-19 22:43:12 -07:00
parent cfc7960c70
commit 30b02a03c4

View File

@ -45,6 +45,7 @@ public class InternalAddon implements BaseAddon {
CommandManager<CommandSender> manager = event.getCommandManager();
manager.command(
manager.commandBuilder("addons", ArgumentDescription.of("List installed Terra addons"))
.permission("terra.addons")
.handler(context -> {
StringBuilder addons = new StringBuilder("Installed addons:\n");
platform.getAddons()
@ -60,6 +61,7 @@ public class InternalAddon implements BaseAddon {
.command(
manager.commandBuilder("addons")
.argument(RegistryArgument.of("addon", platform.getAddons()))
.permission("terra.addons.info")
.handler(context -> {
BaseAddon addon = context.get("addon");
StringBuilder addonInfo = new StringBuilder("Addon ").append(addon.getID()).append('\n');
@ -76,7 +78,9 @@ public class InternalAddon implements BaseAddon {
context.getSender().sendMessage(addonInfo.toString());
})
)
.command(manager.commandBuilder("packs", ArgumentDescription.of("List installed config packs"))
.command(
manager.commandBuilder("packs", ArgumentDescription.of("List installed config packs"))
.permission("terra.packs")
.handler(context -> {
StringBuilder packs = new StringBuilder("Installed packs:\n");
platform.getConfigRegistry().forEach(pack -> packs.append(" - ")
@ -86,8 +90,10 @@ public class InternalAddon implements BaseAddon {
context.getSender().sendMessage(packs.toString());
})
)
.command(manager.commandBuilder("packs")
.command(
manager.commandBuilder("packs")
.literal("info", ArgumentDescription.of("Get information about a pack"))
.permission("terra.packs.info")
.argument(RegistryArgument.of("pack", platform.getConfigRegistry()))
.handler(context -> {
ConfigPack pack = context.get("pack");
@ -105,8 +111,10 @@ public class InternalAddon implements BaseAddon {
.append('\n'));
context.getSender().sendMessage(packInfo.toString());
}))
.command(manager.commandBuilder("packs")
.command(
manager.commandBuilder("packs")
.literal("reload", ArgumentDescription.of("Reload config packs"))
.permission("terra.packs.reload")
.handler(context -> {
context.getSender().sendMessage("Reloading Terra...");
logger.info("Reloading Terra...");
@ -115,31 +123,43 @@ public class InternalAddon implements BaseAddon {
context.getSender().sendMessage("Terra reloaded successfully.");
} else {
logger.error("Terra failed to reload.");
context.getSender().sendMessage("Terra failed to reload. See logs for more information.");
context.getSender().sendMessage(
"Terra failed to reload. See logs for more information.");
}
}))
.command(manager.commandBuilder("profiler", ArgumentDescription.of("Access the profiler"))
.command(
manager.commandBuilder("profiler", ArgumentDescription.of("Access the profiler"))
.literal("start", ArgumentDescription.of("Start profiling"), "st")
.permission("terra.profiler.start")
.handler(context -> {
platform.getProfiler().start();
context.getSender().sendMessage("Profiling started.");
}))
.command(manager.commandBuilder("profiler", ArgumentDescription.of("Access the profiler"))
.command(
manager.commandBuilder("profiler", ArgumentDescription.of("Access the profiler"))
.literal("stop", ArgumentDescription.of("Stop profiling"), "s")
.permission("terra.profiler.stop")
.handler(context -> {
platform.getProfiler().stop();
context.getSender().sendMessage("Profiling stopped.");
}))
.command(manager.commandBuilder("profiler", ArgumentDescription.of("Access the profiler"))
.command(
manager.commandBuilder("profiler", ArgumentDescription.of("Access the profiler"))
.literal("query", ArgumentDescription.of("Query profiler results"), "q")
.permission("terra.profiler.query")
.handler(context -> {
StringBuilder data = new StringBuilder("Terra Profiler data: \n");
platform.getProfiler().getTimings().forEach((id, timings) -> data.append(id).append(": ").append(timings.toString()).append('\n'));
platform.getProfiler().getTimings().forEach((id, timings) -> data.append(id)
.append(": ")
.append(timings.toString())
.append('\n'));
logger.info(data.toString());
context.getSender().sendMessage("Profiling data dumped to console.");
}))
.command(manager.commandBuilder("profiler", ArgumentDescription.of("Access the profiler"))
.command(
manager.commandBuilder("profiler", ArgumentDescription.of("Access the profiler"))
.literal("reset", ArgumentDescription.of("Reset the profiler"), "r")
.permission("terra.profiler.reset")
.handler(context -> {
platform.getProfiler().reset();
context.getSender().sendMessage("Profiler reset.");