9
0
mirror of https://github.com/WiIIiam278/HuskSync.git synced 2026-01-04 15:31:37 +00:00

Use Commodore for rich command completion registering

This commit is contained in:
William
2022-08-08 19:32:09 +01:00
parent d1c95030f0
commit 2f700b2d93
18 changed files with 125 additions and 31 deletions

View File

@@ -3,11 +3,12 @@ dependencies {
implementation 'org.bstats:bstats-bukkit:3.0.0'
implementation 'net.william278:mpdbdataconverter:1.0.1'
implementation 'net.william278:hsldataconverter:1.0'
implementation 'me.lucko:commodore:2.2'
compileOnly 'redis.clients:jedis:4.2.3'
compileOnly 'commons-io:commons-io:2.11.0'
compileOnly 'de.themoep:minedown:1.7.1-SNAPSHOT'
compileOnly 'dev.dejvokep:boosted-yaml:1.2'
compileOnly 'dev.dejvokep:boosted-yaml:1.3'
compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT'
compileOnly 'com.zaxxer:HikariCP:5.0.1'
@@ -15,6 +16,10 @@ dependencies {
}
shadowJar {
dependencies {
exclude(dependency('com.mojang:brigadier'))
}
relocate 'org.apache', 'net.william278.husksync.libraries'
relocate 'de.themoep', 'net.william278.husksync.libraries'
relocate 'org.jetbrains', 'net.william278.husksync.libraries'
@@ -23,6 +28,7 @@ shadowJar {
relocate 'com.google', 'net.william278.husksync.libraries'
relocate 'redis.clients', 'net.william278.husksync.libraries'
relocate 'org.json', 'net.william278.husksync.libraries.json'
relocate 'me.lucko.commodore', 'net.william278.husksync.libraries.commodore'
relocate 'net.byteflux.libby', 'net.william278.husksync.libraries.libby'
relocate 'org.bstats', 'net.william278.husksync.libraries.bstats'

View File

@@ -268,6 +268,12 @@ public class BukkitHuskSync extends JavaPlugin implements HuskSync {
return logger;
}
@NotNull
@Override
public ResourceReader getResourceReader() {
return resourceReader;
}
@Override
public @NotNull Version getPluginVersion() {
return Version.pluginVersion(getDescription().getVersion());

View File

@@ -0,0 +1,32 @@
package net.william278.husksync.command;
import me.lucko.commodore.CommodoreProvider;
import me.lucko.commodore.file.CommodoreFileReader;
import net.william278.husksync.BukkitHuskSync;
import org.bukkit.command.PluginCommand;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.io.InputStream;
import java.util.logging.Level;
/**
* Used for registering Brigadier hooks on platforms that support commodore for rich command syntax
*/
public class BrigadierUtil {
protected static void registerCommodore(@NotNull BukkitHuskSync plugin, @NotNull PluginCommand pluginCommand,
@NotNull CommandBase command) {
// Register command descriptions via commodore (brigadier wrapper)
try (InputStream pluginFile = plugin.getResourceReader()
.getResource("commodore/" + command.command + ".commodore")) {
CommodoreProvider.getCommodore(plugin).register(pluginCommand,
CommodoreFileReader.INSTANCE.parse(pluginFile),
player -> player.hasPermission(command.permission));
} catch (IOException e) {
plugin.getLoggingAdapter().log(Level.SEVERE,
"Failed to load " + command.command + ".commodore command definitions", e);
}
}
}

View File

@@ -1,6 +1,7 @@
package net.william278.husksync.command;
import net.william278.husksync.HuskSync;
import me.lucko.commodore.CommodoreProvider;
import net.william278.husksync.BukkitHuskSync;
import net.william278.husksync.player.BukkitPlayer;
import org.bukkit.command.*;
import org.bukkit.entity.Player;
@@ -18,14 +19,14 @@ public class BukkitCommand implements CommandExecutor, TabExecutor {
/**
* The {@link CommandBase} that will be executed
*/
private final CommandBase command;
protected final CommandBase command;
/**
* The implementing plugin
*/
private final HuskSync plugin;
private final BukkitHuskSync plugin;
public BukkitCommand(@NotNull CommandBase command, @NotNull HuskSync implementor) {
public BukkitCommand(@NotNull CommandBase command, @NotNull BukkitHuskSync implementor) {
this.command = command;
this.plugin = implementor;
}
@@ -40,6 +41,9 @@ public class BukkitCommand implements CommandExecutor, TabExecutor {
pluginCommand.setTabCompleter(this);
pluginCommand.setPermission(command.permission);
pluginCommand.setDescription(command.getDescription());
if (CommodoreProvider.isSupported()) {
BrigadierUtil.registerCommodore(plugin, pluginCommand, command);
}
}
@Override

View File

@@ -3,7 +3,6 @@ package net.william278.husksync.util;
import net.william278.husksync.BukkitHuskSync;
import org.jetbrains.annotations.NotNull;
import java.io.File;
import java.io.InputStream;
import java.util.Objects;
@@ -20,9 +19,4 @@ public class BukkitResourceReader implements ResourceReader {
return Objects.requireNonNull(plugin.getResource(fileName));
}
@Override
public @NotNull File getDataFolder() {
return plugin.getDataFolder();
}
}

View File

@@ -0,0 +1,3 @@
inventory {
name brigadier:string single_word;
}

View File

@@ -0,0 +1,5 @@
husksync {
update;
about;
reload;
}

View File

@@ -0,0 +1,3 @@
enderchest {
name brigadier:string single_word;
}

View File

@@ -0,0 +1,29 @@
userdata {
view {
name brigadier:string single_word {
version brigadier:string single_word;
test;
}
}
list {
name brigadier:string single_word;
test;
}
delete {
name brigadier:string single_word {
version brigadier:string single_word;
test;
}
}
restore {
name brigadier:string single_word {
version brigadier:string single_word;
test;
}
}
pin {
name brigadier:string single_word {
version brigadier:string single_word;
}
}
}

View File

@@ -11,7 +11,7 @@ softdepend:
libraries:
- 'mysql:mysql-connector-java:8.0.29'
- 'org.xerial.snappy:snappy-java:1.1.8.4'
- 'dev.dejvokep:boosted-yaml:1.2'
- 'dev.dejvokep:boosted-yaml:1.3'
commands:
husksync:
usage: '/husksync <update/info/reload/migrate>'