Sponge fixes

This commit is contained in:
Jesse Boyd 2016-09-02 15:58:24 +10:00
parent 6a12a6ba64
commit d75ab130da
5 changed files with 54 additions and 20 deletions

View File

@ -599,17 +599,18 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
setup.step = new ConfigurationNode[0];
setup.world = worldName;
SetupUtils.manager.setupWorld(setup);
world = Bukkit.getWorld(worldName);
} else {
try {
if (!PS.get().hasPlotArea(worldName)) {
SetGenCB.setGenerator(BukkitUtil.getWorld(worldName));
}
} catch (Exception ignored) {
PS.log("Failed to reload world: " + world);
PS.log("Failed to reload world: " + world + " | " + ignored.getMessage());
Bukkit.getServer().unloadWorld(world, false);
return;
}
}
world = Bukkit.getWorld(worldName);
ChunkGenerator gen = world.getGenerator();
if (gen instanceof BukkitPlotGenerator) {
PS.get().loadWorld(worldName, (BukkitPlotGenerator) gen);

View File

@ -171,10 +171,7 @@ public class SpongeMain implements IPlotMain {
@Override
public int[] getPluginVersion() {
String ver = this.plugin.getVersion().orElse("");
if (ver.contains("-")) {
ver = ver.split("-")[0];
}
String[] split = ver.split("\\.");
String[] split = ver.split("[\\.|-]");
return new int[]{Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2])};
}
@ -331,10 +328,10 @@ public class SpongeMain implements IPlotMain {
}
WorldGenerator wg = world.getWorldGenerator();
GenerationPopulator gen = wg.getBaseGenerationPopulator();
if (gen instanceof SpongePlotGenerator) {
PS.get().loadWorld(worldName, (SpongePlotGenerator) gen);
if (gen instanceof GeneratorWrapper) {
PS.get().loadWorld(worldName, (GeneratorWrapper) gen);
} else {
throw new UnsupportedOperationException("NOT IMPLEMENTED YET! " + worldName + " | " + gen);
throw new UnsupportedOperationException("NOT IMPLEMENTED YET2! " + worldName + " | " + gen);
}
}

View File

@ -71,7 +71,7 @@ public class SpongePlotGenerator implements WorldGeneratorModifier, GeneratorWra
@Override
public void modifyWorldGenerator(WorldProperties world, DataContainer settings, WorldGenerator worldGenerator) {
String worldName = world.getWorldName();
worldGenerator.setBaseGenerationPopulator(new SpongeTerrainGen(this, this.plotGenerator));
worldGenerator.setBaseGenerationPopulator(new SpongeTerrainGen(this.plotGenerator));
worldGenerator.setBiomeGenerator(new BiomeGenerator() {
@Override
public void generateBiomes(MutableBiomeArea buffer) {

View File

@ -2,30 +2,47 @@ package com.plotsquared.sponge.generator;
import com.flowpowered.math.vector.Vector3i;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
import com.intellectualcrafters.plot.object.ChunkWrapper;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PseudoRandom;
import com.intellectualcrafters.plot.util.ChunkManager;
import com.intellectualcrafters.plot.util.MainUtil;
import com.plotsquared.sponge.util.SpongeUtil;
import com.plotsquared.sponge.util.block.GenChunk;
import org.spongepowered.api.world.World;
import org.spongepowered.api.world.extent.ImmutableBiomeArea;
import org.spongepowered.api.world.extent.MutableBlockVolume;
import org.spongepowered.api.world.gen.GenerationPopulator;
public class SpongeTerrainGen implements GenerationPopulator {
public class SpongeTerrainGen implements GenerationPopulator, GeneratorWrapper<GenerationPopulator> {
public final SpongePlotGenerator parent;
public final IndependentPlotGenerator child;
private final boolean full;
private final GenerationPopulator platformGenerator;
private final PseudoRandom random = new PseudoRandom();
public SpongeTerrainGen(SpongePlotGenerator parent, IndependentPlotGenerator ipg) {
this.parent = parent;
public SpongeTerrainGen(IndependentPlotGenerator ipg) {
this.child = ipg;
this.full = true;
this.platformGenerator = this;
MainUtil.initCache();
}
public SpongeTerrainGen(GenerationPopulator populator) {
this.child = null;
this.platformGenerator = populator;
this.full = false;
MainUtil.initCache();
}
@Override
public void populate(World world, MutableBlockVolume terrain, ImmutableBiomeArea biomes) {
if (platformGenerator != this) {
platformGenerator.populate(world, terrain, biomes);
return;
}
Vector3i size = terrain.getBlockSize();
if (size.getX() != 16 || size.getZ() != 16) {
throw new UnsupportedOperationException("NON CHUNK POPULATION NOT SUPPORTED");
@ -57,4 +74,24 @@ public class SpongeTerrainGen implements GenerationPopulator {
e.printStackTrace();
}
}
@Override
public IndependentPlotGenerator getPlotGenerator() {
return child;
}
@Override
public GenerationPopulator getPlatformGenerator() {
return platformGenerator;
}
@Override
public void augment(PlotArea area) {
SpongeAugmentedGenerator.get(SpongeUtil.getWorld(area.worldname));
}
@Override
public boolean isFull() {
return this.full;
}
}

View File

@ -1,14 +1,13 @@
package com.plotsquared.sponge.listener;
import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
import org.spongepowered.api.event.Listener;
import org.spongepowered.api.event.world.LoadWorldEvent;
import org.spongepowered.api.world.World;
import org.spongepowered.api.world.gen.GenerationPopulator;
import org.spongepowered.api.world.gen.WorldGenerator;
import com.intellectualcrafters.plot.PS;
import com.plotsquared.sponge.generator.SpongeTerrainGen;
public class WorldEvents {
@Listener
@ -17,9 +16,9 @@ public class WorldEvents {
final String name = world.getName();
WorldGenerator generator = world.getWorldGenerator();
GenerationPopulator terrain = generator.getBaseGenerationPopulator();
if (terrain instanceof SpongeTerrainGen) {
SpongeTerrainGen stg = (SpongeTerrainGen) terrain;
PS.get().loadWorld(name, stg.parent);
if (terrain instanceof GeneratorWrapper) {
GeneratorWrapper stg = (GeneratorWrapper) terrain;
PS.get().loadWorld(name, stg);
}
else {
PS.get().loadWorld(name, null);