Add Add, Div, Mul, and Sub
Dieser Commit ist enthalten in:
Ursprung
4c604d968b
Commit
5acc6b2d76
@ -1,4 +1,53 @@
|
||||
package de.steamwar.bausystem.features.script.command.arithmetic;
|
||||
|
||||
public class Add {
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.features.script.ScriptExecutor;
|
||||
import de.steamwar.bausystem.features.script.SpecialCommand;
|
||||
import de.steamwar.bausystem.features.script.variables.Value;
|
||||
import de.steamwar.bausystem.linkage.LinkageType;
|
||||
import de.steamwar.bausystem.linkage.Linked;
|
||||
|
||||
@Linked(LinkageType.SCRIPT_COMMAND)
|
||||
public class Add implements SpecialCommand {
|
||||
|
||||
@Override
|
||||
public String[] description() {
|
||||
return new String[]{
|
||||
"§eadd §8<§7Variable§8> §8<§7Variable§8>",
|
||||
"§eadd §8<§7Variable§8> §8<§7Variable§8> §8<§7Variable§8>",
|
||||
"",
|
||||
"Addition zwischen den letzten beiden Variablen und schreibe es in die erste."
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String command() {
|
||||
return "add";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
|
||||
if (command.length <= 1) {
|
||||
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte eine Variable sein");
|
||||
return true;
|
||||
}
|
||||
if (command.length <= 2) {
|
||||
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas zweite Argument fehlt und sollte eine Variable sein");
|
||||
return true;
|
||||
}
|
||||
|
||||
Value v1 = scriptExecutor.getOrItselfValue(command[command.length - 2]);
|
||||
Value v2 = scriptExecutor.getOrItselfValue(command[command.length - 1]);
|
||||
if (v1.getClass() != Value.LongValue.class) {
|
||||
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cNur Zahlen können addiert werden");
|
||||
return true;
|
||||
}
|
||||
if (v2.getClass() != Value.LongValue.class) {
|
||||
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cNur Zahlen können addiert werden");
|
||||
return true;
|
||||
}
|
||||
|
||||
scriptExecutor.getLocalVariables().putValue(command[1], new Value.LongValue(v1.asLong() + v2.asLong()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,53 @@
|
||||
package de.steamwar.bausystem.features.script.command.arithmetic;
|
||||
|
||||
public class Div {
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.features.script.ScriptExecutor;
|
||||
import de.steamwar.bausystem.features.script.SpecialCommand;
|
||||
import de.steamwar.bausystem.features.script.variables.Value;
|
||||
import de.steamwar.bausystem.linkage.LinkageType;
|
||||
import de.steamwar.bausystem.linkage.Linked;
|
||||
|
||||
@Linked(LinkageType.SCRIPT_COMMAND)
|
||||
public class Div implements SpecialCommand {
|
||||
|
||||
@Override
|
||||
public String[] description() {
|
||||
return new String[]{
|
||||
"§ediv §8<§7Variable§8> §8<§7Variable§8>",
|
||||
"§ediv §8<§7Variable§8> §8<§7Variable§8> §8<§7Variable§8>",
|
||||
"",
|
||||
"Division zwischen den letzten beiden Variablen und schreibe es in die erste."
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String command() {
|
||||
return "div";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
|
||||
if (command.length <= 1) {
|
||||
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte eine Variable sein");
|
||||
return true;
|
||||
}
|
||||
if (command.length <= 2) {
|
||||
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas zweite Argument fehlt und sollte eine Variable sein");
|
||||
return true;
|
||||
}
|
||||
|
||||
Value v1 = scriptExecutor.getOrItselfValue(command[command.length - 2]);
|
||||
Value v2 = scriptExecutor.getOrItselfValue(command[command.length - 1]);
|
||||
if (v1.getClass() != Value.LongValue.class) {
|
||||
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cNur Zahlen können dividiert werden");
|
||||
return true;
|
||||
}
|
||||
if (v2.getClass() != Value.LongValue.class) {
|
||||
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cNur Zahlen können dividiert werden");
|
||||
return true;
|
||||
}
|
||||
|
||||
scriptExecutor.getLocalVariables().putValue(command[1], new Value.LongValue(v1.asLong() / v2.asLong()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,53 @@
|
||||
package de.steamwar.bausystem.features.script.command.arithmetic;
|
||||
|
||||
public class Mul {
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.features.script.ScriptExecutor;
|
||||
import de.steamwar.bausystem.features.script.SpecialCommand;
|
||||
import de.steamwar.bausystem.features.script.variables.Value;
|
||||
import de.steamwar.bausystem.linkage.LinkageType;
|
||||
import de.steamwar.bausystem.linkage.Linked;
|
||||
|
||||
@Linked(LinkageType.SCRIPT_COMMAND)
|
||||
public class Mul implements SpecialCommand {
|
||||
|
||||
@Override
|
||||
public String[] description() {
|
||||
return new String[]{
|
||||
"§emul §8<§7Variable§8> §8<§7Variable§8>",
|
||||
"§emul §8<§7Variable§8> §8<§7Variable§8> §8<§7Variable§8>",
|
||||
"",
|
||||
"Multiplikation zwischen den letzten beiden Variablen und schreibe es in die erste."
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String command() {
|
||||
return "mul";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
|
||||
if (command.length <= 1) {
|
||||
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte eine Variable sein");
|
||||
return true;
|
||||
}
|
||||
if (command.length <= 2) {
|
||||
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas zweite Argument fehlt und sollte eine Variable sein");
|
||||
return true;
|
||||
}
|
||||
|
||||
Value v1 = scriptExecutor.getOrItselfValue(command[command.length - 2]);
|
||||
Value v2 = scriptExecutor.getOrItselfValue(command[command.length - 1]);
|
||||
if (v1.getClass() != Value.LongValue.class) {
|
||||
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cNur Zahlen können multipliziert werden");
|
||||
return true;
|
||||
}
|
||||
if (v2.getClass() != Value.LongValue.class) {
|
||||
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cNur Zahlen können multipliziert werden");
|
||||
return true;
|
||||
}
|
||||
|
||||
scriptExecutor.getLocalVariables().putValue(command[1], new Value.LongValue(v1.asLong() * v2.asLong()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,53 @@
|
||||
package de.steamwar.bausystem.features.script.command.arithmetic;
|
||||
|
||||
public class Sub {
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.features.script.ScriptExecutor;
|
||||
import de.steamwar.bausystem.features.script.SpecialCommand;
|
||||
import de.steamwar.bausystem.features.script.variables.Value;
|
||||
import de.steamwar.bausystem.linkage.LinkageType;
|
||||
import de.steamwar.bausystem.linkage.Linked;
|
||||
|
||||
@Linked(LinkageType.SCRIPT_COMMAND)
|
||||
public class Sub implements SpecialCommand {
|
||||
|
||||
@Override
|
||||
public String[] description() {
|
||||
return new String[]{
|
||||
"§esub §8<§7Variable§8> §8<§7Variable§8>",
|
||||
"§esub §8<§7Variable§8> §8<§7Variable§8> §8<§7Variable§8>",
|
||||
"",
|
||||
"Subtraktion zwischen den letzten beiden Variablen und schreibe es in die erste."
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String command() {
|
||||
return "sub";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
|
||||
if (command.length <= 1) {
|
||||
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte eine Variable sein");
|
||||
return true;
|
||||
}
|
||||
if (command.length <= 2) {
|
||||
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas zweite Argument fehlt und sollte eine Variable sein");
|
||||
return true;
|
||||
}
|
||||
|
||||
Value v1 = scriptExecutor.getOrItselfValue(command[command.length - 2]);
|
||||
Value v2 = scriptExecutor.getOrItselfValue(command[command.length - 1]);
|
||||
if (v1.getClass() != Value.LongValue.class) {
|
||||
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cNur Zahlen können subtrahiert werden");
|
||||
return true;
|
||||
}
|
||||
if (v2.getClass() != Value.LongValue.class) {
|
||||
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cNur Zahlen können subtrahiert werden");
|
||||
return true;
|
||||
}
|
||||
|
||||
scriptExecutor.getLocalVariables().putValue(command[1], new Value.LongValue(v1.asLong() - v2.asLong()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren