mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-09-07 21:08:03 +02:00
Added PlayersManager#getResetsLeft(World, UUID)
This commit is contained in:
parent
38875829b9
commit
d1a3a8285f
@ -1,13 +1,8 @@
|
|||||||
package world.bentobox.bentobox.api.commands.island;
|
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.GameMode;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.eclipse.jdt.annotation.Nullable;
|
import org.eclipse.jdt.annotation.Nullable;
|
||||||
|
|
||||||
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
import world.bentobox.bentobox.api.commands.CompositeCommand;
|
||||||
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
|
import world.bentobox.bentobox.api.commands.ConfirmableCommand;
|
||||||
import world.bentobox.bentobox.api.events.island.IslandEvent.Reason;
|
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.SchemsManager;
|
||||||
import world.bentobox.bentobox.managers.island.NewIsland;
|
import world.bentobox.bentobox.managers.island.NewIsland;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author tastybento
|
* @author tastybento
|
||||||
*/
|
*/
|
||||||
@ -53,12 +52,15 @@ public class IslandResetCommand extends ConfirmableCommand {
|
|||||||
user.sendMessage("commands.island.reset.must-remove-members");
|
user.sendMessage("commands.island.reset.must-remove-members");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (getIWM().getResetLimit(getWorld()) >= 0) {
|
int resetsLeft = getPlayers().getResetsLeft(getWorld(), user.getUniqueId());
|
||||||
int resetsLeft = getIWM().getResetLimit(getWorld()) - getPlayers().getResets(getWorld(), user.getUniqueId());
|
if (resetsLeft != -1) {
|
||||||
if (resetsLeft <= 0) {
|
// Resets are not unlimited here
|
||||||
|
if (resetsLeft == 0) {
|
||||||
|
// No resets allowed
|
||||||
user.sendMessage("commands.island.reset.none-left");
|
user.sendMessage("commands.island.reset.none-left");
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
// Still some resets left
|
||||||
// Notify how many resets are left
|
// Notify how many resets are left
|
||||||
user.sendMessage("commands.island.reset.resets-left", TextVariables.NUMBER, String.valueOf(resetsLeft));
|
user.sendMessage("commands.island.reset.resets-left", TextVariables.NUMBER, String.valueOf(resetsLeft));
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,15 @@
|
|||||||
package world.bentobox.bentobox.managers;
|
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.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -8,16 +18,6 @@ import java.util.Map;
|
|||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
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 {
|
public class PlayersManager {
|
||||||
|
|
||||||
private BentoBox plugin;
|
private BentoBox plugin;
|
||||||
@ -228,7 +228,8 @@ public class PlayersManager {
|
|||||||
* @param name - name of player
|
* @param name - name of player
|
||||||
* @return UUID of player or null if unknown
|
* @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
|
// See if this is a UUID
|
||||||
// example: 5988eecd-1dcd-4080-a843-785b62419abb
|
// example: 5988eecd-1dcd-4080-a843-785b62419abb
|
||||||
if (name.length() == 36 && name.contains("-")) {
|
if (name.length() == 36 && name.contains("-")) {
|
||||||
@ -249,7 +250,7 @@ public class PlayersManager {
|
|||||||
* Sets the player's name and updates the name>UUID database
|
* Sets the player's name and updates the name>UUID database
|
||||||
* @param user - the User
|
* @param user - the User
|
||||||
*/
|
*/
|
||||||
public void setPlayerName(User user) {
|
public void setPlayerName(@NonNull User user) {
|
||||||
addPlayer(user.getUniqueId());
|
addPlayer(user.getUniqueId());
|
||||||
playerCache.get(user.getUniqueId()).setPlayerName(user.getName());
|
playerCache.get(user.getUniqueId()).setPlayerName(user.getName());
|
||||||
Names newName = new Names(user.getName(), user.getUniqueId());
|
Names newName = new Names(user.getName(), user.getUniqueId());
|
||||||
@ -273,10 +274,9 @@ public class PlayersManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets how many island resets the player has done
|
* Returns how many island resets the player has done.
|
||||||
* @param world - world
|
* @param world world
|
||||||
*
|
* @param playerUUID the player's UUID
|
||||||
* @param playerUUID - the player's UUID
|
|
||||||
* @return number of resets
|
* @return number of resets
|
||||||
*/
|
*/
|
||||||
public int getResets(World world, UUID playerUUID) {
|
public int getResets(World world, UUID playerUUID) {
|
||||||
@ -284,6 +284,23 @@ public class PlayersManager {
|
|||||||
return playerCache.get(playerUUID).getResets(world);
|
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
|
* Sets how many resets the player has performed
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user