mirror of
https://github.com/IntellectualSites/PlotSquared.git
synced 2024-11-26 07:06:44 +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 void initialize(PlotArea area) {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public PlotManager getNewPlotManager(PlotArea plotArea) {
|
|
||||||
return PlotSquared.get().IMP.getDefaultGenerator().getNewPlotManager(plotArea);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public String getName() {
|
@Override public String getName() {
|
||||||
return this.chunkGenerator.getClass().getName();
|
return this.chunkGenerator.getClass().getName();
|
||||||
}
|
}
|
||||||
|
@ -1086,7 +1086,7 @@ import java.util.zip.ZipInputStream;
|
|||||||
}
|
}
|
||||||
// Conventional plot generator
|
// Conventional plot generator
|
||||||
PlotArea plotArea = plotGenerator.getNewPlotArea(world, null, null, null);
|
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 + "&aDetected world load for '" + world + "'");
|
||||||
PlotSquared
|
PlotSquared
|
||||||
.log(Captions.PREFIX + "&3 - generator: &7" + baseGenerator + ">" + plotGenerator);
|
.log(Captions.PREFIX + "&3 - generator: &7" + baseGenerator + ">" + plotGenerator);
|
||||||
|
@ -15,13 +15,9 @@ public class ClassicPlotManager extends SquarePlotManager {
|
|||||||
|
|
||||||
private final ClassicPlotWorld classicPlotWorld;
|
private final ClassicPlotWorld classicPlotWorld;
|
||||||
|
|
||||||
public ClassicPlotManager(PlotArea plotArea) {
|
public ClassicPlotManager(ClassicPlotWorld classicPlotWorld) {
|
||||||
super(plotArea);
|
super(classicPlotWorld);
|
||||||
if (plotArea instanceof ClassicPlotWorld){
|
this.classicPlotWorld = classicPlotWorld;
|
||||||
classicPlotWorld = (ClassicPlotWorld)plotArea;
|
|
||||||
} else {
|
|
||||||
throw new RuntimeException("ClassicPlotManager requires plotArea to be an instance of ClassicPlotWorld");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public boolean setComponent(PlotId plotId, String component,
|
@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);
|
return new HybridPlotWorld(world, id, this, min, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public PlotManager getNewPlotManager(PlotArea plotArea) {
|
|
||||||
return new HybridPlotManager(plotArea);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public void initialize(PlotArea area) {
|
@Override public void initialize(PlotArea area) {
|
||||||
// All initialization is done in the PlotArea class
|
// All initialization is done in the PlotArea class
|
||||||
}
|
}
|
||||||
|
@ -23,13 +23,9 @@ public class HybridPlotManager extends ClassicPlotManager {
|
|||||||
|
|
||||||
private final HybridPlotWorld hybridPlotWorld;
|
private final HybridPlotWorld hybridPlotWorld;
|
||||||
|
|
||||||
public HybridPlotManager(PlotArea plotArea) {
|
public HybridPlotManager(HybridPlotWorld hybridPlotWorld) {
|
||||||
super(plotArea);
|
super(hybridPlotWorld);
|
||||||
if (plotArea instanceof HybridPlotWorld){
|
this.hybridPlotWorld = hybridPlotWorld;
|
||||||
hybridPlotWorld = (HybridPlotWorld)plotArea;
|
|
||||||
} else {
|
|
||||||
throw new RuntimeException("HybridPlotManager requires plotArea to be an instance of HybridPlotWorld");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public void exportTemplate() throws IOException {
|
@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.Plot;
|
||||||
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
|
import com.github.intellectualsites.plotsquared.plot.object.PlotArea;
|
||||||
import com.github.intellectualsites.plotsquared.plot.object.PlotId;
|
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.object.schematic.Schematic;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
|
import com.github.intellectualsites.plotsquared.plot.util.MainUtil;
|
||||||
import com.github.intellectualsites.plotsquared.plot.util.MathMan;
|
import com.github.intellectualsites.plotsquared.plot.util.MathMan;
|
||||||
@ -43,6 +44,11 @@ public class HybridPlotWorld extends ClassicPlotWorld {
|
|||||||
super(worldName, id, generator, min, max);
|
super(worldName, id, generator, min, max);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected PlotManager createManager() {
|
||||||
|
return new HybridPlotManager(this);
|
||||||
|
}
|
||||||
|
|
||||||
public static byte wrap(byte data, int start) {
|
public static byte wrap(byte data, int start) {
|
||||||
if ((data >= start) && (data < (start + 4))) {
|
if ((data >= start) && (data < (start + 4))) {
|
||||||
data = (byte) ((((data - start) + 2) & 3) + start);
|
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);
|
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.
|
* If any additional setup options need to be changed before world creation.
|
||||||
* - e.g. If setup doesn't support some standard options
|
* - e.g. If setup doesn't support some standard options
|
||||||
|
@ -16,13 +16,9 @@ public abstract class SquarePlotManager extends GridPlotManager {
|
|||||||
|
|
||||||
private final SquarePlotWorld squarePlotWorld;
|
private final SquarePlotWorld squarePlotWorld;
|
||||||
|
|
||||||
public SquarePlotManager(PlotArea plotArea) {
|
public SquarePlotManager(SquarePlotWorld squarePlotWorld) {
|
||||||
super(plotArea);
|
super(squarePlotWorld);
|
||||||
if (plotArea instanceof SquarePlotWorld){
|
this.squarePlotWorld = squarePlotWorld;
|
||||||
squarePlotWorld = (SquarePlotWorld)plotArea;
|
|
||||||
} else {
|
|
||||||
throw new RuntimeException("SquarePlotManager requires plotArea to be an instance of SquarePlotWorld");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -81,7 +81,7 @@ public abstract class PlotArea {
|
|||||||
@Nullable final PlotId max) {
|
@Nullable final PlotId max) {
|
||||||
this.worldname = worldName;
|
this.worldname = worldName;
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.manager = generator.getNewPlotManager(this);
|
this.manager = createManager();
|
||||||
this.generator = generator;
|
this.generator = generator;
|
||||||
if (min == null || max == null) {
|
if (min == null || max == null) {
|
||||||
if (min != max) {
|
if (min != max) {
|
||||||
@ -102,6 +102,8 @@ public abstract class PlotArea {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract PlotManager createManager();
|
||||||
|
|
||||||
public LocalBlockQueue getQueue(final boolean autoQueue) {
|
public LocalBlockQueue getQueue(final boolean autoQueue) {
|
||||||
return GlobalBlockQueue.IMP.getNewQueue(worldname, autoQueue);
|
return GlobalBlockQueue.IMP.getNewQueue(worldname, autoQueue);
|
||||||
}
|
}
|
||||||
|
@ -13,7 +13,6 @@ public abstract class PlotManager {
|
|||||||
private final PlotArea plotArea;
|
private final PlotArea plotArea;
|
||||||
|
|
||||||
public PlotManager(PlotArea plotArea) {
|
public PlotManager(PlotArea plotArea) {
|
||||||
|
|
||||||
this.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);
|
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) {
|
@Override public void loadConfiguration(ConfigurationSection config) {
|
||||||
VOID = config.getBoolean("void", false);
|
VOID = config.getBoolean("void", false);
|
||||||
}
|
}
|
||||||
|
@ -81,10 +81,6 @@ public class SingleWorldGenerator extends IndependentPlotGenerator {
|
|||||||
return ((SinglePlotAreaManager) PlotSquared.get().getPlotAreaManager()).getArea();
|
return ((SinglePlotAreaManager) PlotSquared.get().getPlotAreaManager()).getArea();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override public PlotManager getNewPlotManager(PlotArea plotArea) {
|
|
||||||
return new SinglePlotManager(plotArea);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override public void initialize(PlotArea area) {
|
@Override public void initialize(PlotArea area) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user