Dieser Commit ist enthalten in:
Ursprung
675d0d616e
Commit
e9c7d6cf07
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2022 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;
|
||||
|
||||
import de.steamwar.bausystem.BauSystem;
|
||||
import de.steamwar.bausystem.features.script.expression.Expression;
|
||||
import de.steamwar.linkage.Linked;
|
||||
import lombok.SneakyThrows;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import yapion.hierarchy.output.StringOutput;
|
||||
import yapion.hierarchy.types.YAPIONArray;
|
||||
import yapion.hierarchy.types.YAPIONObject;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@Linked
|
||||
public class ScriptSyntaxSender implements Listener {
|
||||
|
||||
private byte[] syntax;
|
||||
|
||||
{
|
||||
Bukkit.getServer().getMessenger().registerOutgoingPluginChannel(BauSystem.getInstance(), "sw:script_syntax");
|
||||
|
||||
// Whole Syntax object
|
||||
YAPIONObject yapionObject = new YAPIONObject();
|
||||
|
||||
ScriptExecutor.SPECIAL_COMMANDS.toString();
|
||||
|
||||
// Operators
|
||||
YAPIONArray operators = new YAPIONArray();
|
||||
yapionObject.add("@operators", operators);
|
||||
Expression.OPERATORS.forEach((s, operator) -> {
|
||||
operators.add(s);
|
||||
});
|
||||
|
||||
// Headers
|
||||
YAPIONArray headers = new YAPIONArray();
|
||||
yapionObject.add("@headers", headers);
|
||||
headers.add("CMD /.*");
|
||||
headers.add("EVENT " + Arrays.stream(EventType.values()).map(Enum::name).reduce((s, s2) -> s + "|" + s2).map(s -> "(" + s + ")").orElse("") + "( .+)?");
|
||||
headers.add("HOTKEY .+");
|
||||
|
||||
// Variable prefixes
|
||||
YAPIONArray prefixes = new YAPIONArray();
|
||||
yapionObject.add("@prefixes", prefixes);
|
||||
prefixes.add("global");
|
||||
prefixes.add("const");
|
||||
prefixes.add("local");
|
||||
|
||||
// Variable suffixes
|
||||
YAPIONArray suffixes = new YAPIONArray();
|
||||
yapionObject.add("@suffixes", suffixes);
|
||||
suffixes.add("isset");
|
||||
suffixes.add("type");
|
||||
suffixes.add("length");
|
||||
|
||||
// Commands
|
||||
ScriptExecutor.SPECIAL_COMMANDS.forEach(specialCommand -> {
|
||||
YAPIONArray yapionArray = new YAPIONArray();
|
||||
yapionObject.add(specialCommand.command(), yapionArray);
|
||||
if (specialCommand.repeating()) {
|
||||
yapionArray.add(true);
|
||||
} else {
|
||||
yapionArray.add(false);
|
||||
}
|
||||
for (SpecialCommand.TokenType[] types : specialCommand.getSyntax()) {
|
||||
YAPIONArray syntax = new YAPIONArray();
|
||||
yapionArray.add(syntax);
|
||||
for (SpecialCommand.TokenType type : types) {
|
||||
syntax.add(type.ordinal());
|
||||
}
|
||||
}
|
||||
});
|
||||
syntax = yapionObject.toJSONLossy(new StringOutput()).getResult().getBytes();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@SneakyThrows
|
||||
public void onPlayerJoin(PlayerJoinEvent event) {
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), () -> {
|
||||
event.getPlayer().sendPluginMessage(BauSystem.getInstance(), "sw:script_syntax", syntax);
|
||||
}, 5);
|
||||
}
|
||||
}
|
@ -16,6 +16,12 @@ public interface SpecialCommand {
|
||||
|
||||
boolean execute(String[] command, ScriptExecutor scriptExecutor);
|
||||
|
||||
default boolean repeating() {
|
||||
return false;
|
||||
}
|
||||
|
||||
TokenType[][] getSyntax();
|
||||
|
||||
default long asLong(String value) {
|
||||
try {
|
||||
return Long.parseLong(value);
|
||||
@ -65,4 +71,16 @@ public interface SpecialCommand {
|
||||
}
|
||||
scriptExecutor.setIndex(scriptExecutor.getReturnStack().pop());
|
||||
}
|
||||
|
||||
enum TokenType {
|
||||
any, // This does not include jump_point and variable
|
||||
expression,
|
||||
jump_point,
|
||||
variable,
|
||||
|
||||
text_type,
|
||||
number_type,
|
||||
floating_number_type,
|
||||
boolean_type,
|
||||
}
|
||||
}
|
||||
|
@ -37,4 +37,13 @@ public class Call implements SpecialCommand {
|
||||
jumpToIndexWithMessageAndReturnStack(scriptExecutor, command[1], BauSystem.MESSAGE.parse("SCRIPT_COMMAND_CALL_ERROR", scriptExecutor.getPlayer(), command[1]));
|
||||
return true;
|
||||
}
|
||||
|
||||
private TokenType[][] syntax = {
|
||||
{ TokenType.jump_point },
|
||||
};
|
||||
|
||||
@Override
|
||||
public TokenType[][] getSyntax() {
|
||||
return syntax;
|
||||
}
|
||||
}
|
||||
|
@ -31,4 +31,11 @@ public class Exit implements SpecialCommand {
|
||||
public boolean execute(String[] command, ScriptExecutor scriptExecutor) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private TokenType[][] syntax = {};
|
||||
|
||||
@Override
|
||||
public TokenType[][] getSyntax() {
|
||||
return syntax;
|
||||
}
|
||||
}
|
||||
|
@ -53,4 +53,16 @@ public class If implements SpecialCommand {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private TokenType[][] syntax = {
|
||||
{ TokenType.boolean_type, TokenType.jump_point },
|
||||
{ TokenType.boolean_type, TokenType.jump_point, TokenType.jump_point },
|
||||
{ TokenType.expression, TokenType.jump_point },
|
||||
{ TokenType.expression, TokenType.jump_point, TokenType.jump_point }
|
||||
};
|
||||
|
||||
@Override
|
||||
public TokenType[][] getSyntax() {
|
||||
return syntax;
|
||||
}
|
||||
}
|
||||
|
@ -37,4 +37,13 @@ public class Jump implements SpecialCommand {
|
||||
jumpToIndexWithMessage(scriptExecutor, command[1], BauSystem.MESSAGE.parse("SCRIPT_COMMAND_JUMP_ERROR", scriptExecutor.getPlayer(), command[1]));
|
||||
return true;
|
||||
}
|
||||
|
||||
private TokenType[][] syntax = {
|
||||
{ TokenType.jump_point }
|
||||
};
|
||||
|
||||
@Override
|
||||
public TokenType[][] getSyntax() {
|
||||
return syntax;
|
||||
}
|
||||
}
|
||||
|
@ -33,4 +33,11 @@ public class Return implements SpecialCommand {
|
||||
returnFromStackWithMessage(scriptExecutor, BauSystem.MESSAGE.parse("SCRIPT_COMMAND_RETURN_ERROR", scriptExecutor.getPlayer()));
|
||||
return true;
|
||||
}
|
||||
|
||||
private TokenType[][] syntax = {};
|
||||
|
||||
@Override
|
||||
public TokenType[][] getSyntax() {
|
||||
return syntax;
|
||||
}
|
||||
}
|
||||
|
@ -46,4 +46,13 @@ public class Sleep implements SpecialCommand {
|
||||
Bukkit.getScheduler().runTaskLater(BauSystem.getInstance(), scriptExecutor::resume, sleepTime);
|
||||
return false;
|
||||
}
|
||||
|
||||
private TokenType[][] syntax = {
|
||||
{ TokenType.number_type }
|
||||
};
|
||||
|
||||
@Override
|
||||
public TokenType[][] getSyntax() {
|
||||
return syntax;
|
||||
}
|
||||
}
|
||||
|
@ -90,4 +90,18 @@ public class Ceil implements SpecialCommand {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private TokenType[][] syntax = {
|
||||
{ TokenType.variable, TokenType.variable },
|
||||
{ TokenType.variable, TokenType.floating_number_type },
|
||||
{ TokenType.variable, TokenType.variable, TokenType.number_type },
|
||||
{ TokenType.variable, TokenType.floating_number_type, TokenType.number_type },
|
||||
{ TokenType.variable, TokenType.variable, TokenType.variable },
|
||||
{ TokenType.variable, TokenType.floating_number_type, TokenType.variable },
|
||||
};
|
||||
|
||||
@Override
|
||||
public TokenType[][] getSyntax() {
|
||||
return syntax;
|
||||
}
|
||||
}
|
||||
|
@ -90,4 +90,18 @@ public class Floor implements SpecialCommand {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private TokenType[][] syntax = {
|
||||
{ TokenType.variable, TokenType.variable },
|
||||
{ TokenType.variable, TokenType.floating_number_type },
|
||||
{ TokenType.variable, TokenType.variable, TokenType.number_type },
|
||||
{ TokenType.variable, TokenType.floating_number_type, TokenType.number_type },
|
||||
{ TokenType.variable, TokenType.variable, TokenType.variable },
|
||||
{ TokenType.variable, TokenType.floating_number_type, TokenType.variable },
|
||||
};
|
||||
|
||||
@Override
|
||||
public TokenType[][] getSyntax() {
|
||||
return syntax;
|
||||
}
|
||||
}
|
||||
|
@ -90,4 +90,18 @@ public class Round implements SpecialCommand {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private TokenType[][] syntax = {
|
||||
{ TokenType.variable, TokenType.variable },
|
||||
{ TokenType.variable, TokenType.floating_number_type },
|
||||
{ TokenType.variable, TokenType.variable, TokenType.number_type },
|
||||
{ TokenType.variable, TokenType.floating_number_type, TokenType.number_type },
|
||||
{ TokenType.variable, TokenType.variable, TokenType.variable },
|
||||
{ TokenType.variable, TokenType.floating_number_type, TokenType.variable },
|
||||
};
|
||||
|
||||
@Override
|
||||
public TokenType[][] getSyntax() {
|
||||
return syntax;
|
||||
}
|
||||
}
|
||||
|
@ -45,4 +45,18 @@ public class Echo implements SpecialCommand {
|
||||
BauSystem.MESSAGE.send("SCRIPT_COMMAND_IO_ECHO_MESSAGE", scriptExecutor.getPlayer(), ChatColor.translateAlternateColorCodes('&', st.toString()));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean repeating() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private TokenType[][] syntax = {
|
||||
{ TokenType.any },
|
||||
};
|
||||
|
||||
@Override
|
||||
public TokenType[][] getSyntax() {
|
||||
return syntax;
|
||||
}
|
||||
}
|
||||
|
@ -45,4 +45,18 @@ public class Echoactionbar implements SpecialCommand {
|
||||
SWUtils.sendToActionbar(scriptExecutor.getPlayer(), ChatColor.translateAlternateColorCodes('&', st.toString()));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean repeating() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private TokenType[][] syntax = {
|
||||
{ TokenType.any },
|
||||
};
|
||||
|
||||
@Override
|
||||
public TokenType[][] getSyntax() {
|
||||
return syntax;
|
||||
}
|
||||
}
|
||||
|
@ -62,4 +62,18 @@ public class Input implements SpecialCommand {
|
||||
swAnvilInv.open();
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean repeating() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private TokenType[][] syntax = {
|
||||
{ TokenType.variable, TokenType.any },
|
||||
};
|
||||
|
||||
@Override
|
||||
public TokenType[][] getSyntax() {
|
||||
return syntax;
|
||||
}
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ public class Insert implements SpecialCommand {
|
||||
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_ONLY_STRINGS_ALLOWED", scriptExecutor.getPlayer());
|
||||
return true;
|
||||
}
|
||||
if (!(v3 instanceof Value.StringValue)) {
|
||||
if (!(v3 instanceof Value.LongValue)) {
|
||||
BauSystem.MESSAGE.send("SCRIPT_COMMAND_ERROR_ONLY_NUMBERS_ALLOWED", scriptExecutor.getPlayer());
|
||||
return true;
|
||||
}
|
||||
@ -85,4 +85,14 @@ public class Insert implements SpecialCommand {
|
||||
scriptExecutor.getLocalVariables().putValue(resultName, new Value.StringValue(new StringBuilder(v1.asString()).insert((int) v3.asLong(), v2.asString()).toString()));
|
||||
return true;
|
||||
}
|
||||
|
||||
private TokenType[][] syntax = {
|
||||
{ TokenType.variable, TokenType.variable, TokenType.number_type },
|
||||
{ TokenType.variable, TokenType.variable, TokenType.variable, TokenType.number_type },
|
||||
};
|
||||
|
||||
@Override
|
||||
public TokenType[][] getSyntax() {
|
||||
return syntax;
|
||||
}
|
||||
}
|
||||
|
@ -76,4 +76,14 @@ public class Remove implements SpecialCommand {
|
||||
scriptExecutor.getLocalVariables().putValue(resultName, new Value.StringValue(v1.asString().replace(v2.asString(), "")));
|
||||
return true;
|
||||
}
|
||||
|
||||
private TokenType[][] syntax = {
|
||||
{ TokenType.variable, TokenType.variable },
|
||||
{ TokenType.variable, TokenType.variable, TokenType.variable },
|
||||
};
|
||||
|
||||
@Override
|
||||
public TokenType[][] getSyntax() {
|
||||
return syntax;
|
||||
}
|
||||
}
|
||||
|
@ -85,4 +85,14 @@ public class Replace implements SpecialCommand {
|
||||
scriptExecutor.getLocalVariables().putValue(resultName, new Value.StringValue(v1.asString().replace(v2.asString(), v3.asString())));
|
||||
return true;
|
||||
}
|
||||
|
||||
private TokenType[][] syntax = {
|
||||
{ TokenType.variable, TokenType.variable, TokenType.variable },
|
||||
{ TokenType.variable, TokenType.variable, TokenType.variable, TokenType.variable },
|
||||
};
|
||||
|
||||
@Override
|
||||
public TokenType[][] getSyntax() {
|
||||
return syntax;
|
||||
}
|
||||
}
|
||||
|
@ -82,4 +82,14 @@ public class Substring implements SpecialCommand {
|
||||
scriptExecutor.getLocalVariables().putValue(resultName, result);
|
||||
return true;
|
||||
}
|
||||
|
||||
private TokenType[][] syntax = {
|
||||
{ TokenType.variable, TokenType.number_type },
|
||||
{ TokenType.variable, TokenType.variable, TokenType.number_type },
|
||||
};
|
||||
|
||||
@Override
|
||||
public TokenType[][] getSyntax() {
|
||||
return syntax;
|
||||
}
|
||||
}
|
||||
|
@ -70,4 +70,18 @@ public class Const implements SpecialCommand {
|
||||
Constants.getConstant(varName, scriptExecutor.getPlayer()).fromValue(Value.parse(varValue.toString()));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean repeating() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private TokenType[][] syntax = {
|
||||
{ TokenType.variable, TokenType.any },
|
||||
};
|
||||
|
||||
@Override
|
||||
public TokenType[][] getSyntax() {
|
||||
return syntax;
|
||||
}
|
||||
}
|
||||
|
@ -62,4 +62,13 @@ public class Convert implements SpecialCommand {
|
||||
scriptExecutor.getLocalVariables().putValue(command[1], Value.parse(command[2]));
|
||||
return true;
|
||||
}
|
||||
|
||||
private TokenType[][] syntax = {
|
||||
{ TokenType.variable, TokenType.any },
|
||||
};
|
||||
|
||||
@Override
|
||||
public TokenType[][] getSyntax() {
|
||||
return syntax;
|
||||
}
|
||||
}
|
||||
|
@ -50,4 +50,18 @@ public class Global implements SpecialCommand {
|
||||
scriptExecutor.getGlobalVariables().putValue(varName, Value.parse(varValue.toString()));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean repeating() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private TokenType[][] syntax = {
|
||||
{ TokenType.variable, TokenType.any },
|
||||
};
|
||||
|
||||
@Override
|
||||
public TokenType[][] getSyntax() {
|
||||
return syntax;
|
||||
}
|
||||
}
|
||||
|
@ -37,4 +37,13 @@ public class Unglobal implements SpecialCommand {
|
||||
scriptExecutor.getGlobalVariables().removeValue(command[1]);
|
||||
return true;
|
||||
}
|
||||
|
||||
private TokenType[][] syntax = {
|
||||
{ TokenType.variable },
|
||||
};
|
||||
|
||||
@Override
|
||||
public TokenType[][] getSyntax() {
|
||||
return syntax;
|
||||
}
|
||||
}
|
||||
|
@ -37,4 +37,13 @@ public class Unvar implements SpecialCommand {
|
||||
scriptExecutor.getLocalVariables().removeValue(command[1]);
|
||||
return true;
|
||||
}
|
||||
|
||||
private TokenType[][] syntax = {
|
||||
{ TokenType.variable, TokenType.any },
|
||||
};
|
||||
|
||||
@Override
|
||||
public TokenType[][] getSyntax() {
|
||||
return syntax;
|
||||
}
|
||||
}
|
||||
|
@ -50,4 +50,18 @@ public class Var implements SpecialCommand {
|
||||
scriptExecutor.getLocalVariables().putValue(varName, Value.parse(varValue.toString()));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean repeating() {
|
||||
return true;
|
||||
}
|
||||
|
||||
private TokenType[][] syntax = {
|
||||
{ TokenType.variable, TokenType.any },
|
||||
};
|
||||
|
||||
@Override
|
||||
public TokenType[][] getSyntax() {
|
||||
return syntax;
|
||||
}
|
||||
}
|
||||
|
@ -77,4 +77,13 @@ public class GetMaterial implements SpecialCommand {
|
||||
scriptExecutor.getLocalVariables().putValue(command[1], new Value.StringValue(world.getBlockAt(x, y, z).getType().name()));
|
||||
return true;
|
||||
}
|
||||
|
||||
private TokenType[][] syntax = {
|
||||
{ TokenType.variable, TokenType.number_type, TokenType.number_type, TokenType.number_type }
|
||||
};
|
||||
|
||||
@Override
|
||||
public TokenType[][] getSyntax() {
|
||||
return syntax;
|
||||
}
|
||||
}
|
||||
|
@ -80,4 +80,13 @@ public class SetMaterial implements SpecialCommand {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private TokenType[][] syntax = {
|
||||
{ TokenType.variable, TokenType.number_type, TokenType.number_type, TokenType.number_type }
|
||||
};
|
||||
|
||||
@Override
|
||||
public TokenType[][] getSyntax() {
|
||||
return syntax;
|
||||
}
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ public class Expression {
|
||||
|
||||
private static int highestPrecedence = 1;
|
||||
|
||||
private static final Map<String, Operator> OPERATORS = new HashMap<>();
|
||||
public static final Map<String, Operator> OPERATORS = new HashMap<>();
|
||||
|
||||
public static void registerOperator(Operator operator) {
|
||||
highestPrecedence = Math.max(highestPrecedence, operator.getPriority()) + 1;
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren