Current progress
This commit is contained in:
		| @@ -8,6 +8,7 @@ import java.util.Arrays; | ||||
| import java.util.Iterator; | ||||
|  | ||||
| import me.libraryaddict.disguise.disguisetypes.watchers.*; | ||||
| import me.libraryaddict.disguise.utilities.*; | ||||
| import org.bukkit.Bukkit; | ||||
| import org.bukkit.command.CommandExecutor; | ||||
| import org.bukkit.command.PluginCommand; | ||||
| @@ -45,13 +46,6 @@ import me.libraryaddict.disguise.commands.UndisguiseRadiusCommand; | ||||
| import me.libraryaddict.disguise.disguisetypes.DisguiseType; | ||||
| import me.libraryaddict.disguise.disguisetypes.FlagWatcher; | ||||
| import me.libraryaddict.disguise.disguisetypes.MetaIndex; | ||||
| import me.libraryaddict.disguise.utilities.DisguiseSound; | ||||
| import me.libraryaddict.disguise.utilities.DisguiseUtilities; | ||||
| import me.libraryaddict.disguise.utilities.DisguiseValues; | ||||
| import me.libraryaddict.disguise.utilities.FakeBoundingBox; | ||||
| import me.libraryaddict.disguise.utilities.Metrics; | ||||
| import me.libraryaddict.disguise.utilities.PacketsManager; | ||||
| import me.libraryaddict.disguise.utilities.ReflectionManager; | ||||
|  | ||||
| public class LibsDisguises extends JavaPlugin { | ||||
|     private static LibsDisguises instance; | ||||
| @@ -87,6 +81,8 @@ public class LibsDisguises extends JavaPlugin { | ||||
|  | ||||
|         PacketsManager.addPacketListeners(); | ||||
|  | ||||
|         TranslateFiller.fillConfigs(); | ||||
|  | ||||
|         listener = new DisguiseListener(this); | ||||
|  | ||||
|         Bukkit.getPluginManager().registerEvents(listener, this); | ||||
|   | ||||
| @@ -36,7 +36,8 @@ public abstract class DisguiseBaseCommand implements CommandExecutor { | ||||
|         return new ArrayList<String>(new HashSet<String>(list)); | ||||
|     } | ||||
|  | ||||
|     protected ArrayList<String> getAllowedDisguises(HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> hashMap) { | ||||
|     protected ArrayList<String> getAllowedDisguises( | ||||
|             HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> hashMap) { | ||||
|         ArrayList<String> allowedDisguises = new ArrayList<>(); | ||||
|  | ||||
|         for (DisguisePerm type : hashMap.keySet()) { | ||||
| @@ -52,7 +53,7 @@ public abstract class DisguiseBaseCommand implements CommandExecutor { | ||||
|     } | ||||
|  | ||||
|     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++) { | ||||
|             String s = args[i]; | ||||
| @@ -69,29 +70,21 @@ public abstract class DisguiseBaseCommand implements CommandExecutor { | ||||
|     public final String getPermNode() { | ||||
|         if (this instanceof DisguiseCommand) { | ||||
|             return "disguise"; | ||||
|         } | ||||
|         else if (this instanceof DisguiseEntityCommand) { | ||||
|         } else if (this instanceof DisguiseEntityCommand) { | ||||
|             return "disguiseentity"; | ||||
|         } | ||||
|         else if (this instanceof DisguisePlayerCommand) { | ||||
|         } else if (this instanceof DisguisePlayerCommand) { | ||||
|             return "disguiseplayer"; | ||||
|         } | ||||
|         else if (this instanceof DisguiseRadiusCommand) { | ||||
|         } else if (this instanceof DisguiseRadiusCommand) { | ||||
|             return "disguiseradius"; | ||||
|         } | ||||
|         else if (this instanceof DisguiseModifyCommand) { | ||||
|         } else if (this instanceof DisguiseModifyCommand) { | ||||
|             return "disguisemodify"; | ||||
|         } | ||||
|         else if (this instanceof DisguiseModifyEntityCommand) { | ||||
|         } else if (this instanceof DisguiseModifyEntityCommand) { | ||||
|             return "disguisemodifyentity"; | ||||
|         } | ||||
|         else if (this instanceof DisguiseModifyPlayerCommand) { | ||||
|         } else if (this instanceof DisguiseModifyPlayerCommand) { | ||||
|             return "disguisemodifyplayer"; | ||||
|         } | ||||
|         else if (this instanceof DisguiseModifyRadiusCommand) { | ||||
|         } else if (this instanceof DisguiseModifyRadiusCommand) { | ||||
|             return "disguisemodifyradius"; | ||||
|         } | ||||
|         else { | ||||
|         } else { | ||||
|             throw new UnsupportedOperationException("Unknown disguise command, perm node not found"); | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -12,6 +12,7 @@ import me.libraryaddict.disguise.utilities.DisguiseParser.DisguiseParseException | ||||
| import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; | ||||
| 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.bukkit.Bukkit; | ||||
| import org.bukkit.ChatColor; | ||||
| @@ -30,7 +31,8 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter | ||||
|     @Override | ||||
|     public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { | ||||
|         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; | ||||
|         } | ||||
|  | ||||
| @@ -69,9 +71,11 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter | ||||
|         DisguiseAPI.disguiseToAll((Player) sender, disguise); | ||||
|  | ||||
|         if (disguise.isDisguiseInUse()) { | ||||
|             sender.sendMessage(ChatColor.RED + "Now disguised as a " + disguise.getType().toReadable()); | ||||
|             sender.sendMessage(String.format(TranslateType.MESSAGE.get(ChatColor.RED + "Now disguised as a %s"), | ||||
|                     disguise.getType().toReadable())); | ||||
|         } else { | ||||
|             sender.sendMessage(ChatColor.RED + "Failed to disguise as a " + disguise.getType().toReadable()); | ||||
|             sender.sendMessage(String.format(TranslateType.MESSAGE.get(ChatColor.RED + "Failed to disguise as a %s"), | ||||
|                     disguise.getType().toReadable())); | ||||
|         } | ||||
|  | ||||
|         return true; | ||||
| @@ -79,15 +83,13 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter | ||||
|  | ||||
|     @Override | ||||
|     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); | ||||
|  | ||||
|         HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> perms = getPermissions(sender); | ||||
|  | ||||
|         if (args.length == 0) { | ||||
|             for (String type : getAllowedDisguises(perms)) { | ||||
|                 tabs.add(type); | ||||
|             } | ||||
|             tabs.addAll(getAllowedDisguises(perms)); | ||||
|         } else { | ||||
|             DisguisePerm disguiseType = DisguiseParser.getDisguisePerm(args[0]); | ||||
|  | ||||
| @@ -100,7 +102,7 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter | ||||
|                     tabs.add(player.getName()); | ||||
|                 } | ||||
|             } else { | ||||
|                 ArrayList<String> usedOptions = new ArrayList<String>(); | ||||
|                 ArrayList<String> usedOptions = new ArrayList<>(); | ||||
|  | ||||
|                 for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(disguiseType.getWatcherClass())) { | ||||
|                     for (int i = disguiseType.getType() == DisguiseType.PLAYER ? 2 : 1; i < args.length; i++) { | ||||
| @@ -160,18 +162,21 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter | ||||
|     protected void sendCommandUsage(CommandSender sender, | ||||
|             HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> map) { | ||||
|         ArrayList<String> allowedDisguises = getAllowedDisguises(map); | ||||
|         sender.sendMessage(ChatColor.DARK_GREEN + "Choose a disguise to become the disguise!"); | ||||
|         sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN + StringUtils.join( | ||||
|                 allowedDisguises, ChatColor.RED + ", " + ChatColor.GREEN)); | ||||
|         sender.sendMessage( | ||||
|                 TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "Choose a disguise to become the disguise!")); | ||||
|         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")) { | ||||
|             sender.sendMessage(ChatColor.DARK_GREEN + "/disguise player <Name>"); | ||||
|             sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "/disguise player " + "<Name>")); | ||||
|         } | ||||
|  | ||||
|         sender.sendMessage(ChatColor.DARK_GREEN + "/disguise <DisguiseType> <Baby>"); | ||||
|         sender.sendMessage(TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "/disguise <DisguiseType> " + "<Baby>")); | ||||
|  | ||||
|         if (allowedDisguises.contains("dropped_item") || allowedDisguises.contains("falling_block")) { | ||||
|             sender.sendMessage(ChatColor.DARK_GREEN + "/disguiseplayer <Dropped_Item/Falling_Block> <Id> <Durability>"); | ||||
|             sender.sendMessage(TranslateType.MESSAGE.get( | ||||
|                     ChatColor.DARK_GREEN + "/disguise " + "<Dropped_Item/Falling_Block> <Id> <Durability>")); | ||||
|         } | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -1,9 +1,9 @@ | ||||
| package me.libraryaddict.disguise.disguisetypes; | ||||
|  | ||||
| import me.libraryaddict.disguise.utilities.TranslateType; | ||||
| import org.apache.commons.lang.StringUtils; | ||||
| import org.bukkit.entity.Entity; | ||||
| import org.bukkit.entity.EntityType; | ||||
| import org.omg.CORBA.UNKNOWN; | ||||
|  | ||||
| public enum DisguiseType { | ||||
|     AREA_EFFECT_CLOUD(3, 0), | ||||
| @@ -322,6 +322,6 @@ public enum DisguiseType { | ||||
|             split[i] = split[i].substring(0, 1) + split[i].substring(1).toLowerCase(); | ||||
|         } | ||||
|  | ||||
|         return StringUtils.join(split, " "); | ||||
|         return TranslateType.DISGUISE.get(StringUtils.join(split, " "), "Name for the " + name() + " disguise"); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -51,8 +51,8 @@ public class ReflectionFlagWatchers { | ||||
|         } | ||||
|  | ||||
|         private ParamInfo(String name, String description) { | ||||
|             this.name = name; | ||||
|             this.description = description; | ||||
|             this.name = TranslateType.METHOD_PARAM.get(name, null); | ||||
|             this.description = TranslateType.METHOD_PARAM.get(description, null); | ||||
|         } | ||||
|  | ||||
|         public ParamInfo(String className, String name, String description) throws ClassNotFoundException { | ||||
| @@ -169,6 +169,7 @@ public class ReflectionFlagWatchers { | ||||
|  | ||||
|             potionEnums.add(toReadable(effectType.getName())); | ||||
|         } | ||||
|  | ||||
|         String[] materials = new String[Material.values().length]; | ||||
|  | ||||
|         for (int i = 0; i < Material.values().length; i++) { | ||||
|   | ||||
							
								
								
									
										34
									
								
								src/me/libraryaddict/disguise/utilities/TranslateFiller.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								src/me/libraryaddict/disguise/utilities/TranslateFiller.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,34 @@ | ||||
| package me.libraryaddict.disguise.utilities; | ||||
|  | ||||
| import me.libraryaddict.disguise.disguisetypes.DisguiseType; | ||||
|  | ||||
| import java.lang.reflect.Method; | ||||
|  | ||||
| /** | ||||
|  * Created by libraryaddict on 10/06/2017. | ||||
|  */ | ||||
| public class TranslateFiller { | ||||
|     public static void fillConfigs() { | ||||
|         // Fill the configs | ||||
|  | ||||
|         for (ReflectionFlagWatchers.ParamInfo info : ReflectionFlagWatchers.getParamInfos()) { | ||||
|             if (!info.isEnums()) | ||||
|                 continue; | ||||
|  | ||||
|             for (String e : info.getEnums("")) { | ||||
|                 TranslateType.METHOD_PARAM.get(e, "Name for the param for " + info.getName()); | ||||
|             } | ||||
|         } | ||||
|  | ||||
|         for (DisguiseType type : DisguiseType.values()) { | ||||
|             type.toReadable(); | ||||
|  | ||||
|             for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(type.getWatcherClass())) { | ||||
|                 TranslateType.METHOD.get(method.getName(), | ||||
|                         "Found in " + method.getDeclaringClass().getSimpleName().replace("Watcher", | ||||
|                                 "") + " and accepts as a parameter " + TranslateType.METHOD_PARAM.get( | ||||
|                                 method.getParameterTypes()[0].getSimpleName())); | ||||
|             } | ||||
|         } | ||||
|     } | ||||
| } | ||||
							
								
								
									
										94
									
								
								src/me/libraryaddict/disguise/utilities/TranslateType.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								src/me/libraryaddict/disguise/utilities/TranslateType.java
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,94 @@ | ||||
| package me.libraryaddict.disguise.utilities; | ||||
|  | ||||
| import org.apache.commons.lang3.StringEscapeUtils; | ||||
| import org.bukkit.configuration.file.YamlConfiguration; | ||||
|  | ||||
| import java.io.File; | ||||
| import java.io.IOException; | ||||
| import java.io.PrintWriter; | ||||
| import java.util.Map; | ||||
| import java.util.Objects; | ||||
|  | ||||
| /** | ||||
|  * Created by libraryaddict on 10/06/2017. | ||||
|  */ | ||||
| public enum TranslateType { | ||||
|     DISGUISE("disguise_names"), MESSAGE("messages"), METHOD_PARAM("option_names"), METHOD("disguise_options"); | ||||
|     private File file; | ||||
|     private YamlConfiguration config; | ||||
|  | ||||
|     TranslateType(String fileName) { | ||||
|         file = new File("translate", fileName + ".yml"); | ||||
|         reload(); | ||||
|     } | ||||
|  | ||||
|     public void reload() { | ||||
|         if (!file.exists()) | ||||
|             file.getParentFile().mkdirs(); | ||||
|  | ||||
|         try { | ||||
|             file.createNewFile(); | ||||
|         } | ||||
|         catch (IOException e) { | ||||
|             e.printStackTrace(); | ||||
|         } | ||||
|  | ||||
|         config = YamlConfiguration.loadConfiguration(file); | ||||
|     } | ||||
|  | ||||
|     private YamlConfiguration getConfig() { | ||||
|         return config; | ||||
|     } | ||||
|  | ||||
|     private File getFile() { | ||||
|         return file; | ||||
|     } | ||||
|  | ||||
|     public void save(String message, String comment) { | ||||
|         message = StringEscapeUtils.escapeJson(message); | ||||
|  | ||||
|         if (getConfig().contains(message)) | ||||
|             return; | ||||
|  | ||||
|         try { | ||||
|             PrintWriter writer = new PrintWriter(getFile()); | ||||
|             writer.write((comment != null ? "# " + comment + "\n" : "") + message + ": " + message + "\n"); | ||||
|  | ||||
|             writer.close(); | ||||
|         } | ||||
|         catch (Exception ex) { | ||||
|             ex.printStackTrace(); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     public String reverseGet(String translated) { | ||||
|         translated = StringEscapeUtils.unescapeJson(translated).toLowerCase(); | ||||
|  | ||||
|         for (Map.Entry<String, Object> entry : getConfig().getValues(false).entrySet()) { | ||||
|             if (!Objects.equals(entry.getValue().toString().toLowerCase(), translated)) | ||||
|                 continue; | ||||
|  | ||||
|             return entry.getKey(); | ||||
|         } | ||||
|  | ||||
|         return translated; | ||||
|     } | ||||
|  | ||||
|     public String get(String message) { | ||||
|         if (this != TranslateType.MESSAGE) | ||||
|             throw new IllegalArgumentException("Can't set no comment for '" + message + "'"); | ||||
|  | ||||
|         return get(message, null); | ||||
|     } | ||||
|  | ||||
|     public String get(String message, String comment) { | ||||
|         String msg = getConfig().getString(StringEscapeUtils.escapeJson(message)); | ||||
|  | ||||
|         if (msg != null) | ||||
|             return msg; | ||||
|  | ||||
|         save(message, comment); | ||||
|  | ||||
|         return message; | ||||
|     } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user