Skip to content

Commit

Permalink
Implement ability to clear biome change queue.
Browse files Browse the repository at this point in the history
  • Loading branch information
BONNe committed May 15, 2023
1 parent 211561b commit d4a6029
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public void setup()
new MigrateCommand(this.getAddon(), this);
new BiomesSetCommand(this.getAddon(), this);
new BiomesUnlockCommand(this.getAddon(), this);

new BiomesClearQueueCommand(this.getAddon(), this);
}


Expand Down Expand Up @@ -541,6 +543,52 @@ public Optional<List<String>> tabComplete(User user, String alias, List<String>
}


/**
* The queue clear command.
*/
private static class BiomesClearQueueCommand extends CompositeCommand
{
/**
* Migrates biomes
*
* @param addon - addon
* @param cmd - command
*/
public BiomesClearQueueCommand(Addon addon, CompositeCommand cmd)
{
super(addon, cmd, "clearqueue");
}


/**
* Execute command.
*
* @param user the user
* @param label the command top label
* @param args the args
* @return always true.
*/
@Override
public boolean execute(User user, String label, List<String> args)
{
this.<BiomesAddon>getAddon().getAddonManager().clearQueues(user, getWorld());
return true;
}


/**
* Sets command settings.
*/
@Override
public void setup()
{
this.inheritPermission();
this.setParametersHelp(Constants.ADMIN_COMMANDS + "clear-queue.parameters");
this.setDescription(Constants.ADMIN_COMMANDS + "clear-queue.description");
}
}


// ---------------------------------------------------------------------
// Section: Static Variables
// ---------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.Database;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.managers.IslandWorldManager;
import world.bentobox.bentobox.util.Util;
import world.bentobox.biomes.BiomesAddon;
import world.bentobox.biomes.database.objects.BiomesBundleObject;
Expand Down Expand Up @@ -1517,6 +1518,42 @@ public boolean hasPriceSet(BiomesObject biomesObject)
}


// ---------------------------------------------------------------------
// Section: Queue methods
// ---------------------------------------------------------------------


/**
* This method clears biome change queue for the given world.
* @param user User who triggers queue cleaning.
* @param world World where queue must be cleared.
*/
public void clearQueues(User user, World world)
{
IslandWorldManager islandWorldManager = this.addon.getPlugin().getIWM();
Optional<GameModeAddon> gameMode = islandWorldManager.getAddon(world);

gameMode.ifPresent(gamemode -> {
// Remove all tasks with the same world as given from the queue.
this.addon.getUpdateQueue().getProcessQueue().removeIf(task -> gamemode.getOverWorld() == task.getWorld());

if (islandWorldManager.isNetherGenerate(world) && islandWorldManager.isNetherIslands(world))
{
this.addon.getUpdateQueue().getProcessQueue().removeIf(task -> gamemode.getNetherWorld() == task.getWorld());
}

if (islandWorldManager.isEndGenerate(world) && islandWorldManager.isEndIslands(world))
{
this.addon.getUpdateQueue().getProcessQueue().removeIf(task -> gamemode.getEndWorld() == task.getWorld());
}

Utils.sendMessage(user,
user.getTranslationOrNothing(Constants.MESSAGES + "queue.clear",
Constants.PARAMETER_GAMEMODE, gamemode.getDescription().getName()));
});
}


// ---------------------------------------------------------------------
// Section: Variables
// ---------------------------------------------------------------------
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/world/bentobox/biomes/tasks/BiomeUpdateTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,17 @@ public void setWorld(World world)
}


/**
* Gets world.
*
* @return the world
*/
public World getWorld()
{
return this.world;
}


/**
* Sets min coordinate.
*
Expand Down
3 changes: 3 additions & 0 deletions src/main/resources/locales/en-US.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ biomes:
unlock:
description: "unlocks biome for the player without checks. Adding `true` at the end will mark it as purchased."
parameters: "<player> <biome-id> [true]"
clear-queue:
description: "clears biome update queue"
# This section contains only player commands translations.
player:
main:
Expand Down Expand Up @@ -864,6 +866,7 @@ biomes:
migrate-finish: "&a Migration to new data format completed."
migrate-valid: "&a All data is valid. Migration is not necessary."
bundle-loaded: "&a Bundle &r [bundle] &a is loaded."
clear-queue: "&a Biome change task queue for [gamemode] is cleared."
errors:
# Message that is displayed if requested user or island does not have any valid data.
no-island-data: "&c Island does not have any stored data."
Expand Down

0 comments on commit d4a6029

Please sign in to comment.