|
|
|
@ -29,12 +29,18 @@ public class Region { |
|
|
|
@DatabaseField(canBeNull = false) |
|
|
|
@DatabaseField(canBeNull = false) |
|
|
|
private int y1; |
|
|
|
private int y1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@DatabaseField(canBeNull = false) |
|
|
|
|
|
|
|
private int z1; |
|
|
|
|
|
|
|
|
|
|
|
@DatabaseField(canBeNull = false) |
|
|
|
@DatabaseField(canBeNull = false) |
|
|
|
private int x2; |
|
|
|
private int x2; |
|
|
|
|
|
|
|
|
|
|
|
@DatabaseField(canBeNull = false) |
|
|
|
@DatabaseField(canBeNull = false) |
|
|
|
private int y2; |
|
|
|
private int y2; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@DatabaseField(canBeNull = false) |
|
|
|
|
|
|
|
private int z2; |
|
|
|
|
|
|
|
|
|
|
|
@ForeignCollectionField(eager = true) |
|
|
|
@ForeignCollectionField(eager = true) |
|
|
|
private ForeignCollection<RegionMember> regionMembers; |
|
|
|
private ForeignCollection<RegionMember> regionMembers; |
|
|
|
|
|
|
|
|
|
|
|
@ -45,15 +51,20 @@ public class Region { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Region(String island, int regionType, int x1, int y1, int x2, int y2) { |
|
|
|
public Region(String island, int regionType, int x1, int y1, int z1, int x2, int y2, int z2) { |
|
|
|
this.island = island; |
|
|
|
this.island = island; |
|
|
|
this.regionType = regionType; |
|
|
|
this.regionType = regionType; |
|
|
|
this.x1 = Math.min(x1, x2); |
|
|
|
this.x1 = Math.min(x1, x2); |
|
|
|
this.y1 = Math.min(y1, y2); |
|
|
|
this.y1 = Math.min(y1, y2); |
|
|
|
this.x2 = Math.max(x1, x2) ; |
|
|
|
this.x2 = Math.max(x1, x2); |
|
|
|
this.y2 = Math.max(y1, y2); |
|
|
|
this.y2 = Math.max(y1, y2); |
|
|
|
|
|
|
|
this.z1 = Math.min(z1, z2); |
|
|
|
|
|
|
|
this.z2 = Math.max(z1, z2); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public int getId() { |
|
|
|
|
|
|
|
return id; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int getRegionType() { |
|
|
|
public int getRegionType() { |
|
|
|
return regionType; |
|
|
|
return regionType; |
|
|
|
@ -63,6 +74,14 @@ public class Region { |
|
|
|
return x1; |
|
|
|
return x1; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int getZ1() { |
|
|
|
|
|
|
|
return z1; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int getZ2() { |
|
|
|
|
|
|
|
return z2; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int getY1() { |
|
|
|
public int getY1() { |
|
|
|
return y1; |
|
|
|
return y1; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -101,7 +120,16 @@ public class Region { |
|
|
|
|
|
|
|
|
|
|
|
public void save(){ |
|
|
|
public void save(){ |
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
DaoRegistry.getRegionDao().createOrUpdate(this); |
|
|
|
DaoRegistry.getRegionDao().createOrUpdate(this); |
|
|
|
|
|
|
|
List<Region> regions = cache.get(island); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (regions == null) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
regions.removeIf(region -> region.getId() == this.id); |
|
|
|
|
|
|
|
regions.add(this); |
|
|
|
} catch (Exception e) { |
|
|
|
} catch (Exception e) { |
|
|
|
e.printStackTrace(); |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -110,10 +138,21 @@ public class Region { |
|
|
|
public void addRegionMember(String memberType, String member, String membershipType){ |
|
|
|
public void addRegionMember(String memberType, String member, String membershipType){ |
|
|
|
RegionMember regionMember = new RegionMember(this, memberType, member, membershipType); |
|
|
|
RegionMember regionMember = new RegionMember(this, memberType, member, membershipType); |
|
|
|
regionMember.save(); |
|
|
|
regionMember.save(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Region updatedRegion = Region.findById(this.id); |
|
|
|
|
|
|
|
List<Region> regions = cache.get(island); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (regions == null) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
regions.removeIf(region -> region.getId() == this.id); |
|
|
|
|
|
|
|
regions.add(updatedRegion); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public boolean isInside(int x, int y) { |
|
|
|
public boolean isInside(int x, int y, int z) { |
|
|
|
return x >= this.x1 && x <= this.x2 && y >= this.y1 && y <= this.y2; |
|
|
|
return x >= this.x1 && x <= this.x2 && y >= this.y1 && y <= this.y2 && z >= this.z1 && z <= this.z2; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static Region findById(int id) { |
|
|
|
public static Region findById(int id) { |
|
|
|
@ -136,7 +175,7 @@ public class Region { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static Region findRegion(int x, int y, String island) { |
|
|
|
public static Region findRegion(int x, int y, int z, String island) { |
|
|
|
|
|
|
|
|
|
|
|
Region region = null; |
|
|
|
Region region = null; |
|
|
|
int highestType = -1; |
|
|
|
int highestType = -1; |
|
|
|
@ -146,7 +185,7 @@ public class Region { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (Region cachedRegion : cache.get(island)) { |
|
|
|
for (Region cachedRegion : cache.get(island)) { |
|
|
|
if (!cachedRegion.isInside(x, y)) { |
|
|
|
if (!cachedRegion.isInside(x, y, z)) { |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
} |
|
|
|
} |
|
|
|
if (highestType >= cachedRegion.getRegionType()){ |
|
|
|
if (highestType >= cachedRegion.getRegionType()){ |
|
|
|
@ -160,6 +199,15 @@ public class Region { |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void changeBoundaries(int x1, int y1, int z1, int x2, int y2, int z2){ |
|
|
|
|
|
|
|
this.x1 = Math.min(x1, x2); |
|
|
|
|
|
|
|
this.y1 = Math.min(y1, y2); |
|
|
|
|
|
|
|
this.x2 = Math.max(x1, x2); |
|
|
|
|
|
|
|
this.y2 = Math.max(y1, y2); |
|
|
|
|
|
|
|
this.z1 = Math.min(z1, z2); |
|
|
|
|
|
|
|
this.z2 = Math.max(z1, z2); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|