SteamWar/BauSystem2.0
Archiviert
12
0

Merge remote-tracking branch 'origin/master'

Dieser Commit ist enthalten in:
Chaoscaot 2021-04-30 16:08:06 +02:00
Commit 437229c867
14 geänderte Dateien mit 347 neuen und 14 gelöschten Zeilen

Datei anzeigen

@ -48,5 +48,5 @@ dependencies {
annotationProcessor 'org.projectlombok:lombok:1.18.6'
testAnnotationProcessor 'org.projectlombok:lombok:1.18.6'
compileOnly files("${projectDir}/../lib/Spigot-1.12.jar")
compileOnly files("${projectDir}/../lib/Spigot-1.15.jar")
}

Datei anzeigen

@ -46,7 +46,7 @@ dependencies {
implementation project(":BauSystem_15")
implementation project(":BauSystem_API")
implementation 'yoyosource:YAPION:0.25.1'
implementation 'yoyosource:YAPION:0.25.2'
compileOnly 'org.projectlombok:lombok:1.18.6'
testCompileOnly 'org.projectlombok:lombok:1.18.6'

Datei anzeigen

@ -0,0 +1,37 @@
package de.steamwar.bausystem.configplayer;
import yapion.hierarchy.types.YAPIONObject;
/**
* A new {@link ConfigConverter} should be written when you remove anything
* from the Config or modify any mayor part. When you move anything from
* any key to any other key you should write a new {@link ConfigConverter}.
* For adding any new key you should be able to get the default without
* having it in the Config. Anything you need to change you should also
* change the {@link ConfigCreator} accordingly, to produce the new Config.
*/
public interface ConfigConverter {
/**
* This describes the version this Converter can convert from. The version
* it should convert to is the version 1 above this number. But this is not
* a necessity. In the config Object as parameter given in {@link #update(YAPIONObject)}
* you should update the <b>@version</b> variable in the root object to the
* new version this converter produced.
*
* @return the version number
*/
int version();
/**
* This method should update everything needed to go from a lower config
* version to a higher. It should update the <b>@version</b> variable
* accordingly. Anything else is up the implementation. If anything goes wrong
* do not silently exit this method, throw an Exception. The updater Code will
* deal with it. Never leave the inputted object in a corrupted state.
*
* @param config the config object to update
*/
void update(YAPIONObject config);
}

Datei anzeigen

@ -0,0 +1,20 @@
package de.steamwar.bausystem.configplayer;
import lombok.experimental.UtilityClass;
import yapion.hierarchy.types.YAPIONObject;
@UtilityClass
public class ConfigCreator {
public static final int currentVersion = 1;
public YAPIONObject createDefaultConfig() {
YAPIONObject yapionObject = new YAPIONObject();
// This call should never be touched
yapionObject.add("@version", currentVersion);
// Any initialising goes into here
return yapionObject;
}
}

Datei anzeigen

@ -0,0 +1,75 @@
package de.steamwar.bausystem.configplayer;
import de.steamwar.bausystem.linkage.LinkageType;
import de.steamwar.bausystem.linkage.Linked;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import yapion.hierarchy.types.YAPIONObject;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Level;
@Linked(LinkageType.LISTENER)
public class ConfigUpdater implements Listener {
// TODO: implement everything
private final Map<UUID, YAPIONObject> playerConfigurations = new HashMap<>();
private static final Map<Integer, ConfigConverter> CONFIG_CONVERTER_MAP = new HashMap<>();
public static void addConfigConverter(ConfigConverter configConverter) {
CONFIG_CONVERTER_MAP.putIfAbsent(configConverter.version(), configConverter);
}
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
// Load call -> Database
}
@EventHandler
public void onPlayerQuit(PlayerQuitEvent event) {
// Save call -> Database
}
public YAPIONObject load(Player player) {
if (!playerConfigurations.containsKey(player.getUniqueId())) {
// Load call -> Database
}
return playerConfigurations.get(player.getUniqueId());
}
public void save(Player player) {
// Save call -> Database
}
private YAPIONObject update(YAPIONObject yapionObject) {
int version = yapionObject.getPlainValue("@version");
while (version < ConfigCreator.currentVersion) {
ConfigConverter configConverter = CONFIG_CONVERTER_MAP.getOrDefault(version, null);
if (configConverter == null) {
Bukkit.getLogger().log(Level.SEVERE, "No updater found for version " + version);
return ConfigCreator.createDefaultConfig();
}
try {
configConverter.update(yapionObject);
} catch (Exception e) {
Bukkit.getLogger().log(Level.SEVERE, e.getMessage(), e);
return ConfigCreator.createDefaultConfig();
}
int newVersion = yapionObject.getPlainValue("@version");
if (version == newVersion) {
Bukkit.getLogger().log(Level.SEVERE, "Version Tag was the same after conversion");
return ConfigCreator.createDefaultConfig();
}
version = newVersion;
}
return yapionObject;
}
}

Datei anzeigen

@ -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();

Datei anzeigen

@ -2,8 +2,8 @@ package de.steamwar.bausystem.features.script;
public interface SpecialCommand {
default String description() {
return "";
default String[] description() {
return new String[0];
}
String command();
@ -25,4 +25,20 @@ public interface SpecialCommand {
default String asString(String value) {
return value;
}
default void jumpToIndex(ScriptExecutor scriptExecutor, String jumpPoint) {
scriptExecutor.jumpPoints.computeIfPresent(jumpPoint, (s, integer) -> {
scriptExecutor.setIndex(integer);
return integer;
});
}
default void jumpToIndexWithMessage(ScriptExecutor scriptExecutor, String jumpPoint, String message) {
Integer jp = scriptExecutor.jumpPoints.getOrDefault(jumpPoint, null);
if (jp == null) {
scriptExecutor.getPlayer().sendMessage(message);
return;
}
scriptExecutor.setIndex(jp);
}
}

Datei anzeigen

@ -9,8 +9,12 @@ import de.steamwar.bausystem.linkage.Linked;
public class Exit implements SpecialCommand {
@Override
public String description() {
return "§eexit §8-§7 Beendet das ausführen des Scripts";
public String[] description() {
return new String[]{
"§eexit",
"",
"Beendet das ausführen des Scripts."
};
}
@Override

Datei anzeigen

@ -1,4 +1,70 @@
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[] description() {
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;
}
if (command[2].equals("exists")) {
if (scriptExecutor.isVariable(command[1])) {
jumpToIndex(scriptExecutor, command[3]);
} else {
if (command.length > 4) {
jumpToIndex(scriptExecutor, command[4]);
}
}
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) {
jumpToIndex(scriptExecutor, command[4]);
}
return true;
}
if (v1.asString().equals(v2.asString())) {
jumpToIndex(scriptExecutor, command[3]);
} else if (command.length > 4) {
jumpToIndex(scriptExecutor, command[4]);
}
return true;
}
}

Datei anzeigen

@ -1,4 +1,35 @@
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 new String[]{
"§ejump §8<§7Jump-Point§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;
}
jumpToIndexWithMessage(scriptExecutor, command[1], BauSystem.PREFIX + "§cDer Jump-Point (" + command[1] + ") ist nicht definiert.");
return true;
}
}

Datei anzeigen

@ -11,8 +11,12 @@ import org.bukkit.Bukkit;
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.";
public String[] description() {
return new String[]{
"§esleep §8<§8Time§8>",
"",
"Pausiert das Ausführen des Scripts. Das erste Argument ist in GameTicks."
};
}
@Override
@ -22,8 +26,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]);

Datei anzeigen

@ -1,4 +1,55 @@
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;
}
}

Datei anzeigen

@ -20,6 +20,8 @@
package de.steamwar.bausystem.linkage;
import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.configplayer.ConfigConverter;
import de.steamwar.bausystem.configplayer.ConfigUpdater;
import de.steamwar.bausystem.features.gui.BauGUI;
import de.steamwar.bausystem.features.script.ScriptExecutor;
import de.steamwar.bausystem.features.script.SpecialCommand;
@ -45,7 +47,8 @@ public enum LinkageType {
LISTENER(2, false, Listener.class::isAssignableFrom, o -> Bukkit.getPluginManager().registerEvents((Listener) o, BauSystem.getInstance())),
UNLINK_LISTENER(2, true, Listener.class::isAssignableFrom, o -> HandlerList.unregisterAll((Listener) o)),
GUI_ITEM(3, false, GuiItem.class::isAssignableFrom, o -> BauGUI.addItem((GuiItem) o)),
SCRIPT_COMMAND(4, false, SpecialCommand.class::isAssignableFrom, o -> ScriptExecutor.SPECIAL_COMMANDS.add((SpecialCommand) o));
SCRIPT_COMMAND(4, false, SpecialCommand.class::isAssignableFrom, o -> ScriptExecutor.SPECIAL_COMMANDS.add((SpecialCommand) o)),
CONFIG_CONVERTER(5, false, ConfigConverter.class::isAssignableFrom, o -> ConfigUpdater.addConfigConverter((ConfigConverter) o));
private final int order;