From e9d072b06b93622cf43a3c74f8f1803d7faf3c20 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 27 Apr 2021 20:12:51 +0200 Subject: [PATCH 01/13] Add If Add Jump --- .../features/script/ScriptExecutor.java | 26 +++++++++ .../features/script/SpecialCommand.java | 7 +++ .../features/script/command/Exit.java | 2 +- .../bausystem/features/script/command/If.java | 57 ++++++++++++++++++- .../features/script/command/Jump.java | 34 ++++++++++- .../features/script/command/Sleep.java | 6 +- 6 files changed, 126 insertions(+), 6 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java index 9a13e08d..4b4a862a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/ScriptExecutor.java @@ -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(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/SpecialCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/SpecialCommand.java index 55aa90ed..d001be9e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/SpecialCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/SpecialCommand.java @@ -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 ""; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Exit.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Exit.java index 37dd8257..4c4e6e91 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Exit.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Exit.java @@ -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 diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java index d755c15b..ca803ea0 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java @@ -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; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Jump.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Jump.java index ef4cf61f..7ed5fd64 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Jump.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Jump.java @@ -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; + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Sleep.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Sleep.java index 55f9e363..f3f3e19e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Sleep.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Sleep.java @@ -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]); From 1e9f7e7cf120d1cb124ad000099190f370db412f Mon Sep 17 00:00:00 2001 From: yoyosource Date: Tue, 27 Apr 2021 20:18:04 +0200 Subject: [PATCH 02/13] Fix SpecialCommand.description --- .../bausystem/features/script/SpecialCommand.java | 11 ++--------- .../bausystem/features/script/command/Exit.java | 8 ++++++-- .../bausystem/features/script/command/If.java | 2 +- .../bausystem/features/script/command/Jump.java | 8 ++++++-- .../bausystem/features/script/command/Sleep.java | 8 ++++++-- 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/SpecialCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/SpecialCommand.java index d001be9e..7fcfd937 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/SpecialCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/SpecialCommand.java @@ -2,15 +2,8 @@ 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 ""; + default String[] description() { + return new String[0]; } String command(); diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Exit.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Exit.java index 4c4e6e91..2e2025d1 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Exit.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Exit.java @@ -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 diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java index ca803ea0..24d84d35 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java @@ -11,7 +11,7 @@ import de.steamwar.bausystem.linkage.Linked; public class If implements SpecialCommand { @Override - public String[] descriptions() { + 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>", diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Jump.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Jump.java index 7ed5fd64..60bb28a4 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Jump.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Jump.java @@ -10,8 +10,12 @@ import de.steamwar.bausystem.linkage.Linked; 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."; + 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 diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Sleep.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Sleep.java index f3f3e19e..3e88313f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Sleep.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Sleep.java @@ -11,8 +11,12 @@ import org.bukkit.Bukkit; public class Sleep implements SpecialCommand { @Override - public String description() { - return "§esleep §8<§8Time§8> §8-§7 Pausiert das Ausführen des Scripts. Das erste Argument ist in GameTicks"; + public String[] description() { + return new String[]{ + "§esleep §8<§8Time§8>", + "", + "Pausiert das Ausführen des Scripts. Das erste Argument ist in GameTicks." + }; } @Override From 91cc6bc64cfaf77cfd2bc38447f62928ed4c782d Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 28 Apr 2021 07:42:45 +0200 Subject: [PATCH 03/13] Fix If --- .../bausystem/features/script/command/If.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java index 24d84d35..e6e76504 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java @@ -40,6 +40,16 @@ public class If implements SpecialCommand { return true; } + if (command[2].equals("exists")) { + if (scriptExecutor.isVariable(command[1])) { + setIndex(scriptExecutor, command[3]); + } else { + if (command.length > 4) { + setIndex(scriptExecutor, command[4]); + } + } + } + Value v1 = scriptExecutor.getOrItselfValue(command[1]); Value v2 = scriptExecutor.getOrItselfValue(command[2]); if (v1.getClass() != v2.getClass()) { @@ -50,10 +60,17 @@ public class If implements SpecialCommand { return true; } if (v1.asString().equals(v2.asString())) { - scriptExecutor.setIndex((int) asLong(command[3])); + setIndex(scriptExecutor, command[3]); } else if (command.length > 4) { - scriptExecutor.setIndex((int) asLong(command[4])); + setIndex(scriptExecutor, command[4]); } return true; } + + private void setIndex(ScriptExecutor scriptExecutor, String name) { + int jp = scriptExecutor.jumpPoints.getOrDefault(name, -1); + if (jp != -1) { + scriptExecutor.setIndex(jp); + } + } } From 98dfe9ed114d04016fa3394709a925b9b011df9f Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 28 Apr 2021 08:11:56 +0200 Subject: [PATCH 04/13] Fix If --- .../de/steamwar/bausystem/features/script/command/If.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java index e6e76504..95bd48ed 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java @@ -68,9 +68,7 @@ public class If implements SpecialCommand { } private void setIndex(ScriptExecutor scriptExecutor, String name) { - int jp = scriptExecutor.jumpPoints.getOrDefault(name, -1); - if (jp != -1) { - scriptExecutor.setIndex(jp); - } + Integer jp = scriptExecutor.jumpPoints.getOrDefault(name, null); + if (jp != null) scriptExecutor.setIndex(jp); } } From 6f8ae5ab6d6e730f24ac133e04598207c24211f6 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 28 Apr 2021 08:18:28 +0200 Subject: [PATCH 05/13] Simplify If and Jump --- .../features/script/SpecialCommand.java | 16 ++++++++++++++++ .../bausystem/features/script/command/If.java | 16 ++++++---------- .../bausystem/features/script/command/Jump.java | 7 +------ 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/SpecialCommand.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/SpecialCommand.java index 7fcfd937..5a44dbe9 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/SpecialCommand.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/SpecialCommand.java @@ -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); + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java index 95bd48ed..7f5db48e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/If.java @@ -42,12 +42,13 @@ public class If implements SpecialCommand { if (command[2].equals("exists")) { if (scriptExecutor.isVariable(command[1])) { - setIndex(scriptExecutor, command[3]); + jumpToIndex(scriptExecutor, command[3]); } else { if (command.length > 4) { - setIndex(scriptExecutor, command[4]); + jumpToIndex(scriptExecutor, command[4]); } } + return true; } Value v1 = scriptExecutor.getOrItselfValue(command[1]); @@ -55,20 +56,15 @@ public class If implements SpecialCommand { if (v1.getClass() != v2.getClass()) { // This is intended if (command.length > 4) { - scriptExecutor.setIndex((int) asLong(command[4])); + jumpToIndex(scriptExecutor, command[4]); } return true; } if (v1.asString().equals(v2.asString())) { - setIndex(scriptExecutor, command[3]); + jumpToIndex(scriptExecutor, command[3]); } else if (command.length > 4) { - setIndex(scriptExecutor, command[4]); + jumpToIndex(scriptExecutor, command[4]); } return true; } - - private void setIndex(ScriptExecutor scriptExecutor, String name) { - Integer jp = scriptExecutor.jumpPoints.getOrDefault(name, null); - if (jp != null) scriptExecutor.setIndex(jp); - } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Jump.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Jump.java index 60bb28a4..9c9bcbdc 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Jump.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/Jump.java @@ -29,12 +29,7 @@ public class Jump implements SpecialCommand { 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); + jumpToIndexWithMessage(scriptExecutor, command[1], BauSystem.PREFIX + "§cDer Jump-Point (" + command[1] + ") ist nicht definiert."); return true; } } From ecc207b561fe5bcc5d8299a15eb4d3a7830d8c91 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Wed, 28 Apr 2021 08:35:10 +0200 Subject: [PATCH 06/13] Add Var --- .../features/script/command/variable/Var.java | 53 ++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Var.java b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Var.java index 3335d47f..750f583d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Var.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/script/command/variable/Var.java @@ -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; + } } From 9ba6dade14e3aefaa57379c13e092a7d7b768e4b Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 29 Apr 2021 09:55:51 +0200 Subject: [PATCH 07/13] Bump build.gradle Version for YAPION --- BauSystem_API/build.gradle | 2 +- BauSystem_Main/build.gradle | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/BauSystem_API/build.gradle b/BauSystem_API/build.gradle index 7ae347df..c8ee702d 100644 --- a/BauSystem_API/build.gradle +++ b/BauSystem_API/build.gradle @@ -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") } \ No newline at end of file diff --git a/BauSystem_Main/build.gradle b/BauSystem_Main/build.gradle index af29b7bd..e770792e 100644 --- a/BauSystem_Main/build.gradle +++ b/BauSystem_Main/build.gradle @@ -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' From c9af5326d10acb458ae7fb2e2d77504543d26913 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 29 Apr 2021 10:13:46 +0200 Subject: [PATCH 08/13] Add ConfigConverter --- .../configplayer/ConfigConverter.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigConverter.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigConverter.java b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigConverter.java new file mode 100644 index 00000000..29b6314c --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigConverter.java @@ -0,0 +1,29 @@ +package de.steamwar.bausystem.configplayer; + +import yapion.hierarchy.types.YAPIONObject; + +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 @version 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 @version 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); + +} From 8944a64d6b55c3dc4195ce106b9eadd059f34fb1 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 29 Apr 2021 10:16:28 +0200 Subject: [PATCH 09/13] Add ConfigUpdater Add LinkageType.CONFIG_CONVERTER --- .../bausystem/configplayer/ConfigUpdater.java | 17 +++++++++++++++++ .../steamwar/bausystem/linkage/LinkageType.java | 5 ++++- 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigUpdater.java diff --git a/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigUpdater.java b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigUpdater.java new file mode 100644 index 00000000..cda0c09f --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigUpdater.java @@ -0,0 +1,17 @@ +package de.steamwar.bausystem.configplayer; + +import lombok.experimental.UtilityClass; + +import java.util.HashMap; +import java.util.Map; + +@UtilityClass +public class ConfigUpdater { + + private static final Map CONFIG_CONVERTER_MAP = new HashMap<>(); + + public static void addConfigConverter(ConfigConverter configConverter) { + CONFIG_CONVERTER_MAP.putIfAbsent(configConverter.version(), configConverter); + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageType.java b/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageType.java index faec5262..32f2d4ae 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageType.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageType.java @@ -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; From 9bad0d47b88db81d610ff1928ac9ca7e3caa3cc3 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 29 Apr 2021 10:25:20 +0200 Subject: [PATCH 10/13] Add ConfigCreator --- .../bausystem/configplayer/ConfigCreator.java | 15 ++++++++ .../bausystem/configplayer/ConfigUpdater.java | 36 +++++++++++++++++-- .../bausystem/configplayer/converter/.gitkeep | 0 3 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigCreator.java create mode 100644 BauSystem_Main/src/de/steamwar/bausystem/configplayer/converter/.gitkeep diff --git a/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigCreator.java b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigCreator.java new file mode 100644 index 00000000..1584c495 --- /dev/null +++ b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigCreator.java @@ -0,0 +1,15 @@ +package de.steamwar.bausystem.configplayer; + +import lombok.experimental.UtilityClass; +import yapion.hierarchy.types.YAPIONObject; + +@UtilityClass +public class ConfigCreator { + + public YAPIONObject createDefaultConfig() { + YAPIONObject yapionObject = new YAPIONObject(); + // Any initialising goes into here + return yapionObject; + } + +} diff --git a/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigUpdater.java b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigUpdater.java index cda0c09f..82e8264a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigUpdater.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigUpdater.java @@ -1,12 +1,22 @@ package de.steamwar.bausystem.configplayer; -import lombok.experimental.UtilityClass; +import de.steamwar.bausystem.linkage.LinkageType; +import de.steamwar.bausystem.linkage.Linked; +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; -@UtilityClass -public class ConfigUpdater { +@Linked(LinkageType.LISTENER) +public class ConfigUpdater implements Listener { + + private final Map playerConfigurations = new HashMap<>(); private static final Map CONFIG_CONVERTER_MAP = new HashMap<>(); @@ -14,4 +24,24 @@ public class ConfigUpdater { 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 + } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/configplayer/converter/.gitkeep b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/converter/.gitkeep new file mode 100644 index 00000000..e69de29b From e12bedec6c6f8623b82257ca44b18302f4f4ce12 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 29 Apr 2021 10:30:32 +0200 Subject: [PATCH 11/13] Add ConfigCreator.createDefaultConfig Add ConfigCreator.currentVersion Add ConfigUpdater.update --- .../bausystem/configplayer/ConfigCreator.java | 5 +++++ .../bausystem/configplayer/ConfigUpdater.java | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigCreator.java b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigCreator.java index 1584c495..19b2831f 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigCreator.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigCreator.java @@ -6,8 +6,13 @@ 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; } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigUpdater.java b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigUpdater.java index 82e8264a..c48cd2f2 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigUpdater.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigUpdater.java @@ -44,4 +44,21 @@ public class ConfigUpdater implements Listener { 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) { + return ConfigCreator.createDefaultConfig(); + } + try { + configConverter.update(yapionObject); + } catch (Exception e) { + return ConfigCreator.createDefaultConfig(); + } + version = yapionObject.getPlainValue("@version"); + } + return yapionObject; + } } From ec771d31dee13b54f08a3df832a5dd3ffb42eace Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 29 Apr 2021 10:33:23 +0200 Subject: [PATCH 12/13] Update ConfigUpdater.update --- .../bausystem/configplayer/ConfigUpdater.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigUpdater.java b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigUpdater.java index c48cd2f2..d028ff1d 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigUpdater.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigUpdater.java @@ -2,6 +2,7 @@ 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; @@ -12,10 +13,13 @@ 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 playerConfigurations = new HashMap<>(); private static final Map CONFIG_CONVERTER_MAP = new HashMap<>(); @@ -50,14 +54,21 @@ public class ConfigUpdater implements Listener { 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(); } - version = yapionObject.getPlainValue("@version"); + 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; } From 11d1683b48f78c4dd4e9117fa132180a69e6fb17 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 29 Apr 2021 11:25:44 +0200 Subject: [PATCH 13/13] Add ConfigConverter JavaDoc --- .../steamwar/bausystem/configplayer/ConfigConverter.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigConverter.java b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigConverter.java index 29b6314c..bf9f1fdf 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigConverter.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/configplayer/ConfigConverter.java @@ -2,6 +2,14 @@ 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 { /**