forked from SteamWar/SteamWar
Fix runtime errors
This commit is contained in:
+5
-1
@@ -48,9 +48,13 @@ public abstract class DynamicRegion implements Region {
|
||||
this.id = id;
|
||||
this.minX = minX;
|
||||
this.minZ = minZ;
|
||||
init();
|
||||
DynamicRegionSystem.INSTANCE.add(this);
|
||||
saveRegion();
|
||||
}
|
||||
|
||||
public abstract void init();
|
||||
|
||||
public void update(DynamicRegion updateFrom) {
|
||||
// TODO: Implement further
|
||||
}
|
||||
@@ -61,7 +65,7 @@ public abstract class DynamicRegion implements Region {
|
||||
}
|
||||
|
||||
public void delete() {
|
||||
if (getType().isCannotDelete()) return;
|
||||
if (!getType().isDeletable()) return;
|
||||
DynamicRegionSystem.INSTANCE.remove(this);
|
||||
DynamicRegionRepository.deleteRegion(this);
|
||||
|
||||
|
||||
+2
-2
@@ -138,7 +138,7 @@ public class DynamicRegionRepository {
|
||||
}
|
||||
RegionConstructorData constructorData = DynamicRegionSystem.constructorDataMap.get(regionClass);
|
||||
|
||||
Tile tile = Tile.fromTile(tileX, tileZ).validOrNull();
|
||||
Tile tile = Tile.fromTile(tileX, tileZ).orElse(null);
|
||||
if (tile == null) {
|
||||
RegionSystem.LOGGER.log(Level.SEVERE, "Failed to read region metadata file (tile is no longer in bounds)");
|
||||
continue;
|
||||
@@ -226,7 +226,7 @@ public class DynamicRegionRepository {
|
||||
if (!region.getType().isGlobal()) {
|
||||
RegionConstructorData constructorData = DynamicRegionSystem.constructorDataMap.get(region.getClass());
|
||||
Point point = region.getArea().getMinPoint(false);
|
||||
Tile tile = Tile.fromPoint(point);
|
||||
Tile tile = Tile.fromPoint(point).get();
|
||||
|
||||
writeMetaFile(regionDirectory, constructorData, tile);
|
||||
}
|
||||
|
||||
+8
-16
@@ -42,29 +42,21 @@ public class Tile {
|
||||
this.tileZ = tileZ;
|
||||
}
|
||||
|
||||
public Optional<Tile> valid() {
|
||||
return Optional.ofNullable(validOrNull());
|
||||
public static Optional<Tile> fromTile(int tileX, int tileZ) {
|
||||
if (tileX < minTile || tileZ < minTile) return Optional.empty();
|
||||
if (tileX > maxTile || tileZ > maxTile) return Optional.empty();
|
||||
return Optional.of(new Tile(tileX, tileZ));
|
||||
}
|
||||
|
||||
public Tile validOrNull() {
|
||||
if (tileX < minTile || tileZ < minTile) return null;
|
||||
if (tileX > maxTile || tileZ > maxTile) return null;
|
||||
return this;
|
||||
}
|
||||
|
||||
public static Tile fromTile(int tileX, int tileZ) {
|
||||
return new Tile(tileX, tileZ);
|
||||
}
|
||||
|
||||
public static Tile fromLocation(Location location) {
|
||||
public static Optional<Tile> fromLocation(Location location) {
|
||||
return fromXZ(location.getBlockX(), location.getBlockZ());
|
||||
}
|
||||
|
||||
public static Tile fromPoint(Point point) {
|
||||
public static Optional<Tile> fromPoint(Point point) {
|
||||
return fromXZ(point.getX(), point.getZ());
|
||||
}
|
||||
|
||||
public static Tile fromXZ(int x, int z) {
|
||||
public static Optional<Tile> fromXZ(int x, int z) {
|
||||
x = (int) Math.floor((x + tileOffset) / (double) tileSize);
|
||||
z = (int) Math.floor((z + tileOffset) / (double) tileSize);
|
||||
return fromTile(x, z);
|
||||
@@ -126,7 +118,7 @@ public class Tile {
|
||||
return getCenterLocation(tileX, tileZ);
|
||||
}
|
||||
|
||||
public Tile add(int offsetX, int offsetZ) {
|
||||
public Optional<Tile> add(int offsetX, int offsetZ) {
|
||||
return fromTile(tileX + offsetX, tileZ + offsetZ);
|
||||
}
|
||||
|
||||
|
||||
+8
-8
@@ -33,6 +33,7 @@ import org.bukkit.Bukkit;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
public class PathArea implements Region.Area {
|
||||
@@ -46,8 +47,8 @@ public class PathArea implements Region.Area {
|
||||
private enum Side {
|
||||
North(0, -1, 7, 0, 0),
|
||||
South(0, 1, 7, 14, 180),
|
||||
West(-1, 0, 0, 7, 90),
|
||||
East(1, 0, 14, 7, 270),
|
||||
West(-1, 0, 0, 7, 90),
|
||||
East(1, 0, 14, 7, 270),
|
||||
;
|
||||
|
||||
private final int tileOffsetX;
|
||||
@@ -203,7 +204,7 @@ public class PathArea implements Region.Area {
|
||||
for (int x = -1; x <= 1; x++) {
|
||||
for (int z = -1; z <= 1; z++) {
|
||||
if (x == 0 && z == 0) continue;
|
||||
Tile tile = this.tile.add(x, z).validOrNull();
|
||||
Tile tile = this.tile.add(x, z).orElse(null);
|
||||
if (tile == null) {
|
||||
return false;
|
||||
}
|
||||
@@ -216,12 +217,11 @@ public class PathArea implements Region.Area {
|
||||
}
|
||||
|
||||
private RegionType.ConnectionType getConnectionType(Side side, Side optionalSide) {
|
||||
Tile optionalTile = this.tile.add(side.tileOffsetX, side.tileOffsetZ).validOrNull();
|
||||
if (optionalTile == null) return RegionType.ConnectionType.Global;
|
||||
Optional<Tile> optionalTile = this.tile.add(side.tileOffsetX, side.tileOffsetZ);
|
||||
if (optionalSide != null) {
|
||||
optionalTile = optionalTile.add(optionalSide.tileOffsetX, optionalSide.tileOffsetZ);
|
||||
if (optionalTile == null) return RegionType.ConnectionType.Global;
|
||||
optionalTile = optionalTile.flatMap(tile -> tile.add(optionalSide.tileOffsetX, optionalSide.tileOffsetZ));
|
||||
}
|
||||
return DynamicRegionSystem.INSTANCE.get(tile).getType().getConnectionType();
|
||||
return optionalTile.map(tile -> DynamicRegionSystem.INSTANCE.get(tile.getCenterLocation()).getType().getConnectionType())
|
||||
.orElse(RegionType.ConnectionType.Global);
|
||||
}
|
||||
}
|
||||
|
||||
+6
-2
@@ -40,11 +40,15 @@ import java.util.UUID;
|
||||
)
|
||||
public class PathRegion extends DynamicRegion {
|
||||
|
||||
private final PathArea area;
|
||||
private PathArea area;
|
||||
|
||||
public PathRegion(UUID id, int minX, int minZ) {
|
||||
super(id, minX, minZ);
|
||||
area = new PathArea(Tile.fromXZ(minX, minZ).valid().orElseThrow(), this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
area = new PathArea(Tile.fromXZ(minX, minZ).orElseThrow(), this);
|
||||
regionData = new PathRegionData(this);
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -44,11 +44,15 @@ public class DryRegion extends DynamicRegion {
|
||||
|
||||
private static final VariantSelector DRY = VariantSelector.Get(new File(SPECIAL_PATH_DIR, "dry"));
|
||||
|
||||
private final SpecialArea area;
|
||||
private SpecialArea area;
|
||||
|
||||
public DryRegion(UUID id, int minX, int minZ) {
|
||||
super(id, minX, minZ);
|
||||
area = new SpecialArea(Tile.fromXZ(minX, minZ).valid().orElseThrow(), this, DRY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
area = new SpecialArea(Tile.fromXZ(minX, minZ).orElseThrow(), this, DRY);
|
||||
regionData = new SpecialRegionData(this);
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -44,11 +44,15 @@ public class WetRegion extends DynamicRegion {
|
||||
|
||||
private static final VariantSelector WET = VariantSelector.Get(new File(SPECIAL_PATH_DIR, "wet"));
|
||||
|
||||
private final SpecialArea area;
|
||||
private SpecialArea area;
|
||||
|
||||
public WetRegion(UUID id, int minX, int minZ) {
|
||||
super(id, minX, minZ);
|
||||
area = new SpecialArea(Tile.fromXZ(minX, minZ).valid().orElseThrow(), this, WET);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init() {
|
||||
area = new SpecialArea(Tile.fromXZ(minX, minZ).orElseThrow(), this, WET);
|
||||
regionData = new SpecialRegionData(this);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user