diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java index e66a44e75..e1b52f943 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/BukkitMain.java @@ -25,7 +25,6 @@ import com.intellectualcrafters.plot.commands.WE_Anywhere; import com.intellectualcrafters.plot.config.C; import com.intellectualcrafters.plot.config.Settings; import com.intellectualcrafters.plot.database.PlotMeConverter; -import com.intellectualcrafters.plot.events.PlotDeleteEvent; import com.intellectualcrafters.plot.flag.FlagManager; import com.intellectualcrafters.plot.generator.BukkitHybridUtils; import com.intellectualcrafters.plot.generator.HybridGen; @@ -36,7 +35,6 @@ import com.intellectualcrafters.plot.listeners.PlayerEvents; import com.intellectualcrafters.plot.listeners.PlayerEvents_1_8; import com.intellectualcrafters.plot.listeners.PlotPlusListener; import com.intellectualcrafters.plot.listeners.WorldEditListener; -import com.intellectualcrafters.plot.object.PlotId; import com.intellectualcrafters.plot.titles.AbstractTitle; import com.intellectualcrafters.plot.titles.DefaultTitle; import com.intellectualcrafters.plot.util.ChunkManager; @@ -203,7 +201,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { if (!PlotSquared.setupPlotWorld(world, id)) { return null; } - return new HybridGen(world); + return new HybridGen(); } @Override @@ -303,7 +301,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain { if ((gen_plugin != null) && gen_plugin.isEnabled()) { gen_plugin.getDefaultWorldGenerator(world, ""); } else { - new HybridGen(world); + new HybridGen(); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java index b61567a35..a552e75f0 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/PlotSquared.java @@ -219,11 +219,14 @@ public class PlotSquared { } public static void loadWorld(final String world, final PlotGenerator generator) { - if (getPlotWorld(world) != null) { + PlotWorld plotWorld = getPlotWorld(world); + if (plotWorld != null) { + if (generator != null) { + generator.init(plotWorld); + } return; } final Set worlds = (config.contains("worlds") ? config.getConfigurationSection("worlds").getKeys(false) : new HashSet()); - final PlotWorld plotWorld; final PlotGenerator plotGenerator; final PlotManager plotManager; final String path = "worlds." + world; @@ -249,6 +252,7 @@ public class PlotSquared { } // Now add it addPlotWorld(world, plotWorld, plotManager); + generator.init(plotWorld); MainUtil.setupBorder(world); } else { if (!worlds.contains(world)) { @@ -259,7 +263,7 @@ public class PlotSquared { try { final String gen_string = config.getString("worlds." + world + "." + "generator.plugin"); if (gen_string == null) { - new HybridGen(world); + new HybridGen(); } else { IMP.getGenerator(world, gen_string); } @@ -301,6 +305,7 @@ public class PlotSquared { } else if (plotWorld.TYPE == 1) { new AugmentedPopulator(world, gen_class, null, plotWorld.TERRAIN == 2, plotWorld.TERRAIN != 2); } + gen_class.init(plotWorld); } } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/PlotMeConverter.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/PlotMeConverter.java index 1e290decc..5a4f255e9 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/PlotMeConverter.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/database/PlotMeConverter.java @@ -293,7 +293,7 @@ public class PlotMeConverter { Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + actualWorldName + " plugin:PlotSquared"); } else { Bukkit.getServer().unloadWorld(world, true); - final World myworld = WorldCreator.name(actualWorldName).generator(new HybridGen(actualWorldName)).createWorld(); + final World myworld = WorldCreator.name(actualWorldName).generator(new HybridGen()).createWorld(); myworld.save(); } } diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java index 7a4fcf5f5..fc60221ee 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/generator/HybridGen.java @@ -31,7 +31,6 @@ import org.bukkit.World; import org.bukkit.block.Biome; import org.bukkit.generator.BlockPopulator; -import com.intellectualcrafters.plot.PlotSquared; import com.intellectualcrafters.plot.object.ChunkLoc; import com.intellectualcrafters.plot.object.PlotGenerator; import com.intellectualcrafters.plot.object.PlotManager; @@ -59,22 +58,22 @@ public class HybridGen extends PlotGenerator { /** * Some generator specific variables (implementation dependent) */ - final int plotsize; - final int pathsize; - final short wall; - final short wallfilling; - final short roadblock; - final int size; - final Biome biome; - final int roadheight; - final int wallheight; - final int plotheight; - final short[] plotfloors; - final short[] filling; - final short pathWidthLower; - final short pathWidthUpper; + int plotsize; + int pathsize; + short wall; + short wallfilling; + short roadblock; + int size; + Biome biome; + int roadheight; + int wallheight; + int plotheight; + short[] plotfloors; + short[] filling; + short pathWidthLower; + short pathWidthUpper; boolean doState = false; - int maxY; + int maxY = 0; /** * result object is returned for each generated chunk, do stuff to it */ @@ -87,11 +86,13 @@ public class HybridGen extends PlotGenerator { /** * Initialize variables, and create plotworld object used in calculations */ - public HybridGen(final String world) { - super(world); + public void init(PlotWorld plotworld) { if (this.plotworld == null) { - this.plotworld = (HybridPlotWorld) PlotSquared.getPlotWorld(world); + this.plotworld = (HybridPlotWorld) plotworld; } + + System.out.print("INITIALIZING ==================================="); + this.plotsize = this.plotworld.PLOT_WIDTH; this.pathsize = this.plotworld.ROAD_WIDTH; this.roadblock = this.plotworld.ROAD_BLOCK.id; @@ -120,10 +121,12 @@ public class HybridGen extends PlotGenerator { this.pathWidthUpper = (short) (this.pathWidthLower + this.plotsize + 1); this.biome = Biome.valueOf(this.plotworld.PLOT_BIOME); try { - this.maxY = Bukkit.getWorld(world).getMaxHeight(); - } catch (final NullPointerException e) { + this.maxY = Bukkit.getWorld(plotworld.worldname).getMaxHeight(); + } catch (final NullPointerException e) {} + if (this.maxY == 0) { this.maxY = 256; } + } /** @@ -197,8 +200,7 @@ public class HybridGen extends PlotGenerator { /** * Return the block populator */ - @Override - public List getDefaultPopulators(final World world) { + public List getPopulators(final World world) { // disabling spawning for this world if (!this.plotworld.MOB_SPAWNING) { world.setSpawnFlags(false, false); @@ -207,6 +209,9 @@ public class HybridGen extends PlotGenerator { world.setMonsterSpawnLimit(0); world.setWaterAnimalSpawnLimit(0); } + else { + world.setSpawnFlags(true, true); + } // You can have as many populators as you would like, e.g. tree // populator, ore populator return Arrays.asList((BlockPopulator) new HybridPop(this.plotworld)); @@ -233,6 +238,7 @@ public class HybridGen extends PlotGenerator { h = (prime * h) + cz; this.state = h; } + System.out.print(this.maxY); this.result = new short[this.maxY / 16][]; if (this.plotworld.PLOT_BEDROCK) { for (short x = 0; x < 16; x++) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java index 794384555..28813447b 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/PlayerEvents.java @@ -117,21 +117,6 @@ import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; * @author Empire92 */ public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotListener implements Listener { - @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) - public static void onWorldInit(final WorldInitEvent event) { - final World world = event.getWorld(); - final ChunkGenerator gen = world.getGenerator(); - if (gen instanceof PlotGenerator) { - PlotSquared.loadWorld(world.getName(), (PlotGenerator) gen); - } else { - PlotSquared.loadWorld(world.getName(), null); - } - } - - @EventHandler - public void worldLoad(final WorldLoadEvent event) { - UUIDHandler.cacheAll(event.getWorld().getName()); - } @EventHandler public void PlayerCommand(final PlayerCommandPreprocessEvent event) { diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldEvents.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldEvents.java new file mode 100644 index 000000000..4dc9a8513 --- /dev/null +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/listeners/WorldEvents.java @@ -0,0 +1,32 @@ +package com.intellectualcrafters.plot.listeners; + +import org.bukkit.World; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.world.WorldInitEvent; +import org.bukkit.event.world.WorldLoadEvent; +import org.bukkit.generator.ChunkGenerator; + +import com.intellectualcrafters.plot.PlotSquared; +import com.intellectualcrafters.plot.object.PlotGenerator; +import com.intellectualcrafters.plot.util.bukkit.UUIDHandler; + +public class WorldEvents { + @EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true) + public static void onWorldInit(final WorldInitEvent event) { + final World world = event.getWorld(); + final ChunkGenerator gen = world.getGenerator(); + if (gen instanceof PlotGenerator) { + PlotSquared.loadWorld(world.getName(), (PlotGenerator) gen); + } else { + if (PlotSquared.isPlotWorld(world.getName())) { + PlotSquared.loadWorld(world.getName(), null); + } + } + } + + @EventHandler + public void worldLoad(final WorldLoadEvent event) { + UUIDHandler.cacheAll(event.getWorld().getName()); + } +} diff --git a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotGenerator.java b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotGenerator.java index 912711102..78758a4d4 100644 --- a/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotGenerator.java +++ b/PlotSquared/src/main/java/com/intellectualcrafters/plot/object/PlotGenerator.java @@ -20,16 +20,28 @@ //////////////////////////////////////////////////////////////////////////////////////////////////// package com.intellectualcrafters.plot.object; +import java.util.List; + +import org.bukkit.World; +import org.bukkit.generator.BlockPopulator; import org.bukkit.generator.ChunkGenerator; import com.intellectualcrafters.plot.PlotSquared; public abstract class PlotGenerator extends ChunkGenerator { - public PlotGenerator(final String world) { - PlotSquared.loadWorld(world, this); + @Override + public List getDefaultPopulators(World world) { + PlotSquared.loadWorld(world.getName(), this); + return getPopulators(world); } + + public abstract List getPopulators(World world); + + public abstract void init(PlotWorld plotworld); public abstract PlotWorld getNewPlotWorld(final String world); public abstract PlotManager getPlotManager(); + + }