SteamWar/BauSystem
Archiviert
13
0

Lazyly load owner to improve startup time

Dieser Commit ist enthalten in:
Lixfel 2020-09-22 17:40:43 +02:00
Ursprung 2d9c6f76ec
Commit d497ecf832

Datei anzeigen

@ -20,9 +20,9 @@
package de.steamwar.bausystem; package de.steamwar.bausystem;
import de.steamwar.bausystem.commands.*; 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.ShowManager;
import de.steamwar.bausystem.tracer.TNTTracer;
import de.steamwar.bausystem.tracer.TraceListener;
import de.steamwar.bausystem.world.*; import de.steamwar.bausystem.world.*;
import de.steamwar.core.CommandRemover; import de.steamwar.core.CommandRemover;
import de.steamwar.core.Core; import de.steamwar.core.Core;
@ -68,13 +68,12 @@ public class BauSystem extends JavaPlugin implements Listener {
String worldName = Bukkit.getWorlds().get(0).getName(); String worldName = Bukkit.getWorlds().get(0).getName();
try{ try{
owner = UUID.fromString(worldName); 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){ }catch(IllegalArgumentException e){
try{ try{
int ownerID = Integer.parseInt(worldName); owner = null;
owner = SteamwarUser.get(ownerID).getUUID(); sections = ArenaSection.loadFromFile(new File(Bukkit.getWorldContainer().getPath() + '/' + worldName + "/sections.yml"));
sections = ArenaSection.loadFromFile(new File(Bukkit.getWorldContainer().getPath() + '/' + ownerID + "/sections.yml")); }catch(IOException | InvalidConfigurationException ex){
}catch(NumberFormatException | IOException | InvalidConfigurationException ex){
getLogger().log(Level.SEVERE, "owner is no UUID / failed to load sections.yml", e); getLogger().log(Level.SEVERE, "owner is no UUID / failed to load sections.yml", e);
Bukkit.shutdown(); Bukkit.shutdown();
return; return;
@ -132,13 +131,22 @@ public class BauSystem extends JavaPlugin implements Listener {
return plugin; return plugin;
} }
public static UUID getOwner(){ 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; return owner;
} }
public static List<ArenaSection> getSections(){ public static List<ArenaSection> getSections(){
return sections; return sections;
} }
public static int getOwnerID(){ public static int getOwnerID(){
return SteamwarUser.get(owner).getId(); return SteamwarUser.get(getOwner()).getId();
} }
@EventHandler @EventHandler