Adds methods for registering a command
All checks were successful
KnarCraft/KnarLib/pipeline/head This commit looks good
All checks were successful
KnarCraft/KnarLib/pipeline/head This commit looks good
This commit is contained in:
@@ -1,9 +1,15 @@
|
||||
package net.knarcraft.knarlib.plugin;
|
||||
|
||||
import net.knarcraft.knarlib.config.StargateYamlConfiguration;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.PluginCommand;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.logging.Level;
|
||||
|
||||
/**
|
||||
* A plugin that uses a Stargate YAML configuration in order to retain all configuration comments
|
||||
@@ -35,4 +41,35 @@ public abstract class ConfigCommentPlugin extends JavaPlugin {
|
||||
return this.configuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a command
|
||||
*
|
||||
* @param commandName <p>The name of the command to register</p>
|
||||
* @param executor <p>The executor to register for the command</p>
|
||||
*/
|
||||
private void registerCommand(@NotNull String commandName, @NotNull CommandExecutor executor) {
|
||||
registerCommand(commandName, executor, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a command
|
||||
*
|
||||
* @param commandName <p>The name of the command to register</p>
|
||||
* @param commandExecutor <p>The command executor to register for the command</p>
|
||||
* @param tabExecutor <p>The tab executor to register for the command</p>
|
||||
*/
|
||||
@SuppressWarnings("SameParameterValue")
|
||||
private void registerCommand(@NotNull String commandName, @NotNull CommandExecutor commandExecutor,
|
||||
@Nullable TabExecutor tabExecutor) {
|
||||
PluginCommand pluginCommand = this.getCommand(commandName);
|
||||
if (pluginCommand != null) {
|
||||
pluginCommand.setExecutor(commandExecutor);
|
||||
if (tabExecutor != null) {
|
||||
pluginCommand.setTabCompleter(tabExecutor);
|
||||
}
|
||||
} else {
|
||||
getLogger().log(Level.SEVERE, "Failed to register command " + commandName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user