mirror of
https://github.com/darksaid98/HuskHomes.git
synced 2026-12-02 22:17:17 +00:00
Add rich syntax highlighting via commodore
This commit is contained in:
1 parent
9a3414c4c0
commit
327c798f6e
25 files changed
+158
-11
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user