mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2024-11-22 10:36:06 +01:00
Add a freshly baked BSD help command
This commit is contained in:
parent
6be11c01ee
commit
1c3d3b0807
@ -1 +1 @@
|
||||
Subproject commit e9151828c2720d800c6604b204b55a2bd1c6aae1
|
||||
Subproject commit a7cbc0f047c8ef06216ea45e1966e0c0914f2658
|
@ -3,22 +3,59 @@ package com.onarandombox.MultiverseCore.command.commands;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.onarandombox.MultiverseCore.MultiverseCore;
|
||||
import com.pneumaticraft.commandhandler.Command;
|
||||
|
||||
public class HelpCommand extends Command {
|
||||
private static final int CMDS_PER_PAGE = 10;
|
||||
|
||||
public HelpCommand(JavaPlugin plugin) {
|
||||
super(plugin);
|
||||
// TODO Auto-generated constructor stub
|
||||
this.commandName = "Get Help with Multiverse";
|
||||
this.commandDesc = "Displays a nice help menu";
|
||||
this.commandUsage = "/mv " + ChatColor.GOLD + "[PAGE #]";
|
||||
this.minimumArgLength = 0;
|
||||
this.maximumArgLength = 1;
|
||||
this.commandKeys.add("mv");
|
||||
this.commandKeys.add("mvhelp");
|
||||
this.commandKeys.add("mv help");
|
||||
this.permission = "multiverse.help";
|
||||
this.opRequired = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void runCommand(CommandSender sender, List<String> args) {
|
||||
// TODO Auto-generated method stub
|
||||
int page = 1;
|
||||
if (args.size() == 1) {
|
||||
try {
|
||||
page = Integer.parseInt(args.get(0));
|
||||
} catch (NumberFormatException e) {
|
||||
}
|
||||
}
|
||||
|
||||
List<Command> availableCommands = ((MultiverseCore) this.plugin).getCommandHandler().getCommands(sender);
|
||||
int totalPages = (int) Math.ceil(availableCommands.size() / ( CMDS_PER_PAGE + 0.0));
|
||||
|
||||
if (page > totalPages) {
|
||||
page = totalPages;
|
||||
}
|
||||
|
||||
sender.sendMessage(ChatColor.AQUA + "====[ Multiverse Help ]====");
|
||||
sender.sendMessage(ChatColor.AQUA + " Page " + page + " of " + totalPages);
|
||||
this.showPage(page, sender, availableCommands);
|
||||
|
||||
}
|
||||
|
||||
private void showPage(int page, CommandSender sender, List<Command> cmds) {
|
||||
int start = (page - 1) * CMDS_PER_PAGE;
|
||||
int end = start + CMDS_PER_PAGE;
|
||||
for (int i = start; i < cmds.size() && i < end; i++) {
|
||||
sender.sendMessage(ChatColor.AQUA + cmds.get(i).getCommandUsage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user