Try avoid letting people use stupid values for numbers. Fixes #635
This commit is contained in:
		| @@ -17,7 +17,13 @@ public class ParamInfoDouble extends ParamInfo { | |||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     protected Object fromString(String string) { |     protected Object fromString(String string) { | ||||||
|         return Double.parseDouble(string); |         double result = Double.parseDouble(string); | ||||||
|  |  | ||||||
|  |         if (!Double.isFinite(result) || Math.abs(result) > 999_999_999) { | ||||||
|  |             throw new NumberFormatException("For input string: \"" + string + "\""); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return result; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|   | |||||||
| @@ -7,12 +7,22 @@ import me.libraryaddict.disguise.utilities.params.ParamInfo; | |||||||
|  */ |  */ | ||||||
| public class ParamInfoFloat extends ParamInfo { | public class ParamInfoFloat extends ParamInfo { | ||||||
|     public ParamInfoFloat(String name, String description) { |     public ParamInfoFloat(String name, String description) { | ||||||
|         super(float.class, name, description); |         this(float.class, name, description); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     public ParamInfoFloat(Class cl, String name, String description) { | ||||||
|  |         super(cl, name, description); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     protected Object fromString(String string) { |     protected Object fromString(String string) { | ||||||
|         return Float.parseFloat(string); |         float result = Float.parseFloat(string); | ||||||
|  |  | ||||||
|  |         if (!Float.isFinite(result) || Math.abs(result) > 999_999_999) { | ||||||
|  |             throw new NumberFormatException("For input string: \"" + string + "\""); | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         return result; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|   | |||||||
| @@ -5,7 +5,7 @@ import me.libraryaddict.disguise.utilities.params.ParamInfo; | |||||||
| /** | /** | ||||||
|  * Created by libraryaddict on 7/09/2018. |  * Created by libraryaddict on 7/09/2018. | ||||||
|  */ |  */ | ||||||
| public class ParamInfoFloatNullable extends ParamInfo { | public class ParamInfoFloatNullable extends ParamInfoFloat { | ||||||
|     public ParamInfoFloatNullable(String name, String description) { |     public ParamInfoFloatNullable(String name, String description) { | ||||||
|         super(Float.class, name, description); |         super(Float.class, name, description); | ||||||
|     } |     } | ||||||
| @@ -16,7 +16,7 @@ public class ParamInfoFloatNullable extends ParamInfo { | |||||||
|             return null; |             return null; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return Float.parseFloat(string); |         return super.fromString(string); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|   | |||||||
| @@ -143,6 +143,11 @@ public class ParamInfoParticle extends ParamInfoEnum { | |||||||
|                     throw new DisguiseParseException(LibsMsg.PARSE_PARTICLE_REDSTONE, particle.name(), string); |                     throw new DisguiseParseException(LibsMsg.PARSE_PARTICLE_REDSTONE, particle.name(), string); | ||||||
|                 } else { |                 } else { | ||||||
|                     size = Math.max(0.2f, Float.parseFloat(split[split.length - 1])); |                     size = Math.max(0.2f, Float.parseFloat(split[split.length - 1])); | ||||||
|  |  | ||||||
|  |                     // Stupid high cap | ||||||
|  |                     if (size > 100) { | ||||||
|  |                         size = 100; | ||||||
|  |                     } | ||||||
|                 } |                 } | ||||||
|  |  | ||||||
|                 data = new Particle.DustOptions(color, size); |                 data = new Particle.DustOptions(color, size); | ||||||
|   | |||||||
| @@ -108,14 +108,14 @@ public class DisguiseParser { | |||||||
|                     } |                     } | ||||||
|  |  | ||||||
|                     if (getMethod == null) { |                     if (getMethod == null) { | ||||||
|                         DisguiseUtilities.getLogger().severe(String |                         DisguiseUtilities.getLogger().severe( | ||||||
|                                 .format("No such method '%s' when looking for the companion of '%s' in '%s'", getName, setMethod.getName(), |                             String.format("No such method '%s' when looking for the companion of '%s' in '%s'", getName, setMethod.getName(), | ||||||
|                                         setMethod.getWatcherClass().getSimpleName())); |                                 setMethod.getWatcherClass().getSimpleName())); | ||||||
|                         continue; |                         continue; | ||||||
|                     } else if (getMethod.getReturnType() != setMethod.getParam()) { |                     } else if (getMethod.getReturnType() != setMethod.getParam()) { | ||||||
|                         DisguiseUtilities.getLogger().severe(String |                         DisguiseUtilities.getLogger().severe( | ||||||
|                                 .format("Invalid return type of '%s' when looking for the companion of '%s' in '%s'", getName, setMethod.getName(), |                             String.format("Invalid return type of '%s' when looking for the companion of '%s' in '%s'", getName, setMethod.getName(), | ||||||
|                                         setMethod.getWatcherClass().getSimpleName())); |                                 setMethod.getWatcherClass().getSimpleName())); | ||||||
|                         continue; |                         continue; | ||||||
|                     } |                     } | ||||||
|  |  | ||||||
| @@ -175,7 +175,7 @@ public class DisguiseParser { | |||||||
|                 // Special handling for this method |                 // Special handling for this method | ||||||
|                 if (m.getName().equals("addPotionEffect")) { |                 if (m.getName().equals("addPotionEffect")) { | ||||||
|                     MethodHandle getPotion = |                     MethodHandle getPotion = | ||||||
|                             MethodHandles.publicLookup().bind(disguise.getWatcher(), "getPotionEffects", MethodType.methodType(PotionEffectType[].class)); |                         MethodHandles.publicLookup().bind(disguise.getWatcher(), "getPotionEffects", MethodType.methodType(PotionEffectType[].class)); | ||||||
|                     PotionEffectType[] types = (PotionEffectType[]) getPotion.invoke(); |                     PotionEffectType[] types = (PotionEffectType[]) getPotion.invoke(); | ||||||
|  |  | ||||||
|                     for (PotionEffectType type : types) { |                     for (PotionEffectType type : types) { | ||||||
| @@ -267,7 +267,7 @@ public class DisguiseParser { | |||||||
|                         serializedMeta.put(entry.getKey(), val.getClass().getName() + ":" + serialized); |                         serializedMeta.put(entry.getKey(), val.getClass().getName() + ":" + serialized); | ||||||
|                     } catch (Throwable throwable) { |                     } catch (Throwable throwable) { | ||||||
|                         DisguiseUtilities.getLogger() |                         DisguiseUtilities.getLogger() | ||||||
|                                 .warning("Unable to properly serialize the metadata on a disguise, the metadata was saved under name '" + entry.getKey() + "'"); |                             .warning("Unable to properly serialize the metadata on a disguise, the metadata was saved under name '" + entry.getKey() + "'"); | ||||||
|  |  | ||||||
|                         if (!(throwable instanceof StackOverflowError)) { |                         if (!(throwable instanceof StackOverflowError)) { | ||||||
|                             throwable.printStackTrace(); |                             throwable.printStackTrace(); | ||||||
| @@ -297,9 +297,8 @@ public class DisguiseParser { | |||||||
|  |  | ||||||
|             if (!Objects.deepEquals(dObj, object)) { |             if (!Objects.deepEquals(dObj, object)) { | ||||||
|                 throw new IllegalStateException(String.format( |                 throw new IllegalStateException(String.format( | ||||||
|                         "%s has conflicting values in class %s! This means it expected the same value again but " + "received a " + |                     "%s has conflicting values in class %s! This means it expected the same value again but " + "received a " + | ||||||
|                                 "different value on a different disguise! %s is not the same as %s!", setMethod.toString(), setMethod.toString(), object, |                         "different value on a different disguise! %s is not the same as %s!", setMethod.toString(), setMethod.toString(), object, dObj)); | ||||||
|                         dObj)); |  | ||||||
|             } |             } | ||||||
|  |  | ||||||
|             return; |             return; | ||||||
| @@ -311,7 +310,7 @@ public class DisguiseParser { | |||||||
|     } |     } | ||||||
|  |  | ||||||
|     private static void doCheck(CommandSender sender, DisguisePermissions permissions, DisguisePerm disguisePerm, Collection<String> usedOptions) |     private static void doCheck(CommandSender sender, DisguisePermissions permissions, DisguisePerm disguisePerm, Collection<String> usedOptions) | ||||||
|             throws DisguiseParseException { |         throws DisguiseParseException { | ||||||
|  |  | ||||||
|         if (!permissions.isAllowedDisguise(disguisePerm, usedOptions)) { |         if (!permissions.isAllowedDisguise(disguisePerm, usedOptions)) { | ||||||
|             throw new DisguiseParseException(LibsMsg.D_PARSE_NOPERM, usedOptions.stream().reduce((first, second) -> second).orElse(null)); |             throw new DisguiseParseException(LibsMsg.D_PARSE_NOPERM, usedOptions.stream().reduce((first, second) -> second).orElse(null)); | ||||||
| @@ -416,15 +415,6 @@ public class DisguiseParser { | |||||||
|         return new DisguisePermissions(sender, commandName); |         return new DisguisePermissions(sender, commandName); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private static boolean isDouble(String string) { |  | ||||||
|         try { |  | ||||||
|             Float.parseFloat(string); |  | ||||||
|             return true; |  | ||||||
|         } catch (Exception ex) { |  | ||||||
|             return false; |  | ||||||
|         } |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|     private static boolean isInteger(String string) { |     private static boolean isInteger(String string) { | ||||||
|         try { |         try { | ||||||
|             Integer.parseInt(string); |             Integer.parseInt(string); | ||||||
| @@ -496,7 +486,7 @@ public class DisguiseParser { | |||||||
|  |  | ||||||
|     public static String[] parsePlaceholders(String[] args, CommandSender user, CommandSender target) { |     public static String[] parsePlaceholders(String[] args, CommandSender user, CommandSender target) { | ||||||
|         return parsePlaceholders(args, getName(user), DisguiseUtilities.getDisplayName(user), getSkin(user), getName(target), |         return parsePlaceholders(args, getName(user), DisguiseUtilities.getDisplayName(user), getSkin(user), getName(target), | ||||||
|                 DisguiseUtilities.getDisplayName(target), DisguiseParser.getSkin(target), getEntityEquipment(user), getEntityEquipment(target)); |             DisguiseUtilities.getDisplayName(target), DisguiseParser.getSkin(target), getEntityEquipment(user), getEntityEquipment(target)); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private static EntityEquipment getEntityEquipment(CommandSender entity) { |     private static EntityEquipment getEntityEquipment(CommandSender entity) { | ||||||
| @@ -647,7 +637,7 @@ public class DisguiseParser { | |||||||
|         } |         } | ||||||
|  |  | ||||||
|         DisguiseParser.callMethods(Bukkit.getConsoleSender(), disguise, new DisguisePermissions(Bukkit.getConsoleSender(), "disguise"), |         DisguiseParser.callMethods(Bukkit.getConsoleSender(), disguise, new DisguisePermissions(Bukkit.getConsoleSender(), "disguise"), | ||||||
|                 new DisguisePerm(disguise.getType()), new ArrayList<>(), params, "Disguise"); |             new DisguisePerm(disguise.getType()), new ArrayList<>(), params, "Disguise"); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static void modifyDisguise(Disguise disguise, String[] params) throws Throwable { |     public static void modifyDisguise(Disguise disguise, String[] params) throws Throwable { | ||||||
| @@ -677,7 +667,7 @@ public class DisguiseParser { | |||||||
|      * disguise has been feed a proper disguisetype. |      * disguise has been feed a proper disguisetype. | ||||||
|      */ |      */ | ||||||
|     public static Disguise parseDisguise(CommandSender sender, Entity target, String permNode, String[] args, DisguisePermissions permissions) |     public static Disguise parseDisguise(CommandSender sender, Entity target, String permNode, String[] args, DisguisePermissions permissions) | ||||||
|             throws Throwable { |         throws Throwable { | ||||||
|         if (!Bukkit.isPrimaryThread()) { |         if (!Bukkit.isPrimaryThread()) { | ||||||
|             throw new IllegalStateException("DisguiseParser should not be called async!"); |             throw new IllegalStateException("DisguiseParser should not be called async!"); | ||||||
|         } |         } | ||||||
| @@ -809,7 +799,7 @@ public class DisguiseParser { | |||||||
|                         boolean adult = true; |                         boolean adult = true; | ||||||
|  |  | ||||||
|                         if (args[1].equalsIgnoreCase(TranslateType.DISGUISE_OPTIONS.get("baby")) || |                         if (args[1].equalsIgnoreCase(TranslateType.DISGUISE_OPTIONS.get("baby")) || | ||||||
|                                 args[1].equalsIgnoreCase(TranslateType.DISGUISE_OPTIONS.get("adult"))) { |                             args[1].equalsIgnoreCase(TranslateType.DISGUISE_OPTIONS.get("adult"))) { | ||||||
|                             usedOptions.add("setbaby"); |                             usedOptions.add("setbaby"); | ||||||
|                             doCheck(sender, permissions, disguisePerm, usedOptions); |                             doCheck(sender, permissions, disguisePerm, usedOptions); | ||||||
|                             adult = args[1].equalsIgnoreCase(TranslateType.DISGUISE_OPTIONS.get("adult")); |                             adult = args[1].equalsIgnoreCase(TranslateType.DISGUISE_OPTIONS.get("adult")); | ||||||
| @@ -1006,8 +996,8 @@ public class DisguiseParser { | |||||||
|                     parseException = ex; |                     parseException = ex; | ||||||
|                 } catch (Exception ignored) { |                 } catch (Exception ignored) { | ||||||
|                     parseException = |                     parseException = | ||||||
|                             new DisguiseParseException(LibsMsg.PARSE_EXPECTED_RECEIVED, paramInfo.getDescriptiveName(), list.isEmpty() ? null : list.get(0), |                         new DisguiseParseException(LibsMsg.PARSE_EXPECTED_RECEIVED, paramInfo.getDescriptiveName(), list.isEmpty() ? null : list.get(0), | ||||||
|                                     TranslateType.DISGUISE_OPTIONS.reverseGet(method.getName())); |                             TranslateType.DISGUISE_OPTIONS.reverseGet(method.getName())); | ||||||
|                 } |                 } | ||||||
|             } |             } | ||||||
|  |  | ||||||
| @@ -1034,8 +1024,8 @@ public class DisguiseParser { | |||||||
|             } |             } | ||||||
|  |  | ||||||
|             if (DisguiseConfig.isArmorstandsName() && ((methodToUse.getName().equals("setName") && disguise.isPlayerDisguise()) || |             if (DisguiseConfig.isArmorstandsName() && ((methodToUse.getName().equals("setName") && disguise.isPlayerDisguise()) || | ||||||
|                     (DisguiseConfig.isOverrideCustomNames() && methodToUse.getName().equals("setCustomName"))) && |                 (DisguiseConfig.isOverrideCustomNames() && methodToUse.getName().equals("setCustomName"))) && | ||||||
|                     !sender.hasPermission("libsdisguises.multiname")) { |                 !sender.hasPermission("libsdisguises.multiname")) { | ||||||
|                 valueToSet = DisguiseUtilities.quoteNewLine((String) valueToSet); |                 valueToSet = DisguiseUtilities.quoteNewLine((String) valueToSet); | ||||||
|             } |             } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user