Fixed bug with protection range (in Island)

minX, minZ, minProtectedX and minProtectedZ are no longer variables : to get them, we have to use the related methods. As they get recalculated at each call, it ensures they follow the changes (especially with the protectionRange)
This commit is contained in:
Florian CUNY 2018-07-19 12:58:59 +02:00
parent 09c0eb846e
commit a5a1ccb7e5
2 changed files with 6 additions and 54 deletions

View File

@ -54,18 +54,6 @@ public class Island implements DataObject {
@Expose
private int range;
// Coordinates of the island area
@Expose
private int minX;
@Expose
private int minZ;
// Coordinates of minimum protected area
@Expose
private int minProtectedX;
@Expose
private int minProtectedZ;
// Protection size
@Expose
private int protectionRange;
@ -117,11 +105,7 @@ public class Island implements DataObject {
// Make a copy of the location
center = new Location(location.getWorld(), location.getX(), location.getY(), location.getZ());
range = BSkyBlock.getInstance().getIWM().getIslandDistance(world);
minX = center.getBlockX() - range;
minZ = center.getBlockZ() - range;
this.protectionRange = protectionRange;
minProtectedX = center.getBlockX() - protectionRange;
minProtectedZ = center.getBlockZ() - protectionRange;
}
/**
@ -225,28 +209,28 @@ public class Island implements DataObject {
* @return the minProtectedX
*/
public int getMinProtectedX() {
return minProtectedX;
return center.getBlockX() - protectionRange;
}
/**
* @return the minProtectedZ
*/
public int getMinProtectedZ() {
return minProtectedZ;
return center.getBlockZ() - protectionRange;
}
/**
* @return the minX
*/
public int getMinX() {
return minX;
return center.getBlockX() - range;
}
/**
* @return the minZ
*/
public int getMinZ() {
return minZ;
return center.getBlockZ() - range;
}
/**
@ -382,7 +366,7 @@ public class Island implements DataObject {
* @return true if in the island space
*/
public boolean inIslandSpace(int x, int z) {
return x >= minX && x < minX + range*2 && z >= minZ && z < minZ + range*2;
return x >= getMinX() && x < getMinX() + range*2 && z >= getMinZ() && z < getMinZ() + range*2;
}
public boolean inIslandSpace(Location location) {
@ -442,7 +426,7 @@ public class Island implements DataObject {
* @return true if it is, false if not
*/
public boolean onIsland(Location target) {
return Util.sameWorld(world, target.getWorld()) && target.getBlockX() >= minProtectedX && target.getBlockX() < (minProtectedX + protectionRange * 2) && target.getBlockZ() >= minProtectedZ && target.getBlockZ() < (minProtectedZ + protectionRange * 2);
return Util.sameWorld(world, target.getWorld()) && target.getBlockX() >= getMinProtectedX() && target.getBlockX() < (getMinProtectedX() + protectionRange * 2) && target.getBlockZ() >= getMinProtectedZ() && target.getBlockZ() < (getMinProtectedZ() + protectionRange * 2);
}
/**
@ -523,34 +507,6 @@ public class Island implements DataObject {
this.members = members;
}
/**
* @param minProtectedX the minProtectedX to set
*/
public final void setMinProtectedX(int minProtectedX) {
this.minProtectedX = minProtectedX;
}
/**
* @param minProtectedZ the minProtectedZ to set
*/
public final void setMinProtectedZ(int minProtectedZ) {
this.minProtectedZ = minProtectedZ;
}
/**
* @param minX the minX to set
*/
public final void setMinX(int minX) {
this.minX = minX;
}
/**
* @param minZ the minZ to set
*/
public final void setMinZ(int minZ) {
this.minZ = minZ;
}
/**
* @param name - the display name to set
* Set to null to remove the display name

View File

@ -140,10 +140,6 @@ public class MySQLDatabaseHandlerTest {
members.put(UUID.randomUUID(), i);
}
island.setMembers(members);
island.setMinProtectedX(-100);
island.setMinProtectedZ(-300);
island.setMinX(-121);
island.setMinZ(-23423);
island.setName("ytasdgfsdfg");
island.setOwner(UUID.randomUUID());
island.setProtectionRange(100);