diff --git a/bukkit/pom.xml b/bukkit/pom.xml
index 28c2a297..18989f43 100644
--- a/bukkit/pom.xml
+++ b/bukkit/pom.xml
@@ -19,6 +19,16 @@
src/main/resources
true
+
+ *.yml
+
+
+
+ src/main/resources
+ false
+
+ luckperms-brigadier.json.gz
+
@@ -68,6 +78,10 @@
okhttp3
me.lucko.luckperms.lib.okhttp3
+
+ me.lucko.commodore
+ me.lucko.luckperms.lib.commodore
+
org.mariadb.jdbc
me.lucko.luckperms.lib.mariadb
@@ -129,6 +143,14 @@
provided
+
+
+ me.lucko
+ commodore
+ 1.0
+ provided
+
+
diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java
index b72e4953..b22c28b3 100644
--- a/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java
+++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/LPBukkitPlugin.java
@@ -29,6 +29,7 @@ import me.lucko.luckperms.api.Contexts;
import me.lucko.luckperms.api.LuckPermsApi;
import me.lucko.luckperms.api.event.user.UserDataRecalculateEvent;
import me.lucko.luckperms.bukkit.calculators.BukkitCalculatorFactory;
+import me.lucko.luckperms.bukkit.compat.LuckPermsBrigadier;
import me.lucko.luckperms.bukkit.contexts.BukkitContextManager;
import me.lucko.luckperms.bukkit.contexts.WorldCalculator;
import me.lucko.luckperms.bukkit.listeners.BukkitConnectionListener;
@@ -111,9 +112,22 @@ public class LPBukkitPlugin extends AbstractLuckPermsPlugin {
this.senderFactory = new BukkitSenderFactory(this);
}
+ private static boolean isBrigadierSupported() {
+ try {
+ Class.forName("com.mojang.brigadier.CommandDispatcher");
+ return true;
+ } catch (ClassNotFoundException var1) {
+ return false;
+ }
+ }
+
@Override
protected Set getGlobalDependencies() {
- return EnumSet.of(Dependency.TEXT, Dependency.CAFFEINE, Dependency.OKIO, Dependency.OKHTTP);
+ EnumSet dependencies = EnumSet.of(Dependency.TEXT, Dependency.CAFFEINE, Dependency.OKIO, Dependency.OKHTTP);
+ if (isBrigadierSupported()) {
+ dependencies.add(Dependency.COMMODORE);
+ }
+ return dependencies;
}
@Override
@@ -139,6 +153,15 @@ public class LPBukkitPlugin extends AbstractLuckPermsPlugin {
PluginCommand cmd = this.bootstrap.getCommand("luckperms");
cmd.setExecutor(this.commandManager);
cmd.setTabCompleter(this.commandManager);
+
+ // setup brigadier
+ if (isBrigadierSupported()) {
+ try {
+ LuckPermsBrigadier.register(this, cmd);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
}
@Override
diff --git a/bukkit/src/main/java/me/lucko/luckperms/bukkit/compat/LuckPermsBrigadier.java b/bukkit/src/main/java/me/lucko/luckperms/bukkit/compat/LuckPermsBrigadier.java
new file mode 100644
index 00000000..377ae523
--- /dev/null
+++ b/bukkit/src/main/java/me/lucko/luckperms/bukkit/compat/LuckPermsBrigadier.java
@@ -0,0 +1,140 @@
+/*
+ * This file is part of LuckPerms, licensed under the MIT License.
+ *
+ * Copyright (c) lucko (Luck)
+ * Copyright (c) contributors
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+package me.lucko.luckperms.bukkit.compat;
+
+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 me.lucko.commodore.Commodore;
+import me.lucko.commodore.CommodoreProvider;
+import me.lucko.luckperms.bukkit.LPBukkitPlugin;
+
+import org.bukkit.command.Command;
+
+import java.io.BufferedReader;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.nio.charset.StandardCharsets;
+import java.util.Objects;
+import java.util.zip.GZIPInputStream;
+
+public class LuckPermsBrigadier {
+
+ public static void register(LPBukkitPlugin plugin, Command pluginCommand) throws Exception {
+ Commodore commodore = CommodoreProvider.getCommodore(plugin.getBootstrap());
+ try (InputStream is = plugin.getBootstrap().getResourceStream("luckperms-brigadier.json.gz")) {
+ if (is == null) {
+ 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);
+ }
+ }
+ }
+
+ 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 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;
+ }
+
+}
diff --git a/bukkit/src/main/resources/luckperms-brigadier.json.gz b/bukkit/src/main/resources/luckperms-brigadier.json.gz
new file mode 100644
index 00000000..92b5463d
Binary files /dev/null and b/bukkit/src/main/resources/luckperms-brigadier.json.gz differ
diff --git a/common/src/main/java/me/lucko/luckperms/common/dependencies/Dependency.java b/common/src/main/java/me/lucko/luckperms/common/dependencies/Dependency.java
index db332e96..c4971e19 100644
--- a/common/src/main/java/me/lucko/luckperms/common/dependencies/Dependency.java
+++ b/common/src/main/java/me/lucko/luckperms/common/dependencies/Dependency.java
@@ -91,6 +91,13 @@ public enum Dependency {
Relocation.of(RelocationHelper.OKIO_STRING, RelocationHelper.OKIO_STRING)
)
),
+ COMMODORE(
+ "me{}lucko",
+ "commodore",
+ "1.0",
+ "Cu7m0zEOTts51dHix2RLKkeUapaek7rKnnxgRQeIlJE=",
+ Relocation.of("commodore", "me{}lucko{}commodore")
+ ),
MARIADB_DRIVER(
"org{}mariadb{}jdbc",
"mariadb-java-client",