diff --git a/src/main/java/com/dfsek/terra/TerraProfiler.java b/src/main/java/com/dfsek/terra/TerraProfiler.java index 179e51c23..a0b03a9e0 100644 --- a/src/main/java/com/dfsek/terra/TerraProfiler.java +++ b/src/main/java/com/dfsek/terra/TerraProfiler.java @@ -1,17 +1,11 @@ package com.dfsek.terra; -import com.dfsek.terra.generation.TerraChunkGenerator; import org.bukkit.World; import org.polydev.gaea.profiler.DataType; import org.polydev.gaea.profiler.Measurement; import org.polydev.gaea.profiler.WorldProfiler; -import java.util.HashMap; -import java.util.Map; - public class TerraProfiler extends WorldProfiler { - private static final Map profilerMap = new HashMap<>(); - public TerraProfiler(World w) { super(w); this @@ -22,13 +16,4 @@ public class TerraProfiler extends WorldProfiler { .addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "StructureTime") .addMeasurement(new Measurement(1500000, DataType.PERIOD_MILLISECONDS), "ElevationTime"); } - - public static TerraProfiler fromWorld(World w) { - if(w.getGenerator() instanceof TerraChunkGenerator) { - if(profilerMap.containsKey(w)) return profilerMap.get(w); - TerraProfiler p = new TerraProfiler(w); - profilerMap.put(w, p); - return p; - } else throw new IllegalArgumentException("Attempted to instantiate/fetch Profiler for non-Terra world!"); - } } diff --git a/src/main/java/com/dfsek/terra/TerraWorld.java b/src/main/java/com/dfsek/terra/TerraWorld.java index 987a656c3..8d2fa9d92 100644 --- a/src/main/java/com/dfsek/terra/TerraWorld.java +++ b/src/main/java/com/dfsek/terra/TerraWorld.java @@ -18,11 +18,13 @@ public class TerraWorld { private final BiomeZone zone; private final ConfigPack config; private boolean safe; + private final TerraProfiler profiler; public TerraWorld(World w, ConfigPack c) { safe = true; config = c; + profiler = new TerraProfiler(w); ConfigPackTemplate template = config.getTemplate(); @@ -71,4 +73,8 @@ public class TerraWorld { public boolean isSafe() { return safe; } + + public TerraProfiler getProfiler() { + return profiler; + } } diff --git a/src/main/java/com/dfsek/terra/command/profile/QueryCommand.java b/src/main/java/com/dfsek/terra/command/profile/QueryCommand.java index 7360e934c..62f6bc88f 100644 --- a/src/main/java/com/dfsek/terra/command/profile/QueryCommand.java +++ b/src/main/java/com/dfsek/terra/command/profile/QueryCommand.java @@ -1,6 +1,6 @@ package com.dfsek.terra.command.profile; -import com.dfsek.terra.TerraProfiler; +import com.dfsek.terra.Terra; import org.bukkit.World; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -18,8 +18,8 @@ public class QueryCommand extends WorldCommand { } @Override - public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World w) { - WorldProfiler profile = TerraProfiler.fromWorld(w); + public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) { + WorldProfiler profile = ((Terra) getMain()).getWorld(world).getProfiler(); sender.sendMessage(profile.getResultsFormatted()); return true; } diff --git a/src/main/java/com/dfsek/terra/command/profile/ResetCommand.java b/src/main/java/com/dfsek/terra/command/profile/ResetCommand.java index 1efa5f3e8..9ac0b02fe 100644 --- a/src/main/java/com/dfsek/terra/command/profile/ResetCommand.java +++ b/src/main/java/com/dfsek/terra/command/profile/ResetCommand.java @@ -1,6 +1,6 @@ package com.dfsek.terra.command.profile; -import com.dfsek.terra.TerraProfiler; +import com.dfsek.terra.Terra; import com.dfsek.terra.config.lang.LangUtil; import org.bukkit.World; import org.bukkit.command.Command; @@ -20,7 +20,7 @@ public class ResetCommand extends WorldCommand { @Override public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) { - WorldProfiler profile = TerraProfiler.fromWorld(world); + WorldProfiler profile = ((Terra) getMain()).getWorld(world).getProfiler(); profile.reset(); LangUtil.send("command.profile.reset", sender); return true; diff --git a/src/main/java/com/dfsek/terra/command/profile/StartCommand.java b/src/main/java/com/dfsek/terra/command/profile/StartCommand.java index 86df09936..a5f71b0f5 100644 --- a/src/main/java/com/dfsek/terra/command/profile/StartCommand.java +++ b/src/main/java/com/dfsek/terra/command/profile/StartCommand.java @@ -1,6 +1,6 @@ package com.dfsek.terra.command.profile; -import com.dfsek.terra.TerraProfiler; +import com.dfsek.terra.Terra; import com.dfsek.terra.config.lang.LangUtil; import org.bukkit.World; import org.bukkit.command.Command; @@ -20,7 +20,7 @@ public class StartCommand extends WorldCommand { @Override public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) { - WorldProfiler profile = TerraProfiler.fromWorld(world); + WorldProfiler profile = ((Terra) getMain()).getWorld(world).getProfiler(); profile.setProfiling(true); LangUtil.send("command.profile.start", sender); return true; diff --git a/src/main/java/com/dfsek/terra/command/profile/StopCommand.java b/src/main/java/com/dfsek/terra/command/profile/StopCommand.java index e246674ba..dd9921b87 100644 --- a/src/main/java/com/dfsek/terra/command/profile/StopCommand.java +++ b/src/main/java/com/dfsek/terra/command/profile/StopCommand.java @@ -1,6 +1,6 @@ package com.dfsek.terra.command.profile; -import com.dfsek.terra.TerraProfiler; +import com.dfsek.terra.Terra; import com.dfsek.terra.config.lang.LangUtil; import org.bukkit.World; import org.bukkit.command.Command; @@ -20,7 +20,7 @@ public class StopCommand extends WorldCommand { @Override public boolean execute(@NotNull Player sender, @NotNull Command command, @NotNull String label, @NotNull String[] args, World world) { - WorldProfiler profile = TerraProfiler.fromWorld(world); + WorldProfiler profile = ((Terra) getMain()).getWorld(world).getProfiler(); profile.setProfiling(false); LangUtil.send("command.profile.stop", sender); return true; diff --git a/src/main/java/com/dfsek/terra/generation/TerraChunkGenerator.java b/src/main/java/com/dfsek/terra/generation/TerraChunkGenerator.java index dfd1f73b2..da0fd8892 100644 --- a/src/main/java/com/dfsek/terra/generation/TerraChunkGenerator.java +++ b/src/main/java/com/dfsek/terra/generation/TerraChunkGenerator.java @@ -1,7 +1,6 @@ package com.dfsek.terra.generation; import com.dfsek.terra.Terra; -import com.dfsek.terra.TerraProfiler; import com.dfsek.terra.TerraWorld; import com.dfsek.terra.biome.UserDefinedBiome; import com.dfsek.terra.config.base.ConfigPack; @@ -98,7 +97,7 @@ public class TerraChunkGenerator extends GaeaChunkGenerator { org.polydev.gaea.biome.BiomeGrid grid = getBiomeGrid(world); ElevationInterpolator elevationInterpolator; - try(ProfileFuture ignore = TerraProfiler.fromWorld(world).measure("ElevationTime")) { + try(ProfileFuture ignore = tw.getProfiler().measure("ElevationTime")) { elevationInterpolator = new ElevationInterpolator(chunkX, chunkZ, tw.getGrid()); } diff --git a/src/main/java/com/dfsek/terra/population/CavePopulator.java b/src/main/java/com/dfsek/terra/population/CavePopulator.java index 329ca243a..907ddc32a 100644 --- a/src/main/java/com/dfsek/terra/population/CavePopulator.java +++ b/src/main/java/com/dfsek/terra/population/CavePopulator.java @@ -1,7 +1,6 @@ package com.dfsek.terra.population; import com.dfsek.terra.Terra; -import com.dfsek.terra.TerraProfiler; import com.dfsek.terra.TerraWorld; import com.dfsek.terra.carving.UserDefinedCarver; import com.dfsek.terra.config.base.ConfigPack; @@ -36,9 +35,9 @@ public class CavePopulator extends BlockPopulator { @SuppressWarnings("try") @Override public void populate(@NotNull World world, @NotNull Random r, @NotNull Chunk chunk) { - try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("CaveTime")) { + TerraWorld tw = main.getWorld(world); + try(ProfileFuture ignored = tw.getProfiler().measure("CaveTime")) { Random random = PopulationUtil.getRandom(chunk); - TerraWorld tw = main.getWorld(world); if(!tw.isSafe()) return; ConfigPack config = tw.getConfig(); diff --git a/src/main/java/com/dfsek/terra/population/FloraPopulator.java b/src/main/java/com/dfsek/terra/population/FloraPopulator.java index 324179d06..779e7d106 100644 --- a/src/main/java/com/dfsek/terra/population/FloraPopulator.java +++ b/src/main/java/com/dfsek/terra/population/FloraPopulator.java @@ -1,7 +1,6 @@ package com.dfsek.terra.population; import com.dfsek.terra.Terra; -import com.dfsek.terra.TerraProfiler; import com.dfsek.terra.TerraWorld; import com.dfsek.terra.biome.UserDefinedBiome; import com.dfsek.terra.biome.grid.master.TerraBiomeGrid; @@ -32,8 +31,8 @@ public class FloraPopulator extends GaeaBlockPopulator { @SuppressWarnings("try") @Override public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) { - try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("FloraTime")) { - TerraWorld tw = main.getWorld(world); + TerraWorld tw = main.getWorld(world); + try(ProfileFuture ignored = tw.getProfiler().measure("FloraTime")) { if(!tw.isSafe()) return; TerraBiomeGrid grid = tw.getGrid(); Map> layers = new HashMap<>(); diff --git a/src/main/java/com/dfsek/terra/population/OrePopulator.java b/src/main/java/com/dfsek/terra/population/OrePopulator.java index b9ac9a311..4443ae591 100644 --- a/src/main/java/com/dfsek/terra/population/OrePopulator.java +++ b/src/main/java/com/dfsek/terra/population/OrePopulator.java @@ -1,7 +1,6 @@ package com.dfsek.terra.population; import com.dfsek.terra.Terra; -import com.dfsek.terra.TerraProfiler; import com.dfsek.terra.TerraWorld; import com.dfsek.terra.biome.UserDefinedBiome; import com.dfsek.terra.config.templates.BiomeTemplate; @@ -28,8 +27,8 @@ public class OrePopulator extends GaeaBlockPopulator { @SuppressWarnings("try") @Override public void populate(@NotNull World world, @NotNull Random r, @NotNull Chunk chunk) { - try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("OreTime")) { - TerraWorld tw = main.getWorld(world); + TerraWorld tw = main.getWorld(world); + try(ProfileFuture ignored = tw.getProfiler().measure("OreTime")) { if(!tw.isSafe()) return; for(int cx = -1; cx <= 1; cx++) { for(int cz = -1; cz <= 1; cz++) { diff --git a/src/main/java/com/dfsek/terra/population/StructurePopulator.java b/src/main/java/com/dfsek/terra/population/StructurePopulator.java index 482a7aaa2..91ba21b21 100644 --- a/src/main/java/com/dfsek/terra/population/StructurePopulator.java +++ b/src/main/java/com/dfsek/terra/population/StructurePopulator.java @@ -1,7 +1,6 @@ package com.dfsek.terra.population; import com.dfsek.terra.Terra; -import com.dfsek.terra.TerraProfiler; import com.dfsek.terra.TerraWorld; import com.dfsek.terra.biome.UserDefinedBiome; import com.dfsek.terra.biome.grid.master.TerraBiomeGrid; @@ -38,11 +37,11 @@ public class StructurePopulator extends BlockPopulator { @SuppressWarnings("try") @Override public void populate(@NotNull World world, @NotNull Random r, @NotNull Chunk chunk) { - try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("StructureTime")) { + TerraWorld tw = main.getWorld(world); + try(ProfileFuture ignored = tw.getProfiler().measure("StructureTime")) { Random random = PopulationUtil.getRandom(chunk); int cx = (chunk.getX() << 4); int cz = (chunk.getZ() << 4); - TerraWorld tw = main.getWorld(world); if(!tw.isSafe()) return; TerraBiomeGrid grid = tw.getGrid(); ConfigPack config = tw.getConfig(); diff --git a/src/main/java/com/dfsek/terra/population/TreePopulator.java b/src/main/java/com/dfsek/terra/population/TreePopulator.java index db5bc02c1..b2b2a95fe 100644 --- a/src/main/java/com/dfsek/terra/population/TreePopulator.java +++ b/src/main/java/com/dfsek/terra/population/TreePopulator.java @@ -1,7 +1,6 @@ package com.dfsek.terra.population; import com.dfsek.terra.Terra; -import com.dfsek.terra.TerraProfiler; import com.dfsek.terra.TerraWorld; import com.dfsek.terra.biome.UserDefinedBiome; import com.dfsek.terra.biome.grid.master.TerraBiomeGrid; @@ -32,8 +31,8 @@ public class TreePopulator extends GaeaBlockPopulator { @Override @SuppressWarnings("try") public void populate(@NotNull World world, @NotNull Random random, @NotNull Chunk chunk) { - try(ProfileFuture ignored = TerraProfiler.fromWorld(world).measure("TreeTime")) { - TerraWorld tw = main.getWorld(world); + TerraWorld tw = main.getWorld(world); + try(ProfileFuture ignored = tw.getProfiler().measure("TreeTime")) { if(!tw.isSafe()) return; TerraBiomeGrid grid = tw.getGrid(); for(int x = 0; x < 16; x += 2) {