From cd2ee3421fa6992d09b7e62f5854792c0fdfb330 Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Sun, 16 Jun 2019 06:09:52 +0200 Subject: [PATCH] World loading performance improvement --- .../java/de/erethon/dungeonsxl/world/DWorldCache.java | 8 ++++++++ .../de/erethon/dungeonsxl/world/DWorldListener.java | 10 ++++++++++ 2 files changed, 18 insertions(+) diff --git a/core/src/main/java/de/erethon/dungeonsxl/world/DWorldCache.java b/core/src/main/java/de/erethon/dungeonsxl/world/DWorldCache.java index 1590dfb2..6de705b8 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/world/DWorldCache.java +++ b/core/src/main/java/de/erethon/dungeonsxl/world/DWorldCache.java @@ -187,6 +187,14 @@ public class DWorldCache { return editWorlds; } + /** + * @param world the world + * @return true if the world is a DXL instance, false if not + */ + public boolean isInstance(World world) { + return world.getName().startsWith("DXL_"); + } + /** * @param name the name of the map; can either be the resource name or the instance name * @return if a map with this name exists diff --git a/core/src/main/java/de/erethon/dungeonsxl/world/DWorldListener.java b/core/src/main/java/de/erethon/dungeonsxl/world/DWorldListener.java index 6f52a968..961e4289 100644 --- a/core/src/main/java/de/erethon/dungeonsxl/world/DWorldListener.java +++ b/core/src/main/java/de/erethon/dungeonsxl/world/DWorldListener.java @@ -23,6 +23,7 @@ import de.erethon.caliburn.mob.ExMob; import de.erethon.dungeonsxl.DungeonsXL; import de.erethon.dungeonsxl.game.Game; import java.util.Set; +import org.bukkit.World; import org.bukkit.block.Block; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; @@ -41,6 +42,7 @@ import org.bukkit.event.hanging.HangingBreakEvent; import org.bukkit.event.player.PlayerArmorStandManipulateEvent; import org.bukkit.event.player.PlayerInteractEntityEvent; import org.bukkit.event.weather.WeatherChangeEvent; +import org.bukkit.event.world.WorldInitEvent; /** * @author Daniel Saukel, Frank Baumann, Milan Albrecht @@ -55,6 +57,14 @@ public class DWorldListener implements Listener { dWorlds = plugin.getDWorldCache(); } + @EventHandler(priority = EventPriority.HIGHEST) + public void onInit(WorldInitEvent event) { + World world = event.getWorld(); + if (dWorlds.isInstance(world)) { + world.setKeepSpawnInMemory(false); + } + } + @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) public void onBlockBreak(BlockBreakEvent event) { Block block = event.getBlock();