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-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;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2014-10-12 17:26:58 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
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-09-24 14:21:43 +02:00
|
|
|
public class MainCommand implements CommandExecutor {
|
2014-09-22 13:02:14 +02:00
|
|
|
|
2014-10-12 17:26:58 +02:00
|
|
|
private static SubCommand[] _subCommands = new SubCommand[] { new Claim(), new Paste(), new Copy(), 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(),
|
|
|
|
new Info(), new list(), new Help(), new Debug(), new Schematic(), new plugin(), new Inventory(),
|
2014-10-11 09:33:10 +02:00
|
|
|
new Reload(), new Merge(), new Unlink(), new Kick(), new Setup() };
|
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-11 09:33:10 +02:00
|
|
|
public static boolean no_permission(Player player) {
|
|
|
|
PlayerFunctions.sendMessage(player, C.NO_PERMISSION);
|
|
|
|
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-11 09:33:10 +02:00
|
|
|
if (!(sender instanceof Player)) {
|
|
|
|
if (args.length > 0) {
|
|
|
|
if (args[0].equalsIgnoreCase("reload")) {
|
|
|
|
new Reload().executeConsole(args);
|
|
|
|
}
|
2014-10-12 09:37:36 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
PlotMain.sendConsoleSenderMessage(C.PREFIX.s() + C.HELP_HEADER.s());
|
2014-10-11 09:33:10 +02:00
|
|
|
PlotMain.sendConsoleSenderMessage("&6/plots reload &c-&6 reloads the plugin");
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Player player = (Player) sender;
|
|
|
|
if (!player.hasPermission("plots.use")) {
|
|
|
|
return no_permission(player);
|
|
|
|
}
|
|
|
|
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)) {
|
|
|
|
return command.execute(player, arguments);
|
2014-10-12 09:37:36 +02:00
|
|
|
}
|
|
|
|
else {
|
2014-10-11 09:33:10 +02:00
|
|
|
return no_permission(player);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
PlayerFunctions.sendMessage(player, C.NOT_VALID_SUBCOMMAND);
|
|
|
|
}
|
|
|
|
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
|
|
|
|
|
|
|
}
|