From 575882067926ce1f30b05f197e50c7261fd70973 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Fri, 26 Aug 2022 20:45:43 +0200 Subject: [PATCH] Optimize some init stuff Signed-off-by: yoyosource --- BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java | 3 ++- .../src/de/steamwar/bausystem/linkage/LinkageUtils.java | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index 63b52115..b95b6b4c 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -58,7 +58,6 @@ public class BauSystem extends JavaPlugin implements Listener { @Override public void onEnable() { - SWScoreboard.class.getName(); world = Bukkit.getWorlds().get(0); fixBauSystem(); @@ -149,6 +148,8 @@ public class BauSystem extends JavaPlugin implements Listener { Bukkit.shutdown(); return; } + } else { + return; } int number = -1; try { diff --git a/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageUtils.java b/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageUtils.java index 356076d3..fbe361ce 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageUtils.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/linkage/LinkageUtils.java @@ -34,6 +34,7 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.util.*; +import java.util.concurrent.atomic.AtomicLong; import java.util.logging.Level; import java.util.stream.Collectors; @@ -61,10 +62,13 @@ public class LinkageUtils { } private void internalLinkOrUnlink(boolean unlink, Class toLink) { + AtomicLong totalTime = new AtomicLong(); try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(BauSystem.class.getResourceAsStream("/de.steamwar.bausystem/" + toLink.getTypeName().replace("$", "."))))) { bufferedReader.lines().forEach(s -> { try { + long time = System.currentTimeMillis(); linkOrUnlink(Class.forName(s), unlink); + totalTime.addAndGet(System.currentTimeMillis() - time); } catch (ClassNotFoundException e) { // ignored } catch (Exception e) { @@ -76,6 +80,7 @@ public class LinkageUtils { } catch (NullPointerException e) { // Ignored } + BauSystem.getInstance().getLogger().info("Linkage took " + totalTime + "ms"); } private void internalLinkFields() { @@ -101,12 +106,11 @@ public class LinkageUtils { return; } - List linkageTypeList = Arrays.stream(linkages).filter(Objects::nonNull).map(Linked::value).filter(linkageType -> linkageType.getLinkagePredicate().test(clazz)).filter(linkageType -> linkageType.isUnlink() == unlink).collect(Collectors.toList()); + List linkageTypeList = Arrays.stream(linkages).map(Linked::value).filter(linkageType -> linkageType.isUnlink() == unlink).filter(linkageType -> linkageType.getLinkagePredicate().test(clazz)).collect(Collectors.toList()); if (linkageTypeList.isEmpty()) { return; } - linkageTypeList.sort(Comparator.comparingInt(LinkageType::getOrder)); if (unlink) { Object object = objectMap.remove(clazz); if (object == null) {