Add And, Not, and Or
Dieser Commit ist enthalten in:
Ursprung
35540e8c6b
Commit
bcbabb8158
@ -1,4 +1,59 @@
|
||||
package de.steamwar.bausystem.features.script.command.logic;
|
||||
|
||||
public class And {
|
||||
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 And implements SpecialCommand {
|
||||
|
||||
@Override
|
||||
public String[] description() {
|
||||
return new String[]{
|
||||
"§eand §8<§7Variable§8> §8<§7Variable§8>",
|
||||
"§eand §8<§7Variable§8> §8<§7Variable§8> §8<§7Variable§8>",
|
||||
"",
|
||||
"Das logische Und zwischen den letzten beiden Variablen und schreibe es in die erste."
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String command() {
|
||||
return "and";
|
||||
}
|
||||
|
||||
@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.BooleanValue.class) {
|
||||
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cNur Booleans können verglichen werden");
|
||||
return true;
|
||||
}
|
||||
if (v2.getClass() != Value.BooleanValue.class) {
|
||||
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cNur Booleans können verglichen werden");
|
||||
return true;
|
||||
}
|
||||
Value result;
|
||||
if (v1.asBoolean() && v2.asBoolean()) {
|
||||
result = new Value.BooleanValue(true);
|
||||
} else {
|
||||
result = new Value.BooleanValue(false);
|
||||
}
|
||||
|
||||
scriptExecutor.getLocalVariables().putValue(command[1], result);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,43 @@
|
||||
package de.steamwar.bausystem.features.script.command.logic;
|
||||
|
||||
public class Not {
|
||||
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 Not implements SpecialCommand {
|
||||
|
||||
@Override
|
||||
public String[] description() {
|
||||
return new String[]{
|
||||
"§enot §8<§7Variable§8>",
|
||||
"§enot §8<§7Variable§8> §8<§7Variable§8>",
|
||||
"",
|
||||
"Das logische Nicht von der letzten Variable und schreibe es in die erste."
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String command() {
|
||||
return "not";
|
||||
}
|
||||
|
||||
@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;
|
||||
}
|
||||
|
||||
Value v1 = scriptExecutor.getOrItselfValue(command[command.length - 1]);
|
||||
if (v1.getClass() != Value.BooleanValue.class) {
|
||||
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cNur Booleans können genichtet werden");
|
||||
return true;
|
||||
}
|
||||
scriptExecutor.getLocalVariables().putValue(command[1], new Value.BooleanValue(!v1.asBoolean()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,59 @@
|
||||
package de.steamwar.bausystem.features.script.command.logic;
|
||||
|
||||
public class Or {
|
||||
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 Or implements SpecialCommand {
|
||||
|
||||
@Override
|
||||
public String[] description() {
|
||||
return new String[]{
|
||||
"§eor §8<§7Variable§8> §8<§7Variable§8>",
|
||||
"§eor §8<§7Variable§8> §8<§7Variable§8> §8<§7Variable§8>",
|
||||
"",
|
||||
"Das logische Oder zwischen den letzten beiden Variablen und schreibe es in die erste."
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String command() {
|
||||
return "or";
|
||||
}
|
||||
|
||||
@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.BooleanValue.class) {
|
||||
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cNur Booleans können verglichen werden");
|
||||
return true;
|
||||
}
|
||||
if (v2.getClass() != Value.BooleanValue.class) {
|
||||
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cNur Booleans können verglichen werden");
|
||||
return true;
|
||||
}
|
||||
Value result;
|
||||
if (v1.asBoolean() || v2.asBoolean()) {
|
||||
result = new Value.BooleanValue(true);
|
||||
} else {
|
||||
result = new Value.BooleanValue(false);
|
||||
}
|
||||
|
||||
scriptExecutor.getLocalVariables().putValue(command[1], result);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren