mirror of
https://github.com/EssentialsX/Essentials.git
synced 2025-01-26 10:01:49 +01:00
Apply patch "Fix float parsing issues" from Spigot-Essentials
This commit is contained in:
parent
ff3b1e810f
commit
b6957db352
@ -6,6 +6,7 @@ import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.UserMap;
|
||||
import com.earth2me.essentials.metrics.Metrics;
|
||||
import com.earth2me.essentials.utils.DateUtil;
|
||||
import com.earth2me.essentials.utils.FloatUtil;
|
||||
import com.earth2me.essentials.utils.NumberUtil;
|
||||
import com.google.common.base.Charsets;
|
||||
import org.bukkit.Material;
|
||||
@ -199,7 +200,7 @@ public class Commandessentials extends EssentialsCommand {
|
||||
sender.sendMessage(tl("cleaning"));
|
||||
|
||||
final long daysArg = Long.parseLong(args[1]);
|
||||
final double moneyArg = args.length >= 3 ? Double.parseDouble(args[2].replaceAll("[^0-9\\.]", "")) : 0;
|
||||
final double moneyArg = args.length >= 3 ? FloatUtil.parseDouble(args[2].replaceAll("[^0-9\\.]", "")) : 0;
|
||||
final int homesArg = args.length >= 4 && NumberUtil.isInt(args[3]) ? Integer.parseInt(args[3]) : 0;
|
||||
final UserMap userMap = ess.getUserMap();
|
||||
|
||||
|
@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.FloatUtil;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@ -30,7 +31,7 @@ public class Commandsetworth extends EssentialsCommand {
|
||||
price = args[1];
|
||||
}
|
||||
|
||||
ess.getWorth().setPrice(stack, Double.parseDouble(price));
|
||||
ess.getWorth().setPrice(stack, FloatUtil.parseDouble(price));
|
||||
user.sendMessage(tl("worthSet"));
|
||||
}
|
||||
|
||||
@ -41,7 +42,7 @@ public class Commandsetworth extends EssentialsCommand {
|
||||
}
|
||||
|
||||
ItemStack stack = ess.getItemDb().get(args[0]);
|
||||
ess.getWorth().setPrice(stack, Double.parseDouble(args[1]));
|
||||
ess.getWorth().setPrice(stack, FloatUtil.parseDouble(args[1]));
|
||||
sender.sendMessage(tl("worthSet"));
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package com.earth2me.essentials.commands;
|
||||
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.FloatUtil;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
@ -107,7 +108,7 @@ public class Commandspeed extends EssentialsCommand {
|
||||
private float getMoveSpeed(final String moveSpeed) throws NotEnoughArgumentsException {
|
||||
float userSpeed;
|
||||
try {
|
||||
userSpeed = Float.parseFloat(moveSpeed);
|
||||
userSpeed = FloatUtil.parseFloat(moveSpeed);
|
||||
if (userSpeed > 10f) {
|
||||
userSpeed = 10f;
|
||||
} else if (userSpeed < 0.0001f) {
|
||||
|
@ -3,6 +3,7 @@ package com.earth2me.essentials.commands;
|
||||
import com.earth2me.essentials.CommandSource;
|
||||
import com.earth2me.essentials.Trade;
|
||||
import com.earth2me.essentials.User;
|
||||
import com.earth2me.essentials.utils.FloatUtil;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
|
||||
@ -26,10 +27,10 @@ public class Commandtppos extends EssentialsCommand {
|
||||
final double z = args[2].startsWith("~") ? user.getLocation().getZ() + Integer.parseInt(args[2].substring(1)) : Integer.parseInt(args[2]);
|
||||
final Location loc = new Location(user.getWorld(), x, y, z, user.getLocation().getYaw(), user.getLocation().getPitch());
|
||||
if (args.length > 3) {
|
||||
loc.setYaw((Float.parseFloat(args[3]) + 180 + 360) % 360);
|
||||
loc.setYaw((FloatUtil.parseFloat(args[3]) + 180 + 360) % 360);
|
||||
}
|
||||
if (args.length > 4) {
|
||||
loc.setPitch(Float.parseFloat(args[4]));
|
||||
loc.setPitch(FloatUtil.parseFloat(args[4]));
|
||||
}
|
||||
if (x > 30000000 || y > 30000000 || z > 30000000 || x < -30000000 || y < -30000000 || z < -30000000) {
|
||||
throw new NotEnoughArgumentsException(tl("teleportInvalidLocation"));
|
||||
@ -53,10 +54,10 @@ public class Commandtppos extends EssentialsCommand {
|
||||
final double z = args[3].startsWith("~") ? user.getLocation().getZ() + Integer.parseInt(args[3].substring(1)) : Integer.parseInt(args[3]);
|
||||
final Location loc = new Location(user.getWorld(), x, y, z, user.getLocation().getYaw(), user.getLocation().getPitch());
|
||||
if (args.length > 4) {
|
||||
loc.setYaw((Float.parseFloat(args[4]) + 180 + 360) % 360);
|
||||
loc.setYaw((FloatUtil.parseFloat(args[4]) + 180 + 360) % 360);
|
||||
}
|
||||
if (args.length > 5) {
|
||||
loc.setPitch(Float.parseFloat(args[5]));
|
||||
loc.setPitch(FloatUtil.parseFloat(args[5]));
|
||||
}
|
||||
if (x > 30000000 || y > 30000000 || z > 30000000 || x < -30000000 || y < -30000000 || z < -30000000) {
|
||||
throw new NotEnoughArgumentsException(tl("teleportInvalidLocation"));
|
||||
|
37
Essentials/src/com/earth2me/essentials/utils/FloatUtil.java
Normal file
37
Essentials/src/com/earth2me/essentials/utils/FloatUtil.java
Normal file
@ -0,0 +1,37 @@
|
||||
package com.earth2me.essentials.utils;
|
||||
|
||||
/**
|
||||
* parseFloat and parseDouble proxies that are protected against non-finite values.
|
||||
*/
|
||||
public class FloatUtil
|
||||
{
|
||||
private FloatUtil() {}
|
||||
|
||||
public static float parseFloat(String s) throws NumberFormatException
|
||||
{
|
||||
float f = Float.parseFloat(s);
|
||||
if (Float.isNaN(f))
|
||||
{
|
||||
throw new NumberFormatException("NaN is not valid");
|
||||
}
|
||||
if (Float.isInfinite(f))
|
||||
{
|
||||
throw new NumberFormatException("Infinity is not valid");
|
||||
}
|
||||
return f;
|
||||
}
|
||||
|
||||
public static double parseDouble(String s) throws NumberFormatException
|
||||
{
|
||||
double d = Double.parseDouble(s);
|
||||
if (Double.isNaN(d))
|
||||
{
|
||||
throw new NumberFormatException("NaN is not valid");
|
||||
}
|
||||
if (Double.isInfinite(d))
|
||||
{
|
||||
throw new NumberFormatException("Infinity is not valid");
|
||||
}
|
||||
return d;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user