Replace internal brigadier command structure with Commodore's file format

This commit is contained in:
Luck 2019-12-29 22:01:38 +00:00
parent 3fae4e5e9e
commit 83883aa7e6
No known key found for this signature in database
GPG Key ID: EFA9B3EC5FD90F8B
5 changed files with 625 additions and 99 deletions

View File

@ -12,7 +12,7 @@ dependencies {
compileOnly 'org.spigotmc:spigot-api:1.14-R0.1-SNAPSHOT'
compileOnly 'net.kyori:text-adapter-bukkit:3.0.2'
compileOnly 'me.lucko:commodore:1.3'
compileOnly 'me.lucko:commodore:1.4'
compileOnly('net.milkbowl.vault:VaultAPI:1.6') {
exclude(module: 'bukkit')
}

View File

@ -25,20 +25,11 @@
package me.lucko.luckperms.bukkit.brigadier;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.arguments.BoolArgumentType;
import com.mojang.brigadier.arguments.IntegerArgumentType;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.ArgumentBuilder;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
import com.mojang.brigadier.tree.LiteralCommandNode;
import me.lucko.commodore.Commodore;
import me.lucko.commodore.CommodoreProvider;
import me.lucko.commodore.file.CommodoreFileFormat;
import me.lucko.luckperms.bukkit.LPBukkitPlugin;
import me.lucko.luckperms.common.sender.Sender;
@ -48,41 +39,32 @@ import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerCommandSendEvent;
import org.bukkit.plugin.PluginManager;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.zip.GZIPInputStream;
/**
* Utility for registering LuckPerms command data to brigadier using {@link Commodore}.
* Registers LuckPerms command data to brigadier using {@link Commodore}.
*/
public class LuckPermsBrigadier {
/**
* Registers LuckPerms command data for the given {@code pluginCommand}.
* Registers LuckPerms command data to the given {@code pluginCommand}.
*
* @param plugin the luckperms plugin
* @param pluginCommand the command
* @throws Exception if something goes wrong
*/
public static void register(LPBukkitPlugin plugin, Command pluginCommand) throws Exception {
// register completions with commodore
Commodore commodore = CommodoreProvider.getCommodore(plugin.getBootstrap());
try (InputStream is = plugin.getBootstrap().getResourceStream("luckperms-brigadier.json.gz")) {
try (InputStream is = plugin.getBootstrap().getResourceStream("luckperms.commodore")) {
if (is == null) {
throw new Exception("Brigadier command data missing from jar!");
throw new Exception("Brigadier command data missing from jar");
}
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new GZIPInputStream(is), StandardCharsets.UTF_8))) {
JsonObject data = new JsonParser().parse(reader).getAsJsonObject();
LiteralArgumentBuilder command = deserializeLiteral(data);
commodore.register(pluginCommand, command);
}
LiteralCommandNode<?> command = CommodoreFileFormat.parse(is);
commodore.register(pluginCommand, command);
}
// add event listener to prevent completions from being send to players without permission
@ -111,74 +93,4 @@ public class LuckPermsBrigadier {
}
}
private static ArgumentBuilder deserialize(JsonObject data) {
String type = data.get("type").getAsString();
switch (type) {
case "literal": {
return deserializeLiteral(data);
}
case "argument": {
return deserializeArgument(data);
}
default:
throw new IllegalArgumentException("type: " + type);
}
}
private static LiteralArgumentBuilder deserializeLiteral(JsonObject data) {
String name = data.get("name").getAsString();
LiteralArgumentBuilder arg = LiteralArgumentBuilder.literal(name);
return deserializeChildren(data, arg);
}
private static RequiredArgumentBuilder deserializeArgument(JsonObject data) {
String name = data.get("name").getAsString();
ArgumentType argumentType = deserializeArgumentType(data);
//noinspection unchecked
RequiredArgumentBuilder arg = RequiredArgumentBuilder.argument(name, argumentType);
return deserializeChildren(data, arg);
}
private static ArgumentType deserializeArgumentType(JsonObject data) {
String parser = data.get("parser").getAsString();
String properties = null;
if (data.has("properties")) {
properties = data.get("properties").getAsString();
}
switch (parser) {
case "brigadier:string": {
Objects.requireNonNull(properties, "string properties");
switch (properties) {
case "SINGLE_WORD":
return StringArgumentType.word();
case "QUOTABLE_PHRASE":
return StringArgumentType.string();
case "GREEDY_PHRASE":
return StringArgumentType.greedyString();
default:
throw new IllegalArgumentException("string property: " + properties);
}
}
case "brigadier:bool":
return BoolArgumentType.bool();
case "brigadier:integer":
return IntegerArgumentType.integer();
default:
throw new IllegalArgumentException("parser: " + parser);
}
}
private static <T extends ArgumentBuilder> T deserializeChildren(JsonObject data, T builder) {
if (data.has("children")) {
JsonArray children = data.get("children").getAsJsonArray();
for (JsonElement child : children) {
//noinspection unchecked
builder.then(deserialize(child.getAsJsonObject()));
}
}
return builder;
}
}

View File

@ -0,0 +1,614 @@
luckperms {
sync;
info;
editor {
all;
groups;
users;
}
debug;
verbose {
off;
on {
filter brigadier:string greedy_phrase;
}
paste;
record {
filter brigadier:string greedy_phrase;
}
}
tree {
scope brigadier:string single_word {
player brigadier:string single_word;
}
}
search {
permission brigadier:string quotable_phrase;
}
check {
user brigadier:string single_word {
permission brigadier:string quotable_phrase;
}
}
networksync;
import {
file brigadier:string quotable_phrase;
}
export {
file brigadier:string quotable_phrase;
}
reloadconfig;
bulkupdate {
datatype brigadier:string single_word {
delete {
constraint brigadier:string greedy_phrase;
}
update {
actionfield brigadier:string single_word {
actionvalue brigadier:string quotable_phrase {
constraint brigadier:string greedy_phrase;
}
}
}
}
}
migration {
plugin brigadier:string single_word;
}
creategroup {
name brigadier:string single_word;
}
deletegroup {
name brigadier:string single_word;
}
listgroups;
createtrack {
name brigadier:string single_word;
}
deletetrack {
name brigadier:string single_word;
}
listtracks;
user {
user brigadier:string single_word {
info;
permission {
info;
set {
node brigadier:string quotable_phrase {
value brigadier:bool {
context brigadier:string greedy_phrase;
}
}
}
unset {
node brigadier:string quotable_phrase {
context brigadier:string greedy_phrase;
}
}
settemp {
node brigadier:string quotable_phrase {
value brigadier:bool {
duration brigadier:string single_word {
context brigadier:string greedy_phrase;
}
}
}
}
unsettemp {
node brigadier:string quotable_phrase {
context brigadier:string greedy_phrase;
}
}
check {
node brigadier:string quotable_phrase {
context brigadier:string greedy_phrase;
}
}
checkinherits {
node brigadier:string quotable_phrase {
context brigadier:string greedy_phrase;
}
}
clear {
context brigadier:string greedy_phrase;
}
}
parent {
info;
set {
group brigadier:string single_word {
context brigadier:string greedy_phrase;
}
}
add {
group brigadier:string single_word {
context brigadier:string greedy_phrase;
}
}
remove {
group brigadier:string single_word {
context brigadier:string greedy_phrase;
}
}
settrack {
track brigadier:string single_word {
group brigadier:string single_word {
context brigadier:string greedy_phrase;
}
}
}
addtemp {
group brigadier:string quotable_phrase {
duration brigadier:string single_word {
context brigadier:string greedy_phrase;
}
}
}
removetemp {
group brigadier:string single_word {
context brigadier:string greedy_phrase;
}
}
clear {
context brigadier:string greedy_phrase;
}
cleartrack {
track brigadier:string single_word {
context brigadier:string greedy_phrase;
}
}
switchprimarygroup {
group brigadier:string quotable_phrase;
}
}
meta {
info;
set {
key brigadier:string quotable_phrase {
value brigadier:string quotable_phrase {
context brigadier:string greedy_phrase;
}
}
}
unset {
key brigadier:string quotable_phrase {
context brigadier:string greedy_phrase;
}
}
settemp {
key brigadier:string quotable_phrase {
value brigadier:string quotable_phrase {
duration brigadier:string single_word {
context brigadier:string greedy_phrase;
}
}
}
}
unsettemp {
key brigadier:string quotable_phrase {
context brigadier:string greedy_phrase;
}
}
addprefix {
priority brigadier:integer {
prefix brigadier:string quotable_phrase {
context brigadier:string greedy_phrase;
}
}
}
addsuffix {
priority brigadier:integer {
suffix brigadier:string quotable_phrase {
context brigadier:string greedy_phrase;
}
}
}
setprefix {
priority brigadier:integer {
prefix brigadier:string quotable_phrase {
context brigadier:string greedy_phrase;
}
}
}
setsuffix {
priority brigadier:integer {
suffix brigadier:string quotable_phrase {
context brigadier:string greedy_phrase;
}
}
}
removeprefix {
priority brigadier:integer {
prefix brigadier:string quotable_phrase {
context brigadier:string greedy_phrase;
}
}
}
removesuffix {
priority brigadier:integer {
suffix brigadier:string quotable_phrase {
context brigadier:string greedy_phrase;
}
}
}
addtempprefix {
priority brigadier:integer {
prefix brigadier:string quotable_phrase {
duration brigadier:string single_word {
context brigadier:string greedy_phrase;
}
}
}
}
addtempsuffix {
priority brigadier:integer {
suffix brigadier:string quotable_phrase {
duration brigadier:string single_word {
context brigadier:string greedy_phrase;
}
}
}
}
settempprefix {
priority brigadier:integer {
prefix brigadier:string quotable_phrase {
duration brigadier:string single_word {
context brigadier:string greedy_phrase;
}
}
}
}
settempsuffix {
priority brigadier:integer {
suffix brigadier:string quotable_phrase {
duration brigadier:string single_word {
context brigadier:string greedy_phrase;
}
}
}
}
removetempprefix {
priority brigadier:integer {
prefix brigadier:string quotable_phrase {
context brigadier:string greedy_phrase;
}
}
}
removetempsuffix {
priority brigadier:integer {
suffix brigadier:string quotable_phrase {
context brigadier:string greedy_phrase;
}
}
}
clear {
context brigadier:string greedy_phrase;
}
}
editor;
promote {
track brigadier:string single_word {
context brigadier:string greedy_phrase;
}
}
demote {
track brigadier:string single_word {
context brigadier:string greedy_phrase;
}
}
showtracks;
clear {
context brigadier:string greedy_phrase;
}
clone {
user brigadier:string single_word;
}
}
}
group {
group brigadier:string single_word {
info;
permission {
info;
set {
node brigadier:string quotable_phrase {
value brigadier:bool {
context brigadier:string greedy_phrase;
}
}
}
unset {
node brigadier:string quotable_phrase {
context brigadier:string greedy_phrase;
}
}
settemp {
node brigadier:string quotable_phrase {
value brigadier:bool {
duration brigadier:string single_word {
context brigadier:string greedy_phrase;
}
}
}
}
unsettemp {
node brigadier:string quotable_phrase {
context brigadier:string greedy_phrase;
}
}
check {
node brigadier:string quotable_phrase {
context brigadier:string greedy_phrase;
}
}
checkinherits {
node brigadier:string quotable_phrase {
context brigadier:string greedy_phrase;
}
}
clear {
context brigadier:string greedy_phrase;
}
}
parent {
info;
set {
group brigadier:string single_word {
context brigadier:string greedy_phrase;
}
}
add {
group brigadier:string single_word {
context brigadier:string greedy_phrase;
}
}
remove {
group brigadier:string single_word {
context brigadier:string greedy_phrase;
}
}
settrack {
track brigadier:string single_word {
group brigadier:string single_word {
context brigadier:string greedy_phrase;
}
}
}
addtemp {
group brigadier:string quotable_phrase {
duration brigadier:string single_word {
context brigadier:string greedy_phrase;
}
}
}
removetemp {
group brigadier:string single_word {
context brigadier:string greedy_phrase;
}
}
clear {
context brigadier:string greedy_phrase;
}
cleartrack {
track brigadier:string single_word {
context brigadier:string greedy_phrase;
}
}
switchprimarygroup {
group brigadier:string quotable_phrase;
}
}
meta {
info;
set {
key brigadier:string quotable_phrase {
value brigadier:string quotable_phrase {
context brigadier:string greedy_phrase;
}
}
}
unset {
key brigadier:string quotable_phrase {
context brigadier:string greedy_phrase;
}
}
settemp {
key brigadier:string quotable_phrase {
value brigadier:string quotable_phrase {
duration brigadier:string single_word {
context brigadier:string greedy_phrase;
}
}
}
}
unsettemp {
key brigadier:string quotable_phrase {
context brigadier:string greedy_phrase;
}
}
addprefix {
priority brigadier:integer {
prefix brigadier:string quotable_phrase {
context brigadier:string greedy_phrase;
}
}
}
addsuffix {
priority brigadier:integer {
suffix brigadier:string quotable_phrase {
context brigadier:string greedy_phrase;
}
}
}
setprefix {
priority brigadier:integer {
prefix brigadier:string quotable_phrase {
context brigadier:string greedy_phrase;
}
}
}
setsuffix {
priority brigadier:integer {
suffix brigadier:string quotable_phrase {
context brigadier:string greedy_phrase;
}
}
}
removeprefix {
priority brigadier:integer {
prefix brigadier:string quotable_phrase {
context brigadier:string greedy_phrase;
}
}
}
removesuffix {
priority brigadier:integer {
suffix brigadier:string quotable_phrase {
context brigadier:string greedy_phrase;
}
}
}
addtempprefix {
priority brigadier:integer {
prefix brigadier:string quotable_phrase {
duration brigadier:string single_word {
context brigadier:string greedy_phrase;
}
}
}
}
addtempsuffix {
priority brigadier:integer {
suffix brigadier:string quotable_phrase {
duration brigadier:string single_word {
context brigadier:string greedy_phrase;
}
}
}
}
settempprefix {
priority brigadier:integer {
prefix brigadier:string quotable_phrase {
duration brigadier:string single_word {
context brigadier:string greedy_phrase;
}
}
}
}
settempsuffix {
priority brigadier:integer {
suffix brigadier:string quotable_phrase {
duration brigadier:string single_word {
context brigadier:string greedy_phrase;
}
}
}
}
removetempprefix {
priority brigadier:integer {
prefix brigadier:string quotable_phrase {
context brigadier:string greedy_phrase;
}
}
}
removetempsuffix {
priority brigadier:integer {
suffix brigadier:string quotable_phrase {
context brigadier:string greedy_phrase;
}
}
}
clear {
context brigadier:string greedy_phrase;
}
}
editor;
listmembers {
page brigadier:integer;
}
setweight {
weight brigadier:integer;
}
setdisplayname {
name brigadier:string single_word;
}
showtracks;
clear {
context brigadier:string greedy_phrase;
}
rename {
newname brigadier:string single_word;
}
clone {
newname brigadier:string single_word;
}
}
}
track {
track brigadier:string single_word {
info;
append {
group brigadier:string single_word;
}
insert {
group brigadier:string single_word {
position brigadier:integer;
}
}
remove {
group brigadier:string single_word;
}
clear;
rename {
newname brigadier:string single_word;
}
clone {
newname brigadier:string single_word;
}
}
}
log {
recent {
user brigadier:string single_word {
page brigadier:integer;
}
}
search {
query brigadier:string quotable_phrase {
page brigadier:integer;
}
}
notify {
off;
on;
}
userhistory {
user brigadier:string single_word {
page brigadier:integer;
}
}
grouphistory {
group brigadier:string single_word {
page brigadier:integer;
}
}
trackhistory {
track brigadier:string single_word {
page brigadier:integer;
}
}
}
}

View File

@ -136,8 +136,8 @@ public enum Dependency {
COMMODORE(
"me{}lucko",
"commodore",
"1.3",
"3+fpQ9eQpO73jm4z7G+6x+q87b8NwjY1KN+nmNGjplk=",
"1.4",
"9jrCBDKswqiT9/i97FtRmVJwYE3pXncxjoKFvdZMgzM=",
Relocation.of("commodore", "me{}lucko{}commodore")
),
MARIADB_DRIVER(