Let generator be up to the implementation

This commit is contained in:
Jesse Boyd 2016-09-17 16:02:05 +10:00
parent 56227a6d7d
commit 264114332b
18 changed files with 79 additions and 34 deletions

View File

@ -357,7 +357,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
@Override
public final ChunkGenerator getDefaultWorldGenerator(String world, String id) {
HybridGen result = new HybridGen();
IndependentPlotGenerator result = PS.get().IMP.getDefaultGenerator();
if (!PS.get().setupPlotWorld(world, id, result)) {
return null;
}
@ -489,7 +489,7 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
}
return new BukkitPlotGenerator(world, gen);
} else {
return new BukkitPlotGenerator(new HybridGen());
return new BukkitPlotGenerator(PS.get().IMP.getDefaultGenerator());
}
}
@ -573,6 +573,11 @@ public final class BukkitMain extends JavaPlugin implements Listener, IPlotMain
getServer().getPluginManager().registerEvents(new WorldEvents(), this);
}
@Override
public IndependentPlotGenerator getDefaultGenerator() {
return new HybridGen();
}
@Override
public InventoryUtil initInventoryUtil() {
return new BukkitInventoryUtil();

View File

@ -318,7 +318,7 @@ public class LikePlotMeConverter {
// Load using Bukkit API
// - User must set generator manually
Bukkit.getServer().unloadWorld(world, true);
World myWorld = WorldCreator.name(actualWorldName).generator(new BukkitPlotGenerator(new HybridGen())).createWorld();
World myWorld = WorldCreator.name(actualWorldName).generator(new BukkitPlotGenerator(PS.get().IMP.getDefaultGenerator())).createWorld();
myWorld.save();
}
}

View File

@ -120,7 +120,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
@Override
public PlotManager getNewPlotManager() {
return new HybridGen().getNewPlotManager();
return PS.get().IMP.getDefaultGenerator().getNewPlotManager();
}
@Override
@ -130,7 +130,7 @@ public class BukkitPlotGenerator extends ChunkGenerator implements GeneratorWrap
@Override
public PlotArea getNewPlotArea(String world, String id, PlotId min, PlotId max) {
return new HybridGen().getNewPlotArea(world, id, min, max);
return PS.get().IMP.getDefaultGenerator().getNewPlotArea(world, id, min, max);
}
@Override

View File

@ -236,6 +236,12 @@ public interface IPlotMain extends ILogger {
*/
void registerWorldEvents();
/**
* Usually HybridGen
* @return Default implementation generator
*/
IndependentPlotGenerator getDefaultGenerator();
/**
* Get the class that will manage player titles.
* @return

View File

@ -157,7 +157,7 @@ public class Area extends SubCommand {
id = null;
}
object.world = split[0];
final HybridPlotWorld pa = new HybridPlotWorld(object.world, id, new HybridGen(), null, null);
final HybridPlotWorld pa = new HybridPlotWorld(object.world, id, PS.get().IMP.getDefaultGenerator(), null, null);
PlotArea other = PS.get().getPlotArea(pa.worldname, id);
if (other != null && Objects.equals(pa.id, other.id)) {
C.SETUP_WORLD_TAKEN.send(player, pa.toString());

View File

@ -79,9 +79,10 @@ public class ClassicPlotManager extends SquarePlotManager {
return false;
}
LocalBlockQueue queue = plotArea.getQueue(false);
int maxY = plotArea.getPlotManager().getWorldHeight();
for (RegionWrapper region : plot.getRegions()) {
Location pos1 = new Location(plotArea.worldname, region.minX, 1, region.minZ);
Location pos2 = new Location(plotArea.worldname, region.maxX, Math.min(plotArea.MAX_BUILD_HEIGHT, 255), region.maxZ);
Location pos2 = new Location(plotArea.worldname, region.maxX, Math.min(maxY, 255), region.maxZ);
queue.setCuboid(pos1, pos2, blocks);
}
queue.enqueue();
@ -95,9 +96,10 @@ public class ClassicPlotManager extends SquarePlotManager {
}
ClassicPlotWorld dpw = (ClassicPlotWorld) plotArea;
LocalBlockQueue queue = plotArea.getQueue(false);
int maxY = plotArea.getPlotManager().getWorldHeight();
for (RegionWrapper region : plot.getRegions()) {
Location pos1 = new Location(plotArea.worldname, region.minX, dpw.PLOT_HEIGHT + 1, region.minZ);
Location pos2 = new Location(plotArea.worldname, region.maxX, Math.min(plotArea.MAX_BUILD_HEIGHT, 255), region.maxZ);
Location pos2 = new Location(plotArea.worldname, region.maxX, Math.min(maxY, 255), region.maxZ);
queue.setCuboid(pos1, pos2, blocks);
}
queue.enqueue();
@ -144,10 +146,11 @@ public class ClassicPlotManager extends SquarePlotManager {
Location top = plot.getExtendedTopAbs();
PseudoRandom random = new PseudoRandom();
LocalBlockQueue queue = plotArea.getQueue(false);
int maxY = plotArea.getPlotManager().getWorldHeight();
if (!plot.getMerged(0)) {
int z = bottom.getZ();
for (int x = bottom.getX(); x <= top.getX(); x++) {
for (int y = dpw.PLOT_HEIGHT; y <= Math.min(plotArea.MAX_BUILD_HEIGHT, 255); y++) {
for (int y = dpw.PLOT_HEIGHT; y <= Math.min(maxY, 255); y++) {
queue.setBlock(x, y, z, blocks[random.random(blocks.length)]);
}
}
@ -155,7 +158,7 @@ public class ClassicPlotManager extends SquarePlotManager {
if (!plot.getMerged(3)) {
int x = bottom.getX();
for (int z = bottom.getZ(); z <= top.getZ(); z++) {
for (int y = dpw.PLOT_HEIGHT; y <= Math.min(plotArea.MAX_BUILD_HEIGHT, 255); y++) {
for (int y = dpw.PLOT_HEIGHT; y <= Math.min(maxY, 255); y++) {
queue.setBlock(x, y, z, blocks[random.random(blocks.length)]);
}
}
@ -164,7 +167,7 @@ public class ClassicPlotManager extends SquarePlotManager {
if (!plot.getMerged(2)) {
int z = top.getZ();
for (int x = bottom.getX(); x <= top.getX(); x++) {
for (int y = dpw.PLOT_HEIGHT; y <= Math.min(plotArea.MAX_BUILD_HEIGHT, 255); y++) {
for (int y = dpw.PLOT_HEIGHT; y <= Math.min(maxY, 255); y++) {
queue.setBlock(x, y, z, blocks[random.random(blocks.length)]);
}
}
@ -172,15 +175,15 @@ public class ClassicPlotManager extends SquarePlotManager {
if (!plot.getMerged(1)) {
int x = top.getX();
for (int z = bottom.getZ(); z <= top.getZ(); z++) {
for (int y = dpw.PLOT_HEIGHT; y <= Math.min(plotArea.MAX_BUILD_HEIGHT, 255); y++) {
for (int y = dpw.PLOT_HEIGHT; y <= Math.min(maxY, 255); y++) {
queue.setBlock(x, y, z, blocks[random.random(blocks.length)]);
}
}
}
if (plot.isBasePlot()) {
for (RegionWrapper region : plot.getRegions()) {
Location pos1 = new Location(plotArea.worldname, region.minX, Math.min(plotArea.MAX_BUILD_HEIGHT, 255), region.minZ);
Location pos2 = new Location(plotArea.worldname, region.maxX, Math.min(plotArea.MAX_BUILD_HEIGHT, 255), region.maxZ);
Location pos1 = new Location(plotArea.worldname, region.minX, Math.min(maxY, 255), region.minZ);
Location pos2 = new Location(plotArea.worldname, region.maxX, Math.min(maxY, 255), region.maxZ);
queue.setCuboid(pos1, pos2, blocks);
}
}
@ -286,9 +289,10 @@ public class ClassicPlotManager extends SquarePlotManager {
int sz = pos1.getZ() - 2;
int ez = pos2.getZ() + 2;
LocalBlockQueue queue = plotArea.getQueue(false);
int maxY = plotArea.getPlotManager().getWorldHeight();
queue.setCuboid(
new Location(plotArea.worldname, sx, Math.min(dpw.WALL_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz + 1),
new Location(plotArea.worldname, ex, Math.min(plotArea.MAX_BUILD_HEIGHT, 255), ez - 1), PlotBlock.get((short) 0, (byte) 0));
new Location(plotArea.worldname, ex, Math.min(maxY, 255), ez - 1), PlotBlock.get((short) 0, (byte) 0));
queue.setCuboid(new Location(plotArea.worldname, sx, 0, sz + 1),
new Location(plotArea.worldname, ex, 0, ez - 1), PlotBlock.get((short) 7,
(byte) 0));
@ -318,9 +322,10 @@ public class ClassicPlotManager extends SquarePlotManager {
int sx = pos1.getX() - 2;
int ex = pos2.getX() + 2;
LocalBlockQueue queue = plotArea.getQueue(false);
int maxY = plotArea.getPlotManager().getWorldHeight();
queue.setCuboid(
new Location(plotArea.worldname, sx + 1, Math.min(dpw.WALL_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz),
new Location(plotArea.worldname, ex - 1, Math.min(plotArea.MAX_BUILD_HEIGHT, 255), ez), PlotBlock.get((short) 0, (byte) 0));
new Location(plotArea.worldname, ex - 1, Math.min(maxY, 255), ez), PlotBlock.get((short) 0, (byte) 0));
queue.setCuboid(new Location(plotArea.worldname, sx + 1, 0, sz),
new Location(plotArea.worldname, ex - 1, 0, ez), PlotBlock.get((short) 7, (byte) 0));
queue.setCuboid(new Location(plotArea.worldname, sx + 1, 1, sz),
@ -369,8 +374,9 @@ public class ClassicPlotManager extends SquarePlotManager {
int sz = pos1.getZ() - 1;
int ez = pos2.getZ() + 1;
LocalBlockQueue queue = plotArea.getQueue(false);
int maxY = plotArea.getPlotManager().getWorldHeight();
queue.setCuboid(new Location(plotArea.worldname, sx, Math.min(dpw.PLOT_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz),
new Location(plotArea.worldname, ex, Math.min(plotArea.MAX_BUILD_HEIGHT, 255), ez), PlotBlock.get((short) 0, (byte) 0));
new Location(plotArea.worldname, ex, Math.min(maxY, 255), ez), PlotBlock.get((short) 0, (byte) 0));
queue.setCuboid(new Location(plotArea.worldname, sx, 1, sz + 1),
new Location(plotArea.worldname, ex, dpw.PLOT_HEIGHT - 1, ez - 1), dpw.MAIN_BLOCK);
queue.setCuboid(new Location(plotArea.worldname, sx, dpw.PLOT_HEIGHT, sz + 1),
@ -389,8 +395,9 @@ public class ClassicPlotManager extends SquarePlotManager {
int sx = pos1.getX() - 1;
int ex = pos2.getX() + 1;
LocalBlockQueue queue = plotArea.getQueue(false);
int maxY = plotArea.getPlotManager().getWorldHeight();
queue.setCuboid(new Location(plotArea.worldname, sx, Math.min(dpw.PLOT_HEIGHT, dpw.ROAD_HEIGHT) + 1, sz),
new Location(plotArea.worldname, ex, Math.min(plotArea.MAX_BUILD_HEIGHT, 255), ez), PlotBlock.get((short) 0, (byte) 0));
new Location(plotArea.worldname, ex, Math.min(maxY, 255), ez), PlotBlock.get((short) 0, (byte) 0));
queue.setCuboid(new Location(plotArea.worldname, sx + 1, 1, sz),
new Location(plotArea.worldname, ex - 1, dpw.PLOT_HEIGHT - 1, ez), dpw.MAIN_BLOCK);
queue.setCuboid(new Location(plotArea.worldname, sx + 1, dpw.PLOT_HEIGHT, sz),

View File

@ -247,7 +247,7 @@ public class HybridGen extends IndependentPlotGenerator {
@Override
public PlotManager getNewPlotManager() {
return new HybridPlotManager();
return new HybridPlotManager();
}
@Override

View File

@ -61,7 +61,7 @@ public class HybridPlotManager extends ClassicPlotManager {
Location bot = getPlotBottomLocAbs(hpw, id2);
Location top = getPlotTopLocAbs(hpw, id);
Location pos1 = new Location(plotArea.worldname, top.getX() + 1, 0, bot.getZ() - 1);
Location pos2 = new Location(plotArea.worldname, bot.getX(), Math.min(plotArea.MAX_BUILD_HEIGHT, 255), top.getZ() + 1);
Location pos2 = new Location(plotArea.worldname, bot.getX(), Math.min(getWorldHeight(), 255), top.getZ() + 1);
MainUtil.resetBiome(plotArea, pos1, pos2);
if (!hpw.ROAD_SCHEMATIC_ENABLED) {
return true;
@ -108,7 +108,7 @@ public class HybridPlotManager extends ClassicPlotManager {
Location bot = getPlotBottomLocAbs(hpw, id2);
Location top = getPlotTopLocAbs(hpw, id);
Location pos1 = new Location(plotArea.worldname, bot.getX() - 1, 0, top.getZ() + 1);
Location pos2 = new Location(plotArea.worldname, top.getX() + 1, Math.min(plotArea.MAX_BUILD_HEIGHT, 255), bot.getZ());
Location pos2 = new Location(plotArea.worldname, top.getX() + 1, Math.min(getWorldHeight(), 255), bot.getZ());
MainUtil.resetBiome(plotArea, pos1, pos2);
if (!hpw.ROAD_SCHEMATIC_ENABLED) {
return true;
@ -128,7 +128,7 @@ public class HybridPlotManager extends ClassicPlotManager {
Location pos1 = getPlotTopLocAbs(hpw, id).add(1, 0, 1);
Location pos2 = getPlotBottomLocAbs(hpw, id2);
pos1.setY(0);
pos2.setY(Math.min(plotArea.MAX_BUILD_HEIGHT, 255));
pos2.setY(Math.min(getWorldHeight(), 255));
LocalBlockQueue queue = hpw.getQueue(false);
createSchemAbs(hpw, queue, pos1, pos2, true);
if (hpw.ROAD_SCHEMATIC_ENABLED) {
@ -189,7 +189,7 @@ public class HybridPlotManager extends ClassicPlotManager {
top.setY(dpw.PLOT_HEIGHT + 1);
queue.setCuboid(bot, top, plotfloor);
bot.setY(dpw.PLOT_HEIGHT + 1);
top.setY(plotArea.MAX_BUILD_HEIGHT);
top.setY(getWorldHeight());
queue.setCuboid(bot, top, air);
// And finally set the schematic, the y value is unimportant for this function
pastePlotSchematic(dpw, queue, bot, top);

View File

@ -47,7 +47,7 @@ public abstract class SquarePlotManager extends GridPlotManager {
int pz = plotId.y;
int x = (dpw.ROAD_OFFSET_X + (px * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH))) - (int) Math.floor(dpw.ROAD_WIDTH / 2) - 1;
int z = (dpw.ROAD_OFFSET_Z + (pz * (dpw.ROAD_WIDTH + dpw.PLOT_WIDTH))) - (int) Math.floor(dpw.ROAD_WIDTH / 2) - 1;
return new Location(plotArea.worldname, x, Math.min(plotArea.MAX_BUILD_HEIGHT, 255), z);
return new Location(plotArea.worldname, x, Math.min(getWorldHeight(), 255), z);
}
@Override

View File

@ -73,4 +73,8 @@ public abstract class PlotManager {
Template.zipAll(plotArea.worldname, files);
}
public int getWorldHeight() {
return 255;
}
}

View File

@ -1,5 +1,5 @@
name: "PlotSquared"
version: "3.4.6-SNAPSHOT-a95b68b"
version: "3.4.6-SNAPSHOT-56227a6"
author: Empire92
api: ["1.0.0"]
main: com.plotsquared.nukkit.NukkitMain

View File

@ -15,10 +15,13 @@ import com.intellectualcrafters.plot.PS;
import com.intellectualcrafters.plot.config.C;
import com.intellectualcrafters.plot.config.Settings;
import com.intellectualcrafters.plot.generator.GeneratorWrapper;
import com.intellectualcrafters.plot.generator.HybridGen;
import com.intellectualcrafters.plot.generator.HybridPlotManager;
import com.intellectualcrafters.plot.generator.HybridUtils;
import com.intellectualcrafters.plot.generator.IndependentPlotGenerator;
import com.intellectualcrafters.plot.object.Plot;
import com.intellectualcrafters.plot.object.PlotArea;
import com.intellectualcrafters.plot.object.PlotManager;
import com.intellectualcrafters.plot.object.PlotPlayer;
import com.intellectualcrafters.plot.object.RunnableVal;
import com.intellectualcrafters.plot.object.chat.PlainChatManager;
@ -407,4 +410,19 @@ public final class NukkitMain extends PluginBase implements Listener, IPlotMain
}
return names;
}
@Override
public IndependentPlotGenerator getDefaultGenerator() {
return new HybridGen() {
@Override
public PlotManager getNewPlotManager() {
return new HybridPlotManager() {
@Override
public int getWorldHeight() {
return 127;
}
};
}
};
}
}

View File

@ -57,7 +57,7 @@ public class NukkitPlotGenerator extends Generator implements GeneratorWrapper<G
@Override
public PlotManager getNewPlotManager() {
return new HybridGen().getNewPlotManager();
return PS.get().IMP.getDefaultGenerator().getNewPlotManager();
}
@Override
@ -67,7 +67,7 @@ public class NukkitPlotGenerator extends Generator implements GeneratorWrapper<G
@Override
public PlotArea getNewPlotArea(String world, String id, PlotId min, PlotId max) {
return new HybridGen().getNewPlotArea(world, id, min, max);
return PS.get().IMP.getDefaultGenerator().getNewPlotArea(world, id, min, max);
}
@Override

View File

@ -49,7 +49,7 @@ public class WorldEvents implements Listener {
settings.put("generator", gen);
PS.get().loadWorld(name, new NukkitPlotGenerator(settings));
for (PlotArea area : PS.get().getPlotAreas(name)) {
area.MAX_BUILD_HEIGHT = Math.min(128, area.MAX_BUILD_HEIGHT);
area.MAX_BUILD_HEIGHT = Math.min(127, area.MAX_BUILD_HEIGHT);
}
}
} catch (Throwable e) {

View File

@ -36,7 +36,7 @@ public class NukkitSetupUtils extends SetupUtils {
String testWorld = "CheckingPlotSquaredGenerator";
HashMap<String, Object> map = new HashMap<>();
map.put("world", testWorld);
map.put("plot-generator", new HybridGen());
map.put("plot-generator", PS.get().IMP.getDefaultGenerator());
NukkitPlotGenerator gen = new NukkitPlotGenerator(map);
SetupUtils.generators.put("PlotSquared", gen);
}
@ -119,7 +119,7 @@ public class NukkitSetupUtils extends SetupUtils {
if (object.setupGenerator != null) {
HashMap<String, Object> map = new HashMap<>();
map.put("world", object.world);
map.put("plot-generator", new HybridGen());
map.put("plot-generator", PS.get().IMP.getDefaultGenerator());
plugin.getServer().generateLevel(object.world, object.world.hashCode(), NukkitPlotGenerator.class, map);
} else {
plugin.getServer().generateLevel(object.world, object.world.hashCode());

View File

@ -24,7 +24,7 @@ public class NukkitHybridGen extends NukkitPlotGenerator {
}
}
}
existing.put("plot-generator", new HybridGen());
existing.put("plot-generator", PS.get().IMP.getDefaultGenerator());
return existing;
}
}

View File

@ -136,7 +136,7 @@ public class SpongeMain implements IPlotMain {
THIS = this;
new PS(this, "Sponge");
this.server = this.game.getServer();
this.game.getRegistry().register(WorldGeneratorModifier.class, (WorldGeneratorModifier) new HybridGen().specify(null));
this.game.getRegistry().register(WorldGeneratorModifier.class, (WorldGeneratorModifier) PS.get().IMP.getDefaultGenerator().specify(null));
}
@Override
@ -390,7 +390,7 @@ public class SpongeMain implements IPlotMain {
return new SpongePlotGenerator(wgm);
}
}
return new SpongePlotGenerator(new HybridGen());
return new SpongePlotGenerator(PS.get().IMP.getDefaultGenerator());
}
@Override
@ -403,4 +403,9 @@ public class SpongeMain implements IPlotMain {
return this.game.getPluginManager().getPlugins().stream().map(plugin1 -> plugin1.getName() + ';' + plugin1.getVersion() + ':' + true)
.collect(Collectors.toCollection(ArrayList::new));
}
@Override
public IndependentPlotGenerator getDefaultGenerator() {
return new HybridGen();
}
}

View File

@ -32,7 +32,7 @@ public class SpongeSetupUtils extends SetupUtils {
if (!SetupUtils.generators.isEmpty()) {
return;
}
SetupUtils.generators.put("PlotSquared", new SpongePlotGenerator(new HybridGen()));
SetupUtils.generators.put("PlotSquared", new SpongePlotGenerator(PS.get().IMP.getDefaultGenerator()));
// TODO get external world generators
Collection<WorldGeneratorModifier> wgms = Sponge.getRegistry().getAllOf(WorldGeneratorModifier.class);
for (WorldGeneratorModifier wgm : wgms) {