Pass the PlotArea into the PlotManager

This commit is contained in:
Alexander Krivács Schrøder 2019-05-31 13:16:05 +02:00 committed by Matt
parent 908a5784a1
commit 6b3960fc3f
12 changed files with 59 additions and 11 deletions

View File

@ -30,8 +30,8 @@ import java.util.Random;
@Override public void initialize(PlotArea area) {
}
@Override public PlotManager getNewPlotManager() {
return PlotSquared.get().IMP.getDefaultGenerator().getNewPlotManager();
@Override public PlotManager getNewPlotManager(PlotArea plotArea) {
return PlotSquared.get().IMP.getDefaultGenerator().getNewPlotManager(plotArea);
}
@Override public String getName() {

View File

@ -1086,7 +1086,7 @@ import java.util.zip.ZipInputStream;
}
// Conventional plot generator
PlotArea plotArea = plotGenerator.getNewPlotArea(world, null, null, null);
PlotManager plotManager = plotGenerator.getNewPlotManager();
PlotManager plotManager = plotGenerator.getNewPlotManager(plotArea);
PlotSquared.log(Captions.PREFIX + "&aDetected world load for '" + world + "'");
PlotSquared
.log(Captions.PREFIX + "&3 - generator: &7" + baseGenerator + ">" + plotGenerator);

View File

@ -13,6 +13,17 @@ import java.util.List;
*/
public class ClassicPlotManager extends SquarePlotManager {
private final ClassicPlotWorld classicPlotWorld;
public ClassicPlotManager(PlotArea plotArea) {
super(plotArea);
if (plotArea instanceof ClassicPlotWorld){
classicPlotWorld = (ClassicPlotWorld)plotArea;
} else {
throw new RuntimeException("ClassicPlotManager requires plotArea to be an instance of ClassicPlotWorld");
}
}
@Override public boolean setComponent(PlotArea plotArea, PlotId plotId, String component,
BlockBucket blocks) {
switch (component) {

View File

@ -1,10 +1,13 @@
package com.github.intellectualsites.plotsquared.plot.generator;
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
import com.github.intellectualsites.plotsquared.plot.object.PlotManager;
/**
* A plot manager where plots tessellate in a grid formation symmetrical about x=z.
*/
public abstract class GridPlotManager extends PlotManager {
public GridPlotManager(PlotArea plotArea) {
super(plotArea);
}
}

View File

@ -253,8 +253,8 @@ public class HybridGen extends IndependentPlotGenerator {
return new HybridPlotWorld(world, id, this, min, max);
}
@Override public PlotManager getNewPlotManager() {
return new HybridPlotManager();
@Override public PlotManager getNewPlotManager(PlotArea plotArea) {
return new HybridPlotManager(plotArea);
}
@Override public void initialize(PlotArea area) {

View File

@ -21,6 +21,17 @@ public class HybridPlotManager extends ClassicPlotManager {
public static boolean REGENERATIVE_CLEAR = true;
private final HybridPlotWorld hybridPlotWorld;
public HybridPlotManager(PlotArea plotArea) {
super(plotArea);
if (plotArea instanceof HybridPlotWorld){
hybridPlotWorld = (HybridPlotWorld)plotArea;
} else {
throw new RuntimeException("HybridPlotManager requires plotArea to be an instance of HybridPlotWorld");
}
}
@Override public void exportTemplate(PlotArea plotArea) throws IOException {
HashSet<FileBytes> files = Sets.newHashSet(
new FileBytes(Settings.Paths.TEMPLATES + "/tmp-data.yml", Template.getBytes(plotArea)));

View File

@ -53,8 +53,9 @@ public abstract class IndependentPlotGenerator {
* Return a new PlotManager object.
*
* @return
* @param plotArea
*/
public abstract PlotManager getNewPlotManager();
public abstract PlotManager getNewPlotManager(PlotArea plotArea);
/**
* If any additional setup options need to be changed before world creation.

View File

@ -14,6 +14,17 @@ import java.util.Iterator;
*/
public abstract class SquarePlotManager extends GridPlotManager {
private final SquarePlotWorld squarePlotWorld;
public SquarePlotManager(PlotArea plotArea) {
super(plotArea);
if (plotArea instanceof SquarePlotWorld){
squarePlotWorld = (SquarePlotWorld)plotArea;
} else {
throw new RuntimeException("SquarePlotManager requires plotArea to be an instance of SquarePlotWorld");
}
}
@Override
public boolean clearPlot(PlotArea plotArea, final Plot plot, final Runnable whenDone) {
final HashSet<RegionWrapper> regions = plot.getRegions();

View File

@ -81,7 +81,7 @@ public abstract class PlotArea {
@Nullable final PlotId max) {
this.worldname = worldName;
this.id = id;
this.manager = generator.getNewPlotManager();
this.manager = generator.getNewPlotManager(this);
this.generator = generator;
if (min == null || max == null) {
if (min != max) {

View File

@ -10,6 +10,13 @@ import java.util.List;
public abstract class PlotManager {
private final PlotArea plotArea;
public PlotManager(PlotArea plotArea) {
this.plotArea = plotArea;
}
/*
* Plot locations (methods with Abs in them will not need to consider mega
* plots).

View File

@ -10,6 +10,10 @@ import java.io.File;
import java.util.List;
public class SinglePlotManager extends PlotManager {
public SinglePlotManager(PlotArea plotArea) {
super(plotArea);
}
@Override public PlotId getPlotIdAbs(PlotArea plotArea, int x, int y, int z) {
return new PlotId(0, 0);
}

View File

@ -81,8 +81,8 @@ public class SingleWorldGenerator extends IndependentPlotGenerator {
return ((SinglePlotAreaManager) PlotSquared.get().getPlotAreaManager()).getArea();
}
@Override public PlotManager getNewPlotManager() {
return new SinglePlotManager();
@Override public PlotManager getNewPlotManager(PlotArea plotArea) {
return new SinglePlotManager(plotArea);
}
@Override public void initialize(PlotArea area) {