mirror of
https://github.com/md5sha256/AreaShop.git
synced 2026-11-07 01:42:34 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b8fbb53633 | ||
|
|
cfda4f56e3 | ||
|
|
832d8967a3 | ||
|
|
c369d23f74 |
No files matched your search
@@ -6,7 +6,7 @@ plugins {
|
||||
}
|
||||
|
||||
description = 'AreaShop'
|
||||
version = '2.6.4'
|
||||
version = '2.6.6'
|
||||
|
||||
dependencies {
|
||||
// Spigot api
|
||||
|
||||
@@ -29,6 +29,7 @@ import org.bukkit.plugin.Plugin;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
@@ -51,6 +52,7 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface {
|
||||
public static final String configFile = "config.yml";
|
||||
public static final String configFileHidden = "hiddenConfig.yml";
|
||||
public static final String versionFile = "versions";
|
||||
public static final String signErrorFile = "sign-errors.yml";
|
||||
// Euro tag for in the config
|
||||
public static final String currencyEuro = "%euro%";
|
||||
// Constants for handling file versions
|
||||
@@ -605,6 +607,8 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface {
|
||||
error = true;
|
||||
}
|
||||
|
||||
this.signErrorLogger = new SignErrorLogger(new File(getDataFolder(), signErrorFile));
|
||||
|
||||
// Setup the NMS helper
|
||||
setupNMS();
|
||||
|
||||
@@ -648,7 +652,8 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface {
|
||||
if (!matcher0.find()) {
|
||||
matcher0 = VERSION_MATCHER_2.matcher(latestVersion);
|
||||
if (!matcher0.find()) {
|
||||
throw new IllegalArgumentException("Invalid Versions Detected!");
|
||||
// FIXME log invalid version
|
||||
return false;
|
||||
}
|
||||
dual0 = true;
|
||||
}
|
||||
@@ -657,7 +662,8 @@ public final class AreaShop extends JavaPlugin implements AreaShopInterface {
|
||||
if (!matcher1.find()) {
|
||||
matcher1 = VERSION_MATCHER_2.matcher(currentVersion);
|
||||
if (!matcher1.find()) {
|
||||
throw new IllegalArgumentException("Invalid Versions Detected!");
|
||||
// FIXME log invalid version
|
||||
return false;
|
||||
}
|
||||
dual1 = true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,152 @@
|
||||
package me.wiefferink.areashop.tools;
|
||||
|
||||
/**
|
||||
* Parse math from a string
|
||||
* Adapted from:
|
||||
* https://stackoverflow.com/questions/3422673/how-to-evaluate-a-math-expression-given-in-string-form
|
||||
*/
|
||||
public final class OperandParser {
|
||||
|
||||
private final String str;
|
||||
|
||||
private OperandParser(final String str) {
|
||||
this.str = str;
|
||||
}
|
||||
|
||||
public static double parse(final String str) throws ParseException {
|
||||
return new OperandParser(str).parse();
|
||||
}
|
||||
|
||||
|
||||
private int pos = -1, ch;
|
||||
|
||||
private void nextChar() {
|
||||
ch = (++pos < str.length()) ? str.charAt(pos) : -1;
|
||||
}
|
||||
|
||||
private boolean eat(int charToEat) {
|
||||
while (ch == ' ') nextChar();
|
||||
if (ch == charToEat) {
|
||||
nextChar();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private double parse() throws ParseException {
|
||||
nextChar();
|
||||
double x = parseExpression();
|
||||
if (pos < str.length())
|
||||
{
|
||||
throw new ParseException("Unexpected: " + (char) ch);
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
// Grammar:
|
||||
// expression = term | expression `+` term | expression `-` term
|
||||
// term = factor | term `*` factor | term `/` factor
|
||||
// factor = `+` factor | `-` factor | `(` expression `)`
|
||||
// | number | functionName factor | factor `^` factor
|
||||
|
||||
private double parseExpression() throws ParseException {
|
||||
double x = parseTerm();
|
||||
for (; ; ) {
|
||||
if (eat('+')) {
|
||||
// addition
|
||||
x += parseTerm();
|
||||
}
|
||||
else if (eat('-')) {
|
||||
// subtraction
|
||||
x -= parseTerm();
|
||||
}
|
||||
else return x;
|
||||
}
|
||||
}
|
||||
|
||||
private double parseTerm() throws ParseException {
|
||||
double x = parseFactor();
|
||||
for (; ; ) {
|
||||
if (eat('*')) {
|
||||
// multiplication
|
||||
x *= parseFactor();
|
||||
}
|
||||
else if (eat('/')) {
|
||||
// division
|
||||
x /= parseFactor();
|
||||
}
|
||||
else return x;
|
||||
}
|
||||
}
|
||||
|
||||
private double parseFactor() throws ParseException {
|
||||
if (eat('+')) {
|
||||
// unary plus
|
||||
return parseFactor();
|
||||
}
|
||||
if (eat('-')) {
|
||||
// unary minus
|
||||
return -parseFactor();
|
||||
}
|
||||
|
||||
double x;
|
||||
int startPos = this.pos;
|
||||
if (eat('(')) {
|
||||
// parentheses
|
||||
x = parseExpression();
|
||||
eat(')');
|
||||
} else if ((ch >= '0' && ch <= '9') || ch == '.') {
|
||||
// numbers
|
||||
while ((ch >= '0' && ch <= '9') || ch == '.') {
|
||||
nextChar();
|
||||
}
|
||||
x = Double.parseDouble(str.substring(startPos, this.pos));
|
||||
} else if (ch >= 'a' && ch <= 'z') {
|
||||
// functions
|
||||
while (ch >= 'a' && ch <= 'z') {
|
||||
nextChar();
|
||||
}
|
||||
String func = str.substring(startPos, this.pos);
|
||||
x = parseFactor();
|
||||
x = switch (func) {
|
||||
case "sqrt" -> Math.sqrt(x);
|
||||
case "sin" -> Math.sin(Math.toRadians(x));
|
||||
case "cos" -> Math.cos(Math.toRadians(x));
|
||||
case "tan" -> Math.tan(Math.toRadians(x));
|
||||
default -> throw new ParseException("Unknown function: " + func);
|
||||
};
|
||||
} else {
|
||||
throw new ParseException("Unexpected: " + (char) ch);
|
||||
}
|
||||
|
||||
if (eat('^')) {
|
||||
// exponentiation
|
||||
x = Math.pow(x, parseFactor());
|
||||
}
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
public static class ParseException extends Exception {
|
||||
|
||||
public ParseException() {
|
||||
}
|
||||
|
||||
public ParseException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public ParseException(String message, Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
public ParseException(Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
public ParseException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) {
|
||||
super(message, cause, enableSuppression, writableStackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,7 +12,10 @@ import me.wiefferink.areashop.regions.RentRegion;
|
||||
import me.wiefferink.interactivemessenger.Log;
|
||||
import me.wiefferink.interactivemessenger.processing.Message;
|
||||
import org.apache.commons.lang.exception.ExceptionUtils;
|
||||
import org.bukkit.*;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.BlockFace;
|
||||
import org.bukkit.configuration.Configuration;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@@ -22,10 +25,6 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.bukkit.scheduler.BukkitTask;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import javax.script.ScriptException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.*;
|
||||
@@ -46,7 +45,6 @@ public class Utils {
|
||||
private static Set<String> weeks;
|
||||
private static Set<String> months;
|
||||
private static Set<String> years;
|
||||
private static ScriptEngine scriptEngine;
|
||||
private static Map<Double, String> suffixes;
|
||||
|
||||
// Not used
|
||||
@@ -768,16 +766,11 @@ public class Utils {
|
||||
return Double.parseDouble(input);
|
||||
}
|
||||
|
||||
// Lazy init scriptEngine
|
||||
if (scriptEngine == null) {
|
||||
scriptEngine = new ScriptEngineManager().getEngineByName("JavaScript");
|
||||
}
|
||||
|
||||
// Evaluate expression
|
||||
Object result;
|
||||
try {
|
||||
result = scriptEngine.eval(input);
|
||||
} catch (ScriptException e) {
|
||||
result = OperandParser.parse(input);
|
||||
} catch (OperandParser.ParseException e) {
|
||||
AreaShop.warn("Price of region", region.getName(), "is set with an invalid expression: '" + input + "', exception:", ExceptionUtils.getStackTrace(e));
|
||||
return 99999999999.0; // High fallback for safety
|
||||
}
|
||||
|
||||
+1
-1
@@ -3,7 +3,7 @@ plugins {
|
||||
}
|
||||
|
||||
group = "me.wiefferink.areashop"
|
||||
version = '2.6.4'
|
||||
version = '2.6.6'
|
||||
|
||||
subprojects {
|
||||
|
||||
|
||||
Reference in new issue
Block a user