mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-29 13:05:41 +01:00
Restructure generators
This commit is contained in:
parent
a3d5326da3
commit
042a295a55
@ -7,6 +7,7 @@ import org.bukkit.generator.ChunkGenerator;
|
|||||||
|
|
||||||
import com.intellectualcrafters.plot.config.C;
|
import com.intellectualcrafters.plot.config.C;
|
||||||
import com.intellectualcrafters.plot.generator.HybridUtils;
|
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||||
|
import com.intellectualcrafters.plot.generator.PlotGenerator2;
|
||||||
import com.plotsquared.bukkit.listeners.APlotListener;
|
import com.plotsquared.bukkit.listeners.APlotListener;
|
||||||
import com.intellectualcrafters.plot.object.PlotPlayer;
|
import com.intellectualcrafters.plot.object.PlotPlayer;
|
||||||
import com.intellectualcrafters.plot.util.BlockManager;
|
import com.intellectualcrafters.plot.util.BlockManager;
|
||||||
@ -70,7 +71,7 @@ public interface IPlotMain {
|
|||||||
|
|
||||||
public void unregister(PlotPlayer player);
|
public void unregister(PlotPlayer player);
|
||||||
|
|
||||||
public ChunkGenerator getGenerator(String world, String name);
|
public PlotGenerator2<?> getGenerator(String world, String name);
|
||||||
|
|
||||||
public APlotListener initPlotListener();
|
public APlotListener initPlotListener();
|
||||||
|
|
||||||
|
@ -844,12 +844,12 @@ public class PS {
|
|||||||
if (ClusterManager.getClusters(world).size() > 0) {
|
if (ClusterManager.getClusters(world).size() > 0) {
|
||||||
for (final PlotCluster cluster : ClusterManager.getClusters(world)) {
|
for (final PlotCluster cluster : ClusterManager.getClusters(world)) {
|
||||||
log(C.PREFIX.s() + "&3 - &7| cluster: " + cluster);
|
log(C.PREFIX.s() + "&3 - &7| cluster: " + cluster);
|
||||||
generator.augment(generator.getName(), cluster, plotWorld);
|
generator.augment(cluster, plotWorld);
|
||||||
// new AugmentedPopulator(world, generator, cluster, plotWorld.TERRAIN == 2, plotWorld.TERRAIN != 2);
|
// new AugmentedPopulator(world, generator, cluster, plotWorld.TERRAIN == 2, plotWorld.TERRAIN != 2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (plotWorld.TYPE == 1) {
|
} else if (plotWorld.TYPE == 1) {
|
||||||
generator.augment(generator.getName(), null, plotWorld);
|
generator.augment(null, plotWorld);
|
||||||
// new AugmentedPopulator(world, gen_class, null, plotWorld.TERRAIN == 2, plotWorld.TERRAIN != 2);
|
// new AugmentedPopulator(world, gen_class, null, plotWorld.TERRAIN == 2, plotWorld.TERRAIN != 2);
|
||||||
}
|
}
|
||||||
generator.initialize(plotWorld);
|
generator.initialize(plotWorld);
|
||||||
|
@ -4,11 +4,13 @@ import com.intellectualcrafters.plot.object.PlotCluster;
|
|||||||
import com.intellectualcrafters.plot.object.PlotManager;
|
import com.intellectualcrafters.plot.object.PlotManager;
|
||||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||||
|
|
||||||
public abstract class PlotGenerator2 {
|
public abstract class PlotGenerator2<T> {
|
||||||
public final String world;
|
public final String world;
|
||||||
|
public T generator;
|
||||||
|
|
||||||
public PlotGenerator2(String world) {
|
public PlotGenerator2(String world, T generator) {
|
||||||
this.world = world;
|
this.world = world;
|
||||||
|
this.generator = generator;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract void initialize(PlotWorld plotworld);
|
public abstract void initialize(PlotWorld plotworld);
|
||||||
@ -22,7 +24,7 @@ public abstract class PlotGenerator2 {
|
|||||||
* @param cluster Will be the cluster, or null
|
* @param cluster Will be the cluster, or null
|
||||||
* @param plotworld
|
* @param plotworld
|
||||||
*/
|
*/
|
||||||
public abstract void augment(String generator, PlotCluster cluster, PlotWorld plotworld);
|
public abstract void augment(PlotCluster cluster, PlotWorld plotworld);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -10,6 +10,9 @@ import com.plotsquared.bukkit.database.plotme.LikePlotMeConverter;
|
|||||||
import com.plotsquared.bukkit.database.plotme.PlotMeConnector_017;
|
import com.plotsquared.bukkit.database.plotme.PlotMeConnector_017;
|
||||||
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.PlotGenerator2;
|
||||||
|
import com.plotsquared.bukkit.generator.BukkitGeneratorWrapper;
|
||||||
|
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
||||||
import com.plotsquared.bukkit.generator.HybridGen;
|
import com.plotsquared.bukkit.generator.HybridGen;
|
||||||
import com.intellectualcrafters.plot.generator.HybridUtils;
|
import com.intellectualcrafters.plot.generator.HybridUtils;
|
||||||
import com.plotsquared.bukkit.listeners.*;
|
import com.plotsquared.bukkit.listeners.*;
|
||||||
@ -472,13 +475,15 @@ public class BukkitMain extends JavaPlugin implements Listener, IPlotMain {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ChunkGenerator getGenerator(final String world, final String name) {
|
public BukkitGeneratorWrapper getGenerator(final String world, final String name) {
|
||||||
final Plugin gen_plugin = Bukkit.getPluginManager().getPlugin(name);
|
final Plugin gen_plugin = Bukkit.getPluginManager().getPlugin(name);
|
||||||
|
ChunkGenerator gen;
|
||||||
if ((gen_plugin != null) && gen_plugin.isEnabled()) {
|
if ((gen_plugin != null) && gen_plugin.isEnabled()) {
|
||||||
return gen_plugin.getDefaultWorldGenerator(world, "");
|
gen = gen_plugin.getDefaultWorldGenerator(world, "");
|
||||||
} else {
|
} else {
|
||||||
return new HybridGen(world);
|
gen = new HybridGen(world);
|
||||||
}
|
}
|
||||||
|
return new BukkitGeneratorWrapper(world, gen);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -15,7 +15,6 @@ import com.intellectualcrafters.plot.PS;
|
|||||||
import com.plotsquared.bukkit.object.BlockWrapper;
|
import com.plotsquared.bukkit.object.BlockWrapper;
|
||||||
import com.intellectualcrafters.plot.object.Location;
|
import com.intellectualcrafters.plot.object.Location;
|
||||||
import com.intellectualcrafters.plot.object.PlotCluster;
|
import com.intellectualcrafters.plot.object.PlotCluster;
|
||||||
import com.plotsquared.bukkit.object.PlotGenerator;
|
|
||||||
import com.intellectualcrafters.plot.object.PlotId;
|
import com.intellectualcrafters.plot.object.PlotId;
|
||||||
import com.intellectualcrafters.plot.object.PlotLoc;
|
import com.intellectualcrafters.plot.object.PlotLoc;
|
||||||
import com.intellectualcrafters.plot.object.PlotManager;
|
import com.intellectualcrafters.plot.object.PlotManager;
|
||||||
@ -32,7 +31,7 @@ public class AugmentedPopulator extends BlockPopulator {
|
|||||||
public static short[][] z_loc;
|
public static short[][] z_loc;
|
||||||
public final PlotWorld plotworld;
|
public final PlotWorld plotworld;
|
||||||
public final PlotManager manager;
|
public final PlotManager manager;
|
||||||
public final PlotGenerator generator;
|
public final BukkitPlotGenerator generator;
|
||||||
public final PlotCluster cluster;
|
public final PlotCluster cluster;
|
||||||
public final Random r = new Random();
|
public final Random r = new Random();
|
||||||
public final boolean p;
|
public final boolean p;
|
||||||
@ -43,7 +42,7 @@ public class AugmentedPopulator extends BlockPopulator {
|
|||||||
private final int tx;
|
private final int tx;
|
||||||
private final int tz;
|
private final int tz;
|
||||||
|
|
||||||
public AugmentedPopulator(final String world, final PlotGenerator generator, final PlotCluster cluster, final boolean p, final boolean b) {
|
public AugmentedPopulator(final String world, final BukkitPlotGenerator generator, final PlotCluster cluster, final boolean p, final boolean b) {
|
||||||
initCache();
|
initCache();
|
||||||
this.cluster = cluster;
|
this.cluster = cluster;
|
||||||
this.generator = generator;
|
this.generator = generator;
|
||||||
|
@ -0,0 +1,84 @@
|
|||||||
|
package com.plotsquared.bukkit.generator;
|
||||||
|
|
||||||
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
|
|
||||||
|
import com.intellectualcrafters.plot.PS;
|
||||||
|
import com.intellectualcrafters.plot.generator.PlotGenerator2;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotCluster;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotManager;
|
||||||
|
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||||
|
|
||||||
|
public class BukkitGeneratorWrapper extends PlotGenerator2<ChunkGenerator> {
|
||||||
|
|
||||||
|
public final boolean full;
|
||||||
|
|
||||||
|
public BukkitGeneratorWrapper(String world, ChunkGenerator generator) {
|
||||||
|
super(world, generator);
|
||||||
|
full = generator != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize(PlotWorld plotworld) {
|
||||||
|
if (generator instanceof BukkitPlotGenerator) {
|
||||||
|
((BukkitPlotGenerator) generator).init(plotworld);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void augment(PlotCluster cluster, PlotWorld plotworld) {
|
||||||
|
if (generator instanceof BukkitPlotGenerator) {
|
||||||
|
BukkitPlotGenerator plotgen = (BukkitPlotGenerator) generator;
|
||||||
|
if (cluster != null) {
|
||||||
|
new AugmentedPopulator(world, plotgen, cluster, plotworld.TERRAIN == 2, plotworld.TERRAIN != 2);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
new AugmentedPopulator(world, plotgen, null, plotworld.TERRAIN == 2, plotworld.TERRAIN != 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setGenerator(String gen_string) {
|
||||||
|
if (gen_string == null) {
|
||||||
|
generator = new HybridGen(world);
|
||||||
|
} else {
|
||||||
|
PlotGenerator2<ChunkGenerator> gen_wrapper = (PlotGenerator2<ChunkGenerator>) PS.get().IMP.getGenerator(world, gen_string);
|
||||||
|
if (gen_wrapper != null) {
|
||||||
|
generator = gen_wrapper.generator;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
System.out.print("INVALID GENERATOR: " + gen_string);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PlotWorld getNewPlotWorld(String world) {
|
||||||
|
if (!(generator instanceof BukkitPlotGenerator)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return ((BukkitPlotGenerator) generator).getNewPlotWorld(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PlotManager getPlotManager() {
|
||||||
|
if (!(generator instanceof BukkitPlotGenerator)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return ((BukkitPlotGenerator) generator).getPlotManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isFull() {
|
||||||
|
return full;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
if (generator == null) {
|
||||||
|
return "Null";
|
||||||
|
}
|
||||||
|
return generator.getClass().getName();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -75,7 +75,8 @@ public abstract class BukkitPlotGenerator extends ChunkGenerator {
|
|||||||
public List<BlockPopulator> getDefaultPopulators(World world) {
|
public List<BlockPopulator> getDefaultPopulators(World world) {
|
||||||
try {
|
try {
|
||||||
if (!loaded) {
|
if (!loaded) {
|
||||||
PS.get().loadWorld(WorldEvents.getName(world), this);
|
String name = WorldEvents.getName(world);
|
||||||
|
PS.get().loadWorld(name, new BukkitGeneratorWrapper(name, this));
|
||||||
PlotWorld plotworld = PS.get().getPlotWorld(WorldEvents.getName(world));
|
PlotWorld plotworld = PS.get().getPlotWorld(WorldEvents.getName(world));
|
||||||
if (!plotworld.MOB_SPAWNING) {
|
if (!plotworld.MOB_SPAWNING) {
|
||||||
if (!plotworld.SPAWN_EGGS) {
|
if (!plotworld.SPAWN_EGGS) {
|
||||||
@ -115,7 +116,8 @@ public abstract class BukkitPlotGenerator extends ChunkGenerator {
|
|||||||
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) {
|
||||||
try {
|
try {
|
||||||
if (!loaded) {
|
if (!loaded) {
|
||||||
PS.get().loadWorld(WorldEvents.getName(world), this);
|
String name = WorldEvents.getName(world);
|
||||||
|
PS.get().loadWorld(name, new BukkitGeneratorWrapper(name, this));
|
||||||
loaded = true;
|
loaded = true;
|
||||||
}
|
}
|
||||||
final int prime = 13;
|
final int prime = 13;
|
||||||
|
@ -9,7 +9,8 @@ import org.bukkit.event.world.WorldLoadEvent;
|
|||||||
import org.bukkit.generator.ChunkGenerator;
|
import org.bukkit.generator.ChunkGenerator;
|
||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.intellectualcrafters.plot.PS;
|
||||||
import com.plotsquared.bukkit.object.PlotGenerator;
|
import com.plotsquared.bukkit.generator.BukkitGeneratorWrapper;
|
||||||
|
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
||||||
import com.plotsquared.bukkit.util.UUIDHandler;
|
import com.plotsquared.bukkit.util.UUIDHandler;
|
||||||
|
|
||||||
public class WorldEvents implements Listener {
|
public class WorldEvents implements Listener {
|
||||||
@ -30,12 +31,15 @@ public class WorldEvents implements Listener {
|
|||||||
final World world = event.getWorld();
|
final World world = event.getWorld();
|
||||||
String name = getName(world);
|
String name = getName(world);
|
||||||
final ChunkGenerator gen = world.getGenerator();
|
final ChunkGenerator gen = world.getGenerator();
|
||||||
if (gen instanceof PlotGenerator) {
|
if (gen instanceof BukkitPlotGenerator) {
|
||||||
//
|
PS.get().loadWorld(name, new BukkitGeneratorWrapper(name, (BukkitPlotGenerator) gen));
|
||||||
PS.get().loadWorld(name, (PlotGenerator) gen);
|
}
|
||||||
} else {
|
else {
|
||||||
if (PS.get().config.contains("worlds." + name)) {
|
if (PS.get().config.contains("worlds." + name)) {
|
||||||
PS.get().loadWorld(name, null);
|
PS.get().loadWorld(name, new BukkitGeneratorWrapper(name, null));
|
||||||
|
}
|
||||||
|
else if (gen != null) {
|
||||||
|
System.out.print("NOT INSTANCE OF BukkitGeneratorWrapper: " + gen.getClass().getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lastWorld = null;
|
lastWorld = null;
|
||||||
|
@ -12,7 +12,7 @@ import org.bukkit.plugin.Plugin;
|
|||||||
|
|
||||||
import com.intellectualcrafters.plot.PS;
|
import com.intellectualcrafters.plot.PS;
|
||||||
import com.intellectualcrafters.plot.config.ConfigurationNode;
|
import com.intellectualcrafters.plot.config.ConfigurationNode;
|
||||||
import com.plotsquared.bukkit.object.PlotGenerator;
|
import com.plotsquared.bukkit.generator.BukkitPlotGenerator;
|
||||||
import com.intellectualcrafters.plot.object.PlotWorld;
|
import com.intellectualcrafters.plot.object.PlotWorld;
|
||||||
import com.intellectualcrafters.plot.object.SetupObject;
|
import com.intellectualcrafters.plot.object.SetupObject;
|
||||||
import com.plotsquared.bukkit.util.SetupUtils;
|
import com.plotsquared.bukkit.util.SetupUtils;
|
||||||
@ -57,7 +57,7 @@ public class BukkitSetupUtils extends SetupUtils {
|
|||||||
PS.get().config.set("worlds." + world + "." + "generator.init", object.setupGenerator);
|
PS.get().config.set("worlds." + world + "." + "generator.init", object.setupGenerator);
|
||||||
}
|
}
|
||||||
ChunkGenerator gen = generators.get(object.setupGenerator);
|
ChunkGenerator gen = generators.get(object.setupGenerator);
|
||||||
if (gen instanceof PlotGenerator) {
|
if (gen instanceof BukkitPlotGenerator) {
|
||||||
object.setupGenerator = null;
|
object.setupGenerator = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -103,7 +103,7 @@ public class BukkitSetupUtils extends SetupUtils {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
ChunkGenerator generator = world.getGenerator();
|
ChunkGenerator generator = world.getGenerator();
|
||||||
if (!(generator instanceof PlotGenerator)) {
|
if (!(generator instanceof BukkitPlotGenerator)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
for (Entry<String, ChunkGenerator> entry : generators.entrySet()) {
|
for (Entry<String, ChunkGenerator> entry : generators.entrySet()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user