mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 12:35:15 +01:00
Restructured world loading approach
This commit is contained in:
parent
2e041c8683
commit
e950678230
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<String> worlds = (config.contains("worlds") ? config.getConfigurationSection("worlds").getKeys(false) : new HashSet<String>());
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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<BlockPopulator> getDefaultPopulators(final World world) {
|
||||
public List<BlockPopulator> 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++) {
|
||||
|
@ -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) {
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
@ -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<BlockPopulator> getDefaultPopulators(World world) {
|
||||
PlotSquared.loadWorld(world.getName(), this);
|
||||
return getPopulators(world);
|
||||
}
|
||||
|
||||
public abstract List<BlockPopulator> getPopulators(World world);
|
||||
|
||||
public abstract void init(PlotWorld plotworld);
|
||||
|
||||
public abstract PlotWorld getNewPlotWorld(final String world);
|
||||
|
||||
public abstract PlotManager getPlotManager();
|
||||
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user