From 9fb66faa201a2415d44d5f911b6c3ea72c1a3387 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 1 May 2021 18:04:59 +0200 Subject: [PATCH 1/3] Optimize AutostartListener --- .../features/autostart/AutostartListener.java | 3 +++ .../src/de/steamwar/bausystem/region/Region.java | 12 +++++------- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java b/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java index 0f58dfc0..4079ca4b 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/features/autostart/AutostartListener.java @@ -79,6 +79,9 @@ public class AutostartListener implements Listener { @EventHandler public void onEntityExplode(EntityExplodeEvent event) { + if (regionStartTime.isEmpty()) { + return; + } event.blockList().forEach(block -> { Region region = Region.getRegion(block.getLocation()); if (!regionStartTime.containsKey(region)) return; diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java index 8a174ba8..7ddb627e 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -37,10 +37,7 @@ import yapion.hierarchy.types.YAPIONValue; import java.io.File; import java.io.IOException; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; import java.util.function.Predicate; import static de.steamwar.bausystem.region.RegionUtils.paste; @@ -53,14 +50,15 @@ public class Region { public static Region getRegion(Location location) { String s = Thread.currentThread().getStackTrace()[2].toString(); if (!s.contains("sidebar")) { - System.out.println(s +" " + location); + System.out.println(s + " " + location); } - for (Region region : REGION_LIST) { + /*for (Region region : REGION_LIST) { if (region.inRegion(location, region.minPoint, region.maxPoint)) { return region; } } - return GlobalRegion.instance; + return GlobalRegion.instance;*/ + return REGION_LIST.stream().filter(r -> r.inRegion(location, r.minPoint, r.maxPoint)).findFirst().orElse(GlobalRegion.instance); } public static void setGlobal(Flag flagType, Flag.Value value) { From fcba3e32965a95ce8b5eab688a31fa4898bd52ea Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 1 May 2021 18:18:49 +0200 Subject: [PATCH 2/3] Optimize Region.getRegion --- .../src/de/steamwar/bausystem/region/Region.java | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java index 7ddb627e..bd74a3b8 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -48,17 +48,10 @@ public class Region { private static final List REGION_LIST = new ArrayList<>(); public static Region getRegion(Location location) { - String s = Thread.currentThread().getStackTrace()[2].toString(); - if (!s.contains("sidebar")) { - System.out.println(s + " " + location); - } - /*for (Region region : REGION_LIST) { - if (region.inRegion(location, region.minPoint, region.maxPoint)) { - return region; - } - } - return GlobalRegion.instance;*/ - return REGION_LIST.stream().filter(r -> r.inRegion(location, r.minPoint, r.maxPoint)).findFirst().orElse(GlobalRegion.instance); + return REGION_LIST.stream() + .filter(r -> r.inRegion(location, r.minPoint, r.maxPoint)) + .findFirst() + .orElse(GlobalRegion.instance); } public static void setGlobal(Flag flagType, Flag.Value value) { From 77793ce66efbe4dbd3ed6f6e04ae9a693918566f Mon Sep 17 00:00:00 2001 From: yoyosource Date: Sat, 1 May 2021 18:29:17 +0200 Subject: [PATCH 3/3] Optimize Region.getRegion --- BauSystem_Main/src/de/steamwar/bausystem/region/Region.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java index bd74a3b8..8f086715 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/region/Region.java @@ -55,9 +55,7 @@ public class Region { } public static void setGlobal(Flag flagType, Flag.Value value) { - for (Region region : REGION_LIST) { - region.set(flagType, value); - } + REGION_LIST.forEach(region -> region.set(flagType, value)); } YAPIONObject regionData;