SteamWar/BauSystem2.0
Archiviert
12
0

Add Unvar and Unglobal and Global

Dieser Commit ist enthalten in:
yoyosource 2021-05-01 21:49:28 +02:00
Ursprung f25fa86db9
Commit 194fce7da5
4 geänderte Dateien mit 122 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -1,4 +1,58 @@
package de.steamwar.bausystem.features.script.command.variable;
public class Global {
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 Global implements SpecialCommand {
@Override
public String[] description() {
return new String[]{
"§eglobal §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 "global";
}
@Override
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
if (command.length <= 1) {
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte ein Name");
return true;
}
if (command.length <= 2) {
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte ein Wert");
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.getGlobalVariables().putValue(varName, new Value.BooleanValue(s.equalsIgnoreCase("true")));
} else {
scriptExecutor.getGlobalVariables().putValue(varName, new Value.StringValue(s));
}
}
return true;
}
}

Datei anzeigen

@ -1,4 +1,35 @@
package de.steamwar.bausystem.features.script.command.variable;
public class Unglobal {
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.SpecialCommand;
import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked;
@Linked(LinkageType.SCRIPT_COMMAND)
public class Unglobal implements SpecialCommand {
@Override
public String[] description() {
return new String[]{
"unglobal §8<§7Name§8>",
"",
"Lösche eine Globale variable"
};
}
@Override
public String command() {
return "unglobal";
}
@Override
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
if (command.length <= 1) {
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte ein Name");
return true;
}
scriptExecutor.getGlobalVariables().removeValue(command[1]);
return true;
}
}

Datei anzeigen

@ -1,4 +1,35 @@
package de.steamwar.bausystem.features.script.command.variable;
public class Unvar {
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.SpecialCommand;
import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked;
@Linked(LinkageType.SCRIPT_COMMAND)
public class Unvar implements SpecialCommand {
@Override
public String[] description() {
return new String[]{
"unvar §8<§7Name§8>",
"",
"Lösche eine Locale variable"
};
}
@Override
public String command() {
return "unvar";
}
@Override
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
if (command.length <= 1) {
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte ein Name");
return true;
}
scriptExecutor.getLocalVariables().removeValue(command[1]);
return true;
}
}

Datei anzeigen

@ -1,5 +1,6 @@
package de.steamwar.bausystem.features.script.command.variable;
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;
@ -26,9 +27,11 @@ public class Var implements SpecialCommand {
@Override
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
if (command.length <= 1) {
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte ein Name");
return true;
}
if (command.length <= 2) {
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt und sollte ein Wert");
return true;
}
String varName = command[1];