Add If
Add Jump
Dieser Commit ist enthalten in:
Ursprung
d74102b66d
Commit
e9d072b06b
@ -3,6 +3,7 @@ package de.steamwar.bausystem.features.script;
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.features.script.variables.Constants;
|
||||
import de.steamwar.bausystem.features.script.variables.Context;
|
||||
import de.steamwar.bausystem.features.script.variables.Value;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.Bukkit;
|
||||
@ -120,6 +121,31 @@ public final class ScriptExecutor {
|
||||
return s.split(" ");
|
||||
}
|
||||
|
||||
public Value getOrItselfValue(String variable) {
|
||||
if (!isVariable(variable)) {
|
||||
return new Value.StringValue(variable);
|
||||
}
|
||||
|
||||
if (Constants.isConstant(variable)) {
|
||||
return Constants.getConstant(variable, player);
|
||||
}
|
||||
if (globalVariables.hasValue(variable)) {
|
||||
return globalVariables.getValue(variable);
|
||||
}
|
||||
return localVariables.getValue(variable);
|
||||
}
|
||||
|
||||
public String getOrItself(String variable) {
|
||||
if (isVariable(variable)) {
|
||||
return getValue(variable);
|
||||
}
|
||||
return variable;
|
||||
}
|
||||
|
||||
public boolean isVariable(String variable) {
|
||||
return Constants.isConstant(variable) || globalVariables.hasValue(variable) || localVariables.hasValue(variable);
|
||||
}
|
||||
|
||||
public String getValue(String variable) {
|
||||
if (Constants.isConstant(variable)) {
|
||||
return Constants.getConstant(variable, player).asString();
|
||||
|
@ -2,6 +2,13 @@ package de.steamwar.bausystem.features.script;
|
||||
|
||||
public interface SpecialCommand {
|
||||
|
||||
default String[] descriptions() {
|
||||
if (description().equals("")) {
|
||||
return new String[0];
|
||||
}
|
||||
return new String[]{description()};
|
||||
}
|
||||
|
||||
default String description() {
|
||||
return "";
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ public class Exit implements SpecialCommand {
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return "§eexit §8-§7 Beendet das ausführen des Scripts";
|
||||
return "§eexit §8-§7 Beendet das ausführen des Scripts.";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,4 +1,59 @@
|
||||
package de.steamwar.bausystem.features.script.command;
|
||||
|
||||
public class If {
|
||||
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 If implements SpecialCommand {
|
||||
|
||||
@Override
|
||||
public String[] descriptions() {
|
||||
return new String[]{
|
||||
"§eif §8<§7Variable§8/§7Wert§8> §8<§7Variable§8/§7Wert§8> §8<§7Jump-Point§8>",
|
||||
"§eif §8<§7Variable§8/§7Wert§8> §8<§7Variable§8/§7Wert§8> §8<§7Jump-Point§8> §8<§7Jump-Point§8>",
|
||||
"",
|
||||
"§7Springe zu einer Stelle, wenn zwei Werte gleich sind. Oder zu einer anderen, wenn dies nicht der fall ist."
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String command() {
|
||||
return "if";
|
||||
}
|
||||
|
||||
@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 oder ein Wert sein");
|
||||
return true;
|
||||
}
|
||||
if (command.length <= 2) {
|
||||
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas zweite Argument fehlt und sollte eine Variable oder ein Wert sein");
|
||||
return true;
|
||||
}
|
||||
if (command.length <= 3) {
|
||||
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas dritte Argument fehlt und sollte ein Jump-Point sein");
|
||||
return true;
|
||||
}
|
||||
|
||||
Value v1 = scriptExecutor.getOrItselfValue(command[1]);
|
||||
Value v2 = scriptExecutor.getOrItselfValue(command[2]);
|
||||
if (v1.getClass() != v2.getClass()) {
|
||||
// This is intended
|
||||
if (command.length > 4) {
|
||||
scriptExecutor.setIndex((int) asLong(command[4]));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
if (v1.asString().equals(v2.asString())) {
|
||||
scriptExecutor.setIndex((int) asLong(command[3]));
|
||||
} else if (command.length > 4) {
|
||||
scriptExecutor.setIndex((int) asLong(command[4]));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,36 @@
|
||||
package de.steamwar.bausystem.features.script.command;
|
||||
|
||||
public class Jump {
|
||||
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 Jump implements SpecialCommand {
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return "§ejump §8<§7Jump-Point§8> §8- §7Springe zu einer anderen Zeile. Hierbei ist ein Jump-Point eine Zeile mit §8'§7.§8'§7 vor.";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String command() {
|
||||
return "jump";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
|
||||
if (command.length <= 1) {
|
||||
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt");
|
||||
return true;
|
||||
}
|
||||
Integer jumpPoint = scriptExecutor.jumpPoints.getOrDefault(command[1], null);
|
||||
if (jumpPoint == null) {
|
||||
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDer Jump-Point (" + command[1] + ") ist nicht definiert.");
|
||||
return true;
|
||||
}
|
||||
scriptExecutor.setIndex(jumpPoint);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ public class Sleep implements SpecialCommand {
|
||||
|
||||
@Override
|
||||
public String description() {
|
||||
return "§esleep §8-§7 Pausiert das Ausführen des Scripts. Das erste Argument ist eine Zahl und gibt die GameTicks an, die pausiert werden sollen.";
|
||||
return "§esleep §8<§8Time§8> §8-§7 Pausiert das Ausführen des Scripts. Das erste Argument ist in GameTicks";
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -22,8 +22,8 @@ public class Sleep implements SpecialCommand {
|
||||
|
||||
@Override
|
||||
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
|
||||
if (command.length == 0) {
|
||||
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlte");
|
||||
if (command.length <= 1) {
|
||||
scriptExecutor.getPlayer().sendMessage(BauSystem.PREFIX + "§cDas erste Argument fehlt");
|
||||
return true;
|
||||
}
|
||||
long sleepTime = asLong(command[1]);
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren