From d497ecf83280e82f123621bddc6df0ca65ff7bd7 Mon Sep 17 00:00:00 2001 From: Lixfel Date: Tue, 22 Sep 2020 17:40:43 +0200 Subject: [PATCH] Lazyly load owner to improve startup time --- .../src/de/steamwar/bausystem/BauSystem.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java index f73a860..18d1f2a 100644 --- a/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java +++ b/BauSystem_Main/src/de/steamwar/bausystem/BauSystem.java @@ -20,9 +20,9 @@ package de.steamwar.bausystem; import de.steamwar.bausystem.commands.*; -import de.steamwar.bausystem.tracer.TraceListener; -import de.steamwar.bausystem.tracer.TNTTracer; import de.steamwar.bausystem.tracer.ShowManager; +import de.steamwar.bausystem.tracer.TNTTracer; +import de.steamwar.bausystem.tracer.TraceListener; import de.steamwar.bausystem.world.*; import de.steamwar.core.CommandRemover; import de.steamwar.core.Core; @@ -68,13 +68,12 @@ public class BauSystem extends JavaPlugin implements Listener { String worldName = Bukkit.getWorlds().get(0).getName(); try{ owner = UUID.fromString(worldName); - sections = ArenaSection.loadFromFile(new File(Bukkit.getWorldContainer().getPath() + '/' + owner.toString() + "/sections.yml")); + sections = ArenaSection.loadFromFile(new File(Bukkit.getWorldContainer().getPath() + '/' + getOwner().toString() + "/sections.yml")); }catch(IllegalArgumentException e){ try{ - int ownerID = Integer.parseInt(worldName); - owner = SteamwarUser.get(ownerID).getUUID(); - sections = ArenaSection.loadFromFile(new File(Bukkit.getWorldContainer().getPath() + '/' + ownerID + "/sections.yml")); - }catch(NumberFormatException | IOException | InvalidConfigurationException ex){ + owner = null; + sections = ArenaSection.loadFromFile(new File(Bukkit.getWorldContainer().getPath() + '/' + worldName + "/sections.yml")); + }catch(IOException | InvalidConfigurationException ex){ getLogger().log(Level.SEVERE, "owner is no UUID / failed to load sections.yml", e); Bukkit.shutdown(); return; @@ -132,13 +131,22 @@ public class BauSystem extends JavaPlugin implements Listener { return plugin; } public static UUID getOwner(){ + //Lazy loading to improve startup time of the server in 1.15 + if(owner == null){ + try{ + owner = SteamwarUser.get(Integer.parseInt(Bukkit.getWorlds().get(0).getName())).getUUID(); + }catch(NumberFormatException e){ + Bukkit.shutdown(); + throw new SecurityException("owner is not a UserID", e); + } + } return owner; } public static List getSections(){ return sections; } public static int getOwnerID(){ - return SteamwarUser.get(owner).getId(); + return SteamwarUser.get(getOwner()).getId(); } @EventHandler