Bug fixes, more translations

This commit is contained in:
libraryaddict 2017-06-22 07:20:12 +12:00
parent 4fe484dc10
commit 27472578cd
11 changed files with 69 additions and 77 deletions

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectCodeStyleSettingsManager">
<option name="PER_PROJECT_SETTINGS">
<value />
</option>
<option name="PREFERRED_PROJECT_CODE_STYLE" value="My Style" />
</component>
</project>

View File

@ -44,11 +44,9 @@ public class DisguiseAPI {
if (disguiseType.isMisc()) { if (disguiseType.isMisc()) {
disguise = new MiscDisguise(disguiseType); disguise = new MiscDisguise(disguiseType);
} } else if (disguiseType.isMob()) {
else if (disguiseType.isMob()) {
disguise = new MobDisguise(disguiseType); disguise = new MobDisguise(disguiseType);
} } else {
else {
disguise = new PlayerDisguise(entity.getName()); disguise = new PlayerDisguise(entity.getName());
} }
@ -60,8 +58,7 @@ public class DisguiseAPI {
if (effect.getType() == PotionEffectType.INVISIBILITY) { if (effect.getType() == PotionEffectType.INVISIBILITY) {
watcher.setInvisible(true); watcher.setInvisible(true);
} } else if (effect.getType() == PotionEffectType.GLOWING) {
else if (effect.getType() == PotionEffectType.GLOWING) {
watcher.setGlowing(true); watcher.setGlowing(true);
} }
} }
@ -91,8 +88,9 @@ public class DisguiseAPI {
} }
} }
for (Method method : entity.getClass().getMethods()) { for (Method method : entity.getClass().getMethods()) {
if ((doSneak || !method.getName().equals("setSneaking")) && (doSprint || !method.getName().equals("setSprinting")) if ((doSneak || !method.getName().equals("setSneaking")) && (doSprint || !method.getName()
&& method.getParameterTypes().length == 0 && method.getReturnType() != void.class) { .equals("setSprinting")) && method.getParameterTypes().length == 0 && method
.getReturnType() != void.class) {
Class methodReturn = method.getReturnType(); Class methodReturn = method.getReturnType();
if (methodReturn == float.class || methodReturn == Float.class || methodReturn == Double.class) { if (methodReturn == float.class || methodReturn == Float.class || methodReturn == Double.class) {
@ -103,8 +101,8 @@ public class DisguiseAPI {
if (firstCapitalMethod > 0) { if (firstCapitalMethod > 0) {
for (Method watcherMethod : watcher.getClass().getMethods()) { for (Method watcherMethod : watcher.getClass().getMethods()) {
if (!watcherMethod.getName().startsWith("get") && watcherMethod.getReturnType() == void.class if (!watcherMethod.getName().startsWith("get") && watcherMethod
&& watcherMethod.getParameterTypes().length == 1) { .getReturnType() == void.class && watcherMethod.getParameterTypes().length == 1) {
int firstCapitalWatcher = firstCapital(watcherMethod.getName()); int firstCapitalWatcher = firstCapital(watcherMethod.getName());
if (firstCapitalWatcher > 0 && method.getName().substring(firstCapitalMethod) if (firstCapitalWatcher > 0 && method.getName().substring(firstCapitalMethod)
@ -113,8 +111,7 @@ public class DisguiseAPI {
if (methodParam == float.class || methodParam == Float.class || methodParam == Double.class) { if (methodParam == float.class || methodParam == Float.class || methodParam == Double.class) {
methodParam = double.class; methodParam = double.class;
} } else if (methodParam == AnimalColor.class) {
else if (methodParam == AnimalColor.class) {
methodParam = DyeColor.class; methodParam = DyeColor.class;
} }
if (methodReturn == methodParam) { if (methodReturn == methodParam) {
@ -128,19 +125,17 @@ public class DisguiseAPI {
double d = (Double) value; double d = (Double) value;
value = (float) d; value = (float) d;
} }
} } else if (toCast == double.class) {
else if (toCast == double.class) {
if (!(value instanceof Double)) { if (!(value instanceof Double)) {
float d = (Float) value; float d = (Float) value;
value = (double) d; value = (double) d;
} }
} } else if (toCast == AnimalColor.class) {
else if (toCast == AnimalColor.class) {
value = AnimalColor.valueOf(((DyeColor) value).name()); value = AnimalColor.valueOf(((DyeColor) value).name());
} }
} }
if (value instanceof Boolean && !(Boolean) value if (value instanceof Boolean && !(Boolean) value && watcherMethod
&& watcherMethod.getDeclaringClass() == FlagWatcher.class) { .getDeclaringClass() == FlagWatcher.class) {
continue; continue;
} }
} }
@ -195,8 +190,7 @@ public class DisguiseAPI {
for (Object obj : playersToNotSeeDisguise) { for (Object obj : playersToNotSeeDisguise) {
if (obj instanceof String) { if (obj instanceof String) {
((TargetedDisguise) disguise).addPlayer((String) obj); ((TargetedDisguise) disguise).addPlayer((String) obj);
} } else if (obj instanceof Player) {
else if (obj instanceof Player) {
((TargetedDisguise) disguise).addPlayer(((Player) obj).getName()); ((TargetedDisguise) disguise).addPlayer(((Player) obj).getName());
} }
} }
@ -275,8 +269,7 @@ public class DisguiseAPI {
for (Object obj : playersToViewDisguise) { for (Object obj : playersToViewDisguise) {
if (obj instanceof String) { if (obj instanceof String) {
((TargetedDisguise) disguise).addPlayer((String) obj); ((TargetedDisguise) disguise).addPlayer((String) obj);
} } else if (obj instanceof Player) {
else if (obj instanceof Player) {
((TargetedDisguise) disguise).addPlayer(((Player) obj).getName()); ((TargetedDisguise) disguise).addPlayer(((Player) obj).getName());
} }
} }
@ -390,8 +383,8 @@ public class DisguiseAPI {
* @return * @return
*/ */
public static boolean isViewSelfToggled(Entity entity) { public static boolean isViewSelfToggled(Entity entity) {
return isDisguised(entity) ? getDisguise(entity).isSelfDisguiseVisible() return isDisguised(entity) ? getDisguise(entity).isSelfDisguiseVisible() :
: Disguise.getViewSelf().contains(entity.getUniqueId()); Disguise.getViewSelf().contains(entity.getUniqueId());
} }
/** /**
@ -416,16 +409,18 @@ public class DisguiseAPI {
*/ */
public static void setViewDisguiseToggled(Entity entity, boolean toggled) { public static void setViewDisguiseToggled(Entity entity, boolean toggled) {
if (isDisguised(entity)) { if (isDisguised(entity)) {
Disguise disguise = getDisguise(entity); Disguise[] disguises = getDisguises(entity);
for (Disguise disguise : disguises) {
disguise.setViewSelfDisguise(toggled); disguise.setViewSelfDisguise(toggled);
} }
}
if (toggled) { if (toggled) {
if (!Disguise.getViewSelf().contains(entity.getUniqueId())) { if (!Disguise.getViewSelf().contains(entity.getUniqueId())) {
Disguise.getViewSelf().add(entity.getUniqueId()); Disguise.getViewSelf().add(entity.getUniqueId());
} }
} } else {
else {
Disguise.getViewSelf().remove(entity.getUniqueId()); Disguise.getViewSelf().remove(entity.getUniqueId());
} }
} }

View File

@ -38,15 +38,14 @@ 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") || StringUtils if (StringUtils.startsWithIgnoreCase(option, LibsMsg.DCLONE_EQUIP.get())) {
.startsWithIgnoreCase(option, "ignoreEnquip")) {
doEquipment = false; doEquipment = false;
} else if (option.equalsIgnoreCase("doSneakSprint")) { } else if (option.equalsIgnoreCase(LibsMsg.DCLONE_SNEAKSPRINT.get())) {
doSneak = true; doSneak = true;
doSprint = true; doSprint = true;
} else if (option.equalsIgnoreCase("doSneak")) { } else if (option.equalsIgnoreCase(LibsMsg.DCLONE_SNEAK.get())) {
doSneak = true; doSneak = true;
} else if (option.equalsIgnoreCase("doSprint")) { } else if (option.equalsIgnoreCase(LibsMsg.DCLONE_SPRINT.get())) {
doSprint = true; doSprint = true;
} else { } else {
sender.sendMessage(LibsMsg.INVALID_CLONE.get(option)); sender.sendMessage(LibsMsg.INVALID_CLONE.get(option));
@ -82,10 +81,10 @@ public class DisguiseCloneCommand extends DisguiseBaseCommand implements TabComp
} }
} }
tabs.add("ignoreEquip"); tabs.add(LibsMsg.DCLONE_EQUIP.get());
tabs.add("doSneakSprint"); tabs.add(LibsMsg.DCLONE_SNEAKSPRINT.get());
tabs.add("doSneak"); tabs.add(LibsMsg.DCLONE_SNEAK.get());
tabs.add("doSprint"); tabs.add(LibsMsg.DCLONE_SPRINT.get());
return filterTabs(tabs, origArgs); return filterTabs(tabs, origArgs);
} }

View File

@ -74,7 +74,7 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl
try { try {
for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(watcher)) { for (Method method : ReflectionFlagWatchers.getDisguiseWatcherMethods(watcher)) {
if (args.length < 2 || !args[1].equalsIgnoreCase("show")) { if (args.length < 2 || !args[1].equalsIgnoreCase(LibsMsg.DHELP_SHOW.get())) {
boolean allowed = false; boolean allowed = false;
for (ArrayList<String> key : permMap.get(type).keySet()) { for (ArrayList<String> key : permMap.get(type).keySet()) {
@ -112,7 +112,8 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl
methodColor = ChatColor.GRAY; methodColor = ChatColor.GRAY;
} }
String str = method.getName() + ChatColor.DARK_RED + "(" + ChatColor.GREEN + info String str = TranslateType.DISGUISE_OPTIONS
.get(method.getName()) + ChatColor.DARK_RED + "(" + ChatColor.GREEN + info
.getName() + ChatColor.DARK_RED + ")"; .getName() + ChatColor.DARK_RED + ")";
map.put(str, methodColor); map.put(str, methodColor);
@ -130,7 +131,7 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl
} }
if (methods.isEmpty()) { if (methods.isEmpty()) {
methods.add(ChatColor.RED + "No options with permission to use"); methods.add(LibsMsg.DHELP_NO_OPTIONS.get());
} }
sender.sendMessage(LibsMsg.DHELP_OPTIONS.get(ChatColor.DARK_RED + type.toReadable(), sender.sendMessage(LibsMsg.DHELP_OPTIONS.get(ChatColor.DARK_RED + type.toReadable(),
@ -170,7 +171,7 @@ public class DisguiseHelpCommand extends DisguiseBaseCommand implements TabCompl
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(LibsMsg.DHELP_SHOW.get());
} }
} }

View File

@ -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 TranslateType.DISGUISES.get(StringUtils.join(split, " "), "Name for the " + name() + " disguise"); return TranslateType.DISGUISES.get(StringUtils.join(split, " "));
} }
} }

View File

@ -86,10 +86,6 @@ public class DisguiseParser {
return getType().isUnknown(); return getType().isUnknown();
} }
public String name() {
return permName == null ? getType().name() : permName;
}
public String toReadable() { public String toReadable() {
return permName == null ? getType().toReadable() : permName; return permName == null ? getType().toReadable() : permName;
} }
@ -169,7 +165,7 @@ public class DisguiseParser {
String[] split = lowerPerm.substring(beginning.length()).split("\\."); String[] split = lowerPerm.substring(beginning.length()).split("\\.");
if (split.length > 1) { if (split.length > 1) {
if (split[0].replace("_", "").equals(type.name().toLowerCase().replace("_", ""))) { if (split[0].replace("_", "").equals(type.toReadable().toLowerCase().replace(" ", ""))) {
for (int i = 1; i < split.length; i++) { for (int i = 1; i < split.length; i++) {
returns.put(split[i], permission.getValue()); returns.put(split[i], permission.getValue());
} }
@ -186,7 +182,7 @@ public class DisguiseParser {
public static DisguisePerm getDisguisePerm(String name) { public static DisguisePerm getDisguisePerm(String name) {
for (DisguisePerm perm : getDisguisePerms()) { for (DisguisePerm perm : getDisguisePerms()) {
if (!perm.name().equalsIgnoreCase(name) && !perm.name().replace("_", "").equalsIgnoreCase(name)) if (!perm.toReadable().equalsIgnoreCase(name) && !perm.toReadable().replace(" ", "").equalsIgnoreCase(name))
continue; continue;
return perm; return perm;

View File

@ -55,6 +55,12 @@ public enum LibsMsg {
DMODPLAYER_NOPERM(ChatColor.RED + "You do not have permission to modify this disguise"), DMODPLAYER_NOPERM(ChatColor.RED + "You do not have permission to modify this disguise"),
DMODRADIUS(ChatColor.RED + "Successfully modified the disguises of %s entities!"), DMODRADIUS(ChatColor.RED + "Successfully modified the disguises of %s entities!"),
DMODRADIUS_HELP1(ChatColor.DARK_GREEN + "Modify the disguises in a radius! Caps at %s blocks!"), DMODRADIUS_HELP1(ChatColor.DARK_GREEN + "Modify the disguises in a radius! Caps at %s blocks!"),
DHELP_SHOW("Show"),
DHELP_NO_OPTIONS(ChatColor.RED + "No options with permission to use"),
DCLONE_EQUIP("ignoreEquip"),
DCLONE_SNEAKSPRINT("doSneakSprint"),
DCLONE_SNEAK("doSneak"),
DCLONE_SPRINT("doSprint"),
DMODRADIUS_HELP3( DMODRADIUS_HELP3(
(ChatColor.DARK_GREEN + "/disguisemodifyradius <EntityType" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")> <Radius> player <Name>") (ChatColor.DARK_GREEN + "/disguisemodifyradius <EntityType" + ChatColor.DARK_GREEN + "(" + ChatColor.GREEN + "Optional" + ChatColor.DARK_GREEN + ")> <Radius> player <Name>")
.replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")), .replace("<", "<" + ChatColor.GREEN).replace(">", ChatColor.DARK_GREEN + ">")),

View File

@ -81,8 +81,7 @@ public class ReflectionFlagWatchers {
} }
public String getName() { public String getName() {
return TranslateType.DISGUISE_OPTIONS_PARAMETERS return TranslateType.DISGUISE_OPTIONS_PARAMETERS.get(getRawName());
.get(getRawName(), "Used as a disguise option for " + getRawName());
} }
public String getRawName() { public String getRawName() {
@ -90,8 +89,7 @@ public class ReflectionFlagWatchers {
} }
public String getDescription() { public String getDescription() {
return TranslateType.DISGUISE_OPTIONS_PARAMETERS return TranslateType.DISGUISE_OPTIONS_PARAMETERS.get(getRawDescription());
.get(getRawDescription(), "Used as a disguise option for " + getRawDescription());
} }
public String getRawDescription() { public String getRawDescription() {

View File

@ -15,16 +15,13 @@ public class TranslateFiller {
// Fill the configs // Fill the configs
for (ReflectionFlagWatchers.ParamInfo info : ReflectionFlagWatchers.getParamInfos()) { for (ReflectionFlagWatchers.ParamInfo info : ReflectionFlagWatchers.getParamInfos()) {
if (!info.isEnums())
continue;
if (info.getParamClass() == ItemStack.class || info.getParamClass() == ItemStack[].class)
continue;
TranslateType.DISGUISE_OPTIONS_PARAMETERS.save(info.getRawName(), "Used as a disguise option"); TranslateType.DISGUISE_OPTIONS_PARAMETERS.save(info.getRawName(), "Used as a disguise option");
TranslateType.DISGUISE_OPTIONS_PARAMETERS TranslateType.DISGUISE_OPTIONS_PARAMETERS
.save(info.getRawDescription(), "Description for the disguise option " + info.getRawName()); .save(info.getRawDescription(), "Description for the disguise option " + info.getRawName());
if (!info.isEnums() || info.getParamClass() == ItemStack.class || info.getParamClass() == ItemStack[].class)
continue;
for (String e : info.getEnums("")) { for (String e : info.getEnums("")) {
TranslateType.DISGUISE_OPTIONS_PARAMETERS.save(e, "Used for the disguise option " + info.getRawName()); TranslateType.DISGUISE_OPTIONS_PARAMETERS.save(e, "Used for the disguise option " + info.getRawName());
} }

View File

@ -2,6 +2,7 @@ package me.libraryaddict.disguise.utilities;
import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.DisguiseConfig;
import org.apache.commons.lang3.StringEscapeUtils; import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.file.YamlConfiguration;
@ -88,6 +89,8 @@ public enum TranslateType {
translated.put(message, message); translated.put(message, message);
message = StringEscapeUtils.escapeJava(message.replaceAll(ChatColor.COLOR_CHAR + "", "&")); message = StringEscapeUtils.escapeJava(message.replaceAll(ChatColor.COLOR_CHAR + "", "&"));
String message1 = StringEscapeUtils.escapeJava(
StringUtils.reverse(message).replaceAll("s%", "%s").replaceAll(ChatColor.COLOR_CHAR + "", "&"));
try { try {
boolean exists = file.exists(); boolean exists = file.exists();
@ -108,7 +111,7 @@ public enum TranslateType {
} }
writer.write("\n" + (comment != null ? "# " + comment + "\n" : writer.write("\n" + (comment != null ? "# " + comment + "\n" :
"") + "\"" + message + "\": \"" + message + "\"\n"); "") + "\"" + message + "\": \"" + message1 + "\"\n");
writer.close(); writer.close();
} }
@ -134,23 +137,11 @@ public enum TranslateType {
} }
public String get(String msg) { public String get(String msg) {
if (this != TranslateType.MESSAGES)
throw new IllegalArgumentException("Can't set no comment for '" + msg + "'");
return get(msg, null);
}
public String get(String msg, String comment) {
if (msg == null || !LibsPremium.isPremium() || !DisguiseConfig.isUseTranslations()) if (msg == null || !LibsPremium.isPremium() || !DisguiseConfig.isUseTranslations())
return msg; return msg;
String toReturn = translated.get(msg); String toReturn = translated.get(msg);
if (toReturn != null) return toReturn == null ? msg : toReturn;
return toReturn;
save(msg, comment);
return msg;
} }
} }