Skip to content

Commit

Permalink
Fixes admin SET biome command.
Browse files Browse the repository at this point in the history
After some rework to the Biomes addon, admins lost ability to change biome at any position. This should fix it, as now admins will be able to change biome based on location he is standing.

Fixes #121
  • Loading branch information
BONNe committed May 15, 2023
1 parent 6e9f9b3 commit 1dcd41b
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,38 @@ public boolean execute(User user, String label, List<String> input)
}

List<String> args = input.subList(1, input.size());
User target = this.getAddon().getPlayers().getUser(input.get(0));

String targetName = input.get(0);
boolean hasTarget;
User target;

if (HERE.equalsIgnoreCase(targetName))
{
target = this.getIslandsManager().getIslandAt(user.getLocation()).
map(Island::getOwner).
map(User::getInstance).
orElse(null);
hasTarget = true;
}
else
{
if (AdminCommand.this.getPlayers().getUUID(targetName) != null)
{
target = AdminCommand.this.getPlayers().getUser(targetName);
}
else
{
target = null;
}

hasTarget = target != null;
}

BiomesObject biome = AdminCommand.this.getBiomeObject(args, user);
Settings.UpdateMode updateMode = AdminCommand.this.getUpdateMode(args, user);
int size = AdminCommand.this.getUpdateRange(args, user);

if (target == null || biome == null || updateMode == null || size < 1)
if (!hasTarget || biome == null || updateMode == null || size < 1)
{
// Show help if something fails.
this.showHelp(this, user);
Expand All @@ -175,9 +201,9 @@ public boolean execute(User user, String label, List<String> input)

BiomeUpdateHelper helper = new BiomeUpdateHelper(this.getAddon(),
user,
target,
target == null ? user : target,
biome,
this.<BiomesAddon>getAddon().getAddonManager().getIslandData(this.getWorld(), user),
this.<BiomesAddon>getAddon().getAddonManager().getIslandData(this.getWorld(), target),
this.getWorld(),
updateMode,
size,
Expand Down Expand Up @@ -214,6 +240,7 @@ public Optional<List<String>> tabComplete(User user, String alias, List<String>
case 3:
// Create suggestions with all player names that is available for users.
Bukkit.getOnlinePlayers().forEach(player -> returnList.add(player.getName()));
returnList.add(HERE);

break;
case 4:
Expand Down Expand Up @@ -512,4 +539,15 @@ public Optional<List<String>> tabComplete(User user, String alias, List<String>
return Optional.of(Util.tabLimit(returnList, lastString));
}
}


// ---------------------------------------------------------------------
// Section: Static Variables
// ---------------------------------------------------------------------


/**
* The constant HERE.
*/
public static final String HERE = "here";
}
33 changes: 20 additions & 13 deletions src/main/java/world/bentobox/biomes/tasks/BiomeUpdateHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public class BiomeUpdateHelper
* @param world the world
* @param updateMode the update mode
* @param range the range
* @param canWithdraw the can withdraw
* @param notForced the biome change is forced. No withdraws are made.
*/
public BiomeUpdateHelper(BiomesAddon addon,
User callerUser,
Expand All @@ -70,7 +70,7 @@ public BiomeUpdateHelper(BiomesAddon addon,
World world,
UpdateMode updateMode,
int range,
boolean canWithdraw)
boolean notForced)
{
this.addon = addon;
this.callerUser = callerUser;
Expand All @@ -80,7 +80,7 @@ public BiomeUpdateHelper(BiomesAddon addon,
this.world = world;
this.updateMode = updateMode;
this.range = range;
this.canWithdraw = canWithdraw;
this.notForced = notForced;

this.worldProtectionFlag = BiomesAddon.BIOMES_WORLD_PROTECTION.isSetForWorld(this.world);
// Initialize standing location to be the location of the target user
Expand Down Expand Up @@ -126,7 +126,7 @@ public boolean canChangeBiome()

this.calculateArea();

if (this.callerUser == this.targetUser)
if (this.notForced)
{
if (!this.biome.getEnvironment().equals(this.callerUser.getWorld().getEnvironment()))
{
Expand Down Expand Up @@ -459,7 +459,7 @@ else if (World.Environment.THE_END.equals(this.biome.getEnvironment()))
}
});

if (this.canWithdraw)
if (this.notForced)
{
switch (this.biome.getCostMode())
{
Expand All @@ -484,9 +484,12 @@ private void runBiomeChangeTask(BiomeUpdateTask task)
{
task.updateChunkQueue();

// Increase counter.
this.islandData.increaseBiomeChangeCounter(this.biome);
this.addon.getAddonManager().saveIslandData(this.islandData);
if (this.islandData != null)
{
// Increase counter.
this.islandData.increaseBiomeChangeCounter(this.biome);
this.addon.getAddonManager().saveIslandData(this.islandData);
}

this.addon.getUpdateQueue().addUpdateTask(task).thenAccept((result) ->
{
Expand Down Expand Up @@ -781,7 +784,8 @@ private void withdrawStatic(CompletableFuture<Boolean> changeBiomeStage)
*/
private boolean checkUnlockStatus()
{
return this.islandData.isUnlocked(this.biome);
return this.islandData != null &&
this.islandData.isUnlocked(this.biome);
}


Expand All @@ -792,7 +796,8 @@ private boolean checkUnlockStatus()
*/
private boolean checkPurchaseStatus()
{
return this.addon.getAddonManager().isPurchased(this.islandData, this.biome);
return this.islandData != null &&
this.addon.getAddonManager().isPurchased(this.islandData, this.biome);
}


Expand Down Expand Up @@ -943,7 +948,8 @@ else if (!this.addon.getVaultHook().has(this.callerUser, cost))
*/
private double getUsageIncrement()
{
return this.biome.getCostIncrement() * this.islandData.getBiomeChangeCounter(this.biome);
return this.islandData == null ? 0 :
this.biome.getCostIncrement() * this.islandData.getBiomeChangeCounter(this.biome);
}


Expand Down Expand Up @@ -1109,9 +1115,10 @@ public boolean hasPermissionToUpdateMode()
private final World world;

/**
* This variable stores if money from caller can be withdrawn.
* This variable stores if biome change is forced or not.
* Forced change does skip unlocks, purchases and monetary settings.
*/
private final boolean canWithdraw;
private final boolean notForced;

/**
* This variable stores if world protection flag is enabled. Avoids checking it each time as flag will not change
Expand Down

0 comments on commit 1dcd41b

Please sign in to comment.