82 lines
3.2 KiB
Java
82 lines
3.2 KiB
Java
package net.knarcraft.paidsigns.command;
|
|
|
|
import net.knarcraft.paidsigns.PaidSigns;
|
|
import org.bukkit.ChatColor;
|
|
import org.bukkit.command.Command;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.command.PluginCommand;
|
|
import org.bukkit.command.TabExecutor;
|
|
import org.bukkit.entity.Player;
|
|
import org.jetbrains.annotations.NotNull;
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class PaidSignsTabCommand implements TabExecutor {
|
|
|
|
private static final ChatColor successColor = ChatColor.GREEN;
|
|
private static final ChatColor commandColor = ChatColor.YELLOW;
|
|
|
|
@Override
|
|
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
|
|
sender.sendMessage(commandColor + "[] denote optional parameters");
|
|
sender.sendMessage(commandColor + "<> denote required parameters");
|
|
sender.sendMessage(commandColor + "{} denote required permission");
|
|
sender.sendMessage(commandColor + "In some cases, commands with required parameters can be called with no parameters");
|
|
if (sender instanceof Player) {
|
|
showPlayerCommands(sender);
|
|
}
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* Shows all commands available to the sending player
|
|
*
|
|
* @param sender <p>The player which sent the command</p>
|
|
*/
|
|
private void showPlayerCommands(CommandSender sender) {
|
|
sender.sendMessage(commandColor + "Commands:");
|
|
|
|
showCommandInfo("addPaidSign", sender);
|
|
showCommandInfo("addPaidSignCondition", sender);
|
|
showCommandInfo("listPaidSigns", sender);
|
|
showCommandInfo("editPaidSign", sender);
|
|
showCommandInfo("removePaidSignCondition", sender);
|
|
showCommandInfo("removePaidSign", sender);
|
|
showCommandInfo("reload", sender);
|
|
}
|
|
|
|
/**
|
|
* Shows information about the given command
|
|
*
|
|
* @param command <p>The command to get information about</p>
|
|
* @param sender <p>The sender asking to see command info</p>
|
|
*/
|
|
private void showCommandInfo(String command, CommandSender sender) {
|
|
PluginCommand pluginCommand = PaidSigns.getInstance().getCommand(command);
|
|
if (pluginCommand != null) {
|
|
String permission = pluginCommand.getPermission();
|
|
if (permission == null || sender.hasPermission(permission)) {
|
|
String commandInfo = "\n" + commandColor + pluginCommand.getUsage().replace("<command>",
|
|
pluginCommand.getName()) + ": " + successColor + pluginCommand.getDescription();
|
|
if (sender.hasPermission("paidsigns.admin")) {
|
|
if (permission == null) {
|
|
permission = "None";
|
|
}
|
|
commandInfo += commandColor + " {" + permission + "}";
|
|
}
|
|
sender.sendMessage(commandInfo);
|
|
}
|
|
}
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public List<String> onTabComplete(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label,
|
|
@NotNull String[] args) {
|
|
return new ArrayList<>();
|
|
}
|
|
|
|
}
|