diff --git a/compatibility/pom.xml b/Compatibility/pom.xml similarity index 96% rename from compatibility/pom.xml rename to Compatibility/pom.xml index fd4d8237..58de3ef6 100644 --- a/compatibility/pom.xml +++ b/Compatibility/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.56 + 2.4.57 ../ diff --git a/compatibility/src/com/songoda/core/compatibility/ClientVersion.java b/Compatibility/src/com/songoda/core/compatibility/ClientVersion.java similarity index 100% rename from compatibility/src/com/songoda/core/compatibility/ClientVersion.java rename to Compatibility/src/com/songoda/core/compatibility/ClientVersion.java diff --git a/compatibility/src/com/songoda/core/compatibility/CompatibleBiome.java b/Compatibility/src/com/songoda/core/compatibility/CompatibleBiome.java similarity index 100% rename from compatibility/src/com/songoda/core/compatibility/CompatibleBiome.java rename to Compatibility/src/com/songoda/core/compatibility/CompatibleBiome.java diff --git a/compatibility/src/com/songoda/core/compatibility/CompatibleHand.java b/Compatibility/src/com/songoda/core/compatibility/CompatibleHand.java similarity index 100% rename from compatibility/src/com/songoda/core/compatibility/CompatibleHand.java rename to Compatibility/src/com/songoda/core/compatibility/CompatibleHand.java diff --git a/compatibility/src/com/songoda/core/compatibility/CompatibleMaterial.java b/Compatibility/src/com/songoda/core/compatibility/CompatibleMaterial.java similarity index 100% rename from compatibility/src/com/songoda/core/compatibility/CompatibleMaterial.java rename to Compatibility/src/com/songoda/core/compatibility/CompatibleMaterial.java diff --git a/compatibility/src/com/songoda/core/compatibility/CompatibleParticleHandler.java b/Compatibility/src/com/songoda/core/compatibility/CompatibleParticleHandler.java similarity index 100% rename from compatibility/src/com/songoda/core/compatibility/CompatibleParticleHandler.java rename to Compatibility/src/com/songoda/core/compatibility/CompatibleParticleHandler.java diff --git a/compatibility/src/com/songoda/core/compatibility/CompatibleSound.java b/Compatibility/src/com/songoda/core/compatibility/CompatibleSound.java similarity index 100% rename from compatibility/src/com/songoda/core/compatibility/CompatibleSound.java rename to Compatibility/src/com/songoda/core/compatibility/CompatibleSound.java diff --git a/compatibility/src/com/songoda/core/compatibility/EntityNamespace.java b/Compatibility/src/com/songoda/core/compatibility/EntityNamespace.java similarity index 100% rename from compatibility/src/com/songoda/core/compatibility/EntityNamespace.java rename to Compatibility/src/com/songoda/core/compatibility/EntityNamespace.java diff --git a/compatibility/src/com/songoda/core/compatibility/LegacyMaterialAnalouge.java b/Compatibility/src/com/songoda/core/compatibility/LegacyMaterialAnalouge.java similarity index 100% rename from compatibility/src/com/songoda/core/compatibility/LegacyMaterialAnalouge.java rename to Compatibility/src/com/songoda/core/compatibility/LegacyMaterialAnalouge.java diff --git a/compatibility/src/com/songoda/core/compatibility/LegacyMaterialBlockType.java b/Compatibility/src/com/songoda/core/compatibility/LegacyMaterialBlockType.java similarity index 100% rename from compatibility/src/com/songoda/core/compatibility/LegacyMaterialBlockType.java rename to Compatibility/src/com/songoda/core/compatibility/LegacyMaterialBlockType.java diff --git a/compatibility/src/com/songoda/core/compatibility/LegacyParticleEffects.java b/Compatibility/src/com/songoda/core/compatibility/LegacyParticleEffects.java similarity index 100% rename from compatibility/src/com/songoda/core/compatibility/LegacyParticleEffects.java rename to Compatibility/src/com/songoda/core/compatibility/LegacyParticleEffects.java diff --git a/compatibility/src/com/songoda/core/compatibility/LegacyPotionEffects.java b/Compatibility/src/com/songoda/core/compatibility/LegacyPotionEffects.java similarity index 100% rename from compatibility/src/com/songoda/core/compatibility/LegacyPotionEffects.java rename to Compatibility/src/com/songoda/core/compatibility/LegacyPotionEffects.java diff --git a/compatibility/src/com/songoda/core/compatibility/ServerProject.java b/Compatibility/src/com/songoda/core/compatibility/ServerProject.java similarity index 100% rename from compatibility/src/com/songoda/core/compatibility/ServerProject.java rename to Compatibility/src/com/songoda/core/compatibility/ServerProject.java diff --git a/compatibility/src/com/songoda/core/compatibility/ServerVersion.java b/Compatibility/src/com/songoda/core/compatibility/ServerVersion.java similarity index 100% rename from compatibility/src/com/songoda/core/compatibility/ServerVersion.java rename to Compatibility/src/com/songoda/core/compatibility/ServerVersion.java diff --git a/Core/pom.xml b/Core/pom.xml index 595088c4..d6a581cc 100644 --- a/Core/pom.xml +++ b/Core/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.56 + 2.4.57 ../ diff --git a/Core/src/main/java/com/songoda/core/SongodaCore.java b/Core/src/main/java/com/songoda/core/SongodaCore.java index bf59682f..8f8d27a0 100644 --- a/Core/src/main/java/com/songoda/core/SongodaCore.java +++ b/Core/src/main/java/com/songoda/core/SongodaCore.java @@ -56,7 +56,7 @@ public class SongodaCore { /** * This has been added as of Rev 6 */ - private final static String coreVersion = "2.4.56"; + private final static String coreVersion = "2.4.57"; /** * This is specific to the website api diff --git a/Core/src/main/java/com/songoda/core/math/Eval.java b/Core/src/main/java/com/songoda/core/math/Eval.java new file mode 100644 index 00000000..d290da9d --- /dev/null +++ b/Core/src/main/java/com/songoda/core/math/Eval.java @@ -0,0 +1,87 @@ +package com.songoda.core.math; + +public class Eval { + + private int pos = -1, ch; + private final String toParse; + private final String warningMessage; + + public Eval(String toParse, String warningMessage) { + this.toParse = toParse; + this.warningMessage = warningMessage + " "; + } + + private void nextChar() { + ch = (++pos < toParse.length()) ? toParse.charAt(pos) : -1; + } + + private boolean eat(int charToEat) { + while (ch == ' ') nextChar(); + if (ch == charToEat) { + nextChar(); + return true; + } + return false; + } + + public double parse() { + nextChar(); + double x = parseExpression(); + if (pos < toParse.length()) throw new RuntimeException(warningMessage + "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() { + double x = parseTerm(); + for (;;) { + if (eat('+')) x += parseTerm(); // addition + else if (eat('-')) x -= parseTerm(); // subtraction + else return x; + } + } + + private double parseTerm() { + double x = parseFactor(); + for (;;) { + if (eat('*')) x *= parseFactor(); // multiplication + else if (eat('/')) x /= parseFactor(); // division + else return x; + } + } + + private double parseFactor() { + if (eat('+')) return parseFactor(); // unary plus + if (eat('-')) return -parseFactor(); // unary minus + + 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(toParse.substring(startPos, this.pos)); + } else if (ch >= 'a' && ch <= 'z') { // functions + while (ch >= 'a' && ch <= 'z') nextChar(); + String func = toParse.substring(startPos, this.pos); + x = parseFactor(); + if (func.equals("sqrt")) x = Math.sqrt(x); + else if (func.equals("sin")) x = Math.sin(Math.toRadians(x)); + else if (func.equals("cos")) x = Math.cos(Math.toRadians(x)); + else if (func.equals("tan")) x = Math.tan(Math.toRadians(x)); + else throw new RuntimeException(warningMessage + "Unknown function: " + func); + } else { + throw new RuntimeException(warningMessage + "Unexpected: " + (char)ch); + } + + if (eat('^')) x = Math.pow(x, parseFactor()); // exponentiation + + return x; + } +} diff --git a/Core/src/main/java/com/songoda/core/math/MathUtils.java b/Core/src/main/java/com/songoda/core/math/MathUtils.java new file mode 100644 index 00000000..4b174229 --- /dev/null +++ b/Core/src/main/java/com/songoda/core/math/MathUtils.java @@ -0,0 +1,17 @@ +package com.songoda.core.math; + +import java.util.HashMap; +import java.util.Map; + +public class MathUtils { + + private static final Map cache = new HashMap<>(); + + public static double eval(String toParse) { + return eval(toParse, "SongodaCore Eval Engine"); + } + + public static double eval(String toParse, String warningMessage) { + return cache.computeIfAbsent(toParse, t -> new Eval(toParse, "[" + warningMessage + "]").parse()); + } +} diff --git a/NMS/NMS-API/pom.xml b/NMS/NMS-API/pom.xml index 4400139d..279dfb1a 100644 --- a/NMS/NMS-API/pom.xml +++ b/NMS/NMS-API/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.56 + 2.4.57 ../../ diff --git a/NMS/NMS-v1_10_R1/pom.xml b/NMS/NMS-v1_10_R1/pom.xml index 87acf8c3..d2e60fae 100644 --- a/NMS/NMS-v1_10_R1/pom.xml +++ b/NMS/NMS-v1_10_R1/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.56 + 2.4.57 ../../ diff --git a/NMS/NMS-v1_11_R1/pom.xml b/NMS/NMS-v1_11_R1/pom.xml index f3afd437..829a5d1c 100644 --- a/NMS/NMS-v1_11_R1/pom.xml +++ b/NMS/NMS-v1_11_R1/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.56 + 2.4.57 ../../ diff --git a/NMS/NMS-v1_12_R1/pom.xml b/NMS/NMS-v1_12_R1/pom.xml index 73046bb4..49b14dec 100644 --- a/NMS/NMS-v1_12_R1/pom.xml +++ b/NMS/NMS-v1_12_R1/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.56 + 2.4.57 ../../ diff --git a/NMS/NMS-v1_13_R1/pom.xml b/NMS/NMS-v1_13_R1/pom.xml index d761455d..0799f282 100644 --- a/NMS/NMS-v1_13_R1/pom.xml +++ b/NMS/NMS-v1_13_R1/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.56 + 2.4.57 ../../ diff --git a/NMS/NMS-v1_13_R2/pom.xml b/NMS/NMS-v1_13_R2/pom.xml index bff1b956..e052b4f0 100644 --- a/NMS/NMS-v1_13_R2/pom.xml +++ b/NMS/NMS-v1_13_R2/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.56 + 2.4.57 ../../ diff --git a/NMS/NMS-v1_14_R1/pom.xml b/NMS/NMS-v1_14_R1/pom.xml index 241ea0e0..f1900ea0 100644 --- a/NMS/NMS-v1_14_R1/pom.xml +++ b/NMS/NMS-v1_14_R1/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.56 + 2.4.57 ../../ diff --git a/NMS/NMS-v1_15_R1/pom.xml b/NMS/NMS-v1_15_R1/pom.xml index 1dbd396d..a5a58255 100644 --- a/NMS/NMS-v1_15_R1/pom.xml +++ b/NMS/NMS-v1_15_R1/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.56 + 2.4.57 ../../ diff --git a/NMS/NMS-v1_16_R1/pom.xml b/NMS/NMS-v1_16_R1/pom.xml index f7080ccf..6fa9ff1a 100644 --- a/NMS/NMS-v1_16_R1/pom.xml +++ b/NMS/NMS-v1_16_R1/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.56 + 2.4.57 ../../ diff --git a/NMS/NMS-v1_16_R2/pom.xml b/NMS/NMS-v1_16_R2/pom.xml index 8f933ba1..76df65f7 100644 --- a/NMS/NMS-v1_16_R2/pom.xml +++ b/NMS/NMS-v1_16_R2/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.56 + 2.4.57 ../../ diff --git a/NMS/NMS-v1_16_R3/pom.xml b/NMS/NMS-v1_16_R3/pom.xml index a1de6020..b2c76491 100644 --- a/NMS/NMS-v1_16_R3/pom.xml +++ b/NMS/NMS-v1_16_R3/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.56 + 2.4.57 ../../ diff --git a/NMS/NMS-v1_8_R1/pom.xml b/NMS/NMS-v1_8_R1/pom.xml index 338b1136..38dd6bbb 100644 --- a/NMS/NMS-v1_8_R1/pom.xml +++ b/NMS/NMS-v1_8_R1/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.56 + 2.4.57 ../../ diff --git a/NMS/NMS-v1_8_R2/pom.xml b/NMS/NMS-v1_8_R2/pom.xml index 2dcc3cc3..ad50e92d 100644 --- a/NMS/NMS-v1_8_R2/pom.xml +++ b/NMS/NMS-v1_8_R2/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.56 + 2.4.57 ../../ diff --git a/NMS/NMS-v1_8_R3/pom.xml b/NMS/NMS-v1_8_R3/pom.xml index c10e66e7..0399dbd1 100644 --- a/NMS/NMS-v1_8_R3/pom.xml +++ b/NMS/NMS-v1_8_R3/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.56 + 2.4.57 ../../ diff --git a/NMS/NMS-v1_9_R1/pom.xml b/NMS/NMS-v1_9_R1/pom.xml index 8d7e59eb..85b62403 100644 --- a/NMS/NMS-v1_9_R1/pom.xml +++ b/NMS/NMS-v1_9_R1/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.56 + 2.4.57 ../../ diff --git a/NMS/NMS-v1_9_R2/pom.xml b/NMS/NMS-v1_9_R2/pom.xml index b9367081..6085dc95 100644 --- a/NMS/NMS-v1_9_R2/pom.xml +++ b/NMS/NMS-v1_9_R2/pom.xml @@ -3,7 +3,7 @@ com.songoda SongodaCore-Modules - 2.4.56 + 2.4.57 ../../ diff --git a/README.md b/README.md index 653d9095..5901e4f7 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Maven Information com.songoda SongodaCore - 2.4.56 + 2.4.57 provided ``` @@ -37,6 +37,6 @@ repositories { * Artifact: ```groovy dependencies { - compileOnly 'com.songoda:SongodaCore:2.4.56' + compileOnly 'com.songoda:SongodaCore:2.4.57' } ``` \ No newline at end of file diff --git a/pom.xml b/pom.xml index 6c239a83..1c417ef2 100644 --- a/pom.xml +++ b/pom.xml @@ -2,7 +2,7 @@ com.songoda SongodaCore-Modules - 2.4.56 + 2.4.57 4.0.0 pom