diff --git a/src/main/java/world/bentobox/bentobox/api/commands/island/IslandResetCommand.java b/src/main/java/world/bentobox/bentobox/api/commands/island/IslandResetCommand.java index aff343b24..bca5b7f1f 100644 --- a/src/main/java/world/bentobox/bentobox/api/commands/island/IslandResetCommand.java +++ b/src/main/java/world/bentobox/bentobox/api/commands/island/IslandResetCommand.java @@ -1,13 +1,8 @@ package world.bentobox.bentobox.api.commands.island; -import java.io.IOException; -import java.util.List; -import java.util.Set; - import org.bukkit.GameMode; import org.bukkit.entity.Player; import org.eclipse.jdt.annotation.Nullable; - import world.bentobox.bentobox.api.commands.CompositeCommand; import world.bentobox.bentobox.api.commands.ConfirmableCommand; import world.bentobox.bentobox.api.events.island.IslandEvent.Reason; @@ -17,6 +12,10 @@ import world.bentobox.bentobox.database.objects.Island; import world.bentobox.bentobox.managers.SchemsManager; import world.bentobox.bentobox.managers.island.NewIsland; +import java.io.IOException; +import java.util.List; +import java.util.Set; + /** * @author tastybento */ @@ -53,12 +52,15 @@ public class IslandResetCommand extends ConfirmableCommand { user.sendMessage("commands.island.reset.must-remove-members"); return false; } - if (getIWM().getResetLimit(getWorld()) >= 0) { - int resetsLeft = getIWM().getResetLimit(getWorld()) - getPlayers().getResets(getWorld(), user.getUniqueId()); - if (resetsLeft <= 0) { + int resetsLeft = getPlayers().getResetsLeft(getWorld(), user.getUniqueId()); + if (resetsLeft != -1) { + // Resets are not unlimited here + if (resetsLeft == 0) { + // No resets allowed user.sendMessage("commands.island.reset.none-left"); return false; } else { + // Still some resets left // Notify how many resets are left user.sendMessage("commands.island.reset.resets-left", TextVariables.NUMBER, String.valueOf(resetsLeft)); } diff --git a/src/main/java/world/bentobox/bentobox/managers/PlayersManager.java b/src/main/java/world/bentobox/bentobox/managers/PlayersManager.java index b8e63f9ee..58ea1bba4 100644 --- a/src/main/java/world/bentobox/bentobox/managers/PlayersManager.java +++ b/src/main/java/world/bentobox/bentobox/managers/PlayersManager.java @@ -1,5 +1,15 @@ package world.bentobox.bentobox.managers; +import org.bukkit.Location; +import org.bukkit.World; +import org.eclipse.jdt.annotation.NonNull; +import org.eclipse.jdt.annotation.Nullable; +import world.bentobox.bentobox.BentoBox; +import world.bentobox.bentobox.api.user.User; +import world.bentobox.bentobox.database.Database; +import world.bentobox.bentobox.database.objects.Names; +import world.bentobox.bentobox.database.objects.Players; + import java.util.Collection; import java.util.Collections; import java.util.HashMap; @@ -8,16 +18,6 @@ import java.util.Map; import java.util.Set; import java.util.UUID; -import org.bukkit.Location; -import org.bukkit.World; -import org.eclipse.jdt.annotation.NonNull; - -import world.bentobox.bentobox.BentoBox; -import world.bentobox.bentobox.api.user.User; -import world.bentobox.bentobox.database.Database; -import world.bentobox.bentobox.database.objects.Names; -import world.bentobox.bentobox.database.objects.Players; - public class PlayersManager { private BentoBox plugin; @@ -228,7 +228,8 @@ public class PlayersManager { * @param name - name of player * @return UUID of player or null if unknown */ - public UUID getUUID(String name) { + @Nullable + public UUID getUUID(@NonNull String name) { // See if this is a UUID // example: 5988eecd-1dcd-4080-a843-785b62419abb if (name.length() == 36 && name.contains("-")) { @@ -249,7 +250,7 @@ public class PlayersManager { * Sets the player's name and updates the name>UUID database * @param user - the User */ - public void setPlayerName(User user) { + public void setPlayerName(@NonNull User user) { addPlayer(user.getUniqueId()); playerCache.get(user.getUniqueId()).setPlayerName(user.getName()); Names newName = new Names(user.getName(), user.getUniqueId()); @@ -273,10 +274,9 @@ public class PlayersManager { } /** - * Gets how many island resets the player has done - * @param world - world - * - * @param playerUUID - the player's UUID + * Returns how many island resets the player has done. + * @param world world + * @param playerUUID the player's UUID * @return number of resets */ public int getResets(World world, UUID playerUUID) { @@ -284,6 +284,23 @@ public class PlayersManager { return playerCache.get(playerUUID).getResets(world); } + /** + * Returns how many island resets the player can still do. + * @param world world + * @param playerUUID the player's UUID + * @return number of resets the player can do (always {@code >= 0}), or {@code -1} if unlimited. + * @since 1.5.0 + * @see #getResets(World, UUID) + */ + public int getResetsLeft(World world, UUID playerUUID) { + addPlayer(playerUUID); + if (plugin.getIWM().getResetLimit(world) == -1) { + return -1; + } else { + return Math.max(plugin.getIWM().getResetLimit(world) - getResets(world, playerUUID), 0); + } + } + /** * Sets how many resets the player has performed *