MineAlert/src/main/java/xyz/etztech/minealert/commands/MainCommand.java

62 lines
2.0 KiB
Java
Raw Normal View History

package xyz.etztech.minealert.commands;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import xyz.etztech.minealert.Color;
import xyz.etztech.minealert.Lang;
import xyz.etztech.minealert.MineAlert;
public class MainCommand implements CommandExecutor {
MineAlert plugin;
public MainCommand(MineAlert plugin) {
this.plugin = plugin;
this.plugin.getCommand("minealert").setExecutor(this);
}
@Override
public boolean onCommand(CommandSender commandSender, Command command, String s, String[] args) {
if (!commandSender.hasPermission("minealert.admin")) {
Lang.NO_PERMISSION.sms(commandSender);
return true;
}
if (args.length == 0) {
help(commandSender);
} else {
switch (args[0]) {
case "help":
help(commandSender);
break;
case "reload":
reload(commandSender);
break;
default:
Lang.UNKNOWN_COMMAND.sms(commandSender);
break;
}
}
return true;
}
private void help(CommandSender commandSender) {
String version = Bukkit.getPluginManager().getPlugin("MineAlert").getDescription().getVersion();
BaseComponent[] message = new ComponentBuilder()
.append(String.format("===== MineAlert v%s =====", version)).color(Color.PRIMARY)
.append("\n/minealert help - Show this message").color(Color.INFO)
.append("\n/minealert reload - Reload the config").color(Color.INFO)
.create();
commandSender.spigot().sendMessage(message);
}
private void reload(CommandSender commandSender) {
this.plugin.reloadConfig();
Lang.PLUGIN_RELOADED.sms(commandSender);
}
}