mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-22 13:16:45 +01:00
Have PlotAreas create their own PlotManager
Leads to cleaner code, less need for instanceof and casting, as a PlotArea knows which kind of PlotManager it needs to make
This commit is contained in:
parent
c5bca66618
commit
d106262454
@ -30,10 +30,6 @@ import java.util.Random;
|
||||
@Override public void initialize(PlotArea area) {
|
||||
}
|
||||
|
||||
@Override public PlotManager getNewPlotManager(PlotArea plotArea) {
|
||||
return PlotSquared.get().IMP.getDefaultGenerator().getNewPlotManager(plotArea);
|
||||
}
|
||||
|
||||
@Override public String getName() {
|
||||
return this.chunkGenerator.getClass().getName();
|
||||
}
|
||||
|
@ -1086,7 +1086,7 @@ import java.util.zip.ZipInputStream;
|
||||
}
|
||||
// Conventional plot generator
|
||||
PlotArea plotArea = plotGenerator.getNewPlotArea(world, null, null, null);
|
||||
PlotManager plotManager = plotGenerator.getNewPlotManager(plotArea);
|
||||
PlotManager plotManager = plotArea.getPlotManager();
|
||||
PlotSquared.log(Captions.PREFIX + "&aDetected world load for '" + world + "'");
|
||||
PlotSquared
|
||||
.log(Captions.PREFIX + "&3 - generator: &7" + baseGenerator + ">" + plotGenerator);
|
||||
|
@ -15,13 +15,9 @@ 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");
|
||||
}
|
||||
public ClassicPlotManager(ClassicPlotWorld classicPlotWorld) {
|
||||
super(classicPlotWorld);
|
||||
this.classicPlotWorld = classicPlotWorld;
|
||||
}
|
||||
|
||||
@Override public boolean setComponent(PlotId plotId, String component,
|
||||
|
@ -253,10 +253,6 @@ public class HybridGen extends IndependentPlotGenerator {
|
||||
return new HybridPlotWorld(world, id, this, min, max);
|
||||
}
|
||||
|
||||
@Override public PlotManager getNewPlotManager(PlotArea plotArea) {
|
||||
return new HybridPlotManager(plotArea);
|
||||
}
|
||||
|
||||
@Override public void initialize(PlotArea area) {
|
||||
// All initialization is done in the PlotArea class
|
||||
}
|
||||
|
@ -23,13 +23,9 @@ public class HybridPlotManager extends ClassicPlotManager {
|
||||
|
||||
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");
|
||||
}
|
||||
public HybridPlotManager(HybridPlotWorld hybridPlotWorld) {
|
||||
super(hybridPlotWorld);
|
||||
this.hybridPlotWorld = hybridPlotWorld;
|
||||
}
|
||||
|
||||
@Override public void exportTemplate() throws IOException {
|
||||
|
@ -7,6 +7,7 @@ import com.github.intellectualsites.plotsquared.plot.object.Location;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.Plot;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotId;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.PlotManager;
|
||||
import com.github.intellectualsites.plotsquared.plot.object.schematic.Schematic;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
|
||||
import com.github.intellectualsites.plotsquared.plot.util.MathMan;
|
||||
@ -43,6 +44,11 @@ public class HybridPlotWorld extends ClassicPlotWorld {
|
||||
super(worldName, id, generator, min, max);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PlotManager createManager() {
|
||||
return new HybridPlotManager(this);
|
||||
}
|
||||
|
||||
public static byte wrap(byte data, int start) {
|
||||
if ((data >= start) && (data < (start + 4))) {
|
||||
data = (byte) ((((data - start) + 2) & 3) + start);
|
||||
|
@ -49,14 +49,6 @@ public abstract class IndependentPlotGenerator {
|
||||
*/
|
||||
public abstract PlotArea getNewPlotArea(String world, String id, PlotId min, PlotId max);
|
||||
|
||||
/**
|
||||
* Return a new PlotManager object.
|
||||
*
|
||||
* @return
|
||||
* @param plotArea
|
||||
*/
|
||||
public abstract PlotManager getNewPlotManager(PlotArea plotArea);
|
||||
|
||||
/**
|
||||
* If any additional setup options need to be changed before world creation.
|
||||
* - e.g. If setup doesn't support some standard options
|
||||
|
@ -16,13 +16,9 @@ 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");
|
||||
}
|
||||
public SquarePlotManager(SquarePlotWorld squarePlotWorld) {
|
||||
super(squarePlotWorld);
|
||||
this.squarePlotWorld = squarePlotWorld;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -81,7 +81,7 @@ public abstract class PlotArea {
|
||||
@Nullable final PlotId max) {
|
||||
this.worldname = worldName;
|
||||
this.id = id;
|
||||
this.manager = generator.getNewPlotManager(this);
|
||||
this.manager = createManager();
|
||||
this.generator = generator;
|
||||
if (min == null || max == null) {
|
||||
if (min != max) {
|
||||
@ -102,6 +102,8 @@ public abstract class PlotArea {
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract PlotManager createManager();
|
||||
|
||||
public LocalBlockQueue getQueue(final boolean autoQueue) {
|
||||
return GlobalBlockQueue.IMP.getNewQueue(worldname, autoQueue);
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ public abstract class PlotManager {
|
||||
private final PlotArea plotArea;
|
||||
|
||||
public PlotManager(PlotArea plotArea) {
|
||||
|
||||
this.plotArea = plotArea;
|
||||
}
|
||||
|
||||
|
@ -26,6 +26,11 @@ public class SinglePlotArea extends GridPlotWorld {
|
||||
this.DEFAULT_HOME = new PlotLoc(Integer.MAX_VALUE, Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PlotManager createManager() {
|
||||
return new SinglePlotManager(this);
|
||||
}
|
||||
|
||||
@Override public void loadConfiguration(ConfigurationSection config) {
|
||||
VOID = config.getBoolean("void", false);
|
||||
}
|
||||
|
@ -81,10 +81,6 @@ public class SingleWorldGenerator extends IndependentPlotGenerator {
|
||||
return ((SinglePlotAreaManager) PlotSquared.get().getPlotAreaManager()).getArea();
|
||||
}
|
||||
|
||||
@Override public PlotManager getNewPlotManager(PlotArea plotArea) {
|
||||
return new SinglePlotManager(plotArea);
|
||||
}
|
||||
|
||||
@Override public void initialize(PlotArea area) {
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user