Initial support for Brigadier (1.13 commands) on Bukkit servers
This commit is contained in:
parent
59c7d77525
commit
efa666445f
@ -19,6 +19,16 @@
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>true</filtering>
|
||||
<includes>
|
||||
<include>*.yml</include>
|
||||
</includes>
|
||||
</resource>
|
||||
<resource>
|
||||
<directory>src/main/resources</directory>
|
||||
<filtering>false</filtering>
|
||||
<includes>
|
||||
<include>luckperms-brigadier.json.gz</include>
|
||||
</includes>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
@ -68,6 +78,10 @@
|
||||
<pattern>okhttp3</pattern>
|
||||
<shadedPattern>me.lucko.luckperms.lib.okhttp3</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>me.lucko.commodore</pattern>
|
||||
<shadedPattern>me.lucko.luckperms.lib.commodore</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>org.mariadb.jdbc</pattern>
|
||||
<shadedPattern>me.lucko.luckperms.lib.mariadb</shadedPattern>
|
||||
@ -129,6 +143,14 @@
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- commodore -->
|
||||
<dependency>
|
||||
<groupId>me.lucko</groupId>
|
||||
<artifactId>commodore</artifactId>
|
||||
<version>1.0</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- Vault -->
|
||||
<dependency>
|
||||
|
@ -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<Dependency> getGlobalDependencies() {
|
||||
return EnumSet.of(Dependency.TEXT, Dependency.CAFFEINE, Dependency.OKIO, Dependency.OKHTTP);
|
||||
EnumSet<Dependency> 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
|
||||
|
@ -0,0 +1,140 @@
|
||||
/*
|
||||
* This file is part of LuckPerms, licensed under the MIT License.
|
||||
*
|
||||
* Copyright (c) lucko (Luck) <luck@lucko.me>
|
||||
* 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 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;
|
||||
}
|
||||
|
||||
}
|
BIN
bukkit/src/main/resources/luckperms-brigadier.json.gz
Normal file
BIN
bukkit/src/main/resources/luckperms-brigadier.json.gz
Normal file
Binary file not shown.
@ -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",
|
||||
|
Loading…
Reference in New Issue
Block a user