From be86b222d10c18e34344a81a504f6fd8a178a254 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 27 Aug 2022 21:22:19 +0200 Subject: [PATCH] Optimize command injection Signed-off-by: yoyosource --- .../src/de/steamwar/bausystem/linkage/LinkageProcessor.java | 4 ++++ .../src/de/steamwar/bausystem/linkage/LinkageType.java | 5 +---- .../steamwar/bausystem/region/loader/PrototypeLoader.java | 5 ----- .../de/steamwar/bausystem/region/loader/RegionLoader.java | 6 ------ 4 files changed, 5 insertions(+), 15 deletions(-) diff --git a/BauSystem_Linkage/src/de/steamwar/bausystem/linkage/LinkageProcessor.java b/BauSystem_Linkage/src/de/steamwar/bausystem/linkage/LinkageProcessor.java index 5c2e83a2..5b5181c3 100644 --- a/BauSystem_Linkage/src/de/steamwar/bausystem/linkage/LinkageProcessor.java +++ b/BauSystem_Linkage/src/de/steamwar/bausystem/linkage/LinkageProcessor.java @@ -185,6 +185,10 @@ public class LinkageProcessor extends AbstractProcessor { }); } + if (linkLines.containsKey(LinkageType.COMMAND)) { + linkLines.get(LinkageType.COMMAND).add(0, "de.steamwar.message.Message message = de.steamwar.bausystem.BauSystem.MESSAGE"); + } + writer.write("package de.steamwar.bausystem.linkage;\n\n"); writer.write("public class LinkageUtils {\n"); for (String s : fields) { diff --git a/BauSystem_Linkage/src/de/steamwar/bausystem/linkage/LinkageType.java b/BauSystem_Linkage/src/de/steamwar/bausystem/linkage/LinkageType.java index 5e7f3c58..551f569a 100644 --- a/BauSystem_Linkage/src/de/steamwar/bausystem/linkage/LinkageType.java +++ b/BauSystem_Linkage/src/de/steamwar/bausystem/linkage/LinkageType.java @@ -19,13 +19,10 @@ package de.steamwar.bausystem.linkage; -import lombok.AllArgsConstructor; -import lombok.RequiredArgsConstructor; - public enum LinkageType { // NORMAL - COMMAND("$.setMessage(de.steamwar.bausystem.BauSystem.MESSAGE)", "de.steamwar.command.SWCommand"), + COMMAND("$.setMessage(message)", "de.steamwar.command.SWCommand"), ENABLE_LINK("$.enable()", null, "de.steamwar.bausystem.linkage.Enable"), DISABLE_LINK("$.disable()", null, "de.steamwar.bausystem.linkage.Disable"), PLAIN(), diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/loader/PrototypeLoader.java b/BauSystem_Main/src/de/steamwar/bausystem/region/loader/PrototypeLoader.java index d1a814a5..851cdcfd 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/loader/PrototypeLoader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/loader/PrototypeLoader.java @@ -19,7 +19,6 @@ package de.steamwar.bausystem.region.loader; -import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.Prototype; import lombok.experimental.UtilityClass; import org.bukkit.Bukkit; @@ -40,11 +39,9 @@ public class PrototypeLoader { public static final File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "prototypes.yapion"); public void load() { - long time = System.currentTimeMillis(); YAPIONObject yapionObject = null; try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file))) { yapionObject = YAPIONParser.parse(bufferedInputStream); - BauSystem.getInstance().getLogger().info("4.1.1 " + (System.currentTimeMillis() - time) + "ms"); } catch (IOException e) { throw new SecurityException(e.getMessage(), e); } @@ -52,7 +49,6 @@ public class PrototypeLoader { if (loaded != null && new YAPIONDiff(loaded, yapionObject).getDiffs().stream().anyMatch(DiffDelete.class::isInstance)) { throw new SecurityException("Version was not the specified version needed."); } - BauSystem.getInstance().getLogger().info("4.1.2 " + (System.currentTimeMillis() - time) + "ms"); loaded = yapionObject; yapionObject.forEach((key, yapionAnyType) -> { @@ -60,6 +56,5 @@ public class PrototypeLoader { new Prototype(key, (YAPIONObject) yapionAnyType); } }); - BauSystem.getInstance().getLogger().info("4.1.3 " + (System.currentTimeMillis() - time) + "ms"); } } diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/loader/RegionLoader.java b/BauSystem_Main/src/de/steamwar/bausystem/region/loader/RegionLoader.java index ff47530f..7a66dbba 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/loader/RegionLoader.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/loader/RegionLoader.java @@ -19,7 +19,6 @@ package de.steamwar.bausystem.region.loader; -import de.steamwar.bausystem.BauSystem; import de.steamwar.bausystem.region.FlagStorage; import de.steamwar.bausystem.region.GlobalRegion; import de.steamwar.bausystem.region.Prototype; @@ -44,11 +43,9 @@ public class RegionLoader { public static final File file = new File(Bukkit.getWorlds().get(0).getWorldFolder(), "regions.yapion"); public void load() { - long time = System.currentTimeMillis(); YAPIONObject yapionObject = null; try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(file))) { yapionObject = YAPIONParser.parse(bufferedInputStream); - BauSystem.getInstance().getLogger().info("4.2.1 " + (System.currentTimeMillis() - time) + "ms"); } catch (IOException e) { throw new SecurityException(e.getMessage(), e); } @@ -56,7 +53,6 @@ public class RegionLoader { if (loaded != null && new YAPIONDiff(loaded, yapionObject).getDiffs().stream().anyMatch(diffBase -> !(diffBase instanceof DiffChange))) { throw new SecurityException("Version was not the specified version needed."); } - BauSystem.getInstance().getLogger().info("4.2.2 " + (System.currentTimeMillis() - time) + "ms"); loaded = yapionObject; YAPIONObject optionsYapionObject = WorldData.getRegionsData(); @@ -78,7 +74,6 @@ public class RegionLoader { Prototype.generateRegion(key, regionConfig, regionData); }); - BauSystem.getInstance().getLogger().info("4.2.3 " + (System.currentTimeMillis() - time) + "ms"); YAPIONObject globalOptions = optionsYapionObject.getObject("global"); if (globalOptions == null) { @@ -92,6 +87,5 @@ public class RegionLoader { flagStorage = new FlagStorage(); } new GlobalRegion(flagStorage, globalOptions); - BauSystem.getInstance().getLogger().info("4.2.4 " + (System.currentTimeMillis() - time) + "ms"); } }