Add Var
Dieser Commit ist enthalten in:
Ursprung
6f8ae5ab6d
Commit
ecc207b561
@ -1,4 +1,55 @@
|
|||||||
package de.steamwar.bausystem.features.script.command.variable;
|
package de.steamwar.bausystem.features.script.command.variable;
|
||||||
|
|
||||||
public class Var {
|
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 Var implements SpecialCommand {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String[] description() {
|
||||||
|
return new String[]{
|
||||||
|
"§evar §8<§7Name§8> §8[§7Value§8(§7s§8)§8]",
|
||||||
|
"",
|
||||||
|
"Schreibt in eine Variable einen Wert rein, welcher eine Zahl sein kann, ein Boolscher Wert oder ein Text."
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String command() {
|
||||||
|
return "var";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
|
||||||
|
if (command.length <= 1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (command.length <= 2) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
String varName = command[1];
|
||||||
|
StringBuilder varValue = new StringBuilder();
|
||||||
|
for (int i = 2; i < command.length; i++) {
|
||||||
|
if (varValue.length() != 0) {
|
||||||
|
varValue.append(" ");
|
||||||
|
}
|
||||||
|
varValue.append(command[i]);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
long value = Long.parseLong(varValue.toString());
|
||||||
|
scriptExecutor.getLocalVariables().putValue(varName, new Value.LongValue(value));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
String s = varValue.toString();
|
||||||
|
if (s.equalsIgnoreCase("true") || s.equalsIgnoreCase("false")) {
|
||||||
|
scriptExecutor.getLocalVariables().putValue(varName, new Value.BooleanValue(s.equalsIgnoreCase("true")));
|
||||||
|
} else {
|
||||||
|
scriptExecutor.getLocalVariables().putValue(varName, new Value.StringValue(s));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
In neuem Issue referenzieren
Einen Benutzer sperren