Current progress
This commit is contained in:
parent
9fa4ae73bf
commit
4b5714ea65
@ -8,6 +8,7 @@ import java.util.Arrays;
|
|||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import me.libraryaddict.disguise.disguisetypes.watchers.*;
|
import me.libraryaddict.disguise.disguisetypes.watchers.*;
|
||||||
|
import me.libraryaddict.disguise.utilities.*;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.command.CommandExecutor;
|
import org.bukkit.command.CommandExecutor;
|
||||||
import org.bukkit.command.PluginCommand;
|
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.DisguiseType;
|
||||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
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 {
|
public class LibsDisguises extends JavaPlugin {
|
||||||
private static LibsDisguises instance;
|
private static LibsDisguises instance;
|
||||||
@ -87,6 +81,8 @@ public class LibsDisguises extends JavaPlugin {
|
|||||||
|
|
||||||
PacketsManager.addPacketListeners();
|
PacketsManager.addPacketListeners();
|
||||||
|
|
||||||
|
TranslateFiller.fillConfigs();
|
||||||
|
|
||||||
listener = new DisguiseListener(this);
|
listener = new DisguiseListener(this);
|
||||||
|
|
||||||
Bukkit.getPluginManager().registerEvents(listener, this);
|
Bukkit.getPluginManager().registerEvents(listener, this);
|
||||||
|
@ -36,7 +36,8 @@ public abstract class DisguiseBaseCommand implements CommandExecutor {
|
|||||||
return new ArrayList<String>(new HashSet<String>(list));
|
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<>();
|
ArrayList<String> allowedDisguises = new ArrayList<>();
|
||||||
|
|
||||||
for (DisguisePerm type : hashMap.keySet()) {
|
for (DisguisePerm type : hashMap.keySet()) {
|
||||||
@ -52,7 +53,7 @@ public abstract class DisguiseBaseCommand implements CommandExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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];
|
||||||
@ -69,29 +70,21 @@ public abstract class DisguiseBaseCommand implements CommandExecutor {
|
|||||||
public final String getPermNode() {
|
public final String getPermNode() {
|
||||||
if (this instanceof DisguiseCommand) {
|
if (this instanceof DisguiseCommand) {
|
||||||
return "disguise";
|
return "disguise";
|
||||||
}
|
} else if (this instanceof DisguiseEntityCommand) {
|
||||||
else if (this instanceof DisguiseEntityCommand) {
|
|
||||||
return "disguiseentity";
|
return "disguiseentity";
|
||||||
}
|
} else if (this instanceof DisguisePlayerCommand) {
|
||||||
else if (this instanceof DisguisePlayerCommand) {
|
|
||||||
return "disguiseplayer";
|
return "disguiseplayer";
|
||||||
}
|
} else if (this instanceof DisguiseRadiusCommand) {
|
||||||
else if (this instanceof DisguiseRadiusCommand) {
|
|
||||||
return "disguiseradius";
|
return "disguiseradius";
|
||||||
}
|
} else if (this instanceof DisguiseModifyCommand) {
|
||||||
else if (this instanceof DisguiseModifyCommand) {
|
|
||||||
return "disguisemodify";
|
return "disguisemodify";
|
||||||
}
|
} else if (this instanceof DisguiseModifyEntityCommand) {
|
||||||
else if (this instanceof DisguiseModifyEntityCommand) {
|
|
||||||
return "disguisemodifyentity";
|
return "disguisemodifyentity";
|
||||||
}
|
} else if (this instanceof DisguiseModifyPlayerCommand) {
|
||||||
else if (this instanceof DisguiseModifyPlayerCommand) {
|
|
||||||
return "disguisemodifyplayer";
|
return "disguisemodifyplayer";
|
||||||
}
|
} else if (this instanceof DisguiseModifyRadiusCommand) {
|
||||||
else if (this instanceof DisguiseModifyRadiusCommand) {
|
|
||||||
return "disguisemodifyradius";
|
return "disguisemodifyradius";
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
throw new UnsupportedOperationException("Unknown disguise command, perm node not found");
|
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.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;
|
||||||
@ -30,7 +31,8 @@ public class DisguiseCommand 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,9 +71,11 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter
|
|||||||
DisguiseAPI.disguiseToAll((Player) sender, disguise);
|
DisguiseAPI.disguiseToAll((Player) sender, disguise);
|
||||||
|
|
||||||
if (disguise.isDisguiseInUse()) {
|
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 {
|
} 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;
|
return true;
|
||||||
@ -79,15 +83,13 @@ public class DisguiseCommand extends DisguiseBaseCommand implements 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);
|
||||||
|
|
||||||
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> perms = getPermissions(sender);
|
HashMap<DisguisePerm, HashMap<ArrayList<String>, Boolean>> perms = getPermissions(sender);
|
||||||
|
|
||||||
if (args.length == 0) {
|
if (args.length == 0) {
|
||||||
for (String type : getAllowedDisguises(perms)) {
|
tabs.addAll(getAllowedDisguises(perms));
|
||||||
tabs.add(type);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
DisguisePerm disguiseType = DisguiseParser.getDisguisePerm(args[0]);
|
DisguisePerm disguiseType = DisguiseParser.getDisguisePerm(args[0]);
|
||||||
|
|
||||||
@ -100,7 +102,7 @@ public class DisguiseCommand extends DisguiseBaseCommand implements TabCompleter
|
|||||||
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 ? 2 : 1; i < args.length; i++) {
|
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,
|
protected void sendCommandUsage(CommandSender sender,
|
||||||
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(ChatColor.DARK_GREEN + "Choose a disguise to become the disguise!");
|
sender.sendMessage(
|
||||||
sender.sendMessage(ChatColor.DARK_GREEN + "You can use the disguises: " + ChatColor.GREEN + StringUtils.join(
|
TranslateType.MESSAGE.get(ChatColor.DARK_GREEN + "Choose a disguise to become the disguise!"));
|
||||||
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 + "/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")) {
|
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;
|
package me.libraryaddict.disguise.disguisetypes;
|
||||||
|
|
||||||
|
import me.libraryaddict.disguise.utilities.TranslateType;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
import org.omg.CORBA.UNKNOWN;
|
|
||||||
|
|
||||||
public enum DisguiseType {
|
public enum DisguiseType {
|
||||||
AREA_EFFECT_CLOUD(3, 0),
|
AREA_EFFECT_CLOUD(3, 0),
|
||||||
@ -322,6 +322,6 @@ public enum DisguiseType {
|
|||||||
split[i] = split[i].substring(0, 1) + split[i].substring(1).toLowerCase();
|
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) {
|
private ParamInfo(String name, String description) {
|
||||||
this.name = name;
|
this.name = TranslateType.METHOD_PARAM.get(name, null);
|
||||||
this.description = description;
|
this.description = TranslateType.METHOD_PARAM.get(description, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ParamInfo(String className, String name, String description) throws ClassNotFoundException {
|
public ParamInfo(String className, String name, String description) throws ClassNotFoundException {
|
||||||
@ -169,6 +169,7 @@ public class ReflectionFlagWatchers {
|
|||||||
|
|
||||||
potionEnums.add(toReadable(effectType.getName()));
|
potionEnums.add(toReadable(effectType.getName()));
|
||||||
}
|
}
|
||||||
|
|
||||||
String[] materials = new String[Material.values().length];
|
String[] materials = new String[Material.values().length];
|
||||||
|
|
||||||
for (int i = 0; i < Material.values().length; i++) {
|
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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user