mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-01-19 16:59:36 +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.C;
|
||||||
import com.intellectualcrafters.plot.config.Settings;
|
import com.intellectualcrafters.plot.config.Settings;
|
||||||
import com.intellectualcrafters.plot.database.PlotMeConverter;
|
import com.intellectualcrafters.plot.database.PlotMeConverter;
|
||||||
import com.intellectualcrafters.plot.events.PlotDeleteEvent;
|
|
||||||
import com.intellectualcrafters.plot.flag.FlagManager;
|
import com.intellectualcrafters.plot.flag.FlagManager;
|
||||||
import com.intellectualcrafters.plot.generator.BukkitHybridUtils;
|
import com.intellectualcrafters.plot.generator.BukkitHybridUtils;
|
||||||
import com.intellectualcrafters.plot.generator.HybridGen;
|
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.PlayerEvents_1_8;
|
||||||
import com.intellectualcrafters.plot.listeners.PlotPlusListener;
|
import com.intellectualcrafters.plot.listeners.PlotPlusListener;
|
||||||
import com.intellectualcrafters.plot.listeners.WorldEditListener;
|
import com.intellectualcrafters.plot.listeners.WorldEditListener;
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
|
||||||
import com.intellectualcrafters.plot.titles.AbstractTitle;
|
import com.intellectualcrafters.plot.titles.AbstractTitle;
|
||||||
import com.intellectualcrafters.plot.titles.DefaultTitle;
|
import com.intellectualcrafters.plot.titles.DefaultTitle;
|
||||||
import com.intellectualcrafters.plot.util.ChunkManager;
|
import com.intellectualcrafters.plot.util.ChunkManager;
|
||||||
@ -203,7 +201,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
|||||||
if (!PlotSquared.setupPlotWorld(world, id)) {
|
if (!PlotSquared.setupPlotWorld(world, id)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return new HybridGen(world);
|
return new HybridGen();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -303,7 +301,7 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
|||||||
if ((gen_plugin != null) && gen_plugin.isEnabled()) {
|
if ((gen_plugin != null) && gen_plugin.isEnabled()) {
|
||||||
gen_plugin.getDefaultWorldGenerator(world, "");
|
gen_plugin.getDefaultWorldGenerator(world, "");
|
||||||
} else {
|
} else {
|
||||||
new HybridGen(world);
|
new HybridGen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -219,11 +219,14 @@ public class PlotSquared {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void loadWorld(final String world, final PlotGenerator generator) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
final Set<String> worlds = (config.contains("worlds") ? config.getConfigurationSection("worlds").getKeys(false) : new HashSet<String>());
|
final Set<String> worlds = (config.contains("worlds") ? config.getConfigurationSection("worlds").getKeys(false) : new HashSet<String>());
|
||||||
final PlotWorld plotWorld;
|
|
||||||
final PlotGenerator plotGenerator;
|
final PlotGenerator plotGenerator;
|
||||||
final PlotManager plotManager;
|
final PlotManager plotManager;
|
||||||
final String path = "worlds." + world;
|
final String path = "worlds." + world;
|
||||||
@ -249,6 +252,7 @@ public class PlotSquared {
|
|||||||
}
|
}
|
||||||
// Now add it
|
// Now add it
|
||||||
addPlotWorld(world, plotWorld, plotManager);
|
addPlotWorld(world, plotWorld, plotManager);
|
||||||
|
generator.init(plotWorld);
|
||||||
MainUtil.setupBorder(world);
|
MainUtil.setupBorder(world);
|
||||||
} else {
|
} else {
|
||||||
if (!worlds.contains(world)) {
|
if (!worlds.contains(world)) {
|
||||||
@ -259,7 +263,7 @@ public class PlotSquared {
|
|||||||
try {
|
try {
|
||||||
final String gen_string = config.getString("worlds." + world + "." + "generator.plugin");
|
final String gen_string = config.getString("worlds." + world + "." + "generator.plugin");
|
||||||
if (gen_string == null) {
|
if (gen_string == null) {
|
||||||
new HybridGen(world);
|
new HybridGen();
|
||||||
} else {
|
} else {
|
||||||
IMP.getGenerator(world, gen_string);
|
IMP.getGenerator(world, gen_string);
|
||||||
}
|
}
|
||||||
@ -301,6 +305,7 @@ public class PlotSquared {
|
|||||||
} else if (plotWorld.TYPE == 1) {
|
} else if (plotWorld.TYPE == 1) {
|
||||||
new AugmentedPopulator(world, gen_class, null, plotWorld.TERRAIN == 2, plotWorld.TERRAIN != 2);
|
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");
|
Bukkit.getServer().dispatchCommand(Bukkit.getServer().getConsoleSender(), "mw create " + actualWorldName + " plugin:PlotSquared");
|
||||||
} else {
|
} else {
|
||||||
Bukkit.getServer().unloadWorld(world, true);
|
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();
|
myworld.save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,6 @@ import org.bukkit.World;
|
|||||||
import org.bukkit.block.Biome;
|
import org.bukkit.block.Biome;
|
||||||
import org.bukkit.generator.BlockPopulator;
|
import org.bukkit.generator.BlockPopulator;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PlotSquared;
|
|
||||||
import com.intellectualcrafters.plot.object.ChunkLoc;
|
import com.intellectualcrafters.plot.object.ChunkLoc;
|
||||||
import com.intellectualcrafters.plot.object.PlotGenerator;
|
import com.intellectualcrafters.plot.object.PlotGenerator;
|
||||||
import com.intellectualcrafters.plot.object.PlotManager;
|
import com.intellectualcrafters.plot.object.PlotManager;
|
||||||
@ -59,22 +58,22 @@ public class HybridGen extends PlotGenerator {
|
|||||||
/**
|
/**
|
||||||
* Some generator specific variables (implementation dependent)
|
* Some generator specific variables (implementation dependent)
|
||||||
*/
|
*/
|
||||||
final int plotsize;
|
int plotsize;
|
||||||
final int pathsize;
|
int pathsize;
|
||||||
final short wall;
|
short wall;
|
||||||
final short wallfilling;
|
short wallfilling;
|
||||||
final short roadblock;
|
short roadblock;
|
||||||
final int size;
|
int size;
|
||||||
final Biome biome;
|
Biome biome;
|
||||||
final int roadheight;
|
int roadheight;
|
||||||
final int wallheight;
|
int wallheight;
|
||||||
final int plotheight;
|
int plotheight;
|
||||||
final short[] plotfloors;
|
short[] plotfloors;
|
||||||
final short[] filling;
|
short[] filling;
|
||||||
final short pathWidthLower;
|
short pathWidthLower;
|
||||||
final short pathWidthUpper;
|
short pathWidthUpper;
|
||||||
boolean doState = false;
|
boolean doState = false;
|
||||||
int maxY;
|
int maxY = 0;
|
||||||
/**
|
/**
|
||||||
* result object is returned for each generated chunk, do stuff to it
|
* 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
|
* Initialize variables, and create plotworld object used in calculations
|
||||||
*/
|
*/
|
||||||
public HybridGen(final String world) {
|
public void init(PlotWorld plotworld) {
|
||||||
super(world);
|
|
||||||
if (this.plotworld == null) {
|
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.plotsize = this.plotworld.PLOT_WIDTH;
|
||||||
this.pathsize = this.plotworld.ROAD_WIDTH;
|
this.pathsize = this.plotworld.ROAD_WIDTH;
|
||||||
this.roadblock = this.plotworld.ROAD_BLOCK.id;
|
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.pathWidthUpper = (short) (this.pathWidthLower + this.plotsize + 1);
|
||||||
this.biome = Biome.valueOf(this.plotworld.PLOT_BIOME);
|
this.biome = Biome.valueOf(this.plotworld.PLOT_BIOME);
|
||||||
try {
|
try {
|
||||||
this.maxY = Bukkit.getWorld(world).getMaxHeight();
|
this.maxY = Bukkit.getWorld(plotworld.worldname).getMaxHeight();
|
||||||
} catch (final NullPointerException e) {
|
} catch (final NullPointerException e) {}
|
||||||
|
if (this.maxY == 0) {
|
||||||
this.maxY = 256;
|
this.maxY = 256;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -197,8 +200,7 @@ public class HybridGen extends PlotGenerator {
|
|||||||
/**
|
/**
|
||||||
* Return the block populator
|
* Return the block populator
|
||||||
*/
|
*/
|
||||||
@Override
|
public List<BlockPopulator> getPopulators(final World world) {
|
||||||
public List<BlockPopulator> getDefaultPopulators(final World world) {
|
|
||||||
// disabling spawning for this world
|
// disabling spawning for this world
|
||||||
if (!this.plotworld.MOB_SPAWNING) {
|
if (!this.plotworld.MOB_SPAWNING) {
|
||||||
world.setSpawnFlags(false, false);
|
world.setSpawnFlags(false, false);
|
||||||
@ -207,6 +209,9 @@ public class HybridGen extends PlotGenerator {
|
|||||||
world.setMonsterSpawnLimit(0);
|
world.setMonsterSpawnLimit(0);
|
||||||
world.setWaterAnimalSpawnLimit(0);
|
world.setWaterAnimalSpawnLimit(0);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
world.setSpawnFlags(true, true);
|
||||||
|
}
|
||||||
// You can have as many populators as you would like, e.g. tree
|
// You can have as many populators as you would like, e.g. tree
|
||||||
// populator, ore populator
|
// populator, ore populator
|
||||||
return Arrays.asList((BlockPopulator) new HybridPop(this.plotworld));
|
return Arrays.asList((BlockPopulator) new HybridPop(this.plotworld));
|
||||||
@ -233,6 +238,7 @@ public class HybridGen extends PlotGenerator {
|
|||||||
h = (prime * h) + cz;
|
h = (prime * h) + cz;
|
||||||
this.state = h;
|
this.state = h;
|
||||||
}
|
}
|
||||||
|
System.out.print(this.maxY);
|
||||||
this.result = new short[this.maxY / 16][];
|
this.result = new short[this.maxY / 16][];
|
||||||
if (this.plotworld.PLOT_BEDROCK) {
|
if (this.plotworld.PLOT_BEDROCK) {
|
||||||
for (short x = 0; x < 16; x++) {
|
for (short x = 0; x < 16; x++) {
|
||||||
|
@ -117,21 +117,6 @@ import com.intellectualcrafters.plot.util.bukkit.UUIDHandler;
|
|||||||
* @author Empire92
|
* @author Empire92
|
||||||
*/
|
*/
|
||||||
public class PlayerEvents extends com.intellectualcrafters.plot.listeners.PlotListener implements Listener {
|
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
|
@EventHandler
|
||||||
public void PlayerCommand(final PlayerCommandPreprocessEvent event) {
|
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;
|
package com.intellectualcrafters.plot.object;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.bukkit.World;
|
||||||
|
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;
|
||||||
|
|
||||||
public abstract class PlotGenerator extends ChunkGenerator {
|
public abstract class PlotGenerator extends ChunkGenerator {
|
||||||
public PlotGenerator(final String world) {
|
@Override
|
||||||
PlotSquared.loadWorld(world, this);
|
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 PlotWorld getNewPlotWorld(final String world);
|
||||||
|
|
||||||
public abstract PlotManager getPlotManager();
|
public abstract PlotManager getPlotManager();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user