mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2025-07-14 03:14:42 +02:00
Restructure generators
This commit is contained in:
@ -15,7 +15,6 @@ import com.intellectualcrafters.plot.PS;
|
||||
import com.plotsquared.bukkit.object.BlockWrapper;
|
||||
import com.intellectualcrafters.plot.object.Location;
|
||||
import com.intellectualcrafters.plot.object.PlotCluster;
|
||||
import com.plotsquared.bukkit.object.PlotGenerator;
|
||||
import com.intellectualcrafters.plot.object.PlotId;
|
||||
import com.intellectualcrafters.plot.object.PlotLoc;
|
||||
import com.intellectualcrafters.plot.object.PlotManager;
|
||||
@ -32,7 +31,7 @@ public class AugmentedPopulator extends BlockPopulator {
|
||||
public static short[][] z_loc;
|
||||
public final PlotWorld plotworld;
|
||||
public final PlotManager manager;
|
||||
public final PlotGenerator generator;
|
||||
public final BukkitPlotGenerator generator;
|
||||
public final PlotCluster cluster;
|
||||
public final Random r = new Random();
|
||||
public final boolean p;
|
||||
@ -43,7 +42,7 @@ public class AugmentedPopulator extends BlockPopulator {
|
||||
private final int tx;
|
||||
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();
|
||||
this.cluster = cluster;
|
||||
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) {
|
||||
try {
|
||||
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));
|
||||
if (!plotworld.MOB_SPAWNING) {
|
||||
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) {
|
||||
try {
|
||||
if (!loaded) {
|
||||
PS.get().loadWorld(WorldEvents.getName(world), this);
|
||||
String name = WorldEvents.getName(world);
|
||||
PS.get().loadWorld(name, new BukkitGeneratorWrapper(name, this));
|
||||
loaded = true;
|
||||
}
|
||||
final int prime = 13;
|
||||
|
Reference in New Issue
Block a user