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.step = new ConfigurationNode[0];
setup.world = worldName; setup.world = worldName;
SetupUtils.manager.setupWorld(setup); SetupUtils.manager.setupWorld(setup);
world = Bukkit.getWorld(worldName);
} else { } else {
try { try {
if (!PS.get().hasPlotArea(worldName)) { if (!PS.get().hasPlotArea(worldName)) {
SetGenCB.setGenerator(BukkitUtil.getWorld(worldName)); SetGenCB.setGenerator(BukkitUtil.getWorld(worldName));
} }
} catch (Exception ignored) { } catch (Exception ignored) {
PS.log("Failed to reload world: " + world); PS.log("Failed to reload world: " + world + " | " + ignored.getMessage());
Bukkit.getServer().unloadWorld(world, false); Bukkit.getServer().unloadWorld(world, false);
return;
} }
} }
world = Bukkit.getWorld(worldName);
ChunkGenerator gen = world.getGenerator(); ChunkGenerator gen = world.getGenerator();
if (gen instanceof BukkitPlotGenerator) { if (gen instanceof BukkitPlotGenerator) {
PS.get().loadWorld(worldName, (BukkitPlotGenerator) gen); PS.get().loadWorld(worldName, (BukkitPlotGenerator) gen);

View File

@ -171,10 +171,7 @@ public class SpongeMain implements IPlotMain {
@Override @Override
public int[] getPluginVersion() { public int[] getPluginVersion() {
String ver = this.plugin.getVersion().orElse(""); String ver = this.plugin.getVersion().orElse("");
if (ver.contains("-")) { String[] split = ver.split("[\\.|-]");
ver = ver.split("-")[0];
}
String[] split = ver.split("\\.");
return new int[]{Integer.parseInt(split[0]), Integer.parseInt(split[1]), Integer.parseInt(split[2])}; 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(); WorldGenerator wg = world.getWorldGenerator();
GenerationPopulator gen = wg.getBaseGenerationPopulator(); GenerationPopulator gen = wg.getBaseGenerationPopulator();
if (gen instanceof SpongePlotGenerator) { if (gen instanceof GeneratorWrapper) {
PS.get().loadWorld(worldName, (SpongePlotGenerator) gen); PS.get().loadWorld(worldName, (GeneratorWrapper) gen);
} else { } 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 @Override
public void modifyWorldGenerator(WorldProperties world, DataContainer settings, WorldGenerator worldGenerator) { public void modifyWorldGenerator(WorldProperties world, DataContainer settings, WorldGenerator worldGenerator) {
String worldName = world.getWorldName(); String worldName = world.getWorldName();
worldGenerator.setBaseGenerationPopulator(new SpongeTerrainGen(this, this.plotGenerator)); worldGenerator.setBaseGenerationPopulator(new SpongeTerrainGen(this.plotGenerator));
worldGenerator.setBiomeGenerator(new BiomeGenerator() { worldGenerator.setBiomeGenerator(new BiomeGenerator() {
@Override @Override
public void generateBiomes(MutableBiomeArea buffer) { public void generateBiomes(MutableBiomeArea buffer) {

View File

@ -2,30 +2,47 @@ package com.plotsquared.sponge.generator;
import com.flowpowered.math.vector.Vector3i; import com.flowpowered.math.vector.Vector3i;
import com.intellectualcrafters.plot.PS; import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
import com.intellectualcrafters.plot.generator.IndependentPlotGenerator; import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
import com.intellectualcrafters.plot.object.ChunkWrapper; import com.intellectualcrafters.plot.object.ChunkWrapper;
import com.intellectualcrafters.plot.object.PlotArea; import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PseudoRandom; import com.intellectualcrafters.plot.object.PseudoRandom;
import com.intellectualcrafters.plot.util.ChunkManager; 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 com.plotsquared.sponge.util.block.GenChunk;
import org.spongepowered.api.world.World; import org.spongepowered.api.world.World;
import org.spongepowered.api.world.extent.ImmutableBiomeArea; import org.spongepowered.api.world.extent.ImmutableBiomeArea;
import org.spongepowered.api.world.extent.MutableBlockVolume; import org.spongepowered.api.world.extent.MutableBlockVolume;
import org.spongepowered.api.world.gen.GenerationPopulator; 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; public final IndependentPlotGenerator child;
private final boolean full;
private final GenerationPopulator platformGenerator;
private final PseudoRandom random = new PseudoRandom(); private final PseudoRandom random = new PseudoRandom();
public SpongeTerrainGen(SpongePlotGenerator parent, IndependentPlotGenerator ipg) { public SpongeTerrainGen(IndependentPlotGenerator ipg) {
this.parent = parent;
this.child = 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 @Override
public void populate(World world, MutableBlockVolume terrain, ImmutableBiomeArea biomes) { public void populate(World world, MutableBlockVolume terrain, ImmutableBiomeArea biomes) {
if (platformGenerator != this) {
platformGenerator.populate(world, terrain, biomes);
return;
}
Vector3i size = terrain.getBlockSize(); Vector3i size = terrain.getBlockSize();
if (size.getX() != 16 || size.getZ() != 16) { if (size.getX() != 16 || size.getZ() != 16) {
throw new UnsupportedOperationException("NON CHUNK POPULATION NOT SUPPORTED"); throw new UnsupportedOperationException("NON CHUNK POPULATION NOT SUPPORTED");
@ -57,4 +74,24 @@ public class SpongeTerrainGen implements GenerationPopulator {
e.printStackTrace(); 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; 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.Listener;
import org.spongepowered.api.event.world.LoadWorldEvent; import org.spongepowered.api.event.world.LoadWorldEvent;
import org.spongepowered.api.world.World; import org.spongepowered.api.world.World;
import org.spongepowered.api.world.gen.GenerationPopulator; import org.spongepowered.api.world.gen.GenerationPopulator;
import org.spongepowered.api.world.gen.WorldGenerator; import org.spongepowered.api.world.gen.WorldGenerator;
import com.intellectualcrafters.plot.PS;
import com.plotsquared.sponge.generator.SpongeTerrainGen;
public class WorldEvents { public class WorldEvents {
@Listener @Listener
@ -17,9 +16,9 @@ public class WorldEvents {
final String name = world.getName(); final String name = world.getName();
WorldGenerator generator = world.getWorldGenerator(); WorldGenerator generator = world.getWorldGenerator();
GenerationPopulator terrain = generator.getBaseGenerationPopulator(); GenerationPopulator terrain = generator.getBaseGenerationPopulator();
if (terrain instanceof SpongeTerrainGen) { if (terrain instanceof GeneratorWrapper) {
SpongeTerrainGen stg = (SpongeTerrainGen) terrain; GeneratorWrapper stg = (GeneratorWrapper) terrain;
PS.get().loadWorld(name, stg.parent); PS.get().loadWorld(name, stg);
} }
else { else {
PS.get().loadWorld(name, null); PS.get().loadWorld(name, null);