Current work

This commit is contained in:
libraryaddict 2017-06-19 21:23:02 +12:00
parent f4bc7ef3a4
commit cba8cb417c
24 changed files with 622 additions and 486 deletions

View File

@ -28,6 +28,9 @@ SaveDisguises:
KeepDisguises: KeepDisguises:
PlayerDeath: false PlayerDeath: false
# Should the plugin use translations? Note that a player must see the message before it will appear in translations.yml
Translations: false
# How should the plugin handle self disguises scoreboards? # How should the plugin handle self disguises scoreboards?
# MODIFY_SCOREBOARD - Modifies the player's current team if possible, otherwise assigns them to a new scoreboard team # MODIFY_SCOREBOARD - Modifies the player's current team if possible, otherwise assigns them to a new scoreboard team
# IGNORE_SCOREBOARD - Doesn't touch scoreboards at all, effectively means that if you didn't disable pushing in their scoreboard team; They will still be pushed around # IGNORE_SCOREBOARD - Doesn't touch scoreboards at all, effectively means that if you didn't disable pushing in their scoreboard team; They will still be pushed around

View File

@ -4,6 +4,7 @@ import java.io.File;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map.Entry; import java.util.Map.Entry;
import me.libraryaddict.disguise.utilities.TranslateType;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
@ -60,6 +61,7 @@ public class DisguiseConfig {
private static boolean updatePlayerCache; private static boolean updatePlayerCache;
private static boolean savePlayerDisguises; private static boolean savePlayerDisguises;
private static boolean saveEntityDisguises; private static boolean saveEntityDisguises;
private static boolean useTranslations;
public static Entry<String, Disguise> getCustomDisguise(String disguise) { public static Entry<String, Disguise> getCustomDisguise(String disguise) {
for (Entry<String, Disguise> entry : customDisguises.entrySet()) { for (Entry<String, Disguise> entry : customDisguises.entrySet()) {
@ -77,6 +79,16 @@ public class DisguiseConfig {
return savePlayerDisguises; return savePlayerDisguises;
} }
public static boolean isUseTranslations() {
return useTranslations;
}
public static void setUseTranslations(boolean setUseTranslations) {
useTranslations = setUseTranslations;
TranslateType.reloadTranslations();
}
public static boolean isSaveEntityDisguises() { public static boolean isSaveEntityDisguises() {
return saveEntityDisguises; return saveEntityDisguises;
} }
@ -180,6 +192,7 @@ public class DisguiseConfig {
setUpdateGameProfiles(config.getBoolean("UpdateGameProfiles")); setUpdateGameProfiles(config.getBoolean("UpdateGameProfiles"));
setSavePlayerDisguises(config.getBoolean("SaveDisguises.Players")); setSavePlayerDisguises(config.getBoolean("SaveDisguises.Players"));
setSaveEntityDisguises(config.getBoolean("SaveDisguises.Entities")); setSaveEntityDisguises(config.getBoolean("SaveDisguises.Entities"));
setUseTranslations(config.getBoolean("Translations"));
try { try {
String option = config.getString("SelfDisguisesScoreboard", String option = config.getString("SelfDisguisesScoreboard",

View File

@ -81,7 +81,7 @@ public class LibsDisguises extends JavaPlugin {
PacketsManager.addPacketListeners(); PacketsManager.addPacketListeners();
TranslateFiller.fillConfigs(); TranslateType.MESSAGE.name(); // Call the static loader
listener = new DisguiseListener(this); listener = new DisguiseListener(this);

View File

@ -1,9 +1,10 @@
package me.libraryaddict.disguise.commands; package me.libraryaddict.disguise.commands;
import java.util.ArrayList; import me.libraryaddict.disguise.DisguiseConfig;
import java.util.HashMap; import me.libraryaddict.disguise.LibsDisguises;
import java.util.List; import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.TranslateType;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -12,16 +13,16 @@ import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter; import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import me.libraryaddict.disguise.DisguiseConfig; import java.util.ArrayList;
import me.libraryaddict.disguise.LibsDisguises; import java.util.HashMap;
import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; import java.util.List;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabCompleter { public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabCompleter {
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.getName().equals("CONSOLE")) { if (sender.getName().equals("CONSOLE")) {
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!"); sender.sendMessage(
TranslateType.MESSAGE.get(ChatColor.RED + "You may not use this command from the console!"));
return true; return true;
} }
@ -37,43 +38,37 @@ public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabComp
for (int i = player == null ? 0 : 1; i < args.length; i++) { for (int i = player == null ? 0 : 1; i < args.length; i++) {
String option = args[i]; String option = args[i];
if (StringUtils.startsWithIgnoreCase(option, "ignoreEquip") if (StringUtils.startsWithIgnoreCase(option, "ignoreEquip") || StringUtils.startsWithIgnoreCase(option,
|| StringUtils.startsWithIgnoreCase(option, "ignoreEnquip")) { "ignoreEnquip")) {
doEquipment = false; doEquipment = false;
} } else if (option.equalsIgnoreCase("doSneakSprint")) {
else if (option.equalsIgnoreCase("doSneakSprint")) {
doSneak = true; doSneak = true;
doSprint = true; doSprint = true;
} } else if (option.equalsIgnoreCase("doSneak")) {
else if (option.equalsIgnoreCase("doSneak")) {
doSneak = true; doSneak = true;
} } else if (option.equalsIgnoreCase("doSprint")) {
else if (option.equalsIgnoreCase("doSprint")) {
doSprint = true; doSprint = true;
} } else {
else { sender.sendMessage(String.format(TranslateType.MESSAGE.get(
sender.sendMessage(ChatColor.DARK_RED + "Unknown option '" + option ChatColor.DARK_RED + "Unknown " + "option '%s" + "' - Valid options are 'IgnoreEquipment' 'DoSneakSprint' 'DoSneak' 'DoSprint'"),
+ "' - Valid options are 'IgnoreEquipment' 'DoSneakSprint' 'DoSneak' 'DoSprint'"); option));
return true; return true;
} }
} }
Boolean[] options = new Boolean[] { Boolean[] options = new Boolean[]{doEquipment, doSneak, doSprint};
doEquipment, doSneak, doSprint
};
if (player != null) { if (player != null) {
DisguiseUtilities.createClonedDisguise((Player) sender, player, options); DisguiseUtilities.createClonedDisguise((Player) sender, player, options);
} } else {
else {
LibsDisguises.getInstance().getListener().setDisguiseClone(sender.getName(), options); LibsDisguises.getInstance().getListener().setDisguiseClone(sender.getName(), options);
sender.sendMessage(ChatColor.RED + "Right click a entity in the next " + DisguiseConfig.getDisguiseCloneExpire() sender.sendMessage(String.format(TranslateType.MESSAGE.get(
+ " seconds to grab the disguise reference!"); ChatColor.RED + "Right click a entity in the next %s" + " seconds to grab the disguise reference!"),
DisguiseConfig.getDisguiseCloneExpire()));
} }
} } else {
else { sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command."));
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
} }
return true; return true;
@ -81,7 +76,7 @@ public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabComp
@Override @Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<String>(); ArrayList<String> tabs = new ArrayList<>();
String[] args = getArgs(origArgs); String[] args = getArgs(origArgs);
@ -103,12 +98,13 @@ public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabComp
* Send the player the information * Send the player the information
*/ */
@Override @Override
protected void sendCommandUsage(CommandSender sender, HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map) { protected void sendCommandUsage(CommandSender sender,
sender.sendMessage(ChatColor.DARK_GREEN HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map) {
+ "Right click a entity to get a disguise reference you can pass to other disguise commands!"); sender.sendMessage(TranslateType.MESSAGE.get(
sender.sendMessage(ChatColor.DARK_GREEN ChatColor.DARK_GREEN + "Right click a entity to get a disguise reference you can pass to other " + "disguise commands!"));
+ "Security note: Any references you create will be available to all players able to use disguise references."); sender.sendMessage(TranslateType.MESSAGE.get(
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseclone IgnoreEquipment" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN ChatColor.DARK_GREEN + "Security note: Any references you create will be available to all players " + "able to use disguise references."));
+ "Optional" + ChatColor.DARK_GREEN + ")"); sender.sendMessage(TranslateType.MESSAGE.get(
ChatColor.DARK_GREEN + "/disguiseclone IgnoreEquipment" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")"));
} }
} }

View File

@ -1,19 +1,5 @@
package me.libraryaddict.disguise.commands; package me.libraryaddict.disguise.commands;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.LibsDisguises; import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
@ -23,17 +9,32 @@ import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException
import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm;
import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers;
import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo;
import me.libraryaddict.disguise.utilities.TranslateType;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCompleter { public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCompleter {
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player)) { if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!"); sender.sendMessage(
TranslateType.MESSAGE.get(ChatColor.RED + "You may not use this command from the " + "console!"));
return true; return true;
} }
if (getPermissions(sender).isEmpty()) { if (getPermissions(sender).isEmpty()) {
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command."));
return true; return true;
} }
@ -61,14 +62,14 @@ public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCom
LibsDisguises.getInstance().getListener().setDisguiseEntity(sender.getName(), disguise); LibsDisguises.getInstance().getListener().setDisguiseEntity(sender.getName(), disguise);
sender.sendMessage(ChatColor.RED + "Right click an entity in the next " + DisguiseConfig.getDisguiseEntityExpire() sender.sendMessage(TranslateType.MESSAGE.get(
+ " seconds to disguise it as a " + disguise.getType().toReadable() + "!"); ChatColor.RED + "Right click an entity in the next " + DisguiseConfig.getDisguiseEntityExpire() + " " + "seconds to disguise it as a " + disguise.getType().toReadable() + "!"));
return true; return true;
} }
@Override @Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<String>(); ArrayList<String> tabs = new ArrayList<>();
if (!(sender instanceof Player)) { if (!(sender instanceof Player)) {
return tabs; return tabs;
@ -82,8 +83,7 @@ public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCom
for (String type : getAllowedDisguises(perms)) { for (String type : getAllowedDisguises(perms)) {
tabs.add(type); tabs.add(type);
} }
} } else {
else {
DisguisePerm disguiseType = DisguiseParser.getDisguisePerm(args[0]); DisguisePerm disguiseType = DisguiseParser.getDisguisePerm(args[0]);
if (disguiseType == null) if (disguiseType == null)
@ -93,9 +93,8 @@ public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCom
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
tabs.add(player.getName()); tabs.add(player.getName());
} }
} } else {
else { ArrayList<String> usedOptions = new ArrayList<>();
ArrayList<String> usedOptions = new ArrayList<String>();
for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) {
for (int i = disguiseType.getType() == DisguiseType.PLAYER ? 2 : 1; i < args.length; i++) { for (int i = disguiseType.getType() == DisguiseType.PLAYER ? 2 : 1; i < args.length; i++) {
@ -124,8 +123,7 @@ public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCom
for (String e : info.getEnums(origArgs[origArgs.length - 1])) { for (String e : info.getEnums(origArgs[origArgs.length - 1])) {
tabs.add(e); tabs.add(e);
} }
} } else {
else {
if (info.getParamClass() == String.class) { if (info.getParamClass() == String.class) {
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
tabs.add(player.getName()); tabs.add(player.getName());
@ -137,7 +135,8 @@ public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCom
if (addMethods) { if (addMethods) {
// If this is a method, add. Else if it can be a param of the previous argument, add. // If this is a method, add. Else if it can be a param of the previous argument, add.
for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(
disguiseType.getWatcherClass())) {
tabs.add(method.getName()); tabs.add(method.getName());
} }
} }
@ -155,22 +154,25 @@ public class DisguiseEntityCommand extends DisguiseBaseCommand implements TabCom
* @param map * @param map
*/ */
@Override @Override
protected void sendCommandUsage(CommandSender sender, HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map) { protected void sendCommandUsage(CommandSender sender,
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map) {
ArrayList<String> allowedDisguises = getAllowedDisguises(map); ArrayList<String> allowedDisguises = getAllowedDisguises(map);
sender.sendMessage(ChatColor.DARK_GREEN + "Choose a disguise then right click a entity to disguise it!"); sender.sendMessage(TranslateType.MESSAGE.get(
sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN ChatColor.DARK_GREEN + "Choose a disguise then right click an entity to disguise it!"));
+ StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)); sender.sendMessage(
String.format(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "You can use the " + "disguises: %s"),
ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)));
if (allowedDisguises.contains("player")) { if (allowedDisguises.contains("player")) {
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseentity player <Name>"); sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "/disguiseentity player <Name>"));
} }
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseentity <DisguiseType> <Baby>"); sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "/disguiseentity <DisguiseType> <Baby>"));
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) { if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) {
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseentity <Dropped_Item/Falling_Block> <Id> <Durability>"); sender.sendMessage(TranslateType.MESSAGE.get(
ChatColor.DARK_GREEN + "/disguiseentity <Dropped_Item/Falling_Block> <Id> " + "<Durability>"));
} }
} }
} }

View File

@ -1,31 +1,29 @@
package me.libraryaddict.disguise.commands; package me.libraryaddict.disguise.commands;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher; import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
import me.libraryaddict.disguise.utilities.DisguiseParser; import me.libraryaddict.disguise.utilities.DisguiseParser;
import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm;
import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers;
import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo;
import me.libraryaddict.disguise.utilities.TranslateType;
import org.apache.commons.lang.StringUtils;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompleter { public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompleter {
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
for (String node : new String[] { for (String node : new String[]{"disguise", "disguiseradius", "disguiseentity", "disguiseplayer"}) {
"disguise", "disguiseradius", "disguiseentity", "disguiseplayer"
}) {
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> permMap = DisguiseParser.getPermissions(sender, HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> permMap = DisguiseParser.getPermissions(sender,
"libsdisguises." + node + "."); "libsdisguises." + node + ".");
@ -33,8 +31,7 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl
if (args.length == 0) { if (args.length == 0) {
sendCommandUsage(sender, null); sendCommandUsage(sender, null);
return true; return true;
} } else {
else {
ParamInfo help = null; ParamInfo help = null;
for (ParamInfo s : ReflectionFlagWatchers.getParamInfos()) { for (ParamInfo s : ReflectionFlagWatchers.getParamInfos()) {
@ -47,20 +44,28 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl
} }
if (help != null) { if (help != null) {
sender.sendMessage(ChatColor.RED + help.getName() + ": " + ChatColor.GREEN if (help.isEnums()) {
+ StringUtils.join(help.getEnums(""), ChatColor.RED + ", " + ChatColor.GREEN)); sender.sendMessage(
ChatColor.RED + help.getName() + ": " + ChatColor.GREEN + StringUtils.join(
help.getEnums(""), ChatColor.RED + ", " + ChatColor.GREEN));
} else {
sender.sendMessage(
ChatColor.RED + help.getName() + ": " + ChatColor.GREEN + help.getDescription());
}
return true; return true;
} }
DisguisePerm type = DisguiseParser.getDisguisePerm(args[0]); DisguisePerm type = DisguiseParser.getDisguisePerm(args[0]);
if (type == null) { if (type == null) {
sender.sendMessage(ChatColor.RED + "Cannot find the disguise " + args[0]); sender.sendMessage(
TranslateType.MESSAGE.get(ChatColor.RED + "Cannot find the disguise ") + args[0]);
return true; return true;
} }
if (!permMap.containsKey(type)) { if (!permMap.containsKey(type)) {
sender.sendMessage(ChatColor.RED + "You do not have permission for that disguise!"); sender.sendMessage(TranslateType.MESSAGE.get(
ChatColor.RED + "You do not have permission for " + "that disguise!"));
return true; return true;
} }
@ -80,8 +85,7 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl
allowed = true; allowed = true;
break; break;
} }
} } else if (!key.contains(method.getName().toLowerCase())) {
else if (!key.contains(method.getName().toLowerCase())) {
allowed = true; allowed = true;
break; break;
} }
@ -105,13 +109,12 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl
if (declaring == LivingWatcher.class) { if (declaring == LivingWatcher.class) {
methodColor = ChatColor.AQUA; methodColor = ChatColor.AQUA;
} } else if (!(FlagWatcher.class.isAssignableFrom(
else if (!(FlagWatcher.class.isAssignableFrom(declaring)) || declaring == FlagWatcher.class) { declaring)) || declaring == FlagWatcher.class) {
methodColor = ChatColor.GRAY; methodColor = ChatColor.GRAY;
} }
String str = method.getName() + ChatColor.DARK_RED + "(" + ChatColor.GREEN + info.getName() String str = method.getName() + ChatColor.DARK_RED + "(" + ChatColor.GREEN + info.getName() + ChatColor.DARK_RED + ")";
+ ChatColor.DARK_RED + ")";
map.put(str, methodColor); map.put(str, methodColor);
methods.add(str); methods.add(str);
@ -131,12 +134,13 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl
methods.add(ChatColor.RED + "No options with permission to use"); methods.add(ChatColor.RED + "No options with permission to use");
} }
sender.sendMessage(ChatColor.DARK_RED + type.toReadable() + " options: " sender.sendMessage(ChatColor.DARK_RED + type.toReadable() + TranslateType.MESSAGE.get(
+ StringUtils.join(methods, ChatColor.DARK_RED + ", ")); " options: ") + StringUtils.join(methods, ChatColor.DARK_RED + ", "));
if (ignored > 0) { if (ignored > 0) {
sender.sendMessage(ChatColor.RED + "Ignored " + ignored sender.sendMessage(String.format(TranslateType.MESSAGE.get(
+ " options you do not have permission to use. Add 'show' to view unusable options."); ChatColor.RED + "Ignored %s" + " options you do not have permission to use. Add " + "'show' to view unusable options."),
ignored));
} }
return true; return true;
@ -144,18 +148,16 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl
} }
} }
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command."));
return true; return true;
} }
@Override @Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<String>(); ArrayList<String> tabs = new ArrayList<>();
String[] args = getArgs(origArgs); String[] args = getArgs(origArgs);
for (String node : new String[] { for (String node : new String[]{"disguise", "disguiseradius", "disguiseentity", "disguiseplayer"}) {
"disguise", "disguiseradius", "disguiseentity", "disguiseplayer"
}) {
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> perms = DisguiseParser.getPermissions(sender, HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> perms = DisguiseParser.getPermissions(sender,
"libsdisguises." + node + "."); "libsdisguises." + node + ".");
@ -170,8 +172,7 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl
for (ParamInfo s : ReflectionFlagWatchers.getParamInfos()) { for (ParamInfo s : ReflectionFlagWatchers.getParamInfos()) {
tabs.add(s.getName().replaceAll(" ", "")); tabs.add(s.getName().replaceAll(" ", ""));
} }
} } else if (DisguiseParser.getDisguisePerm(args[0]) == null) {
else if (DisguiseParser.getDisguisePerm(args[0]) == null) {
tabs.add("Show"); tabs.add("Show");
} }
} }
@ -183,13 +184,14 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl
* Send the player the information * Send the player the information
*/ */
@Override @Override
protected void sendCommandUsage(CommandSender sender, HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map) { protected void sendCommandUsage(CommandSender sender,
sender.sendMessage(ChatColor.RED + "/disguisehelp <DisguiseType> " + ChatColor.GREEN HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map) {
+ "- View the options you can set on a disguise. Add 'show' to reveal the options you don't have permission to use"); sender.sendMessage(TranslateType.MESSAGE.get(
ChatColor.RED + "/disguisehelp <DisguiseType> " + ChatColor.GREEN + "- View the options you can set " + "on a disguise. Add 'show' to reveal the options you don't have permission to use"));
for (ParamInfo s : ReflectionFlagWatchers.getParamInfos()) { for (ParamInfo s : ReflectionFlagWatchers.getParamInfos()) {
sender.sendMessage(ChatColor.RED + "/disguisehelp " + s.getName().replaceAll(" ", "") + ChatColor.GREEN + " - " sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "/disguisehelp " + s.getName().replaceAll(" ",
+ s.getDescription()); "") + ChatColor.GREEN + " - " + s.getDescription()));
} }
} }
} }

View File

@ -1,19 +1,5 @@
package me.libraryaddict.disguise.commands; package me.libraryaddict.disguise.commands;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.DisguiseType;
@ -22,19 +8,34 @@ import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException
import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm;
import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers;
import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo;
import me.libraryaddict.disguise.utilities.TranslateType;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class DisguiseModifyCommand extends DisguiseBaseCommand implements TabCompleter { public class DisguiseModifyCommand extends DisguiseBaseCommand implements TabCompleter {
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Entity)) { if (!(sender instanceof Entity)) {
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!"); sender.sendMessage(
TranslateType.MESSAGE.get(ChatColor.RED + "You may not use this command from the console!"));
return true; return true;
} }
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map = getPermissions(sender); HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map = getPermissions(sender);
if (map.isEmpty()) { if (map.isEmpty()) {
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command."));
return true; return true;
} }
@ -46,18 +47,18 @@ public class DisguiseModifyCommand extends DisguiseBaseCommand implements TabCom
Disguise disguise = DisguiseAPI.getDisguise((Player) sender, (Entity) sender); Disguise disguise = DisguiseAPI.getDisguise((Player) sender, (Entity) sender);
if (disguise == null) { if (disguise == null) {
sender.sendMessage(ChatColor.RED + "You are not disguised!"); sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are not disguised!"));
return true; return true;
} }
if (!map.containsKey(new DisguisePerm(disguise.getType()))) { if (!map.containsKey(new DisguisePerm(disguise.getType()))) {
sender.sendMessage(ChatColor.RED + "No permission to modify your disguise!"); sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "No permission to modify your disguise!"));
return true; return true;
} }
try { try {
DisguiseParser.callMethods(sender, disguise, getPermissions(sender).get(new DisguisePerm(disguise.getType())), DisguiseParser.callMethods(sender, disguise,
new ArrayList<String>(), args); getPermissions(sender).get(new DisguisePerm(disguise.getType())), new ArrayList<String>(), args);
} }
catch (DisguiseParseException ex) { catch (DisguiseParseException ex) {
if (ex.getMessage() != null) { if (ex.getMessage() != null) {
@ -71,14 +72,14 @@ public class DisguiseModifyCommand extends DisguiseBaseCommand implements TabCom
return true; return true;
} }
sender.sendMessage(ChatColor.RED + "Your disguise has been modified!"); sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "Your disguise has been modified!"));
return true; return true;
} }
@Override @Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<String>(); ArrayList<String> tabs = new ArrayList<>();
if (!(sender instanceof Player)) if (!(sender instanceof Player))
return tabs; return tabs;
@ -94,7 +95,7 @@ public class DisguiseModifyCommand extends DisguiseBaseCommand implements TabCom
DisguisePerm disguiseType = new DisguisePerm(disguise.getType()); DisguisePerm disguiseType = new DisguisePerm(disguise.getType());
ArrayList<String> usedOptions = new ArrayList<String>(); ArrayList<String> usedOptions = new ArrayList<>();
for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) {
for (int i = disguiseType.getType() == DisguiseType.PLAYER ? 2 : 1; i < args.length; i++) { for (int i = disguiseType.getType() == DisguiseType.PLAYER ? 2 : 1; i < args.length; i++) {
@ -123,8 +124,7 @@ public class DisguiseModifyCommand extends DisguiseBaseCommand implements TabCom
for (String e : info.getEnums(origArgs[origArgs.length - 1])) { for (String e : info.getEnums(origArgs[origArgs.length - 1])) {
tabs.add(e); tabs.add(e);
} }
} } else {
else {
if (info.getParamClass() == String.class) { if (info.getParamClass() == String.class) {
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
tabs.add(player.getName()); tabs.add(player.getName());
@ -149,11 +149,15 @@ public class DisguiseModifyCommand extends DisguiseBaseCommand implements TabCom
* Send the player the information * Send the player the information
*/ */
@Override @Override
protected void sendCommandUsage(CommandSender sender, HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map) { protected void sendCommandUsage(CommandSender sender,
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map) {
ArrayList<String> allowedDisguises = getAllowedDisguises(map); ArrayList<String> allowedDisguises = getAllowedDisguises(map);
sender.sendMessage(ChatColor.DARK_GREEN + "Modify your own disguise as you wear it!"); sender.sendMessage(
sender.sendMessage(ChatColor.DARK_GREEN + "/disguisemodify setBaby true setSprinting true"); TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "Modify your own disguise as you wear " + "it!"));
sender.sendMessage(ChatColor.DARK_GREEN + "You can modify the disguises: " + ChatColor.GREEN sender.sendMessage(
+ StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)); TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "/disguisemodify setBaby true setSprinting true"));
sender.sendMessage(
String.format(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "You can modify the " + "disguises: %s"),
ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)));
} }
} }

View File

@ -1,10 +1,11 @@
package me.libraryaddict.disguise.commands; package me.libraryaddict.disguise.commands;
import java.lang.reflect.Method; import me.libraryaddict.disguise.DisguiseConfig;
import java.util.ArrayList; import me.libraryaddict.disguise.LibsDisguises;
import java.util.HashMap; import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm;
import java.util.List; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers;
import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo;
import me.libraryaddict.disguise.utilities.TranslateType;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -13,22 +14,22 @@ import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter; import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import me.libraryaddict.disguise.DisguiseConfig; import java.lang.reflect.Method;
import me.libraryaddict.disguise.LibsDisguises; import java.util.ArrayList;
import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; import java.util.HashMap;
import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import java.util.List;
import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo;
public class DisguiseModifyEntityCommand extends DisguiseBaseCommand implements TabCompleter { public class DisguiseModifyEntityCommand extends DisguiseBaseCommand implements TabCompleter {
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (!(sender instanceof Player)) { if (!(sender instanceof Player)) {
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!"); sender.sendMessage(
TranslateType.MESSAGE.get(ChatColor.RED + "You may not use this command from the " + "console!"));
return true; return true;
} }
if (getPermissions(sender).isEmpty()) { if (getPermissions(sender).isEmpty()) {
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command."));
return true; return true;
} }
@ -39,14 +40,15 @@ public class DisguiseModifyEntityCommand extends DisguiseBaseCommand implements
LibsDisguises.getInstance().getListener().setDisguiseModify(sender.getName(), args); LibsDisguises.getInstance().getListener().setDisguiseModify(sender.getName(), args);
sender.sendMessage(ChatColor.RED + "Right click a disguised entity in the next " sender.sendMessage(String.format(TranslateType.MESSAGE.get(
+ DisguiseConfig.getDisguiseEntityExpire() + " seconds to modify their disguise!"); ChatColor.RED + "Right click a disguised entity " + "in the next %s seconds to modify their disguise!"),
DisguiseConfig.getDisguiseEntityExpire()));
return true; return true;
} }
@Override @Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<String>(); ArrayList<String> tabs = new ArrayList<>();
if (!(sender instanceof Player)) { if (!(sender instanceof Player)) {
return tabs; return tabs;
@ -75,8 +77,7 @@ public class DisguiseModifyEntityCommand extends DisguiseBaseCommand implements
for (String e : info.getEnums(origArgs[origArgs.length - 1])) { for (String e : info.getEnums(origArgs[origArgs.length - 1])) {
tabs.add(e); tabs.add(e);
} }
} } else {
else {
if (info.getParamClass() == String.class) { if (info.getParamClass() == String.class) {
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
tabs.add(player.getName()); tabs.add(player.getName());
@ -88,7 +89,8 @@ public class DisguiseModifyEntityCommand extends DisguiseBaseCommand implements
if (addMethods) { if (addMethods) {
// If this is a method, add. Else if it can be a param of the previous argument, add. // If this is a method, add. Else if it can be a param of the previous argument, add.
for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(perm.getType().getWatcherClass())) { for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(
perm.getType().getWatcherClass())) {
tabs.add(method.getName()); tabs.add(method.getName());
} }
} }
@ -104,12 +106,14 @@ public class DisguiseModifyEntityCommand extends DisguiseBaseCommand implements
* @param map * @param map
*/ */
@Override @Override
protected void sendCommandUsage(CommandSender sender, HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map) { protected void sendCommandUsage(CommandSender sender,
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map) {
ArrayList<String> allowedDisguises = getAllowedDisguises(map); ArrayList<String> allowedDisguises = getAllowedDisguises(map);
sender.sendMessage(ChatColor.DARK_GREEN + "Choose the options for a disguise then right click a entity to modify it!"); sender.sendMessage(TranslateType.MESSAGE.get(
sender.sendMessage(ChatColor.DARK_GREEN + "You can modify the disguises: " + ChatColor.GREEN ChatColor.DARK_GREEN + "Choose the options for a disguise then right click a entity to modify it!"));
+ StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)); sender.sendMessage(
String.format(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "You can modify the " + "disguises: %s"),
ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)));
} }
} }

View File

@ -1,18 +1,5 @@
package me.libraryaddict.disguise.commands; package me.libraryaddict.disguise.commands;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.utilities.DisguiseParser; import me.libraryaddict.disguise.utilities.DisguiseParser;
@ -20,6 +7,19 @@ import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException
import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm;
import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers;
import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo;
import me.libraryaddict.disguise.utilities.TranslateType;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements TabCompleter { public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements TabCompleter {
@ -28,7 +28,7 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map = getPermissions(sender); HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map = getPermissions(sender);
if (map.isEmpty()) { if (map.isEmpty()) {
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command."));
return true; return true;
} }
@ -40,7 +40,9 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements
Player player = Bukkit.getPlayer(args[0]); Player player = Bukkit.getPlayer(args[0]);
if (player == null) { if (player == null) {
sender.sendMessage(ChatColor.RED + "Cannot find the player '" + args[0] + "'"); sender.sendMessage(
String.format(TranslateType.MESSAGE.get(ChatColor.RED + "Cannot find the player '%s" + "'"),
args[0]));
return true; return true;
} }
@ -61,18 +63,21 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements
disguise = DisguiseAPI.getDisguise(player); disguise = DisguiseAPI.getDisguise(player);
if (disguise == null) { if (disguise == null) {
sender.sendMessage(ChatColor.RED + "The player '" + player.getName() + "' is not disguised"); sender.sendMessage(
String.format(TranslateType.MESSAGE.get(ChatColor.RED + "The player '%s' is " + "not disguised"),
player.getName()));
return true; return true;
} }
if (!map.containsKey(new DisguisePerm(disguise.getType()))) { if (!map.containsKey(new DisguisePerm(disguise.getType()))) {
sender.sendMessage(ChatColor.RED + "You do not have permission to modify this disguise"); sender.sendMessage(TranslateType.MESSAGE.get(
ChatColor.RED + "You do not have permission to modify this " + "disguise"));
return true; return true;
} }
try { try {
DisguiseParser.callMethods(sender, disguise, map.get(new DisguisePerm(disguise.getType())), new ArrayList<String>(), DisguiseParser.callMethods(sender, disguise, map.get(new DisguisePerm(disguise.getType())),
newArgs); new ArrayList<String>(), newArgs);
} }
catch (DisguiseParseException ex) { catch (DisguiseParseException ex) {
if (ex.getMessage() != null) { if (ex.getMessage() != null) {
@ -86,14 +91,15 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements
return true; return true;
} }
sender.sendMessage(ChatColor.RED + "Modified the disguise of " + player.getName() + "!"); sender.sendMessage(
TranslateType.MESSAGE.get(ChatColor.RED + "Modified the disguise of " + player.getName() + "!"));
return true; return true;
} }
@Override @Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<String>(); ArrayList<String> tabs = new ArrayList<>();
String[] args = getArgs(origArgs); String[] args = getArgs(origArgs);
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> perms = getPermissions(sender); HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> perms = getPermissions(sender);
@ -105,12 +111,13 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
tabs.add(player.getName()); tabs.add(player.getName());
} }
} } else {
else {
Player player = Bukkit.getPlayer(args[0]); Player player = Bukkit.getPlayer(args[0]);
if (player == null) { if (player == null) {
sender.sendMessage(ChatColor.RED + "Cannot find the player '" + args[0] + "'"); sender.sendMessage(
String.format(TranslateType.MESSAGE.get(ChatColor.RED + "Cannot find the player '%s'"),
args[0]));
return tabs; return tabs;
} }
@ -123,13 +130,15 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements
disguise = DisguiseAPI.getDisguise(player); disguise = DisguiseAPI.getDisguise(player);
if (disguise == null) { if (disguise == null) {
sender.sendMessage(ChatColor.RED + "The player '" + player.getName() + "' is not disguised"); sender.sendMessage(String.format(
TranslateType.MESSAGE.get(ChatColor.RED + "The player '%s' " + "is not disguised"),
player.getName()));
return tabs; return tabs;
} }
DisguisePerm disguiseType = new DisguisePerm(disguise.getType()); DisguisePerm disguiseType = new DisguisePerm(disguise.getType());
ArrayList<String> usedOptions = new ArrayList<String>(); ArrayList<String> usedOptions = new ArrayList<>();
for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) {
for (int i = 1; i < args.length; i++) { for (int i = 1; i < args.length; i++) {
@ -158,8 +167,7 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements
for (String e : info.getEnums(origArgs[origArgs.length - 1])) { for (String e : info.getEnums(origArgs[origArgs.length - 1])) {
tabs.add(e); tabs.add(e);
} }
} } else {
else {
if (info.getParamClass() == String.class) { if (info.getParamClass() == String.class) {
for (Player p : Bukkit.getOnlinePlayers()) { for (Player p : Bukkit.getOnlinePlayers()) {
tabs.add(p.getName()); tabs.add(p.getName());
@ -171,7 +179,8 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements
if (addMethods) { if (addMethods) {
// If this is a method, add. Else if it can be a param of the previous argument, add. // If this is a method, add. Else if it can be a param of the previous argument, add.
for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(
disguiseType.getWatcherClass())) {
tabs.add(method.getName()); tabs.add(method.getName());
} }
} }
@ -185,11 +194,13 @@ public class DisguiseModifyPlayerCommand extends DisguiseBaseCommand implements
* Send the player the information * Send the player the information
*/ */
@Override @Override
protected void sendCommandUsage(CommandSender sender, HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map) { protected void sendCommandUsage(CommandSender sender,
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map) {
ArrayList<String> allowedDisguises = getAllowedDisguises(map); ArrayList<String> allowedDisguises = getAllowedDisguises(map);
sender.sendMessage(ChatColor.DARK_GREEN + "Modify the disguise of another player!"); sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "Modify the disguise of another player!"));
sender.sendMessage(ChatColor.DARK_GREEN + "You can modify the disguises: " + ChatColor.GREEN sender.sendMessage(
+ StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)); String.format(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "You can modify the " + "disguises: %s"),
ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)));
} }
} }

View File

@ -9,6 +9,7 @@ import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException
import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm;
import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers;
import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo;
import me.libraryaddict.disguise.utilities.TranslateType;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -42,8 +43,7 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
if (sender instanceof Player) { if (sender instanceof Player) {
center = ((Player) sender).getLocation(); center = ((Player) sender).getLocation();
} } else {
else {
center = ((BlockCommandSender) sender).getBlock().getLocation().add(0.5, 0, 0.5); center = ((BlockCommandSender) sender).getBlock().getLocation().add(0.5, 0, 0.5);
} }
@ -53,14 +53,15 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.getName().equals("CONSOLE")) { if (sender.getName().equals("CONSOLE")) {
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!"); sender.sendMessage(
TranslateType.MESSAGE.get(ChatColor.RED + "You may not use this command from the " + "console!"));
return true; return true;
} }
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map = getPermissions(sender); HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map = getPermissions(sender);
if (map.isEmpty()) { if (map.isEmpty()) {
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command."));
return true; return true;
} }
@ -78,8 +79,10 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
Collections.sort(classes); Collections.sort(classes);
sender.sendMessage(ChatColor.DARK_GREEN + "EntityTypes usable are: " + ChatColor.GREEN sender.sendMessage(
+ StringUtils.join(classes, ChatColor.DARK_GREEN + ", " + ChatColor.GREEN) + ChatColor.DARK_GREEN + "."); String.format(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "EntityTypes usable " + "are: %s"),
ChatColor.GREEN + StringUtils.join(classes,
ChatColor.DARK_GREEN + ", " + ChatColor.GREEN) + ChatColor.DARK_GREEN + "."));
return true; return true;
} }
@ -104,31 +107,36 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
} }
if (type == null) { if (type == null) {
sender.sendMessage(ChatColor.RED + "Unrecognised EntityType " + args[0]); sender.sendMessage(
String.format(TranslateType.MESSAGE.get(ChatColor.RED + "Unrecognised " + "EntityType %s"),
args[0]));
return true; return true;
} }
} }
} }
if (args.length == starting + 1) { if (args.length == starting + 1) {
sender.sendMessage(ChatColor.RED + "You need to supply the disguise options as well as the radius" sender.sendMessage(TranslateType.MESSAGE.get(
+ (starting != 0 ? " and EntityType" : "")); ChatColor.RED + "You need to supply the disguise options as well as the radius" + (starting != 0 ?
" and EntityType" : "")));
return true; return true;
} } else if (args.length < 2) {
else if (args.length < 2) { sender.sendMessage(TranslateType.MESSAGE.get(
sender.sendMessage(ChatColor.RED + "You need to supply a radius as well as the disguise options"); ChatColor.RED + "You need to supply a radius as well as " + "the disguise options"));
return true; return true;
} }
if (!isNumeric(args[starting])) { if (!isNumeric(args[starting])) {
sender.sendMessage(ChatColor.RED + args[starting] + " is not a number"); sender.sendMessage(String.format(TranslateType.MESSAGE.get(ChatColor.RED + "%s is not a " + "number"),
args[starting]));
return true; return true;
} }
int radius = Integer.parseInt(args[starting]); int radius = Integer.parseInt(args[starting]);
if (radius > maxRadius) { if (radius > maxRadius) {
sender.sendMessage(ChatColor.RED + "Limited radius to " + maxRadius + "! Don't want to make too much lag right?"); sender.sendMessage(String.format(TranslateType.MESSAGE.get(
ChatColor.RED + "Limited radius to %s! Don't want to make too much lag right?"), maxRadius));
radius = maxRadius; radius = maxRadius;
} }
@ -184,14 +192,16 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
} }
if (noPermission > 0) { if (noPermission > 0) {
sender.sendMessage(ChatColor.RED + "No permission to modify " + noPermission + " disguises!"); sender.sendMessage(String.format(
TranslateType.MESSAGE.get(ChatColor.RED + "No permission to modify " + "%s disguises!"),
noPermission));
} }
if (modifiedDisguises > 0) { if (modifiedDisguises > 0) {
sender.sendMessage(ChatColor.RED + "Successfully modified the disguises of " + modifiedDisguises + " entities!"); sender.sendMessage(String.format(TranslateType.MESSAGE.get(
} ChatColor.RED + "Successfully modified the disguises of %s" + " entities!"), modifiedDisguises));
else { } else {
sender.sendMessage(ChatColor.RED + "Couldn't find any disguised entities!"); sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "Couldn't find any disguised entities!"));
} }
return true; return true;
@ -199,7 +209,7 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
@Override @Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<String>(); ArrayList<String> tabs = new ArrayList<>();
String[] args = getArgs(origArgs); String[] args = getArgs(origArgs);
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> perms = getPermissions(sender); HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> perms = getPermissions(sender);
@ -231,11 +241,12 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
int radius = Integer.parseInt(args[starting]); int radius = Integer.parseInt(args[starting]);
if (radius > maxRadius) { if (radius > maxRadius) {
sender.sendMessage(ChatColor.RED + "Limited radius to " + maxRadius + "! Don't want to make too much lag right?"); sender.sendMessage(String.format(TranslateType.MESSAGE.get(
ChatColor.RED + "Limited radius to %s! Don't want to make too much lag right?"), maxRadius));
radius = maxRadius; radius = maxRadius;
} }
ArrayList<String> usedOptions = new ArrayList<String>(); ArrayList<String> usedOptions = new ArrayList<>();
for (Entity entity : getNearbyEntities(sender, radius)) { for (Entity entity : getNearbyEntities(sender, radius)) {
Disguise disguise = DisguiseAPI.getDisguise(entity); Disguise disguise = DisguiseAPI.getDisguise(entity);
@ -246,9 +257,7 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
DisguiseType disguiseType = disguise.getType(); DisguiseType disguiseType = disguise.getType();
for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) {
for (int i = 0; i < args.length; i++) { for (String arg : args) {
String arg = args[i];
if (!method.getName().equalsIgnoreCase(arg)) if (!method.getName().equalsIgnoreCase(arg))
continue; continue;
@ -256,7 +265,7 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
} }
} }
if (passesCheck(sender, perms.get(disguiseType), usedOptions)) { if (passesCheck(sender, perms.get(new DisguisePerm(disguiseType)), usedOptions)) {
boolean addMethods = true; boolean addMethods = true;
if (args.length > 1 + starting) { if (args.length > 1 + starting) {
@ -272,8 +281,7 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
for (String e : info.getEnums(origArgs[origArgs.length - 1])) { for (String e : info.getEnums(origArgs[origArgs.length - 1])) {
tabs.add(e); tabs.add(e);
} }
} } else {
else {
if (info.getParamClass() == String.class) { if (info.getParamClass() == String.class) {
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
tabs.add(player.getName()); tabs.add(player.getName());
@ -285,7 +293,8 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
if (addMethods) { if (addMethods) {
// If this is a method, add. Else if it can be a param of the previous argument, add. // If this is a method, add. Else if it can be a param of the previous argument, add.
for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(
disguiseType.getWatcherClass())) {
tabs.add(method.getName()); tabs.add(method.getName());
} }
} }
@ -299,31 +308,35 @@ public class DisguiseModifyRadiusCommand extends DisguiseBaseCommand implements
* Send the player the information * Send the player the information
*/ */
@Override @Override
protected void sendCommandUsage(CommandSender sender, HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map) { protected void sendCommandUsage(CommandSender sender,
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map) {
ArrayList<String> allowedDisguises = getAllowedDisguises(map); ArrayList<String> allowedDisguises = getAllowedDisguises(map);
sender.sendMessage(ChatColor.DARK_GREEN + "Modify the disguises in a radius! Caps at " + maxRadius + " blocks!"); sender.sendMessage(String.format(TranslateType.MESSAGE.get(
sender.sendMessage(ChatColor.DARK_GREEN + "You can modify the disguises: " + ChatColor.GREEN ChatColor.DARK_GREEN + "Modify the disguises in a radius! Caps at %s blocks!"), maxRadius));
+ StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)); sender.sendMessage(
String.format(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "You can modify the disguises: %s"),
ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)));
String optional = ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")"; String optional = ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")";
if (allowedDisguises.contains("player")) { if (allowedDisguises.contains("player")) {
sender.sendMessage((ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + optional + "> <Radius> player <Name>") sender.sendMessage(TranslateType.MESSAGE.get(
.replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")); (ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + optional + "> <Radius> player <Name>").replace(
"<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")));
} }
sender.sendMessage((ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + optional + "> <Radius> <DisguiseType> <Baby" sender.sendMessage(TranslateType.MESSAGE.get(
+ optional + ">").replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")); (ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + optional + "> <Radius> <DisguiseType> <Baby" + optional + ">").replace(
"<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")));
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) { if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) {
sender.sendMessage((ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + optional sender.sendMessage(TranslateType.MESSAGE.get(
+ "> <Radius> <Dropped_Item/Falling_Block> <Id> <Durability" + optional + ">") (ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + optional + "> <Radius> <Dropped_Item/Falling_Block> <Id> <Durability" + optional + ">").replace(
.replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")); "<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")));
} }
sender.sendMessage( sender.sendMessage(TranslateType.MESSAGE.get(
ChatColor.DARK_GREEN + "See the EntityType's usable by " + ChatColor.GREEN + "/disguiseradius EntityTypes"); ChatColor.DARK_GREEN + "See the EntityType's usable by " + ChatColor.GREEN + "/disguiseradius " + "EntityTypes"));
} }
} }

View File

@ -1,18 +1,5 @@
package me.libraryaddict.disguise.commands; package me.libraryaddict.disguise.commands;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
@ -23,6 +10,20 @@ import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException
import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm;
import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers;
import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo;
import me.libraryaddict.disguise.utilities.TranslateType;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCompleter { public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCompleter {
@ -31,7 +32,7 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map = getPermissions(sender); HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map = getPermissions(sender);
if (map.isEmpty()) { if (map.isEmpty()) {
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command."));
return true; return true;
} }
@ -41,14 +42,16 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom
} }
if (args.length == 1) { if (args.length == 1) {
sender.sendMessage(ChatColor.RED + "You need to supply a disguise as well as the player"); sender.sendMessage(TranslateType.MESSAGE.get(
ChatColor.RED + "You need to supply a disguise as well as " + "the player"));
return true; return true;
} }
Player player = Bukkit.getPlayer(args[0]); Player player = Bukkit.getPlayer(args[0]);
if (player == null) { if (player == null) {
sender.sendMessage(ChatColor.RED + "Cannot find the player '" + args[0] + "'"); sender.sendMessage(
String.format(TranslateType.MESSAGE.get(ChatColor.RED + "Cannot find the player '%s'"), args[0]));
return true; return true;
} }
@ -78,8 +81,8 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom
} }
if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled()) { if (disguise.isMiscDisguise() && !DisguiseConfig.isMiscDisguisesForLivingEnabled()) {
sender.sendMessage( sender.sendMessage(TranslateType.MESSAGE.get(
ChatColor.RED + "Can't disguise a living entity as a misc disguise. This has been disabled in the config!"); ChatColor.RED + "Can't disguise a living entity as a misc disguise. This has been disabled in the" + " config!"));
return true; return true;
} }
@ -97,12 +100,13 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom
DisguiseAPI.disguiseToAll(player, disguise); DisguiseAPI.disguiseToAll(player, disguise);
if (disguise.isDisguiseInUse()) { if (disguise.isDisguiseInUse()) {
sender.sendMessage(ChatColor.RED + "Successfully disguised " + player.getName() + " as a "
+ disguise.getType().toReadable() + "!");
}
else {
sender.sendMessage( sender.sendMessage(
ChatColor.RED + "Failed to disguise " + player.getName() + " as a " + disguise.getType().toReadable() + "!"); String.format(TranslateType.MESSAGE.get(ChatColor.RED + "Successfully disguised %s as a %s!"),
player.getName(), disguise.getType().toReadable()));
} else {
sender.sendMessage(
String.format(TranslateType.MESSAGE.get(ChatColor.RED + "Failed to disguise %s as a %s!"),
player.getName(), disguise.getType().toReadable()));
} }
return true; return true;
@ -110,7 +114,7 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom
@Override @Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<String>(); ArrayList<String> tabs = new ArrayList<>();
String[] args = getArgs(origArgs); String[] args = getArgs(origArgs);
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> perms = getPermissions(sender); HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> perms = getPermissions(sender);
@ -119,13 +123,9 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
tabs.add(player.getName()); tabs.add(player.getName());
} }
} } else if (args.length == 1) {
else if (args.length == 1) { tabs.addAll(getAllowedDisguises(perms));
for (String type : getAllowedDisguises(perms)) { } else {
tabs.add(type);
}
}
else {
DisguisePerm disguiseType = DisguiseParser.getDisguisePerm(args[1]); DisguisePerm disguiseType = DisguiseParser.getDisguisePerm(args[1]);
if (disguiseType == null) if (disguiseType == null)
@ -135,9 +135,8 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
tabs.add(player.getName()); tabs.add(player.getName());
} }
} } else {
else { ArrayList<String> usedOptions = new ArrayList<>();
ArrayList<String> usedOptions = new ArrayList<String>();
for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) {
for (int i = disguiseType.getType() == DisguiseType.PLAYER ? 3 : 2; i < args.length; i++) { for (int i = disguiseType.getType() == DisguiseType.PLAYER ? 3 : 2; i < args.length; i++) {
@ -163,11 +162,8 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom
addMethods = false; addMethods = false;
if (info.isEnums()) { if (info.isEnums()) {
for (String e : info.getEnums(origArgs[origArgs.length - 1])) { tabs.addAll(Arrays.asList(info.getEnums(origArgs[origArgs.length - 1])));
tabs.add(e); } else {
}
}
else {
if (info.getParamClass() == String.class) { if (info.getParamClass() == String.class) {
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
tabs.add(player.getName()); tabs.add(player.getName());
@ -179,7 +175,8 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom
if (addMethods) { if (addMethods) {
// If this is a method, add. Else if it can be a param of the previous argument, add. // If this is a method, add. Else if it can be a param of the previous argument, add.
for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(
disguiseType.getWatcherClass())) {
tabs.add(method.getName()); tabs.add(method.getName());
} }
} }
@ -194,22 +191,26 @@ public class DisguisePlayerCommand extends DisguiseBaseCommand implements TabCom
* Send the player the information * Send the player the information
*/ */
@Override @Override
protected void sendCommandUsage(CommandSender sender, HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map) { protected void sendCommandUsage(CommandSender sender,
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map) {
ArrayList<String> allowedDisguises = getAllowedDisguises(map); ArrayList<String> allowedDisguises = getAllowedDisguises(map);
sender.sendMessage(ChatColor.DARK_GREEN + "Disguise another player!"); sender.sendMessage(ChatColor.DARK_GREEN + "Disguise another player!");
sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN sender.sendMessage(
+ StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)); String.format(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "You can use the " + "disguises: %s"),
ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)));
if (allowedDisguises.contains("player")) { if (allowedDisguises.contains("player")) {
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseplayer <PlayerName> player <Name>"); sender.sendMessage(TranslateType.MESSAGE.get(
ChatColor.DARK_GREEN + "/disguiseplayer <PlayerName> player " + "<Name>"));
} }
sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseplayer <PlayerName> <DisguiseType> <Baby>"); sender.sendMessage(TranslateType.MESSAGE.get(
ChatColor.DARK_GREEN + "/disguiseplayer <PlayerName> " + "<DisguiseType> <Baby>"));
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) { if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) {
sender.sendMessage( sender.sendMessage(TranslateType.MESSAGE.get(
ChatColor.DARK_GREEN + "/disguiseplayer <PlayerName> <Dropped_Item/Falling_Block> <Id> <Durability>"); ChatColor.DARK_GREEN + "/disguiseplayer <PlayerName> <Dropped_Item/Falling_Block> <Id> " + "<Durability>"));
} }
} }
} }

View File

@ -11,6 +11,7 @@ import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException
import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm;
import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers;
import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo; import me.libraryaddict.disguise.utilities.ReflectionFlagWatchers.ParamInfo;
import me.libraryaddict.disguise.utilities.TranslateType;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -25,10 +26,7 @@ import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.ArrayList; import java.util.*;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCompleter { public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCompleter {
private int maxRadius = 30; private int maxRadius = 30;
@ -46,14 +44,15 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.getName().equals("CONSOLE")) { if (sender.getName().equals("CONSOLE")) {
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!"); sender.sendMessage(
TranslateType.MESSAGE.get(ChatColor.RED + "You may not use this command from the console!"));
return true; return true;
} }
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map = getPermissions(sender); HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map = getPermissions(sender);
if (map.isEmpty()) { if (map.isEmpty()) {
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command."));
return true; return true;
} }
@ -72,8 +71,9 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
Collections.sort(classes); Collections.sort(classes);
sender.sendMessage( sender.sendMessage(
ChatColor.DARK_GREEN + "EntityTypes usable are: " + ChatColor.GREEN + StringUtils.join(classes, String.format(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "EntityTypes usable are: %s"),
ChatColor.DARK_GREEN + ", " + ChatColor.GREEN) + ChatColor.DARK_GREEN + "."); ChatColor.GREEN + StringUtils.join(classes,
ChatColor.DARK_GREEN + ", " + ChatColor.GREEN)));
return true; return true;
} }
@ -94,35 +94,40 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
try { try {
type = EntityType.valueOf(args[0].toUpperCase()); type = EntityType.valueOf(args[0].toUpperCase());
} }
catch (Exception ex) { catch (Exception ignored) {
} }
if (type == null) { if (type == null) {
sender.sendMessage(ChatColor.RED + "Unrecognised EntityType " + args[0]); sender.sendMessage(
String.format(TranslateType.MESSAGE.get(ChatColor.RED + "Unrecognised " + "EntityType %s"),
args[0]));
return true; return true;
} }
} }
} }
if (args.length == starting + 1) { if (args.length == starting + 1) {
sender.sendMessage(ChatColor.RED + "You need to supply a disguise as well as the radius" + (starting != 0 ? sender.sendMessage(TranslateType.MESSAGE.get(
" and EntityType" : "")); ChatColor.RED + "You need to supply a disguise as well as the radius" + (starting != 0 ?
" and EntityType" : "")));
return true; return true;
} else if (args.length < 2) { } else if (args.length < 2) {
sender.sendMessage(ChatColor.RED + "You need to supply a radius as well as the disguise"); sender.sendMessage(TranslateType.MESSAGE.get(
ChatColor.RED + "You need to supply a radius as well as " + "the disguise"));
return true; return true;
} }
if (!isNumeric(args[starting])) { if (!isNumeric(args[starting])) {
sender.sendMessage(ChatColor.RED + args[starting] + " is not a number"); sender.sendMessage(
String.format(TranslateType.MESSAGE.get(ChatColor.RED + "%s is not a number"), args[starting]));
return true; return true;
} }
int radius = Integer.parseInt(args[starting]); int radius = Integer.parseInt(args[starting]);
if (radius > maxRadius) { if (radius > maxRadius) {
sender.sendMessage( sender.sendMessage(String.format(TranslateType.MESSAGE.get(
ChatColor.RED + "Limited radius to " + maxRadius + "! Don't want to make too much lag right?"); ChatColor.RED + "Limited radius to %s! Don't want to make too much lag right?"), maxRadius));
radius = maxRadius; radius = maxRadius;
} }
@ -193,14 +198,17 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
} }
if (disguisedEntitys > 0) { if (disguisedEntitys > 0) {
sender.sendMessage(ChatColor.RED + "Successfully disguised " + disguisedEntitys + " entities!"); sender.sendMessage(
String.format(TranslateType.MESSAGE.get(ChatColor.RED + "Successfully disguised %s" + " entities!"),
disguisedEntitys));
} else { } else {
sender.sendMessage(ChatColor.RED + "Couldn't find any entities to disguise!"); sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "Couldn't find any entities to disguise!"));
} }
if (miscDisguises > 0) { if (miscDisguises > 0) {
sender.sendMessage( sender.sendMessage(String.format(TranslateType.MESSAGE.get(
ChatColor.RED + "Failed to disguise " + miscDisguises + " entities because the option to disguise a living entity as a non-living has been disabled in the config"); ChatColor.RED + "Failed to disguise %s entities because the option to disguise a living entity as" + " a non-living has been disabled in the config"),
miscDisguises));
} }
return true; return true;
@ -208,7 +216,7 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
@Override @Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<String>(); ArrayList<String> tabs = new ArrayList<>();
String[] args = getArgs(origArgs); String[] args = getArgs(origArgs);
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> perms = getPermissions(sender); HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> perms = getPermissions(sender);
@ -238,9 +246,7 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
} }
if (args.length == starting) { if (args.length == starting) {
for (String type : getAllowedDisguises(perms)) { tabs.addAll(getAllowedDisguises(perms));
tabs.add(type);
}
} else { } else {
DisguisePerm disguiseType = DisguiseParser.getDisguisePerm(args[starting]); DisguisePerm disguiseType = DisguiseParser.getDisguisePerm(args[starting]);
@ -253,7 +259,7 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
tabs.add(player.getName()); tabs.add(player.getName());
} }
} else { } else {
ArrayList<String> usedOptions = new ArrayList<String>(); ArrayList<String> usedOptions = new ArrayList<>();
for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) {
for (int i = disguiseType.getType() == DisguiseType.PLAYER ? starting + 2 : for (int i = disguiseType.getType() == DisguiseType.PLAYER ? starting + 2 :
@ -280,9 +286,7 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
addMethods = false; addMethods = false;
if (info.isEnums()) { if (info.isEnums()) {
for (String e : info.getEnums(origArgs[origArgs.length - 1])) { tabs.addAll(Arrays.asList(info.getEnums(origArgs[origArgs.length - 1])));
tabs.add(e);
}
} else { } else {
if (info.getParamClass() == String.class) { if (info.getParamClass() == String.class) {
for (Player player : Bukkit.getOnlinePlayers()) { for (Player player : Bukkit.getOnlinePlayers()) {
@ -315,30 +319,31 @@ public class DisguiseRadiusCommand extends DisguiseBaseCommand implements TabCom
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map) { HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map) {
ArrayList<String> allowedDisguises = getAllowedDisguises(map); ArrayList<String> allowedDisguises = getAllowedDisguises(map);
sender.sendMessage(String.format(TranslateType.MESSAGE.get(
ChatColor.DARK_GREEN + "Disguise all entities in a radius! Caps at %s blocks!"), maxRadius));
sender.sendMessage( sender.sendMessage(
ChatColor.DARK_GREEN + "Disguise all entities in a radius! Caps at " + maxRadius + " blocks!"); String.format(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "You can use the " + "disguises: %s"),
sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN + StringUtils.join( ChatColor.GREEN + StringUtils.join(allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)));
allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN));
String optional = ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")"; String optional = ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")";
if (allowedDisguises.contains("player")) { if (allowedDisguises.contains("player")) {
sender.sendMessage( sender.sendMessage(TranslateType.MESSAGE.get(
(ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + optional + "> <Radius> player <Name>").replace( (ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + optional + "> <Radius> player <Name>").replace(
"<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")); "<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")));
} }
sender.sendMessage( sender.sendMessage(TranslateType.MESSAGE.get(
(ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + optional + "> <Radius> <DisguiseType> <Baby" + optional + ">").replace( (ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + optional + "> <Radius> <DisguiseType> <Baby" + optional + ">").replace(
"<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")); "<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")));
if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) { if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) {
sender.sendMessage( sender.sendMessage(TranslateType.MESSAGE.get(
(ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + optional + "> <Radius> <Dropped_Item/Falling_Block> <Id> <Durability" + optional + ">").replace( (ChatColor.DARK_GREEN + "/disguiseradius <EntityType" + optional + "> <Radius> <Dropped_Item/Falling_Block> <Id> <Durability" + optional + ">").replace(
"<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")); "<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")));
} }
sender.sendMessage( sender.sendMessage(TranslateType.MESSAGE.get(
ChatColor.DARK_GREEN + "See the EntityType's usable by " + ChatColor.GREEN + "/disguiseradius EntityTypes"); ChatColor.DARK_GREEN + "See the EntityType's usable by " + ChatColor.GREEN + "/disguiseradius " + "EntityTypes"));
} }
} }

View File

@ -1,5 +1,6 @@
package me.libraryaddict.disguise.commands; package me.libraryaddict.disguise.commands;
import me.libraryaddict.disguise.utilities.TranslateType;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
@ -16,7 +17,8 @@ public class DisguiseViewSelfCommand implements CommandExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
if (sender.getName().equals("CONSOLE")) { if (sender.getName().equals("CONSOLE")) {
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!"); sender.sendMessage(
TranslateType.MESSAGE.get(ChatColor.RED + "You may not use this command from the " + "console!"));
return true; return true;
} }
@ -24,14 +26,12 @@ public class DisguiseViewSelfCommand implements CommandExecutor {
if (DisguiseAPI.isViewSelfToggled(player)) { if (DisguiseAPI.isViewSelfToggled(player)) {
DisguiseAPI.setViewDisguiseToggled(player, false); DisguiseAPI.setViewDisguiseToggled(player, false);
sender.sendMessage(ChatColor.GREEN + "Toggled viewing own disguise off!"); sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.GREEN + "Toggled viewing own disguise off!"));
} } else {
else {
DisguiseAPI.setViewDisguiseToggled(player, true); DisguiseAPI.setViewDisguiseToggled(player, true);
sender.sendMessage(ChatColor.GREEN + "Toggled viewing own disguise on!"); sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.GREEN + "Toggled viewing own disguise on!"));
} }
return true; return true;
} }
} }

View File

@ -1,10 +1,8 @@
package me.libraryaddict.disguise.commands; package me.libraryaddict.disguise.commands;
import java.util.ArrayList; import me.libraryaddict.disguise.LibsDisguises;
import java.util.Iterator;
import java.util.List;
import me.libraryaddict.disguise.utilities.LibsPremium; import me.libraryaddict.disguise.utilities.LibsPremium;
import me.libraryaddict.disguise.utilities.TranslateType;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -12,7 +10,9 @@ import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter; import org.bukkit.command.TabCompleter;
import me.libraryaddict.disguise.LibsDisguises; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class LibsDisguisesCommand implements CommandExecutor, TabCompleter { public class LibsDisguisesCommand implements CommandExecutor, TabCompleter {
protected ArrayList<String> filterTabs(ArrayList<String> list, String[] origArgs) { protected ArrayList<String> filterTabs(ArrayList<String> list, String[] origArgs) {
@ -52,29 +52,28 @@ public class LibsDisguisesCommand implements CommandExecutor, TabCompleter {
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (args.length == 0) { if (args.length == 0) {
sender.sendMessage(ChatColor.DARK_GREEN + "This server is running " + "Lib's Disguises v" sender.sendMessage(
+ Bukkit.getPluginManager().getPlugin("LibsDisguises").getDescription().getVersion() ChatColor.DARK_GREEN + "This server is running " + "Lib's Disguises v" + Bukkit.getPluginManager().getPlugin(
+ " by libraryaddict, formerly maintained by Byteflux and NavidK0.\n" + "Use " + ChatColor.GREEN "LibsDisguises").getDescription().getVersion() + " by libraryaddict, formerly maintained " + "by Byteflux and NavidK0." + (
+ "/libsdisguises reload" + ChatColor.DARK_GREEN sender.hasPermission("libsdisguises.reload") ?
+ " to reload the config. All disguises will be blown by doing this."); "\nUse " + ChatColor.GREEN + "/libsdisguises " + "reload" + ChatColor.DARK_GREEN + " to reload the config. All disguises will be blown by doing this" + "." :
""));
if (LibsPremium.isPremium()) { if (LibsPremium.isPremium()) {
sender.sendMessage(ChatColor.DARK_GREEN + "This server supports the plugin developer!"); sender.sendMessage(ChatColor.DARK_GREEN + "This server supports the plugin developer!");
} }
} } else if (args.length > 0) {
else if (args.length > 0) {
if (sender.hasPermission("libsdisguises.reload")) { if (sender.hasPermission("libsdisguises.reload")) {
if (args[0].equalsIgnoreCase("reload")) { if (args[0].equalsIgnoreCase("reload")) {
LibsDisguises.getInstance().reload(); LibsDisguises.getInstance().reload();
sender.sendMessage(ChatColor.GREEN + "[LibsDisguises] Reloaded config."); sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.GREEN + "[LibsDisguises] Reloaded config."));
return true; return true;
} else {
sender.sendMessage(TranslateType.MESSAGE.get(
ChatColor.RED + "[LibsDisguises] Did you mean 'reload'?"));
} }
else { } else {
sender.sendMessage(ChatColor.RED + "[LibsDisguises] That command doesn't exist!"); sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command."));
}
}
else {
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
} }
} }
return true; return true;
@ -82,7 +81,7 @@ public class LibsDisguisesCommand implements CommandExecutor, TabCompleter {
@Override @Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<String>(); ArrayList<String> tabs = new ArrayList<>();
String[] args = getArgs(origArgs); String[] args = getArgs(origArgs);
if (args.length == 0) if (args.length == 0)

View File

@ -1,5 +1,6 @@
package me.libraryaddict.disguise.commands; package me.libraryaddict.disguise.commands;
import me.libraryaddict.disguise.utilities.TranslateType;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
@ -9,32 +10,24 @@ import org.bukkit.entity.Player;
import me.libraryaddict.disguise.DisguiseAPI; import me.libraryaddict.disguise.DisguiseAPI;
public class UndisguiseCommand implements CommandExecutor public class UndisguiseCommand implements CommandExecutor {
{
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
{ if (sender.getName().equals("CONSOLE")) {
if (sender.getName().equals("CONSOLE")) sender.sendMessage(
{ TranslateType.MESSAGE.get(ChatColor.RED + "You may not use this command from the " + "console!"));
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
return true; return true;
} }
if (sender.hasPermission("libsdisguises.undisguise")) if (sender.hasPermission("libsdisguises.undisguise")) {
{ if (DisguiseAPI.isDisguised((Entity) sender)) {
if (DisguiseAPI.isDisguised((Entity) sender))
{
DisguiseAPI.undisguiseToAll((Player) sender); DisguiseAPI.undisguiseToAll((Player) sender);
sender.sendMessage(ChatColor.RED + "You are no longer disguised"); sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are no longer disguised"));
} else {
sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are not disguised!"));
} }
else } else {
{ sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command."));
sender.sendMessage(ChatColor.RED + "You are not disguised!");
}
}
else
{
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
} }
return true; return true;
} }

View File

@ -1,31 +1,27 @@
package me.libraryaddict.disguise.commands; package me.libraryaddict.disguise.commands;
import me.libraryaddict.disguise.LibsDisguises;
import me.libraryaddict.disguise.utilities.TranslateType;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import me.libraryaddict.disguise.LibsDisguises; public class UndisguiseEntityCommand implements CommandExecutor {
public class UndisguiseEntityCommand implements CommandExecutor
{
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
{ if (sender.getName().equals("CONSOLE")) {
if (sender.getName().equals("CONSOLE")) sender.sendMessage(
{ TranslateType.MESSAGE.get(ChatColor.RED + "You may not use this command from the console!"));
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!");
return true; return true;
} }
if (sender.hasPermission("libsdisguises.undisguiseentity")) if (sender.hasPermission("libsdisguises.undisguiseentity")) {
{
LibsDisguises.getInstance().getListener().setDisguiseEntity(sender.getName(), null); LibsDisguises.getInstance().getListener().setDisguiseEntity(sender.getName(), null);
sender.sendMessage(ChatColor.RED + "Right click a disguised entity to undisguise them!"); sender.sendMessage(TranslateType.MESSAGE.get(
} ChatColor.RED + "Right click a disguised entity to " + "undisguise them!"));
else } else {
{ sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command."));
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
} }
return true; return true;
} }

View File

@ -1,9 +1,7 @@
package me.libraryaddict.disguise.commands; package me.libraryaddict.disguise.commands;
import java.util.ArrayList; import me.libraryaddict.disguise.DisguiseAPI;
import java.util.Iterator; import me.libraryaddict.disguise.utilities.TranslateType;
import java.util.List;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -12,7 +10,9 @@ import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter; import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import me.libraryaddict.disguise.DisguiseAPI; import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class UndisguisePlayerCommand implements CommandExecutor, TabCompleter { public class UndisguisePlayerCommand implements CommandExecutor, TabCompleter {
protected ArrayList<String> filterTabs(ArrayList<String> list, String[] origArgs) { protected ArrayList<String> filterTabs(ArrayList<String> list, String[] origArgs) {
@ -35,7 +35,7 @@ public class UndisguisePlayerCommand implements CommandExecutor, TabCompleter {
} }
protected String[] getArgs(String[] args) { protected String[] getArgs(String[] args) {
ArrayList<String> newArgs = new ArrayList<String>(); ArrayList<String> newArgs = new ArrayList<>();
for (int i = 0; i < args.length - 1; i++) { for (int i = 0; i < args.length - 1; i++) {
String s = args[i]; String s = args[i];
@ -57,29 +57,26 @@ public class UndisguisePlayerCommand implements CommandExecutor, TabCompleter {
if (p != null) { if (p != null) {
if (DisguiseAPI.isDisguised(p)) { if (DisguiseAPI.isDisguised(p)) {
DisguiseAPI.undisguiseToAll(p); DisguiseAPI.undisguiseToAll(p);
sender.sendMessage(ChatColor.RED + "The player is no longer disguised"); sender.sendMessage(
TranslateType.MESSAGE.get(ChatColor.RED + "The player is no longer disguised"));
} else {
sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "The player is not disguised!"));
} }
else { } else {
sender.sendMessage(ChatColor.RED + "The player is not disguised!"); sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "Player not found"));
} }
} else {
sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "/undisguiseplayer <Name>"));
} }
else { } else {
sender.sendMessage(ChatColor.RED + "Player not found"); sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command."));
}
}
else {
sender.sendMessage(ChatColor.RED + "/undisguiseplayer <Name>");
}
}
else {
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command.");
} }
return true; return true;
} }
@Override @Override
public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) { public List<String> onTabComplete(CommandSender sender, Command cmd, String label, String[] origArgs) {
ArrayList<String> tabs = new ArrayList<String>(); ArrayList<String> tabs = new ArrayList<>();
String[] args = getArgs(origArgs); String[] args = getArgs(origArgs);
if (args.length != 0) if (args.length != 0)

View File

@ -1,5 +1,7 @@
package me.libraryaddict.disguise.commands; package me.libraryaddict.disguise.commands;
import me.libraryaddict.disguise.DisguiseAPI;
import me.libraryaddict.disguise.utilities.TranslateType;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.command.Command; import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
@ -7,8 +9,6 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Entity; import org.bukkit.entity.Entity;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import me.libraryaddict.disguise.DisguiseAPI;
public class UndisguiseRadiusCommand implements CommandExecutor { public class UndisguiseRadiusCommand implements CommandExecutor {
private int maxRadius = 30; private int maxRadius = 30;
@ -29,24 +29,28 @@ public class UndisguiseRadiusCommand implements CommandExecutor {
@Override @Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (sender.getName().equals("CONSOLE")) { if (sender.getName().equals("CONSOLE")) {
sender.sendMessage(ChatColor.RED + "You may not use this command from the console!"); sender.sendMessage(
TranslateType.MESSAGE.get(ChatColor.RED + "You may not use this command from the console!"));
return true; return true;
} }
if (sender.hasPermission("libsdisguises.undisguiseradius")) { if (sender.hasPermission("libsdisguises.undisguiseradius")) {
int radius = maxRadius; int radius = maxRadius;
if (args.length > 0) { if (args.length > 0) {
if (!isNumeric(args[0])) { if (!isNumeric(args[0])) {
sender.sendMessage( sender.sendMessage(String.format(TranslateType.MESSAGE.get(
ChatColor.RED + "Error! " + ChatColor.GREEN + args[0] + ChatColor.RED + " is not a number!"); ChatColor.RED + "Error! " + ChatColor.GREEN + "%s" + ChatColor.RED + " is not a " + "number!"),
args[0]));
return true; return true;
} }
radius = Integer.parseInt(args[0]); radius = Integer.parseInt(args[0]);
if (radius > maxRadius) { if (radius > maxRadius) {
sender.sendMessage( sender.sendMessage(String.format(TranslateType.MESSAGE.get(
ChatColor.RED + "Limited radius to " + maxRadius + "! Don't want to make too much lag right?"); ChatColor.RED + "Limited radius to %s" + "! Don't want to make too much lag right?"),
maxRadius));
radius = maxRadius; radius = maxRadius;
} }
} }
int disguisedEntitys = 0; int disguisedEntitys = 0;
for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius)) { for (Entity entity : ((Player) sender).getNearbyEntities(radius, radius, radius)) {
if (entity == sender) { if (entity == sender) {
@ -57,10 +61,11 @@ public class UndisguiseRadiusCommand implements CommandExecutor {
disguisedEntitys++; disguisedEntitys++;
} }
} }
sender.sendMessage(ChatColor.RED + "Successfully undisguised " + disguisedEntitys + " entities!"); sender.sendMessage(
} String.format(TranslateType.MESSAGE.get(ChatColor.RED + "Successfully undisguised %s entities!"),
else { disguisedEntitys));
sender.sendMessage(ChatColor.RED + "You are forbidden to use this command."); } else {
sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this command."));
} }
return true; return true;
} }

View File

@ -36,8 +36,8 @@ public class DisguiseParser {
super(); super();
} }
public DisguiseParseException(String string) { public DisguiseParseException(LibsMessages message, String... params) {
super(string); super(message.get(params));
} }
} }
@ -467,11 +467,12 @@ public class DisguiseParser {
public static Disguise parseDisguise(CommandSender sender, String permNode, String[] args, public static Disguise parseDisguise(CommandSender sender, String permNode, String[] args,
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> permissionMap) throws DisguiseParseException, IllegalAccessException, InvocationTargetException { HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> permissionMap) throws DisguiseParseException, IllegalAccessException, InvocationTargetException {
if (permissionMap.isEmpty()) { if (permissionMap.isEmpty()) {
throw new DisguiseParseException(ChatColor.RED + "You are forbidden to use this command."); throw new DisguiseParseException(
TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use this " + "command."));
} }
if (args.length == 0) { if (args.length == 0) {
throw new DisguiseParseException("No arguments defined"); throw new DisguiseParseException(TranslateType.MESSAGE.get("No arguments defined"));
} }
// How many args to skip due to the disugise being constructed // How many args to skip due to the disugise being constructed
@ -487,15 +488,17 @@ public class DisguiseParser {
disguise = DisguiseUtilities.getClonedDisguise(args[0].toLowerCase()); disguise = DisguiseUtilities.getClonedDisguise(args[0].toLowerCase());
if (disguise == null) { if (disguise == null) {
throw new DisguiseParseException( throw new DisguiseParseException(String.format(
ChatColor.RED + "Cannot find a disguise under the reference " + args[0]); TranslateType.MESSAGE.get(ChatColor.RED + "Cannot find a disguise under the reference %s"),
args[0]));
} }
} else { } else {
throw new DisguiseParseException( throw new DisguiseParseException(TranslateType.MESSAGE.get(
ChatColor.RED + "You do not have perimssion to use disguise references!"); ChatColor.RED + "You do not have perimssion to use disguise references!"));
} }
optionPermissions = (permissionMap.containsKey(disguise.getType()) ? permissionMap.get(disguise.getType()) : optionPermissions = (permissionMap.containsKey(new DisguisePerm(disguise.getType())) ?
permissionMap.get(new DisguisePerm(disguise.getType())) :
new HashMap<ArrayList<String>, Boolean>()); new HashMap<ArrayList<String>, Boolean>());
} else { } else {
DisguisePerm disguisePerm = getDisguisePerm(args[0]); DisguisePerm disguisePerm = getDisguisePerm(args[0]);
@ -506,21 +509,24 @@ public class DisguiseParser {
} }
if (disguisePerm == null) { if (disguisePerm == null) {
throw new DisguiseParseException( throw new DisguiseParseException(String.format(TranslateType.MESSAGE.get(
ChatColor.RED + "Error! The disguise " + ChatColor.GREEN + args[0] + ChatColor.RED + " doesn't exist!"); ChatColor.RED + "Error! The disguise " + ChatColor.GREEN + "%s" + ChatColor.RED + " " + "doesn't exist!"),
args[0]));
} }
if (disguisePerm.isUnknown()) { if (disguisePerm.isUnknown()) {
throw new DisguiseParseException( throw new DisguiseParseException(TranslateType.MESSAGE.get(
ChatColor.RED + "Error! You cannot disguise as " + ChatColor.GREEN + "Unknown!"); ChatColor.RED + "Error! You cannot disguise as " + ChatColor.GREEN + "Unknown!"));
} }
if (disguisePerm.getEntityType() == null) { if (disguisePerm.getEntityType() == null) {
throw new DisguiseParseException(ChatColor.RED + "Error! This disguise couldn't be loaded!"); throw new DisguiseParseException(
TranslateType.MESSAGE.get(ChatColor.RED + "Error! This disguise " + "couldn't be loaded!"));
} }
if (!permissionMap.containsKey(disguisePerm)) { if (!permissionMap.containsKey(disguisePerm)) {
throw new DisguiseParseException(ChatColor.RED + "You are forbidden to use this disguise."); throw new DisguiseParseException(
TranslateType.MESSAGE.get(ChatColor.RED + "You are forbidden to use " + "this disguise."));
} }
optionPermissions = permissionMap.get(disguisePerm); optionPermissions = permissionMap.get(disguisePerm);
@ -532,12 +538,13 @@ public class DisguiseParser {
// If he is doing a player disguise // If he is doing a player disguise
if (args.length == 1) { if (args.length == 1) {
// He needs to give the player name // He needs to give the player name
throw new DisguiseParseException(ChatColor.RED + "Error! You need to give a player name!"); throw new DisguiseParseException(TranslateType.MESSAGE.get(
ChatColor.RED + "Error! You need " + "to give a player name!"));
} else { } else {
if (!disguiseOptions.isEmpty() && (!disguiseOptions.containsKey( if (!disguiseOptions.isEmpty() && (!disguiseOptions.containsKey(
args[1].toLowerCase()) || !disguiseOptions.get(args[1].toLowerCase()))) { args[1].toLowerCase()) || !disguiseOptions.get(args[1].toLowerCase()))) {
throw new DisguiseParseException( throw new DisguiseParseException(TranslateType.MESSAGE.get(
ChatColor.RED + "Error! You don't have permission to use that name!"); ChatColor.RED + "Error! You don't have permission to use that name!"));
} }
args[1] = args[1].replace("\\_", " "); args[1] = args[1].replace("\\_", " ");
@ -604,8 +611,9 @@ public class DisguiseParser {
case WITHER_SKULL: case WITHER_SKULL:
break; break;
default: default:
throw new DisguiseParseException( throw new DisguiseParseException(String.format(TranslateType.MESSAGE.get(
ChatColor.RED + "Error! " + disguisePerm.toReadable() + " doesn't know what to do with " + args[1] + "!"); ChatColor.RED + "Error! %s doesn't know" + " " + "what to do with %s!"),
disguisePerm.toReadable(), args[1]));
} }
toSkip++; toSkip++;
// If they also defined a data value // If they also defined a data value
@ -615,8 +623,10 @@ public class DisguiseParser {
} }
if (secondArg != null) { if (secondArg != null) {
if (disguisePerm.getType() != DisguiseType.FALLING_BLOCK && disguisePerm.getType() != DisguiseType.DROPPED_ITEM) { if (disguisePerm.getType() != DisguiseType.FALLING_BLOCK && disguisePerm.getType() != DisguiseType.DROPPED_ITEM) {
throw new DisguiseParseException( throw new DisguiseParseException(String.format(TranslateType.MESSAGE.get(
ChatColor.RED + "Error! Only the disguises " + DisguiseType.FALLING_BLOCK.toReadable() + " and " + DisguiseType.DROPPED_ITEM.toReadable() + " uses a second number!"); ChatColor.RED + "Error! Only the disguises " + DisguiseType.FALLING_BLOCK.toReadable() + " and " + DisguiseType.DROPPED_ITEM.toReadable() + " uses a second number!"),
DisguiseType.FALLING_BLOCK.toReadable(),
DisguiseType.DROPPED_ITEM.toReadable()));
} }
miscData = Integer.parseInt(secondArg); miscData = Integer.parseInt(secondArg);
} }
@ -635,8 +645,9 @@ public class DisguiseParser {
} }
if (!disguiseOptions.containsKey(toCheck) || !disguiseOptions.get(toCheck)) { if (!disguiseOptions.containsKey(toCheck) || !disguiseOptions.get(toCheck)) {
throw new DisguiseParseException( throw new DisguiseParseException(String.format(TranslateType.MESSAGE.get(
ChatColor.RED + "Error! You do not have permission to use the parameter " + toCheck + " on the " + disguisePerm.toReadable() + " disguise!"); ChatColor.RED + "Error! You do not have permission to use the parameter %s on the" + " %s disguise!"),
toCheck, disguisePerm.toReadable()));
} }
} }

View File

@ -0,0 +1,22 @@
package me.libraryaddict.disguise.utilities;
/**
* Created by libraryaddict on 15/06/2017.
*/
public enum LibsMessages {
// Format being CLASS_STRING. So no perm = DISG_COMMAND_NO_PERM. Or DISG_PARSE_NO_PERM_OPTION
TEST("This is a test string");
private String string;
LibsMessages(String string) {
this.string = string;
}
public String get(String... strings) {
if (strings.length == 0)
return TranslateType.MESSAGE.get(string);
return String.format(TranslateType.MESSAGE.get(string), (Object[]) strings);
}
}

View File

@ -149,7 +149,7 @@ public class ReflectionFlagWatchers {
new ParamInfo(Ocelot.Type.class, "Ocelot Type", "View all the ocelot types you can use for ocelots"); new ParamInfo(Ocelot.Type.class, "Ocelot Type", "View all the ocelot types you can use for ocelots");
new ParamInfo(Villager.Profession.class, "Villager Profession", new ParamInfo(Villager.Profession.class, "Villager Profession",
"View all the professions you can set on a villager"); "View all the professions you can set on a villager");
new ParamInfo(BlockFace.class, Arrays.copyOf(BlockFace.values(), 5), "Direction", new ParamInfo(BlockFace.class, Arrays.copyOf(BlockFace.values(), 4), "Direction",
"View the five directions usable on player setSleeping disguise"); "View the five directions usable on player setSleeping disguise");
new ParamInfo(Rabbit.Type.class, "Rabbit Type", "View the kinds of rabbits you can turn into"); new ParamInfo(Rabbit.Type.class, "Rabbit Type", "View the kinds of rabbits you can turn into");
new ParamInfo(TreeSpecies.class, "Tree Species", "View the different types of tree species"); new ParamInfo(TreeSpecies.class, "Tree Species", "View the different types of tree species");
@ -178,7 +178,7 @@ public class ReflectionFlagWatchers {
new ParamInfo(ItemStack.class, "Item (id:damage)", "An ItemStack compromised of ID:Durability", materials); new ParamInfo(ItemStack.class, "Item (id:damage)", "An ItemStack compromised of ID:Durability", materials);
new ParamInfo(ItemStack[].class, "Four ItemStacks (id:damage,id:damage..)", "Four ItemStacks seperated by an ,", new ParamInfo(ItemStack[].class, "Four ItemStacks (id:damage,id:damage..)", "Four ItemStacks separated by an ,",
materials) { materials) {
@Override @Override
public String[] getEnums(String tabComplete) { public String[] getEnums(String tabComplete) {
@ -203,14 +203,14 @@ public class ReflectionFlagWatchers {
potionEnums.toArray(new String[0])); potionEnums.toArray(new String[0]));
new ParamInfo(String.class, "Text", "A line of text"); new ParamInfo(String.class, "Text", "A line of text");
new ParamInfo(boolean.class, "True/False", "True or False", new String[]{"true", "false"}); new ParamInfo(boolean.class, "True/False", "True or False", new String[]{"true", "false"});
new ParamInfo(int.class, "Number", "A whole number, no decimcals"); new ParamInfo(int.class, "Number", "A whole number, no decimals");
new ParamInfo(double.class, "Number", "A number which can have decimals"); new ParamInfo(double.class, "Number", "A number which can have decimals");
new ParamInfo(float.class, "Number", "A number which can have decimals"); new ParamInfo(float.class, "Number", "A number which can have decimals");
new ParamInfo(Horse.Style.class, "Horse Style", "Horse style which is the patterns on the horse"); new ParamInfo(Horse.Style.class, "Horse Style", "Horse style which is the patterns on the horse");
new ParamInfo(int[].class, "number,number,number...", "Numbers seperated by an ,"); new ParamInfo(int[].class, "number,number,number..", "Numbers separated by an ,");
new ParamInfo(BlockPosition.class, "Block Position (num,num,num)", "Three numbers seperated by an ,"); new ParamInfo(BlockPosition.class, "Block Position (num,num,num)", "Three numbers separated by a ,");
new ParamInfo(GameProfile.class, "GameProfile", new ParamInfo(GameProfile.class, "GameProfile",
"Get the gameprofile here https://sessionserver.mojang.com/session/minecraft/profile/PLAYER_UUID_GOES_HERE?unsigned=false"); "Get the gameprofile here https://sessionserver.mojang.com/session/minecraft/profile/PLAYER_UUID_GOES_HERE?unsigned=false");
@ -223,7 +223,7 @@ public class ReflectionFlagWatchers {
} }
public static Method[] getDisguiseWatcherMethods(Class<? extends FlagWatcher> watcherClass) { public static Method[] getDisguiseWatcherMethods(Class<? extends FlagWatcher> watcherClass) {
ArrayList<Method> methods = new ArrayList<Method>(Arrays.asList(watcherClass.getMethods())); ArrayList<Method> methods = new ArrayList<>(Arrays.asList(watcherClass.getMethods()));
Iterator<Method> itel = methods.iterator(); Iterator<Method> itel = methods.iterator();

View File

@ -1,6 +1,7 @@
package me.libraryaddict.disguise.utilities; package me.libraryaddict.disguise.utilities;
import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import org.bukkit.inventory.ItemStack;
import java.lang.reflect.Method; import java.lang.reflect.Method;
@ -15,8 +16,11 @@ public class TranslateFiller {
if (!info.isEnums()) if (!info.isEnums())
continue; continue;
if (info.getParamClass() == ItemStack.class || info.getParamClass() == ItemStack[].class)
continue;
for (String e : info.getEnums("")) { for (String e : info.getEnums("")) {
TranslateType.METHOD_PARAM.get(e, "Name for the param for " + info.getName()); TranslateType.METHOD_PARAM.get(e, "Used as a disguise option for " + info.getName());
} }
} }
@ -24,10 +28,23 @@ public class TranslateFiller {
type.toReadable(); type.toReadable();
for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(type.getWatcherClass())) { for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(type.getWatcherClass())) {
Class para = method.getParameterTypes()[0];
String className = method.getDeclaringClass().getSimpleName().replace("Watcher", "");
if (className.equals("Flag") || className.equals("Disguise"))
className = "Entity";
else if (className.equals("Living"))
className = "Living Entity";
else if (className.equals("AbstractHorse"))
className = "Horse";
else if (className.equals("DroppedItem"))
className = "Item";
else if (className.equals("IllagerWizard"))
className = "Illager";
TranslateType.METHOD.get(method.getName(), TranslateType.METHOD.get(method.getName(),
"Found in " + method.getDeclaringClass().getSimpleName().replace("Watcher", "Found in the disguise options for " + className + " and uses " + (para.isArray() ?
"") + " and accepts as a parameter " + TranslateType.METHOD_PARAM.get( "multiple" + " " : "a ") + para.getSimpleName().replace("[]", "s"));
method.getParameterTypes()[0].getSimpleName()));
} }
} }
} }

View File

@ -1,11 +1,15 @@
package me.libraryaddict.disguise.utilities; package me.libraryaddict.disguise.utilities;
import me.libraryaddict.disguise.DisguiseConfig;
import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringEscapeUtils;
import org.bukkit.configuration.InvalidConfigurationException;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
import java.io.File; import java.io.File;
import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@ -13,46 +17,80 @@ import java.util.Objects;
* Created by libraryaddict on 10/06/2017. * Created by libraryaddict on 10/06/2017.
*/ */
public enum TranslateType { public enum TranslateType {
DISGUISE("disguise_names"), MESSAGE("messages"), METHOD_PARAM("option_names"), METHOD("disguise_options"); DISGUISE("disguises"), MESSAGE("messages"), METHOD_PARAM("disguise_options"), METHOD("disguise_option_parameters");
private File file; private File file;
private YamlConfiguration config; private HashMap<String, String> translated = new HashMap<>();
TranslateType(String fileName) { TranslateType(String fileName) {
file = new File("translate", fileName + ".yml"); file = new File("plugins/LibsDisguises/Translations", fileName + ".yml");
reload(); reload();
} }
public void reload() { public static void reloadTranslations() {
for (TranslateType type : values()) {
type.reload();
}
TranslateFiller.fillConfigs();
}
private void reload() {
if (!LibsPremium.isPremium() || !DisguiseConfig.isUseTranslations())
return;
translated.clear();
if (!file.exists()) if (!file.exists())
file.getParentFile().mkdirs(); return;
System.out.println("[LibsDisguises] Loading translations: " + name());
YamlConfiguration config = new YamlConfiguration();
config.options().pathSeparator(Character.toChars(0)[0]);
try { try {
file.createNewFile(); config.load(file);
for (String key : config.getKeys(false)) {
String value = config.getString(key);
if (value == null)
System.err.println("Translation for " + name() + " has a null value for the key '" + key + "'");
else
translated.put(key, value);
} }
catch (IOException e) { }
catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
config = YamlConfiguration.loadConfiguration(file);
}
private YamlConfiguration getConfig() {
return config;
} }
private File getFile() { private File getFile() {
return file; return file;
} }
public void save(String message, String comment) { private void save(String message, String comment) {
message = StringEscapeUtils.escapeJson(message); if (translated.containsKey(message))
if (getConfig().contains(message))
return; return;
translated.put(message, message);
message = StringEscapeUtils.escapeJava(message);
try { try {
PrintWriter writer = new PrintWriter(getFile()); boolean exists = file.exists();
writer.write((comment != null ? "# " + comment + "\n" : "") + message + ": " + message + "\n");
if (!exists) {
file.getParentFile().mkdirs();
file.createNewFile();
}
FileWriter writer = new FileWriter(getFile(), true);
if (!exists)
writer.write("# To use translations in Lib's Disguises, you must have the purchased plugin\n");
writer.write("\n" + (comment != null ? "# " + comment + "\n" :
"") + "\"" + message + "\": \"" + message + "\"\n");
writer.close(); writer.close();
} }
@ -62,10 +100,10 @@ public enum TranslateType {
} }
public String reverseGet(String translated) { public String reverseGet(String translated) {
translated = StringEscapeUtils.unescapeJson(translated).toLowerCase(); translated = translated.toLowerCase();
for (Map.Entry<String, Object> entry : getConfig().getValues(false).entrySet()) { for (Map.Entry<String, String> entry : this.translated.entrySet()) {
if (!Objects.equals(entry.getValue().toString().toLowerCase(), translated)) if (!Objects.equals(entry.getValue().toLowerCase(), translated))
continue; continue;
return entry.getKey(); return entry.getKey();
@ -82,10 +120,15 @@ public enum TranslateType {
} }
public String get(String message, String comment) { public String get(String message, String comment) {
String msg = getConfig().getString(StringEscapeUtils.escapeJson(message)); if (!LibsPremium.isPremium() || !DisguiseConfig.isUseTranslations())
return message;
System.out.println("1");
String msg = translated.get(message);
if (msg != null) if (msg != null)
return msg; return msg;
System.out.println("2");
save(message, comment); save(message, comment);

View File

@ -13,7 +13,6 @@ public class SerializerGameProfile implements JsonSerializer<WrappedGameProfile>
@Override @Override
public JsonElement serialize(WrappedGameProfile src, Type typeOfSrc, JsonSerializationContext context) { public JsonElement serialize(WrappedGameProfile src, Type typeOfSrc, JsonSerializationContext context) {
System.out.println(src.getHandle().toString());
return context.serialize(src.getHandle(), GameProfile.class); return context.serialize(src.getHandle(), GameProfile.class);
} }