SteamWar/BauSystem2.0
Archiviert
12
0

Add Convert and Isset and Vartype
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Signed-off-by: yoyosource <yoyosource@nidido.de>
Dieser Commit ist enthalten in:
yoyosource 2021-11-13 17:09:47 +01:00
Ursprung fd601dc9ce
Commit cab26b2592
6 geänderte Dateien mit 223 neuen und 2 gelöschten Zeilen

Datei anzeigen

@ -80,7 +80,7 @@ public class ScriptCommand extends SWCommand {
}); });
swItems.add(new SWListInv.SWListEntry<>(swItem, specialCommand)); swItems.add(new SWListInv.SWListEntry<>(swItem, specialCommand));
}); });
for (int i = 0; i < 9 + 3; i++) { for (int i = 0; i < 9; i++) {
swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7", new ArrayList<>(), false, clickType -> { swItems.add(new SWListInv.SWListEntry<>(new SWItem(Material.GRAY_STAINED_GLASS_PANE, "§7", new ArrayList<>(), false, clickType -> {
}), null)); }), null));
} }

Datei anzeigen

@ -0,0 +1,65 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked;
import org.bukkit.Material;
@Linked(LinkageType.SCRIPT_COMMAND)
public class Convert implements SpecialCommand {
@Override
public String[] description() {
return new String[]{
"§econvert §8<§7Variable§8> §8<§7Value§8>",
"",
"Konvertiere den Value zu 'number' wenn es eine Zahl ist, oder zu 'boolean' bei 'true' oder 'false' und behalte 'text' bei wenn nichts zutrifft.",
};
}
@Override
public Material material() {
return Material.ENDER_CHEST;
}
@Override
public String command() {
return "convert";
}
@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;
}
scriptExecutor.getLocalVariables().putValue(command[1], scriptExecutor.parse(command[2]));
return true;
}
}

Datei anzeigen

@ -0,0 +1,66 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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;
import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked;
import org.bukkit.Material;
@Linked(LinkageType.SCRIPT_COMMAND)
public class Isset implements SpecialCommand {
@Override
public String[] description() {
return new String[]{
"§eisset §8<§7Variable§8> §8<§7Variable§8>",
"",
"Schreibt in eine Variable true/false rein, ob in die zweiten Variable existiert."
};
}
@Override
public Material material() {
return Material.REDSTONE_TORCH;
}
@Override
public String command() {
return "isset";
}
@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;
}
scriptExecutor.getLocalVariables().putValue(command[1], scriptExecutor.isVariable(command[2]) ? new Value.BooleanValue(true) : new Value.BooleanValue(false));
return true;
}
}

Datei anzeigen

@ -0,0 +1,70 @@
/*
* This file is a part of the SteamWar software.
*
* Copyright (C) 2021 SteamWar.de-Serverteam
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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;
import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked;
import org.bukkit.Material;
@Linked(LinkageType.SCRIPT_COMMAND)
public class Vartype implements SpecialCommand {
@Override
public String[] description() {
return new String[]{
"§evartype §8<§7Variable§8> §8<§7Variable§8>",
"",
"Schreibt in eine Variable den Type der zweiten Variable rein. Wenn die zweite Variable nicht gesetzt ist wird false in die erste geschrieben. Ansonsten gibt es die Werte: 'text', 'number' und 'boolean'",
};
}
@Override
public Material material() {
return Material.CHEST;
}
@Override
public String command() {
return "vartype";
}
@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;
}
if (!scriptExecutor.isVariable(command[2])) {
scriptExecutor.getLocalVariables().putValue(command[1], new Value.BooleanValue(false));
}
Value value = scriptExecutor.getOrItselfValue(command[2]);
scriptExecutor.getLocalVariables().putValue(command[1], new Value.StringValue(value.type()));
return true;
}
}

Datei anzeigen

@ -10,7 +10,11 @@ public class Context {
public void putValue(String variableName, Value value) { public void putValue(String variableName, Value value) {
if (variables.containsKey(variableName)) { if (variables.containsKey(variableName)) {
variables.get(variableName).fromValue(value); if (variables.get(variableName).type().equals(value.type())) {
variables.get(variableName).fromValue(value);
} else {
variables.put(variableName, value);
}
} else { } else {
variables.put(variableName, value); variables.put(variableName, value);
} }

Datei anzeigen

@ -4,6 +4,7 @@ import lombok.AllArgsConstructor;
import lombok.ToString; import lombok.ToString;
public interface Value { public interface Value {
String type();
long asLong(); long asLong();
boolean asBoolean(); boolean asBoolean();
String asString(); String asString();
@ -16,6 +17,11 @@ public interface Value {
protected long value; protected long value;
@Override
public String type() {
return "number";
}
@Override @Override
public long asLong() { public long asLong() {
return value; return value;
@ -43,6 +49,11 @@ public interface Value {
protected boolean value; protected boolean value;
@Override
public String type() {
return "boolean";
}
@Override @Override
public long asLong() { public long asLong() {
return value ? 1 : 0; return value ? 1 : 0;
@ -70,6 +81,11 @@ public interface Value {
protected String value; protected String value;
@Override
public String type() {
return "text";
}
@Override @Override
public long asLong() { public long asLong() {
try { try {