mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 05:06:44 +01:00
Secondary world loading
This commit is contained in:
parent
a1af1d1ee3
commit
024aa995f6
@ -20,6 +20,7 @@
|
|||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
package com.intellectualcrafters.plot.object;
|
package com.intellectualcrafters.plot.object;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
@ -31,12 +32,12 @@ import org.bukkit.generator.BlockPopulator;
|
|||||||
import org.bukkit.generator.ChunkGenerator;
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotSquared;
|
import com.intellectualcrafters.plot.PlotSquared;
|
||||||
import com.intellectualcrafters.plot.generator.HybridPlotWorld;
|
|
||||||
import com.intellectualcrafters.plot.listeners.WorldEvents;
|
import com.intellectualcrafters.plot.listeners.WorldEvents;
|
||||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||||
|
|
||||||
public abstract class PlotGenerator extends ChunkGenerator {
|
public abstract class PlotGenerator extends ChunkGenerator {
|
||||||
|
|
||||||
|
private boolean loaded = false;
|
||||||
private short[][] result;
|
private short[][] result;
|
||||||
public int X;
|
public int X;
|
||||||
public int Z;
|
public int Z;
|
||||||
@ -49,73 +50,87 @@ public abstract class PlotGenerator extends ChunkGenerator {
|
|||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
@Override
|
@Override
|
||||||
public List<BlockPopulator> getDefaultPopulators(World world) {
|
public List<BlockPopulator> getDefaultPopulators(World world) {
|
||||||
PlotSquared.loadWorld(WorldEvents.getName(world), this);
|
try {
|
||||||
PlotWorld plotworld = PlotSquared.getPlotWorld(WorldEvents.getName(world));
|
if (!loaded) {
|
||||||
if (!plotworld.MOB_SPAWNING) {
|
PlotSquared.loadWorld(WorldEvents.getName(world), this);
|
||||||
if (!plotworld.SPAWN_EGGS) {
|
PlotWorld plotworld = PlotSquared.getPlotWorld(WorldEvents.getName(world));
|
||||||
world.setSpawnFlags(false, false);
|
if (!plotworld.MOB_SPAWNING) {
|
||||||
|
if (!plotworld.SPAWN_EGGS) {
|
||||||
|
world.setSpawnFlags(false, false);
|
||||||
|
}
|
||||||
|
world.setAmbientSpawnLimit(0);
|
||||||
|
world.setAnimalSpawnLimit(0);
|
||||||
|
world.setMonsterSpawnLimit(0);
|
||||||
|
world.setWaterAnimalSpawnLimit(0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
world.setSpawnFlags(true, true);
|
||||||
|
world.setAmbientSpawnLimit(-1);
|
||||||
|
world.setAnimalSpawnLimit(-1);
|
||||||
|
world.setMonsterSpawnLimit(-1);
|
||||||
|
world.setWaterAnimalSpawnLimit(-1);
|
||||||
|
}
|
||||||
|
loaded = true;
|
||||||
|
return (List<BlockPopulator>)(List<?>) getPopulators(WorldEvents.getName(world));
|
||||||
}
|
}
|
||||||
world.setAmbientSpawnLimit(0);
|
|
||||||
world.setAnimalSpawnLimit(0);
|
|
||||||
world.setMonsterSpawnLimit(0);
|
|
||||||
world.setWaterAnimalSpawnLimit(0);
|
|
||||||
}
|
}
|
||||||
else {
|
catch (Exception e) {
|
||||||
world.setSpawnFlags(true, true);
|
e.printStackTrace();
|
||||||
world.setAmbientSpawnLimit(-1);
|
|
||||||
world.setAnimalSpawnLimit(-1);
|
|
||||||
world.setMonsterSpawnLimit(-1);
|
|
||||||
world.setWaterAnimalSpawnLimit(-1);
|
|
||||||
}
|
}
|
||||||
return (List<BlockPopulator>)(List<?>) getPopulators(WorldEvents.getName(world));
|
return new ArrayList<BlockPopulator>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public short[][] generateExtBlockSections(World world, Random r, int cx, int cz, BiomeGrid biomes) {
|
public short[][] generateExtBlockSections(World world, Random r, int cx, int cz, BiomeGrid biomes) {
|
||||||
final int prime = 13;
|
try {
|
||||||
int h = 1;
|
if (!loaded) {
|
||||||
h = (prime * h) + cx;
|
PlotSquared.loadWorld(WorldEvents.getName(world), this);
|
||||||
h = (prime * h) + cz;
|
loaded = true;
|
||||||
this.random.state = h;
|
}
|
||||||
this.result = new short[16][];
|
final int prime = 13;
|
||||||
PlotWorld plotworld = PlotSquared.getPlotWorld(world.getName());
|
int h = 1;
|
||||||
if (plotworld == null) {
|
h = (prime * h) + cx;
|
||||||
plotworld = getNewPlotWorld(world.getName());
|
h = (prime * h) + cz;
|
||||||
PlotSquared.addPlotWorld(world.getName(), plotworld, getPlotManager());
|
this.random.state = h;
|
||||||
}
|
this.result = new short[16][];
|
||||||
Biome biome = Biome.valueOf(plotworld.PLOT_BIOME);
|
this.X = cx << 4;
|
||||||
this.X = cx << 4;
|
this.Z = cz << 4;
|
||||||
this.Z = cz << 4;
|
if (ChunkManager.FORCE_PASTE) {
|
||||||
if (ChunkManager.FORCE_PASTE) {
|
PlotWorld plotworld = PlotSquared.getPlotWorld(world.getName());
|
||||||
for (short x = 0; x < 16; x++) {
|
Biome biome = Biome.valueOf(plotworld.PLOT_BIOME);
|
||||||
for (short z = 0; z < 16; z++) {
|
for (short x = 0; x < 16; x++) {
|
||||||
if (biomes != null) {
|
for (short z = 0; z < 16; z++) {
|
||||||
biomes.setBiome(x, z, biome);
|
if (biomes != null) {
|
||||||
|
biomes.setBiome(x, z, biome);
|
||||||
|
}
|
||||||
|
final PlotLoc loc = new PlotLoc((X + x), (Z + z));
|
||||||
|
final HashMap<Short, Short> blocks = ChunkManager.GENERATE_BLOCKS.get(loc);
|
||||||
|
for (final Entry<Short, Short> entry : blocks.entrySet()) {
|
||||||
|
setBlock(x, entry.getKey(), z, entry.getValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
final PlotLoc loc = new PlotLoc((X + x), (Z + z));
|
}
|
||||||
final HashMap<Short, Short> blocks = ChunkManager.GENERATE_BLOCKS.get(loc);
|
return this.result;
|
||||||
for (final Entry<Short, Short> entry : blocks.entrySet()) {
|
}
|
||||||
setBlock(x, entry.getKey(), z, entry.getValue());
|
generateChunk(world, ChunkManager.CURRENT_PLOT_CLEAR, random, cx, cz, biomes);
|
||||||
|
if (ChunkManager.CURRENT_PLOT_CLEAR != null) {
|
||||||
|
PlotLoc loc;
|
||||||
|
for (Entry<PlotLoc, HashMap<Short, Short>> entry : ChunkManager.GENERATE_BLOCKS.entrySet()) {
|
||||||
|
for (Entry<Short, Short> entry2 : entry.getValue().entrySet()) {
|
||||||
|
loc = entry.getKey();
|
||||||
|
int xx = loc.x - X;
|
||||||
|
int zz = loc.z - Z;
|
||||||
|
if (xx >= 0 && xx < 16) {
|
||||||
|
if (zz >= 0 && zz < 16) {
|
||||||
|
setBlock(xx, entry2.getKey(), zz, entry2.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.result;
|
|
||||||
}
|
}
|
||||||
generateChunk(world, ChunkManager.CURRENT_PLOT_CLEAR, random, cx, cz, biomes);
|
catch (Exception e) {
|
||||||
if (ChunkManager.CURRENT_PLOT_CLEAR != null) {
|
e.printStackTrace();
|
||||||
PlotLoc loc;
|
|
||||||
for (Entry<PlotLoc, HashMap<Short, Short>> entry : ChunkManager.GENERATE_BLOCKS.entrySet()) {
|
|
||||||
for (Entry<Short, Short> entry2 : entry.getValue().entrySet()) {
|
|
||||||
loc = entry.getKey();
|
|
||||||
int xx = loc.x - X;
|
|
||||||
int zz = loc.z - Z;
|
|
||||||
if (xx >= 0 && xx < 16) {
|
|
||||||
if (zz >= 0 && zz < 16) {
|
|
||||||
setBlock(xx, entry2.getKey(), zz, entry2.getValue());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user