From 327c798f6ef861fc7f4946df811d5d054ef9fddf Mon Sep 17 00:00:00 2001 From: William Date: Thu, 25 Aug 2022 17:07:25 +0100 Subject: [PATCH] Add rich syntax highlighting via commodore --- build.gradle | 1 + bukkit/build.gradle | 8 +++- .../huskhomes/command/BrigadierUtil.java | 38 +++++++++++++++++++ .../huskhomes/command/BukkitCommand.java | 21 +++++----- .../resources/commodore/delhome.commodore | 3 ++ .../resources/commodore/delwarp.commodore | 3 ++ .../resources/commodore/edithome.commodore | 15 ++++++++ .../resources/commodore/editwarp.commodore | 11 ++++++ .../main/resources/commodore/home.commodore | 3 ++ .../resources/commodore/homelist.commodore | 6 +++ .../resources/commodore/huskhomes.commodore | 8 ++++ .../resources/commodore/publichome.commodore | 3 ++ .../commodore/publichomelist.commodore | 3 ++ .../main/resources/commodore/rtp.commodore | 3 ++ .../resources/commodore/sethome.commodore | 3 ++ .../resources/commodore/setwarp.commodore | 3 ++ .../src/main/resources/commodore/tp.commodore | 13 +++++++ .../main/resources/commodore/tpa.commodore | 3 ++ .../resources/commodore/tpaccept.commodore | 3 ++ .../resources/commodore/tpahere.commodore | 3 ++ .../resources/commodore/tpdecline.commodore | 3 ++ .../main/resources/commodore/tphere.commodore | 3 ++ .../resources/commodore/tpoffline.commodore | 3 ++ .../main/resources/commodore/warp.commodore | 3 ++ .../resources/commodore/warplist.commodore | 3 ++ 25 files changed, 158 insertions(+), 11 deletions(-) create mode 100644 bukkit/src/main/java/net/william278/huskhomes/command/BrigadierUtil.java create mode 100644 bukkit/src/main/resources/commodore/delhome.commodore create mode 100644 bukkit/src/main/resources/commodore/delwarp.commodore create mode 100644 bukkit/src/main/resources/commodore/edithome.commodore create mode 100644 bukkit/src/main/resources/commodore/editwarp.commodore create mode 100644 bukkit/src/main/resources/commodore/home.commodore create mode 100644 bukkit/src/main/resources/commodore/homelist.commodore create mode 100644 bukkit/src/main/resources/commodore/huskhomes.commodore create mode 100644 bukkit/src/main/resources/commodore/publichome.commodore create mode 100644 bukkit/src/main/resources/commodore/publichomelist.commodore create mode 100644 bukkit/src/main/resources/commodore/rtp.commodore create mode 100644 bukkit/src/main/resources/commodore/sethome.commodore create mode 100644 bukkit/src/main/resources/commodore/setwarp.commodore create mode 100644 bukkit/src/main/resources/commodore/tp.commodore create mode 100644 bukkit/src/main/resources/commodore/tpa.commodore create mode 100644 bukkit/src/main/resources/commodore/tpaccept.commodore create mode 100644 bukkit/src/main/resources/commodore/tpahere.commodore create mode 100644 bukkit/src/main/resources/commodore/tpdecline.commodore create mode 100644 bukkit/src/main/resources/commodore/tphere.commodore create mode 100644 bukkit/src/main/resources/commodore/tpoffline.commodore create mode 100644 bukkit/src/main/resources/commodore/warp.commodore create mode 100644 bukkit/src/main/resources/commodore/warplist.commodore diff --git a/build.gradle b/build.gradle index edb6e5f7..132750b3 100644 --- a/build.gradle +++ b/build.gradle @@ -29,6 +29,7 @@ allprojects { repositories { mavenLocal() mavenCentral() + maven { url 'https://libraries.minecraft.net/' } maven { url 'https://hub.spigotmc.org/nexus/content/repositories/snapshots/' } maven { url 'https://repo.papermc.io/repository/maven-public/' } maven { url 'https://repo.minebench.de/' } diff --git a/bukkit/build.gradle b/bukkit/build.gradle index 5698c94a..f51deb7f 100644 --- a/bukkit/build.gradle +++ b/bukkit/build.gradle @@ -3,6 +3,7 @@ dependencies { implementation 'org.bstats:bstats-bukkit:3.0.0' implementation 'io.papermc:paperlib:1.0.7' + implementation 'me.lucko:commodore:2.2' compileOnly 'org.spigotmc:spigot-api:1.16.5-R0.1-SNAPSHOT' compileOnly 'redis.clients:jedis:' + jedis_version @@ -23,6 +24,10 @@ dependencies { } shadowJar { + dependencies { + exclude(dependency('com.mojang:brigadier')) + } + relocate 'org.apache.commons.io', 'net.william278.huskhomes.libraries.commons.io' relocate 'de.themoep', 'net.william278.huskhomes.libraries' relocate 'org.jetbrains', 'net.william278.huskhomes.libraries' @@ -34,6 +39,7 @@ shadowJar { relocate 'org.yaml.snakeyaml', 'net.william278.huskhomes.libraries.snakeyaml' relocate 'com.google.gson', 'net.william278.huskhomes.libraries.gson' - relocate 'io.papermc.lib', 'net.william278.huskhomes.libraries.paperlib' relocate 'org.bstats', 'net.william278.huskhomes.libraries.bstats' + relocate 'io.papermc.lib', 'net.william278.huskhomes.libraries.paperlib' + relocate 'me.lucko.commodore', 'net.william278.huskhomes.libraries.commodore' } \ No newline at end of file diff --git a/bukkit/src/main/java/net/william278/huskhomes/command/BrigadierUtil.java b/bukkit/src/main/java/net/william278/huskhomes/command/BrigadierUtil.java new file mode 100644 index 00000000..9e584e38 --- /dev/null +++ b/bukkit/src/main/java/net/william278/huskhomes/command/BrigadierUtil.java @@ -0,0 +1,38 @@ +package net.william278.huskhomes.command; + +import me.lucko.commodore.CommodoreProvider; +import me.lucko.commodore.file.CommodoreFileReader; +import net.william278.huskhomes.BukkitHuskHomes; +import org.bukkit.command.PluginCommand; +import org.jetbrains.annotations.NotNull; + +import java.io.IOException; +import java.io.InputStream; +import java.util.logging.Level; + +public class BrigadierUtil { + + /** + * Uses commodore to register command completions + * + * @param plugin instance of the registering Bukkit plugin + * @param pluginCommand the Bukkit PluginCommand to register completions for + * @param command the {@link CommandBase} to register completions for + */ + protected static void registerCommodore(@NotNull BukkitHuskHomes plugin, @NotNull PluginCommand pluginCommand, + @NotNull CommandBase command) { + final InputStream commandCommodore = plugin.getResource("commodore/" + pluginCommand.getName() + ".commodore"); + if (commandCommodore == null) { + return; + } + try { + CommodoreProvider.getCommodore(plugin).register(pluginCommand, + CommodoreFileReader.INSTANCE.parse(commandCommodore), + player -> player.hasPermission(command.permission)); + } catch (IOException e) { + plugin.getLoggingAdapter().log(Level.SEVERE, "Failed to read command commodore completions for " + + pluginCommand.getName(), e); + } + } + +} diff --git a/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommand.java b/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommand.java index 443a7aa4..9567ab22 100644 --- a/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommand.java +++ b/bukkit/src/main/java/net/william278/huskhomes/command/BukkitCommand.java @@ -1,6 +1,7 @@ package net.william278.huskhomes.command; -import net.william278.huskhomes.HuskHomes; +import me.lucko.commodore.CommodoreProvider; +import net.william278.huskhomes.BukkitHuskHomes; import net.william278.huskhomes.player.BukkitPlayer; import org.bukkit.command.*; import org.bukkit.entity.Player; @@ -23,9 +24,9 @@ public class BukkitCommand implements CommandExecutor, TabExecutor { /** * The implementing plugin */ - private final HuskHomes plugin; + private final BukkitHuskHomes plugin; - public BukkitCommand(@NotNull CommandBase command, @NotNull HuskHomes implementor) { + public BukkitCommand(@NotNull CommandBase command, @NotNull BukkitHuskHomes implementor) { this.command = command; this.plugin = implementor; } @@ -36,13 +37,13 @@ public class BukkitCommand implements CommandExecutor, TabExecutor { * @param pluginCommand {@link PluginCommand} to register */ public void register(@NotNull PluginCommand pluginCommand) { - try { - pluginCommand.setPermission(command.permission); - pluginCommand.setDescription(command.getDescription()); - pluginCommand.setExecutor(this); - pluginCommand.setTabCompleter(this); - } catch (final Exception e) { - e.printStackTrace(); + pluginCommand.setPermission(command.permission); + pluginCommand.setDescription(command.getDescription()); + pluginCommand.setExecutor(this); + pluginCommand.setTabCompleter(this); + + if (CommodoreProvider.isSupported()) { + BrigadierUtil.registerCommodore(plugin, pluginCommand, command); } } diff --git a/bukkit/src/main/resources/commodore/delhome.commodore b/bukkit/src/main/resources/commodore/delhome.commodore new file mode 100644 index 00000000..37b5940a --- /dev/null +++ b/bukkit/src/main/resources/commodore/delhome.commodore @@ -0,0 +1,3 @@ +delhome { + name brigadier:string single_word; +} \ No newline at end of file diff --git a/bukkit/src/main/resources/commodore/delwarp.commodore b/bukkit/src/main/resources/commodore/delwarp.commodore new file mode 100644 index 00000000..80e4b116 --- /dev/null +++ b/bukkit/src/main/resources/commodore/delwarp.commodore @@ -0,0 +1,3 @@ +delwarp { + name brigadier:string single_word; +} \ No newline at end of file diff --git a/bukkit/src/main/resources/commodore/edithome.commodore b/bukkit/src/main/resources/commodore/edithome.commodore new file mode 100644 index 00000000..63f6e273 --- /dev/null +++ b/bukkit/src/main/resources/commodore/edithome.commodore @@ -0,0 +1,15 @@ +edithome { + name brigadier:string single_word { + rename { + new brigadier:string single_word; + } + description { + text brigadier:string greedy_phrase; + } + relocate; + privacy { + public; + private; + } + } +} \ No newline at end of file diff --git a/bukkit/src/main/resources/commodore/editwarp.commodore b/bukkit/src/main/resources/commodore/editwarp.commodore new file mode 100644 index 00000000..20965f0f --- /dev/null +++ b/bukkit/src/main/resources/commodore/editwarp.commodore @@ -0,0 +1,11 @@ +editwarp { + name brigadier:string single_word { + rename { + new brigadier:string single_word; + } + description { + text brigadier:string greedy_phrase; + } + relocate; + } +} \ No newline at end of file diff --git a/bukkit/src/main/resources/commodore/home.commodore b/bukkit/src/main/resources/commodore/home.commodore new file mode 100644 index 00000000..97e37cdf --- /dev/null +++ b/bukkit/src/main/resources/commodore/home.commodore @@ -0,0 +1,3 @@ +home { + name brigadier:string single_word; +} \ No newline at end of file diff --git a/bukkit/src/main/resources/commodore/homelist.commodore b/bukkit/src/main/resources/commodore/homelist.commodore new file mode 100644 index 00000000..c21a54f6 --- /dev/null +++ b/bukkit/src/main/resources/commodore/homelist.commodore @@ -0,0 +1,6 @@ +homelist { + page brigadier:integer; + player brigadier:string single_word { + page brigadier:integer; + } +} \ No newline at end of file diff --git a/bukkit/src/main/resources/commodore/huskhomes.commodore b/bukkit/src/main/resources/commodore/huskhomes.commodore new file mode 100644 index 00000000..202d286d --- /dev/null +++ b/bukkit/src/main/resources/commodore/huskhomes.commodore @@ -0,0 +1,8 @@ +huskhomes { + about; + help { + page brigadier:integer; + } + reload; + update; +} \ No newline at end of file diff --git a/bukkit/src/main/resources/commodore/publichome.commodore b/bukkit/src/main/resources/commodore/publichome.commodore new file mode 100644 index 00000000..ba6a6cb5 --- /dev/null +++ b/bukkit/src/main/resources/commodore/publichome.commodore @@ -0,0 +1,3 @@ +publichome { + name brigadier:string single_word; +} \ No newline at end of file diff --git a/bukkit/src/main/resources/commodore/publichomelist.commodore b/bukkit/src/main/resources/commodore/publichomelist.commodore new file mode 100644 index 00000000..2f2d06c0 --- /dev/null +++ b/bukkit/src/main/resources/commodore/publichomelist.commodore @@ -0,0 +1,3 @@ +publichomelist { + page brigadier:integer; +} \ No newline at end of file diff --git a/bukkit/src/main/resources/commodore/rtp.commodore b/bukkit/src/main/resources/commodore/rtp.commodore new file mode 100644 index 00000000..fc0b3488 --- /dev/null +++ b/bukkit/src/main/resources/commodore/rtp.commodore @@ -0,0 +1,3 @@ +rtp { + player brigadier:string single_word; +} \ No newline at end of file diff --git a/bukkit/src/main/resources/commodore/sethome.commodore b/bukkit/src/main/resources/commodore/sethome.commodore new file mode 100644 index 00000000..427a8c3b --- /dev/null +++ b/bukkit/src/main/resources/commodore/sethome.commodore @@ -0,0 +1,3 @@ +sethome { + name brigadier:string single_word; +} \ No newline at end of file diff --git a/bukkit/src/main/resources/commodore/setwarp.commodore b/bukkit/src/main/resources/commodore/setwarp.commodore new file mode 100644 index 00000000..9d99ee72 --- /dev/null +++ b/bukkit/src/main/resources/commodore/setwarp.commodore @@ -0,0 +1,3 @@ +setwarp { + name brigadier:string single_word; +} \ No newline at end of file diff --git a/bukkit/src/main/resources/commodore/tp.commodore b/bukkit/src/main/resources/commodore/tp.commodore new file mode 100644 index 00000000..8c9ed542 --- /dev/null +++ b/bukkit/src/main/resources/commodore/tp.commodore @@ -0,0 +1,13 @@ +tp { + x|player brigadier:string single_word { + y|x|player brigadier:string single_word { + z|y brigadier:string single_word { + world|z brigadier:string single_word { + server|world brigadier:string single_word { + server brigadier:string single_word; + } + } + } + } + } +} \ No newline at end of file diff --git a/bukkit/src/main/resources/commodore/tpa.commodore b/bukkit/src/main/resources/commodore/tpa.commodore new file mode 100644 index 00000000..22d697c8 --- /dev/null +++ b/bukkit/src/main/resources/commodore/tpa.commodore @@ -0,0 +1,3 @@ +tpa { + player brigadier:string single_word; +} \ No newline at end of file diff --git a/bukkit/src/main/resources/commodore/tpaccept.commodore b/bukkit/src/main/resources/commodore/tpaccept.commodore new file mode 100644 index 00000000..b1ecc9eb --- /dev/null +++ b/bukkit/src/main/resources/commodore/tpaccept.commodore @@ -0,0 +1,3 @@ +tpaccept { + player brigadier:string single_word; +} \ No newline at end of file diff --git a/bukkit/src/main/resources/commodore/tpahere.commodore b/bukkit/src/main/resources/commodore/tpahere.commodore new file mode 100644 index 00000000..1d8ac28f --- /dev/null +++ b/bukkit/src/main/resources/commodore/tpahere.commodore @@ -0,0 +1,3 @@ +tpahere { + player brigadier:string single_word; +} \ No newline at end of file diff --git a/bukkit/src/main/resources/commodore/tpdecline.commodore b/bukkit/src/main/resources/commodore/tpdecline.commodore new file mode 100644 index 00000000..9c17e424 --- /dev/null +++ b/bukkit/src/main/resources/commodore/tpdecline.commodore @@ -0,0 +1,3 @@ +tpdecline { + player brigadier:string single_word; +} \ No newline at end of file diff --git a/bukkit/src/main/resources/commodore/tphere.commodore b/bukkit/src/main/resources/commodore/tphere.commodore new file mode 100644 index 00000000..a8efd74d --- /dev/null +++ b/bukkit/src/main/resources/commodore/tphere.commodore @@ -0,0 +1,3 @@ +tphere { + player brigadier:string single_word; +} \ No newline at end of file diff --git a/bukkit/src/main/resources/commodore/tpoffline.commodore b/bukkit/src/main/resources/commodore/tpoffline.commodore new file mode 100644 index 00000000..8a959eba --- /dev/null +++ b/bukkit/src/main/resources/commodore/tpoffline.commodore @@ -0,0 +1,3 @@ +tpoffline { + player brigadier:string single_word; +} \ No newline at end of file diff --git a/bukkit/src/main/resources/commodore/warp.commodore b/bukkit/src/main/resources/commodore/warp.commodore new file mode 100644 index 00000000..4b176d05 --- /dev/null +++ b/bukkit/src/main/resources/commodore/warp.commodore @@ -0,0 +1,3 @@ +warp { + name brigadier:string single_word; +} \ No newline at end of file diff --git a/bukkit/src/main/resources/commodore/warplist.commodore b/bukkit/src/main/resources/commodore/warplist.commodore new file mode 100644 index 00000000..d9e57885 --- /dev/null +++ b/bukkit/src/main/resources/commodore/warplist.commodore @@ -0,0 +1,3 @@ +warplist { + page brigadier:integer; +} \ No newline at end of file