mirror of
https://github.com/TotalFreedomMC/TF-ProjectKorra.git
synced 2025-02-12 03:59:06 +00:00
commit
aa845f47e3
3 changed files with 82 additions and 10 deletions
|
@ -12,6 +12,7 @@ import com.projectkorra.projectkorra.waterbending.WaterMethods;
|
||||||
import org.bukkit.ChatColor;
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -20,7 +21,7 @@ import java.util.List;
|
||||||
*/
|
*/
|
||||||
public class HelpCommand extends PKCommand {
|
public class HelpCommand extends PKCommand {
|
||||||
public HelpCommand() {
|
public HelpCommand() {
|
||||||
super("help", "/bending help", "This command provides information on how to use other commands in ProjectKorra.", new String[] { "help", "h" });
|
super("help", "/bending help [Topic/Page]", "This command provides information on how to use other commands in ProjectKorra.", new String[] { "help", "h" });
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -28,15 +29,27 @@ public class HelpCommand extends PKCommand {
|
||||||
if (!hasPermission(sender) || !correctLength(sender, args.size(), 0, 1))
|
if (!hasPermission(sender) || !correctLength(sender, args.size(), 0, 1))
|
||||||
return;
|
return;
|
||||||
else if (args.size() == 0) {
|
else if (args.size() == 0) {
|
||||||
|
List<String> strings = new ArrayList<String>();
|
||||||
for (PKCommand command : instances.values()) {
|
for (PKCommand command : instances.values()) {
|
||||||
sender.sendMessage(ChatColor.YELLOW + command.getProperUse());
|
strings.add(command.getProperUse());
|
||||||
|
}
|
||||||
|
for (String s : getPage(strings, ChatColor.GOLD + "Commands: <required> [optional]", 1)) {
|
||||||
|
sender.sendMessage(ChatColor.YELLOW + s);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String arg = args.get(0);
|
String arg = args.get(0);
|
||||||
|
|
||||||
if (instances.keySet().contains(arg.toLowerCase())) {//bending help command
|
if (isNumeric(arg)) {
|
||||||
|
List<String> strings = new ArrayList<String>();
|
||||||
|
for (PKCommand command : instances.values()) {
|
||||||
|
strings.add(command.getProperUse());
|
||||||
|
}
|
||||||
|
for (String s : getPage(strings, ChatColor.GOLD + "Commands: <required> [optional]", Integer.valueOf(arg))) {
|
||||||
|
sender.sendMessage(ChatColor.YELLOW + s);
|
||||||
|
}
|
||||||
|
} else if (instances.keySet().contains(arg.toLowerCase())) {//bending help command
|
||||||
instances.get(arg).help(sender, true);
|
instances.get(arg).help(sender, true);
|
||||||
} else if (Arrays.asList(Commands.comboaliases).contains(arg)) { //bending help elementcombo
|
} else if (Arrays.asList(Commands.comboaliases).contains(arg)) { //bending help elementcombo
|
||||||
sender.sendMessage(ChatColor.GOLD + "Proper Usage: " + ChatColor.RED + "/bending display " + arg + ChatColor.GOLD + " or " + ChatColor.RED + "/bending help <Combo Name>");
|
sender.sendMessage(ChatColor.GOLD + "Proper Usage: " + ChatColor.RED + "/bending display " + arg + ChatColor.GOLD + " or " + ChatColor.RED + "/bending help <Combo Name>");
|
||||||
|
|
|
@ -4,8 +4,13 @@ import org.bukkit.ChatColor;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.text.NumberFormat;
|
||||||
|
import java.text.ParsePosition;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -162,4 +167,51 @@ public abstract class PKCommand implements SubCommand {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a boolean if the string provided is numerical.
|
||||||
|
* @param id
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
protected boolean isNumeric(String id) {
|
||||||
|
NumberFormat formatter = NumberFormat.getInstance();
|
||||||
|
ParsePosition pos = new ParsePosition(0);
|
||||||
|
formatter.parse(id, pos);
|
||||||
|
return id.length() == pos.getIndex();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a list for of commands for a page.
|
||||||
|
* @param entries
|
||||||
|
* @param title
|
||||||
|
* @param page
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
protected List<String> getPage(List<String> entries, String title, int page) {
|
||||||
|
List<String> strings = new ArrayList<String>();
|
||||||
|
Collections.sort(entries);
|
||||||
|
|
||||||
|
if (page < 1) {
|
||||||
|
page = 1;
|
||||||
|
}
|
||||||
|
if ((page * 8) - 8 >= entries.size()) {
|
||||||
|
page = Math.round(entries.size() / 8) + 1;
|
||||||
|
if (page < 1) {
|
||||||
|
page = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
strings.add(ChatColor.GOLD + "ProjectKorra " + ChatColor.DARK_GRAY + "- [" + ChatColor.GRAY + page + "/" + (int) Math.ceil((entries.size()+.0)/(8+.0)) + ChatColor.DARK_GRAY + "]");
|
||||||
|
strings.add(title);
|
||||||
|
if (entries.size() > ((page * 8) - 8)) {
|
||||||
|
for (int i = ((page * 8) - 8); i < entries.size(); i++) {
|
||||||
|
if (entries.get(i) != null) {
|
||||||
|
strings.add(entries.get(i).toString());
|
||||||
|
}
|
||||||
|
if (i >= (page * 8)-1) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class WhoCommand extends PKCommand {
|
||||||
Map<String, String> staff = new HashMap<String, String>();
|
Map<String, String> staff = new HashMap<String, String>();
|
||||||
|
|
||||||
public WhoCommand() {
|
public WhoCommand() {
|
||||||
super("who", "/bending who [Player]", "This command will tell you what element all players that are online are (If you don't specify a player) or give you information about the player that you specify.", new String[] { "who", "w" });
|
super("who", "/bending who [Player/Page]", "This command will tell you what element all players that are online are (If you don't specify a player) or give you information about the player that you specify.", new String[] { "who", "w" });
|
||||||
|
|
||||||
staff.put("8621211e-283b-46f5-87bc-95a66d68880e", ChatColor.RED + "ProjectKorra Founder"); // MistPhizzle
|
staff.put("8621211e-283b-46f5-87bc-95a66d68880e", ChatColor.RED + "ProjectKorra Founder"); // MistPhizzle
|
||||||
|
|
||||||
|
@ -70,9 +70,13 @@ public class WhoCommand extends PKCommand {
|
||||||
public void execute(CommandSender sender, List<String> args) {
|
public void execute(CommandSender sender, List<String> args) {
|
||||||
if (!hasPermission(sender) || !correctLength(sender, args.size(), 0, 1)) {
|
if (!hasPermission(sender) || !correctLength(sender, args.size(), 0, 1)) {
|
||||||
return;
|
return;
|
||||||
} else if (args.size() == 1) {
|
} else if (args.size() == 1 && args.get(0).length() > 2) {
|
||||||
whoPlayer(sender, args.get(0));
|
whoPlayer(sender, args.get(0));
|
||||||
} else if (args.size() == 0) {
|
} else if (args.size() == 0 || args.size() == 1) {
|
||||||
|
int page = 1;
|
||||||
|
if (args.size() == 1 && isNumeric(args.get(0))) {
|
||||||
|
page = Integer.valueOf(args.get(0));
|
||||||
|
}
|
||||||
List<String> players = new ArrayList<String>();
|
List<String> players = new ArrayList<String>();
|
||||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||||
String playerName = player.getName();
|
String playerName = player.getName();
|
||||||
|
@ -125,8 +129,11 @@ public class WhoCommand extends PKCommand {
|
||||||
if (players.isEmpty()) {
|
if (players.isEmpty()) {
|
||||||
sender.sendMessage(ChatColor.RED + "There is no one online.");
|
sender.sendMessage(ChatColor.RED + "There is no one online.");
|
||||||
} else {
|
} else {
|
||||||
for (String st : players) {
|
//for (String st : players) {
|
||||||
sender.sendMessage(st);
|
// sender.sendMessage(st);
|
||||||
|
//}
|
||||||
|
for (String s : getPage(players, ChatColor.GOLD + "Players:", page)) {
|
||||||
|
sender.sendMessage(s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue