2014-09-22 13:02:14 +02:00
|
|
|
/*
|
2014-10-12 09:37:36 +02:00
|
|
|
* Copyright (c) IntellectualCrafters - 2014. You are not allowed to distribute
|
|
|
|
* and/or monetize any of our intellectual property. IntellectualCrafters is not
|
|
|
|
* affiliated with Mojang AB. Minecraft is a trademark of Mojang AB.
|
|
|
|
*
|
|
|
|
* >> File = MainCommand.java >> Generated by: Citymonstret at 2014-08-09 01:42
|
2014-09-22 13:02:14 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package com.intellectualcrafters.plot.commands;
|
|
|
|
|
2014-10-12 17:26:58 +02:00
|
|
|
import com.intellectualcrafters.plot.C;
|
|
|
|
import com.intellectualcrafters.plot.PlayerFunctions;
|
|
|
|
import com.intellectualcrafters.plot.PlotMain;
|
2014-11-01 16:13:44 +01:00
|
|
|
import com.intellectualcrafters.plot.StringComparsion;
|
2014-09-22 13:02:14 +02:00
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandExecutor;
|
|
|
|
import org.bukkit.command.CommandSender;
|
2014-11-01 16:13:44 +01:00
|
|
|
import org.bukkit.command.TabCompleter;
|
2014-09-22 13:02:14 +02:00
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2014-10-12 17:26:58 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
2014-11-01 16:13:44 +01:00
|
|
|
import java.util.List;
|
2014-09-22 13:02:14 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* PlotMain command class
|
2014-10-11 09:33:10 +02:00
|
|
|
*
|
2014-09-22 13:02:14 +02:00
|
|
|
* @author Citymonstret
|
|
|
|
*/
|
2014-11-01 16:13:44 +01:00
|
|
|
public class MainCommand implements CommandExecutor, TabCompleter {
|
2014-09-22 13:02:14 +02:00
|
|
|
|
2014-10-13 19:40:30 +02:00
|
|
|
private static SubCommand[] _subCommands = new SubCommand[] { new Claim(), new Paste(), new Copy(), new Clipboard(), new Auto(), new Home(), new Visit(),
|
2014-10-12 09:37:36 +02:00
|
|
|
new TP(), new Set(), new Clear(), new Delete(), new SetOwner(), new Denied(), new Helpers(), new Trusted(),
|
2014-10-18 04:24:47 +02:00
|
|
|
new Info(), new list(), new Help(), new Debug(), new Schematic(), new plugin(), new Inventory(), new Purge(),
|
2014-10-30 16:16:26 +01:00
|
|
|
new Reload(), new Merge(), new Unlink(), new Kick(), new Setup(), new DebugClaimTest(), new Inbox(), new Comment(), new Swap(), new MusicSubcommand() };
|
2014-09-22 13:02:14 +02:00
|
|
|
|
2014-10-11 09:33:10 +02:00
|
|
|
public static ArrayList<SubCommand> subCommands = new ArrayList<SubCommand>() {
|
|
|
|
{
|
|
|
|
addAll(Arrays.asList(_subCommands));
|
|
|
|
}
|
|
|
|
};
|
2014-09-22 13:02:14 +02:00
|
|
|
|
2014-10-21 11:58:52 +02:00
|
|
|
public static boolean no_permission(Player player, String permission) {
|
|
|
|
PlayerFunctions.sendMessage(player, C.NO_PERMISSION, permission);
|
2014-10-11 09:33:10 +02:00
|
|
|
return false;
|
|
|
|
}
|
2014-09-24 14:21:43 +02:00
|
|
|
|
2014-10-11 09:33:10 +02:00
|
|
|
@Override
|
2014-10-12 09:37:36 +02:00
|
|
|
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
|
2014-10-18 20:06:29 +02:00
|
|
|
Player player;
|
|
|
|
if (sender instanceof Player) {
|
|
|
|
player = (Player) sender;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
player = null;
|
2014-10-11 09:33:10 +02:00
|
|
|
}
|
2014-10-18 04:24:47 +02:00
|
|
|
if (!PlotMain.hasPermission(player, "plots.use")) {
|
2014-10-21 11:58:52 +02:00
|
|
|
return no_permission(player, "plots.use");
|
2014-10-11 09:33:10 +02:00
|
|
|
}
|
|
|
|
if ((args.length < 1)
|
2014-10-12 09:37:36 +02:00
|
|
|
|| ((args.length >= 1) && (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("he")))) {
|
2014-10-11 09:33:10 +02:00
|
|
|
if (args.length < 2) {
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
builder.append(C.HELP_INFO.s());
|
2014-10-12 09:37:36 +02:00
|
|
|
for (SubCommand.CommandCategory category : SubCommand.CommandCategory.values()) {
|
2014-10-11 09:33:10 +02:00
|
|
|
builder.append("\n"
|
2014-10-12 09:37:36 +02:00
|
|
|
+ C.HELP_INFO_ITEM.s().replaceAll("%category%", category.toString().toLowerCase()).replaceAll("%category_desc%", category.toString()));
|
2014-10-11 09:33:10 +02:00
|
|
|
}
|
|
|
|
PlayerFunctions.sendMessage(player, builder.toString());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
String cat = args[1];
|
|
|
|
SubCommand.CommandCategory cato = null;
|
2014-10-12 09:37:36 +02:00
|
|
|
for (SubCommand.CommandCategory category : SubCommand.CommandCategory.values()) {
|
2014-10-11 09:33:10 +02:00
|
|
|
if (cat.equalsIgnoreCase(category.toString())) {
|
|
|
|
cato = category;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (cato == null) {
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
builder.append(C.HELP_INFO.s());
|
2014-10-12 09:37:36 +02:00
|
|
|
for (SubCommand.CommandCategory category : SubCommand.CommandCategory.values()) {
|
2014-10-11 09:33:10 +02:00
|
|
|
builder.append("\n"
|
2014-10-12 09:37:36 +02:00
|
|
|
+ C.HELP_INFO_ITEM.s().replaceAll("%category%", category.toString().toLowerCase()).replaceAll("%category_desc%", category.toString()));
|
2014-10-11 09:33:10 +02:00
|
|
|
}
|
|
|
|
PlayerFunctions.sendMessage(player, builder.toString());
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
StringBuilder help = new StringBuilder();
|
|
|
|
for (String string : helpMenu(player, cato)) {
|
|
|
|
help.append(string + "\n");
|
|
|
|
}
|
|
|
|
PlayerFunctions.sendMessage(player, help.toString());
|
|
|
|
return true;
|
2014-10-12 09:37:36 +02:00
|
|
|
}
|
|
|
|
else {
|
2014-10-11 09:33:10 +02:00
|
|
|
for (SubCommand command : subCommands) {
|
2014-10-12 09:37:36 +02:00
|
|
|
if (command.cmd.equalsIgnoreCase(args[0]) || command.alias.equalsIgnoreCase(args[0])) {
|
2014-10-11 09:33:10 +02:00
|
|
|
String[] arguments = new String[args.length - 1];
|
|
|
|
for (int x = 1; x < args.length; x++) {
|
|
|
|
arguments[x - 1] = args[x];
|
|
|
|
}
|
|
|
|
if (command.permission.hasPermission(player)) {
|
2014-10-18 20:06:29 +02:00
|
|
|
if (player!=null || !command.isPlayer ) {
|
|
|
|
return command.execute(player, arguments);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
PlayerFunctions.sendMessage(player, C.IS_CONSOLE);
|
|
|
|
return false;
|
|
|
|
}
|
2014-10-12 09:37:36 +02:00
|
|
|
}
|
|
|
|
else {
|
2014-10-21 11:58:52 +02:00
|
|
|
return no_permission(player, command.permission.permission.toLowerCase());
|
2014-10-11 09:33:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PlayerFunctions.sendMessage(player, C.NOT_VALID_SUBCOMMAND);
|
2014-11-01 16:13:44 +01:00
|
|
|
|
|
|
|
String[] commands = new String[subCommands.size()];
|
|
|
|
for(int x = 0; x < subCommands.size(); x++)
|
|
|
|
commands[x] = subCommands.get(x).cmd;
|
|
|
|
|
|
|
|
PlayerFunctions.sendMessage(player, C.DID_YOU_MEAN, new StringComparsion(args[0], commands).getBestMatch());
|
2014-10-11 09:33:10 +02:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2014-09-22 13:02:14 +02:00
|
|
|
|
2014-10-12 09:37:36 +02:00
|
|
|
public static ArrayList<String> helpMenu(Player player, final SubCommand.CommandCategory category) {
|
2014-10-11 09:33:10 +02:00
|
|
|
ArrayList<String> help = new ArrayList<String>() {
|
|
|
|
{
|
|
|
|
add(t(C.HELP_HEADER.s()));
|
2014-10-12 09:37:36 +02:00
|
|
|
add(t(C.HELP_CATEGORY.s().replaceAll("%category%", category.toString())));
|
2014-10-11 09:33:10 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
for (SubCommand cmd : subCommands) {
|
2014-10-12 09:37:36 +02:00
|
|
|
if (cmd.permission.hasPermission(player) && (cmd.category == category)) {
|
2014-10-11 09:33:10 +02:00
|
|
|
String s = t(C.HELP_PAGE.s());
|
|
|
|
s = s.replaceAll("%alias%", cmd.alias);
|
2014-10-12 09:37:36 +02:00
|
|
|
s = s.replaceAll("%usage%", cmd.usage.contains("plot") ? cmd.usage : "/plot " + cmd.usage);
|
2014-10-11 09:33:10 +02:00
|
|
|
s = s.replaceAll("%cmd%", cmd.cmd);
|
|
|
|
s = s.replaceAll("%desc%", cmd.description);
|
|
|
|
help.add(s);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (help.size() < 2) {
|
|
|
|
help.add(t(C.NO_COMMANDS.s()));
|
|
|
|
}
|
|
|
|
return help;
|
|
|
|
}
|
2014-09-22 13:02:14 +02:00
|
|
|
|
2014-10-11 09:33:10 +02:00
|
|
|
private static String t(String s) {
|
|
|
|
return ChatColor.translateAlternateColorCodes('&', s);
|
|
|
|
}
|
2014-09-22 13:02:14 +02:00
|
|
|
|
2014-11-01 16:13:44 +01:00
|
|
|
@Override
|
|
|
|
public List<String> onTabComplete(CommandSender commandSender, Command command, String s, String[] strings) {
|
|
|
|
if(!(commandSender instanceof Player)) return null;
|
|
|
|
Player player = (Player) commandSender;
|
|
|
|
ArrayList<SubCommand> subo = subCommands;
|
2014-11-01 16:22:22 +01:00
|
|
|
if(strings.length < 1 || strings[0].length() < 2) return null;
|
2014-11-01 16:13:44 +01:00
|
|
|
while(true) {
|
|
|
|
String sub = new StringComparsion(strings[0], subo.toArray()).getBestMatch();
|
|
|
|
if(subo.isEmpty())
|
|
|
|
break;
|
|
|
|
for (SubCommand subCommand : subo) {
|
|
|
|
if (subCommand.cmd.equals(sub)) {
|
|
|
|
if(subCommand.permission.hasPermission(player))
|
|
|
|
return Arrays.asList(sub);
|
|
|
|
else {
|
|
|
|
subo.remove(subCommand);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2014-09-22 13:02:14 +02:00
|
|
|
}
|