mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-11-30 06:33:49 +01:00
Proper dimension processing (#2015)
* Adds ProtectionBoundingBox for environment Since minecraft introduced different island heights for different dimensions, protection bounding box were returned wrong area for nether and end dimensions. This change adds a new method that allows to get proper protection bounding box for requested dimension. Due to the fact, that nether and end islands can be disabled, then this method may return null. Fixes #2014 * Adds BoundingBox for environment Since minecraft introduced different island heights for different dimensions, bounding box were returned wrong area for nether and end dimensions. This change adds a new method that allows to get proper bounding box for requested dimension. Due to the fact, that nether and end islands can be disabled, then this method may return null. Part of #2014 * Fixes Island#onIsland check for non-island worlds Island#onIsland method was missing checks if island mode is enabled for requested dimension. It returned false positive situations in cases when island generation were disabled in nether or the end worlds. * Fixes Island#inIslandSpace check for non-island worlds Island#inIslandSpace method was missing checks if island mode is enabled for requested dimension. It returned false positive situations in cases when island generation were disabled in nether or the end worlds. * Adds some helper methods in Island object. - Island#getNetherWorld - returns the nether world or null - Island#getEndWorld - returns the end world or null - Island#getWorld(Environment) - returns world of requested environment or null - Island#isNetherIslandEnabled - returns if nether is generated and nether islands are enabled. - Island#isEndIslandEnabled - returns if end is generated and end islands are enabled.
This commit is contained in:
parent
6c1399c2b4
commit
6f791420e7
@ -640,6 +640,55 @@ public class Island implements DataObject, MetaDataAble {
|
|||||||
return world;
|
return world;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the nether world
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public World getNetherWorld()
|
||||||
|
{
|
||||||
|
return this.getWorld(Environment.NETHER);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the end world
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public World getEndWorld()
|
||||||
|
{
|
||||||
|
return this.getWorld(Environment.THE_END);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method returns this island world in given environment. This method can return {@code null} if dimension is
|
||||||
|
* disabled.
|
||||||
|
* @param environment The environment of the island world.
|
||||||
|
* @return the world in given environment.
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public World getWorld(Environment environment)
|
||||||
|
{
|
||||||
|
if (Environment.NORMAL.equals(environment))
|
||||||
|
{
|
||||||
|
return this.world;
|
||||||
|
}
|
||||||
|
else if (Environment.THE_END.equals(environment) && this.isEndIslandEnabled())
|
||||||
|
{
|
||||||
|
return this.getPlugin().getIWM().getEndWorld(this.world);
|
||||||
|
}
|
||||||
|
else if (Environment.NETHER.equals(environment) && this.isNetherIslandEnabled())
|
||||||
|
{
|
||||||
|
return this.getPlugin().getIWM().getNetherWorld(this.world);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return the x coordinate of the island center
|
* @return the x coordinate of the island center
|
||||||
*/
|
*/
|
||||||
@ -676,8 +725,13 @@ public class Island implements DataObject, MetaDataAble {
|
|||||||
* @param location - location
|
* @param location - location
|
||||||
* @return true if in island space
|
* @return true if in island space
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("ConstantConditions")
|
||||||
public boolean inIslandSpace(Location location) {
|
public boolean inIslandSpace(Location location) {
|
||||||
return Util.sameWorld(world, location.getWorld()) && inIslandSpace(location.getBlockX(), location.getBlockZ());
|
return Util.sameWorld(this.world, location.getWorld()) &&
|
||||||
|
(location.getWorld().getEnvironment().equals(Environment.NORMAL) ||
|
||||||
|
this.getPlugin().getIWM().isIslandNether(location.getWorld()) ||
|
||||||
|
this.getPlugin().getIWM().isIslandEnd(location.getWorld())) &&
|
||||||
|
this.inIslandSpace(location.getBlockX(), location.getBlockZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -690,26 +744,81 @@ public class Island implements DataObject, MetaDataAble {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a {@link BoundingBox} of the full island space.
|
* Returns a {@link BoundingBox} of the full island space for overworld.
|
||||||
* @return a {@link BoundingBox} of the full island space.
|
* @return a {@link BoundingBox} of the full island space.
|
||||||
* @since 1.5.2
|
* @since 1.5.2
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("ConstantConditions")
|
||||||
|
@NotNull
|
||||||
public BoundingBox getBoundingBox() {
|
public BoundingBox getBoundingBox() {
|
||||||
return new BoundingBox(getMinX(), world.getMinHeight(), getMinZ(), getMaxX(), world.getMaxHeight(), getMaxZ());
|
return this.getBoundingBox(Environment.NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Using this method in the filtering for getVisitors and hasVisitors
|
|
||||||
* @param player
|
|
||||||
* @return true if player is a visitor
|
|
||||||
*/
|
|
||||||
private boolean playerIsVisitor(Player player) {
|
|
||||||
if (player.getGameMode() == GameMode.SPECTATOR) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return onIsland(player.getLocation()) && getRank(User.getInstance(player)) == RanksManager.VISITOR_RANK;
|
/**
|
||||||
}
|
* Returns a {@link BoundingBox} of this island's space area in requested dimension.
|
||||||
|
* @param environment the requested dimension.
|
||||||
|
* @return a {@link BoundingBox} of this island's space area or {@code null} if island is not created in requested dimension.
|
||||||
|
* @since 1.21.0
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public BoundingBox getBoundingBox(Environment environment)
|
||||||
|
{
|
||||||
|
BoundingBox boundingBox;
|
||||||
|
|
||||||
|
if (Environment.NORMAL.equals(environment))
|
||||||
|
{
|
||||||
|
// Return normal world bounding box.
|
||||||
|
boundingBox = new BoundingBox(this.getMinX(),
|
||||||
|
this.world.getMinHeight(),
|
||||||
|
this.getMinZ(),
|
||||||
|
this.getMaxX(),
|
||||||
|
this.world.getMaxHeight(),
|
||||||
|
this.getMaxZ());
|
||||||
|
}
|
||||||
|
else if (Environment.THE_END.equals(environment) && this.isEndIslandEnabled())
|
||||||
|
{
|
||||||
|
// If end world is generated, return end island bounding box.
|
||||||
|
//noinspection ConstantConditions
|
||||||
|
boundingBox = new BoundingBox(this.getMinX(),
|
||||||
|
this.getEndWorld().getMinHeight(),
|
||||||
|
this.getMinZ(),
|
||||||
|
this.getMaxX(),
|
||||||
|
this.getEndWorld().getMaxHeight(),
|
||||||
|
this.getMaxZ());
|
||||||
|
}
|
||||||
|
else if (Environment.NETHER.equals(environment) && this.isNetherIslandEnabled())
|
||||||
|
{
|
||||||
|
// If nether world is generated, return nether island bounding box.
|
||||||
|
//noinspection ConstantConditions
|
||||||
|
boundingBox = new BoundingBox(this.getMinX(),
|
||||||
|
this.getNetherWorld().getMinHeight(),
|
||||||
|
this.getMinZ(),
|
||||||
|
this.getMaxX(),
|
||||||
|
this.getNetherWorld().getMaxHeight(),
|
||||||
|
this.getMaxZ());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
boundingBox = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return boundingBox;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Using this method in the filtering for getVisitors and hasVisitors
|
||||||
|
* @param player The player that must be checked.
|
||||||
|
* @return true if player is a visitor
|
||||||
|
*/
|
||||||
|
private boolean playerIsVisitor(Player player) {
|
||||||
|
if (player.getGameMode() == GameMode.SPECTATOR) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return onIsland(player.getLocation()) && getRank(User.getInstance(player)) == RanksManager.VISITOR_RANK;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of players that are physically inside the island's protection range and that are visitors.
|
* Returns a list of players that are physically inside the island's protection range and that are visitors.
|
||||||
@ -801,24 +910,83 @@ public class Island implements DataObject, MetaDataAble {
|
|||||||
* @param target location to check, not null
|
* @param target location to check, not null
|
||||||
* @return {@code true} if this location is within this island's protected area, {@code false} otherwise.
|
* @return {@code true} if this location is within this island's protected area, {@code false} otherwise.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("ConstantConditions")
|
||||||
public boolean onIsland(@NonNull Location target) {
|
public boolean onIsland(@NonNull Location target) {
|
||||||
return Util.sameWorld(world, target.getWorld()) && target.getBlockX() >= getMinProtectedX() && target.getBlockX() < (getMinProtectedX() + protectionRange * 2) && target.getBlockZ() >= getMinProtectedZ() && target.getBlockZ() < (getMinProtectedZ() + protectionRange * 2);
|
return Util.sameWorld(this.world, target.getWorld()) &&
|
||||||
|
(target.getWorld().getEnvironment().equals(Environment.NORMAL) ||
|
||||||
|
this.getPlugin().getIWM().isIslandNether(target.getWorld()) ||
|
||||||
|
this.getPlugin().getIWM().isIslandEnd(target.getWorld())) &&
|
||||||
|
target.getBlockX() >= this.getMinProtectedX() &&
|
||||||
|
target.getBlockX() < (this.getMinProtectedX() + this.protectionRange * 2) &&
|
||||||
|
target.getBlockZ() >= this.getMinProtectedZ() &&
|
||||||
|
target.getBlockZ() < (this.getMinProtectedZ() + this.protectionRange * 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a {@link BoundingBox} of this island's protected area.
|
* Returns a {@link BoundingBox} of this island's protected area for overworld.
|
||||||
* @return a {@link BoundingBox} of this island's protected area.
|
* @return a {@link BoundingBox} of this island's protected area.
|
||||||
* @since 1.5.2
|
* @since 1.5.2
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("ConstantConditions")
|
||||||
|
@NotNull
|
||||||
public BoundingBox getProtectionBoundingBox() {
|
public BoundingBox getProtectionBoundingBox() {
|
||||||
return new BoundingBox(this.getMinProtectedX(),
|
return this.getProtectionBoundingBox(Environment.NORMAL);
|
||||||
this.world.getMinHeight(),
|
|
||||||
this.getMinProtectedZ(),
|
|
||||||
this.getMaxProtectedX(),
|
|
||||||
this.world.getMaxHeight(),
|
|
||||||
this.getMaxProtectedZ());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a {@link BoundingBox} of this island's protected area.
|
||||||
|
* @param environment an environment of bounding box area.
|
||||||
|
* @return a {@link BoundingBox} of this island's protected area or {@code null} if island is not created in required dimension.
|
||||||
|
* in required dimension.
|
||||||
|
* @since 1.21.0
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public BoundingBox getProtectionBoundingBox(Environment environment)
|
||||||
|
{
|
||||||
|
BoundingBox boundingBox;
|
||||||
|
|
||||||
|
if (Environment.NORMAL.equals(environment))
|
||||||
|
{
|
||||||
|
// Return normal world bounding box.
|
||||||
|
boundingBox = new BoundingBox(this.getMinProtectedX(),
|
||||||
|
this.world.getMinHeight(),
|
||||||
|
this.getMinProtectedZ(),
|
||||||
|
this.getMaxProtectedX(),
|
||||||
|
this.world.getMaxHeight(),
|
||||||
|
this.getMaxProtectedZ());
|
||||||
|
}
|
||||||
|
else if (Environment.THE_END.equals(environment) && this.isEndIslandEnabled())
|
||||||
|
{
|
||||||
|
// If end world is generated, return end island bounding box.
|
||||||
|
//noinspection ConstantConditions
|
||||||
|
boundingBox = new BoundingBox(this.getMinProtectedX(),
|
||||||
|
this.getEndWorld().getMinHeight(),
|
||||||
|
this.getMinProtectedZ(),
|
||||||
|
this.getMaxProtectedX(),
|
||||||
|
this.getEndWorld().getMaxHeight(),
|
||||||
|
this.getMaxProtectedZ());
|
||||||
|
}
|
||||||
|
else if (Environment.NETHER.equals(environment) && this.isNetherIslandEnabled())
|
||||||
|
{
|
||||||
|
// If nether world is generated, return nether island bounding box.
|
||||||
|
//noinspection ConstantConditions
|
||||||
|
boundingBox = new BoundingBox(this.getMinProtectedX(),
|
||||||
|
this.getNetherWorld().getMinHeight(),
|
||||||
|
this.getMinProtectedZ(),
|
||||||
|
this.getMaxProtectedX(),
|
||||||
|
this.getNetherWorld().getMaxHeight(),
|
||||||
|
this.getMaxProtectedZ());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
boundingBox = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return boundingBox;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes a player from the team member map. Generally, you should
|
* Removes a player from the team member map. Generally, you should
|
||||||
* use {@link world.bentobox.bentobox.managers.IslandsManager#removePlayer(World, UUID)}
|
* use {@link world.bentobox.bentobox.managers.IslandsManager#removePlayer(World, UUID)}
|
||||||
@ -1258,6 +1426,15 @@ public class Island implements DataObject, MetaDataAble {
|
|||||||
return nether != null && !getCenter().toVector().toLocation(nether).getBlock().getType().isAir();
|
return nether != null && !getCenter().toVector().toLocation(nether).getBlock().getType().isAir();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether this island has its nether island mode enabled or not.
|
||||||
|
* @return {@code true} if this island has its nether island enabled, {@code false} otherwise.
|
||||||
|
* @since 1.21.0
|
||||||
|
*/
|
||||||
|
public boolean isNetherIslandEnabled() {
|
||||||
|
return this.getPlugin().getIWM().isNetherGenerate(this.world) && this.getPlugin().getIWM().isNetherIslands(this.world);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether this island has its end island generated or not.
|
* Checks whether this island has its end island generated or not.
|
||||||
* @return {@code true} if this island has its end island generated, {@code false} otherwise.
|
* @return {@code true} if this island has its end island generated, {@code false} otherwise.
|
||||||
@ -1269,6 +1446,16 @@ public class Island implements DataObject, MetaDataAble {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks whether this island has its end island mode enabled or not.
|
||||||
|
* @return {@code true} if this island has its end island enabled, {@code false} otherwise.
|
||||||
|
* @since 1.21.0
|
||||||
|
*/
|
||||||
|
public boolean isEndIslandEnabled() {
|
||||||
|
return this.getPlugin().getIWM().isEndGenerate(this.world) && this.getPlugin().getIWM().isEndIslands(this.world);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if a flag is on cooldown. Only stored in memory so a server restart will reset the cooldown.
|
* Checks if a flag is on cooldown. Only stored in memory so a server restart will reset the cooldown.
|
||||||
* @param flag - flag
|
* @param flag - flag
|
||||||
|
Loading…
Reference in New Issue
Block a user