mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 07:06:44 +01:00
Some minor improvements to the MainCommand code.
This commit is contained in:
parent
0ff50aed11
commit
536ae7fe2f
@ -9,20 +9,12 @@
|
|||||||
|
|
||||||
package com.intellectualcrafters.plot;
|
package com.intellectualcrafters.plot;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import org.bukkit.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.bukkit.Bukkit;
|
|
||||||
import org.bukkit.ChatColor;
|
|
||||||
import org.bukkit.Location;
|
|
||||||
import org.bukkit.OfflinePlayer;
|
|
||||||
import org.bukkit.World;
|
|
||||||
import org.bukkit.block.Biome;
|
import org.bukkit.block.Biome;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Functions involving players, plots and locations.
|
* Functions involving players, plots and locations.
|
||||||
*
|
*
|
||||||
@ -32,8 +24,7 @@ import org.bukkit.entity.Player;
|
|||||||
public class PlayerFunctions {
|
public class PlayerFunctions {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param player
|
* @param player player
|
||||||
* player
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean isInPlot(final Player player) {
|
public static boolean isInPlot(final Player player) {
|
||||||
@ -41,8 +32,7 @@ public class PlayerFunctions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param plot
|
* @param plot plot
|
||||||
* plot
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean hasExpired(final Plot plot) {
|
public static boolean hasExpired(final Plot plot) {
|
||||||
@ -173,9 +163,8 @@ public class PlayerFunctions {
|
|||||||
/**
|
/**
|
||||||
* Updates a given plot with another instance
|
* Updates a given plot with another instance
|
||||||
*
|
*
|
||||||
* @deprecated
|
|
||||||
*
|
|
||||||
* @param plot
|
* @param plot
|
||||||
|
* @deprecated
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public static void set(final Plot plot) {
|
public static void set(final Plot plot) {
|
||||||
@ -237,8 +226,7 @@ public class PlayerFunctions {
|
|||||||
* \\previous\\
|
* \\previous\\
|
||||||
*
|
*
|
||||||
* @param plr
|
* @param plr
|
||||||
* @param msg
|
* @param msg Was used to wrap the chat client length (Packets out--)
|
||||||
* Was used to wrap the chat client length (Packets out--)
|
|
||||||
*/
|
*/
|
||||||
public static void sendMessageWrapped(final Player plr, final String msg) {
|
public static void sendMessageWrapped(final Player plr, final String msg) {
|
||||||
plr.sendMessage(msg);
|
plr.sendMessage(msg);
|
||||||
@ -247,14 +235,23 @@ public class PlayerFunctions {
|
|||||||
/**
|
/**
|
||||||
* Send a message to the player
|
* Send a message to the player
|
||||||
*
|
*
|
||||||
* @param plr
|
* @param plr Player to recieve message
|
||||||
* Player to recieve message
|
* @param msg Message to send
|
||||||
* @param msg
|
* @return true
|
||||||
* Message to send
|
* Can be used in things such as commands (return PlayerFunctions.sendMessage(...))
|
||||||
*/
|
*/
|
||||||
public static void sendMessage(final Player plr, final String msg) {
|
public static boolean sendMessage(final Player plr, final String msg) {
|
||||||
|
if (msg.length() > 0 && !msg.equals("")) {
|
||||||
|
if (plr == null) {
|
||||||
|
PlotMain.sendConsoleSenderMessage(C.PREFIX.s() + msg);
|
||||||
|
} else {
|
||||||
|
sendMessageWrapped(plr, ChatColor.translateAlternateColorCodes('&', C.PREFIX.s() + msg));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
/*
|
||||||
if ((msg.length() == 0) || msg.equalsIgnoreCase("")) {
|
if ((msg.length() == 0) || msg.equalsIgnoreCase("")) {
|
||||||
return;
|
return ;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (plr == null) {
|
if (plr == null) {
|
||||||
@ -263,18 +260,30 @@ public class PlayerFunctions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sendMessageWrapped(plr, ChatColor.translateAlternateColorCodes('&', C.PREFIX.s() + msg));
|
sendMessageWrapped(plr, ChatColor.translateAlternateColorCodes('&', C.PREFIX.s() + msg));
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a message to the player
|
* Send a message to the player
|
||||||
*
|
*
|
||||||
* @param plr
|
* @param plr Player to recieve message
|
||||||
* Player to recieve message
|
* @param c Caption to send
|
||||||
* @param c
|
|
||||||
* Caption to send
|
|
||||||
*/
|
*/
|
||||||
public static void sendMessage(final Player plr, final C c, final String... args) {
|
public static boolean sendMessage(final Player plr, final C c, final String... args) {
|
||||||
|
if (c.s().length() > 1) {
|
||||||
|
if (plr == null)
|
||||||
|
PlotMain.sendConsoleSenderMessage(c);
|
||||||
|
else {
|
||||||
|
String msg = c.s();
|
||||||
|
if ((args != null) && (args.length > 0)) {
|
||||||
|
for (final String str : args)
|
||||||
|
msg = msg.replaceFirst("%s", str);
|
||||||
|
}
|
||||||
|
sendMessage(plr, msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
/*
|
||||||
if (plr == null) {
|
if (plr == null) {
|
||||||
PlotMain.sendConsoleSenderMessage(c);
|
PlotMain.sendConsoleSenderMessage(c);
|
||||||
return;
|
return;
|
||||||
@ -290,5 +299,6 @@ public class PlayerFunctions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
sendMessage(plr, msg);
|
sendMessage(plr, msg);
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,6 +31,9 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class MainCommand implements CommandExecutor, TabCompleter {
|
public class MainCommand implements CommandExecutor, TabCompleter {
|
||||||
|
|
||||||
|
public static final String
|
||||||
|
MAIN_PERMISSION = "plots.use";
|
||||||
|
|
||||||
private static SubCommand[] _subCommands = new SubCommand[] { new Claim(), new Paste(), new Copy(), new Clipboard(), new Auto(), new Home(), new Visit(), 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(), new Purge(), new Reload(), new Merge(), new Unlink(), new Kick(), new Setup(), new DebugClaimTest(), new Inbox(), new Comment(), new Swap(), new MusicSubcommand() };
|
private static SubCommand[] _subCommands = new SubCommand[] { new Claim(), new Paste(), new Copy(), new Clipboard(), new Auto(), new Home(), new Visit(), 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(), new Purge(), new Reload(), new Merge(), new Unlink(), new Kick(), new Setup(), new DebugClaimTest(), new Inbox(), new Comment(), new Swap(), new MusicSubcommand() };
|
||||||
|
|
||||||
public static ArrayList<SubCommand> subCommands = new ArrayList<SubCommand>() {
|
public static ArrayList<SubCommand> subCommands = new ArrayList<SubCommand>() {
|
||||||
@ -48,9 +51,8 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
|||||||
public boolean onCommand(final CommandSender sender, final Command cmd, final String commandLabel, final String[] args) {
|
public boolean onCommand(final CommandSender sender, final Command cmd, final String commandLabel, final String[] args) {
|
||||||
final Player player = (sender instanceof Player) ? (Player) sender : null;
|
final Player player = (sender instanceof Player) ? (Player) sender : null;
|
||||||
|
|
||||||
if (!PlotMain.hasPermission(player, "plots.use")) {
|
if (!PlotMain.hasPermission(player, MAIN_PERMISSION))
|
||||||
return no_permission(player, "plots.use");
|
return no_permission(player, MAIN_PERMISSION);
|
||||||
}
|
|
||||||
|
|
||||||
if ((args.length < 1) || ((args.length >= 1) && (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("he")))) {
|
if ((args.length < 1) || ((args.length >= 1) && (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("he")))) {
|
||||||
if (args.length < 2) {
|
if (args.length < 2) {
|
||||||
@ -59,8 +61,7 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
|||||||
for (final SubCommand.CommandCategory category : SubCommand.CommandCategory.values()) {
|
for (final SubCommand.CommandCategory category : SubCommand.CommandCategory.values()) {
|
||||||
builder.append("\n").append(C.HELP_INFO_ITEM.s().replaceAll("%category%", category.toString().toLowerCase()).replaceAll("%category_desc%", category.toString()));
|
builder.append("\n").append(C.HELP_INFO_ITEM.s().replaceAll("%category%", category.toString().toLowerCase()).replaceAll("%category_desc%", category.toString()));
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(player, builder.toString());
|
return PlayerFunctions.sendMessage(player, builder.toString());
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
final String cat = args[1];
|
final String cat = args[1];
|
||||||
SubCommand.CommandCategory cato = null;
|
SubCommand.CommandCategory cato = null;
|
||||||
@ -76,8 +77,7 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
|||||||
for (final SubCommand.CommandCategory category : SubCommand.CommandCategory.values()) {
|
for (final SubCommand.CommandCategory category : SubCommand.CommandCategory.values()) {
|
||||||
builder.append("\n").append(C.HELP_INFO_ITEM.s().replaceAll("%category%", category.toString().toLowerCase()).replaceAll("%category_desc%", category.toString()));
|
builder.append("\n").append(C.HELP_INFO_ITEM.s().replaceAll("%category%", category.toString().toLowerCase()).replaceAll("%category_desc%", category.toString()));
|
||||||
}
|
}
|
||||||
PlayerFunctions.sendMessage(player, builder.toString());
|
return PlayerFunctions.sendMessage(player, builder.toString());
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
final StringBuilder help = new StringBuilder();
|
final StringBuilder help = new StringBuilder();
|
||||||
int page = 0;
|
int page = 0;
|
||||||
@ -109,8 +109,7 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
|||||||
help.append(string).append("\n");
|
help.append(string).append("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
PlayerFunctions.sendMessage(player, help.toString());
|
return PlayerFunctions.sendMessage(player, help.toString());
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for (final SubCommand command : subCommands) {
|
for (final SubCommand command : subCommands) {
|
||||||
@ -122,8 +121,7 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
|||||||
return command.execute(player, arguments);
|
return command.execute(player, arguments);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
PlayerFunctions.sendMessage(null, C.IS_CONSOLE);
|
return !PlayerFunctions.sendMessage(null, C.IS_CONSOLE);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -140,10 +138,9 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
|||||||
|
|
||||||
/* Let's try to get a proper usage string */
|
/* Let's try to get a proper usage string */
|
||||||
SubCommand command = (SubCommand) new StringComparsion(args[0], commands).getMatchObject();
|
SubCommand command = (SubCommand) new StringComparsion(args[0], commands).getMatchObject();
|
||||||
PlayerFunctions.sendMessage(player, C.DID_YOU_MEAN, command.usage.contains("plot") ? command.usage : "/plot " + command.usage);
|
return PlayerFunctions.sendMessage(player, C.DID_YOU_MEAN, command.usage.contains("plot") ? command.usage : "/plot " + command.usage);
|
||||||
//PlayerFunctions.sendMessage(player, C.DID_YOU_MEAN, new StringComparsion(args[0], commands).getBestMatch());
|
//PlayerFunctions.sendMessage(player, C.DID_YOU_MEAN, new StringComparsion(args[0], commands).getBestMatch());
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static List<SubCommand> getCommands(final SubCommand.CommandCategory category, final Player player) {
|
public static List<SubCommand> getCommands(final SubCommand.CommandCategory category, final Player player) {
|
||||||
@ -212,7 +209,7 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
|||||||
|
|
||||||
if (strings.length < 1) {
|
if (strings.length < 1) {
|
||||||
if ((strings.length == 0) || "plots".startsWith(s)) {
|
if ((strings.length == 0) || "plots".startsWith(s)) {
|
||||||
return Arrays.asList(new String[] { "plots" });
|
return Arrays.asList("plots");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (strings.length > 1) {
|
if (strings.length > 1) {
|
||||||
@ -221,7 +218,7 @@ public class MainCommand implements CommandExecutor, TabCompleter {
|
|||||||
if (!command.getLabel().equalsIgnoreCase("plots")) {
|
if (!command.getLabel().equalsIgnoreCase("plots")) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final List<String> tabOptions = new ArrayList<String>();
|
final List<String> tabOptions = new ArrayList<>();
|
||||||
final String arg = strings[0].toLowerCase();
|
final String arg = strings[0].toLowerCase();
|
||||||
for (final SubCommand cmd : subCommands) {
|
for (final SubCommand cmd : subCommands) {
|
||||||
if (cmd.permission.hasPermission(player)) {
|
if (cmd.permission.hasPermission(player)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user