diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlayerFunctions.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlayerFunctions.java index 2dbded55f..f7c7a5f79 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlayerFunctions.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlayerFunctions.java @@ -9,20 +9,12 @@ package com.intellectualcrafters.plot; -import java.util.ArrayList; -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.*; import org.bukkit.block.Biome; import org.bukkit.entity.Player; +import java.util.*; + /** * Functions involving players, plots and locations. * @@ -32,8 +24,7 @@ import org.bukkit.entity.Player; public class PlayerFunctions { /** - * @param player - * player + * @param player player * @return */ public static boolean isInPlot(final Player player) { @@ -41,8 +32,7 @@ public class PlayerFunctions { } /** - * @param plot - * plot + * @param plot plot * @return */ public static boolean hasExpired(final Plot plot) { @@ -173,9 +163,8 @@ public class PlayerFunctions { /** * Updates a given plot with another instance * - * @deprecated - * * @param plot + * @deprecated */ @Deprecated public static void set(final Plot plot) { @@ -237,8 +226,7 @@ public class PlayerFunctions { * \\previous\\ * * @param plr - * @param msg - * Was used to wrap the chat client length (Packets out--) + * @param msg Was used to wrap the chat client length (Packets out--) */ public static void sendMessageWrapped(final Player plr, final String msg) { plr.sendMessage(msg); @@ -247,14 +235,23 @@ public class PlayerFunctions { /** * Send a message to the player * - * @param plr - * Player to recieve message - * @param msg - * Message to send + * @param plr Player to recieve message + * @param msg Message to send + * @return true + * 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("")) { - return; + return ; } if (plr == null) { @@ -263,18 +260,30 @@ public class PlayerFunctions { } sendMessageWrapped(plr, ChatColor.translateAlternateColorCodes('&', C.PREFIX.s() + msg)); + */ } /** * Send a message to the player * - * @param plr - * Player to recieve message - * @param c - * Caption to send + * @param plr Player to recieve message + * @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) { PlotMain.sendConsoleSenderMessage(c); return; @@ -290,5 +299,6 @@ public class PlayerFunctions { } } sendMessage(plr, msg); + */ } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java index 2c6f673fa..8f0007552 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/commands/MainCommand.java @@ -31,6 +31,9 @@ import java.util.List; */ 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() }; public static ArrayList subCommands = new ArrayList() { @@ -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) { final Player player = (sender instanceof Player) ? (Player) sender : null; - if (!PlotMain.hasPermission(player, "plots.use")) { - return no_permission(player, "plots.use"); - } + if (!PlotMain.hasPermission(player, MAIN_PERMISSION)) + return no_permission(player, MAIN_PERMISSION); if ((args.length < 1) || ((args.length >= 1) && (args[0].equalsIgnoreCase("help") || args[0].equalsIgnoreCase("he")))) { if (args.length < 2) { @@ -59,8 +61,7 @@ public class MainCommand implements CommandExecutor, TabCompleter { 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())); } - PlayerFunctions.sendMessage(player, builder.toString()); - return true; + return PlayerFunctions.sendMessage(player, builder.toString()); } final String cat = args[1]; SubCommand.CommandCategory cato = null; @@ -76,8 +77,7 @@ public class MainCommand implements CommandExecutor, TabCompleter { 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())); } - PlayerFunctions.sendMessage(player, builder.toString()); - return true; + return PlayerFunctions.sendMessage(player, builder.toString()); } final StringBuilder help = new StringBuilder(); int page = 0; @@ -109,8 +109,7 @@ public class MainCommand implements CommandExecutor, TabCompleter { help.append(string).append("\n"); } - PlayerFunctions.sendMessage(player, help.toString()); - return true; + return PlayerFunctions.sendMessage(player, help.toString()); } else { for (final SubCommand command : subCommands) { @@ -122,8 +121,7 @@ public class MainCommand implements CommandExecutor, TabCompleter { return command.execute(player, arguments); } else { - PlayerFunctions.sendMessage(null, C.IS_CONSOLE); - return false; + return !PlayerFunctions.sendMessage(null, C.IS_CONSOLE); } } else { @@ -140,10 +138,9 @@ public class MainCommand implements CommandExecutor, TabCompleter { /* Let's try to get a proper usage string */ 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()); } - return false; } public static List 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 == 0) || "plots".startsWith(s)) { - return Arrays.asList(new String[] { "plots" }); + return Arrays.asList("plots"); } } if (strings.length > 1) { @@ -221,7 +218,7 @@ public class MainCommand implements CommandExecutor, TabCompleter { if (!command.getLabel().equalsIgnoreCase("plots")) { return null; } - final List tabOptions = new ArrayList(); + final List tabOptions = new ArrayList<>(); final String arg = strings[0].toLowerCase(); for (final SubCommand cmd : subCommands) { if (cmd.permission.hasPermission(player)) {