Skip to content

Commit

Permalink
Implement ability to change player Biome via Console. (#24).
Browse files Browse the repository at this point in the history
There were no ability to change player biomes from console. It always required to be player as I never thought that someone will need to do it from console.
Now it should work.
  • Loading branch information
BONNe committed May 10, 2019
1 parent 424057d commit 12e82c0
Showing 1 changed file with 63 additions and 23 deletions.
86 changes: 63 additions & 23 deletions src/main/java/world/bentobox/biomes/tasks/BiomeUpdateHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,22 +126,59 @@ public boolean canChangeBiome()
return false;
}
}

// Init starting location.
this.standingLocation = this.targetUser.getLocation();
}
else
{
Island island = this.addon.getIslands().getIsland(this.world, this.targetUser);
if (this.updateMode.equals(UpdateMode.ISLAND))
{
this.standingLocation = this.targetUser.getLocation();

Optional<Island> onIsland =
this.addon.getIslands().getIslandAt(this.callerUser.getLocation());
// Return false if targeted user has no island.
return this.addon.getIslands().getIsland(this.world, this.targetUser) != null;
}
else if (this.callerUser.isPlayer())
{
// Chunk and square based update modes can be called only by player.

Island island = this.addon.getIslands().getIsland(this.world, this.targetUser);

Optional<Island> onIsland =
this.addon.getIslands().getIslandAt(this.callerUser.getLocation());

if (!onIsland.isPresent() || onIsland.get() != island)
{
// Admin is not on user island.
this.callerUser.sendMessage("biomes.messages.errors.missing-admin-island",
"[user]",
this.targetUser.getName());

return false;
}

if (this.updateMode != UpdateMode.ISLAND &&
(!onIsland.isPresent() || onIsland.get() != island))
// Admin must be located on island to change biome, as his location will be
// taken for update.
this.standingLocation = this.callerUser.getLocation();
}
else
{
// Admin is not on user island.
this.callerUser.sendMessage("biomes.messages.errors.missing-admin-island",
"[user]",
this.targetUser.getName());
return false;
// Check if target user is his island.
Island island = this.addon.getIslands().getIsland(this.world, this.targetUser);

Optional<Island> onIsland =
this.addon.getIslands().getIslandAt(this.targetUser.getLocation());

if (!onIsland.isPresent() || onIsland.get() != island)
{
// Admin is not on user island.
this.addon.logWarning("Biome change for player " + this.targetUser.getName() + " is not possible as he is not on his island!");
return false;
}

// Init start location
this.standingLocation = this.targetUser.getLocation();
}
}

Expand All @@ -157,13 +194,11 @@ public void updateIslandBiome()
Island island = this.addon.getIslands().getIsland(this.world, this.targetUser);
int range = island.getRange();

int minX = island.getMinX();
int minZ = island.getMinZ();

int maxX = minX + 2 * range;
int maxZ = minZ + 2 * range;
int minX = island.getCenter().getBlockX() - range;
int minZ = island.getCenter().getBlockZ() - range;

Location playerLocation = this.callerUser.getLocation();
int maxX = island.getCenter().getBlockX() + range;
int maxZ = island.getCenter().getBlockZ() + range;

// Calculate minimal and maximal coordinate based on update mode.

Expand All @@ -172,14 +207,14 @@ public void updateIslandBiome()
switch (this.updateMode)
{
case ISLAND:
task.setMinX(minX > maxX ? maxX : minX);
task.setMaxX(minX < maxX ? maxX : minX);
task.setMinZ(minZ > maxZ ? maxZ : minZ);
task.setMaxZ(minZ < maxZ ? maxZ : minZ);
task.setMinX(minX);
task.setMaxX(maxX);
task.setMinZ(minZ);
task.setMaxZ(maxZ);

break;
case CHUNK:
Chunk chunk = playerLocation.getChunk();
Chunk chunk = this.standingLocation.getChunk();

task.setMinX(Math.max(minX, (chunk.getX() - (this.updateNumber - 1)) << 4));
task.setMaxX(Math.min(maxX, (chunk.getX() + this.updateNumber) << 4) - 1);
Expand All @@ -191,7 +226,7 @@ public void updateIslandBiome()
case SQUARE:
int halfDiameter = this.updateNumber / 2;

int x = playerLocation.getBlockX();
int x = this.standingLocation.getBlockX();

if (x < 0)
{
Expand All @@ -204,7 +239,7 @@ public void updateIslandBiome()
task.setMaxX(Math.min(maxX, x + halfDiameter));
}

int z = playerLocation.getBlockZ();
int z = this.standingLocation.getBlockZ();

if (z < 0)
{
Expand Down Expand Up @@ -255,6 +290,11 @@ public void updateIslandBiome()
*/
private User targetUser;

/**
* This variable holds from which location Update process should start.
*/
private Location standingLocation;

/**
* This variable stores BiomesObject that must be applied.
*/
Expand Down

0 comments on commit 12e82c0

Please sign in to comment.