-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Version 1.3.5 (update to script system)
Mathematical expressions and Else action included to script system
- Loading branch information
Showing
12 changed files
with
300 additions
and
235 deletions.
There are no files selected for viewing
6 changes: 3 additions & 3 deletions
6
.idea/libraries/Maven__org_bukkit_bukkit_1_12_2_R0_1_SNAPSHOT.xml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
6 changes: 3 additions & 3 deletions
6
.idea/libraries/Maven__org_spigotmc_spigot_api_1_12_2_R0_1_SNAPSHOT.xml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 62 additions & 17 deletions
79
src/main/java/com/drawwdev/raffle/utils/ScriptSystem.java
Large diffs are not rendered by default.
Oops, something went wrong.
87 changes: 87 additions & 0 deletions
87
src/main/java/com/drawwdev/raffle/utils/arithmeticExpression.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
package com.drawwdev.raffle.utils; | ||
|
||
public class arithmeticExpression { | ||
|
||
public static double eval(final String str) { | ||
return new Object() { | ||
int pos = -1, ch; | ||
|
||
void nextChar() { | ||
ch = (++pos < str.length()) ? str.charAt(pos) : -1; | ||
} | ||
|
||
boolean eat(int charToEat) { | ||
while (ch == ' ') nextChar(); | ||
if (ch == charToEat) { | ||
nextChar(); | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
double parse() { | ||
nextChar(); | ||
double x = parseExpression(); | ||
if (pos < str.length()) throw new RuntimeException("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 | ||
|
||
double parseExpression() { | ||
double x = parseTerm(); | ||
for (; ; ) { | ||
if (eat('+')) x += parseTerm(); // addition | ||
else if (eat('-')) x -= parseTerm(); // subtraction | ||
else return x; | ||
} | ||
} | ||
|
||
double parseTerm() { | ||
double x = parseFactor(); | ||
for (; ; ) { | ||
if (eat('*')) x *= parseFactor(); // multiplication | ||
else if (eat('/')) x /= parseFactor(); // division | ||
else if (eat('^')) | ||
x = Math.pow(x, parseFactor()); //exponentiation -> Moved in to here. So the problem is fixed | ||
else return x; | ||
} | ||
} | ||
|
||
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(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(); | ||
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("Unknown function: " + func); | ||
} else { | ||
throw new RuntimeException("Unexpected: " + (char) ch); | ||
} | ||
|
||
//if (eat('^')) x = Math.pow(x, parseFactor()); // exponentiation -> This is causing a bit of problem | ||
|
||
return x; | ||
} | ||
}.parse(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
CustomRaffles: | ||
example: | ||
name: 'example1' | ||
name: example1 | ||
datatype: 'Numeral' | ||
time: 5 | ||
predicate: | ||
- '#Script#[IF]$arg1.type=NUMBER' | ||
- '#Script#[IF]%player%==Draww' | ||
- '#Script#[IF]$math($arg1 + 1)==6.0 [ElseAction] [Message] example1;[Message] example2' | ||
actions: | ||
- '[Broadcast] %prefix% &7Hello, &a%player%' | ||
- '[Broadcast] %prefix% &7Your World, &a%player_world%' | ||
- '[Broadcast] %prefix% &7Example, &6$arg1' | ||
- '[Broadcast] %prefix% &7Example, &6$math($arg1 + 1)' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
name: Raffle | ||
main: com.drawwdev.raffle.Main | ||
version: 1.3.4a | ||
version: 1.3.5 | ||
author: drawwdev | ||
commands: | ||
raffle: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
CustomRaffles: | ||
example: | ||
name: 'example1' | ||
name: example1 | ||
datatype: 'Numeral' | ||
time: 5 | ||
predicate: | ||
- '#Script#[IF]$arg1.type=NUMBER' | ||
- '#Script#[IF]%player%==Draww' | ||
- '#Script#[IF]$math($arg1 + 1)==6.0 [ElseAction] [Message] example1;[Message] example2' | ||
actions: | ||
- '[Broadcast] %prefix% &7Hello, &a%player%' | ||
- '[Broadcast] %prefix% &7Your World, &a%player_world%' | ||
- '[Broadcast] %prefix% &7Example, &6$arg1' | ||
- '[Broadcast] %prefix% &7Example, &6$math($arg1 + 1)' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
name: Raffle | ||
main: com.drawwdev.raffle.Main | ||
version: 1.3.4 | ||
version: 1.3.5 | ||
author: drawwdev | ||
commands: | ||
raffle: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
#Generated by Maven | ||
#Fri Feb 09 08:51:35 EET 2018 | ||
version=1.3.4 | ||
#Sat Feb 10 09:17:21 EET 2018 | ||
version=1.3.5 | ||
groupId=com.drawwdev | ||
artifactId=Raffle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters