Delete all vaults (1-100)
This commit is contained in:
committed by
Trent Hensler
parent
3bd3368f4d
commit
79fe9b53f8
@@ -34,11 +34,19 @@ public class DeleteCommand implements CommandExecutor {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: fix the stupid message inconsistencies where sometimes this class sends, sometimes vaultops does.
|
||||||
|
if (args[1].equalsIgnoreCase("all")) {
|
||||||
|
VaultOperations.deleteOtherAllVaults(sender, player.getUniqueId());
|
||||||
|
sender.sendMessage(Lang.TITLE.toString() + Lang.DELETE_OTHER_VAULT_ALL.toString().replaceAll("%p", player.getName()));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
VaultOperations.deleteOtherVault(sender, player, args[1]);
|
VaultOperations.deleteOtherVault(sender, player, args[1]);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
sender.sendMessage(Lang.TITLE + "/pvdel <number>");
|
sender.sendMessage(Lang.TITLE + "/pvdel <number>");
|
||||||
sender.sendMessage(Lang.TITLE + "/pvdel <player> <number>");
|
sender.sendMessage(Lang.TITLE + "/pvdel <player> <number>");
|
||||||
|
sender.sendMessage(Lang.TITLE + "/pvdel <player> all");
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -29,9 +29,9 @@ public enum Lang {
|
|||||||
INVALID_ARGS("invalid-args", "&cInvalid args!"),
|
INVALID_ARGS("invalid-args", "&cInvalid args!"),
|
||||||
DELETE_VAULT("delete-vault", "&fDeleted vault &a%v"),
|
DELETE_VAULT("delete-vault", "&fDeleted vault &a%v"),
|
||||||
DELETE_OTHER_VAULT("delete-other-vault", "&fDeleted vault &a%v &fof &a%p"),
|
DELETE_OTHER_VAULT("delete-other-vault", "&fDeleted vault &a%v &fof &a%p"),
|
||||||
|
DELETE_OTHER_VAULT_ALL("delete-other-vault", "&4Deleted all vaults belonging to &a%p"),
|
||||||
PLAYER_ONLY("player-only", "&cSorry but that can only be run by a player!"),
|
PLAYER_ONLY("player-only", "&cSorry but that can only be run by a player!"),
|
||||||
MUST_BE_NUMBER("must-be-number", "&cYou need to specify a valid number."),
|
MUST_BE_NUMBER("must-be-number", "&cYou need to specify a valid number."),
|
||||||
DELETE_VAULT_ERROR("delete-vault-error", "&cError deleting vault :("),
|
|
||||||
NO_PERMS("no-permissions", "&cYou don''t have permission for that!"),
|
NO_PERMS("no-permissions", "&cYou don''t have permission for that!"),
|
||||||
INSUFFICIENT_FUNDS("insufficient-funds", "&cYou don''t have enough money for that!"),
|
INSUFFICIENT_FUNDS("insufficient-funds", "&cYou don''t have enough money for that!"),
|
||||||
REFUND_AMOUNT("refund-amount", "&fYou were refunded &a%price &ffor deleting that vault."),
|
REFUND_AMOUNT("refund-amount", "&fYou were refunded &a%price &ffor deleting that vault."),
|
||||||
|
|||||||
@@ -14,7 +14,9 @@ import org.bukkit.scheduler.BukkitRunnable;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
@@ -179,6 +181,38 @@ public class VaultManager {
|
|||||||
return getPlayerVaultFile(holder).contains(String.format(VAULTKEY, number));
|
return getPlayerVaultFile(holder).contains(String.format(VAULTKEY, number));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the numbers belonging to all their vaults.
|
||||||
|
*
|
||||||
|
* @param holder
|
||||||
|
* @return a set of Integers, which are player's vaults' numbers (fuck grammar).
|
||||||
|
*/
|
||||||
|
public Set<Integer> getVaultNumbers(UUID holder) {
|
||||||
|
Set<Integer> vaults = new HashSet<>();
|
||||||
|
YamlConfiguration file = getPlayerVaultFile(holder);
|
||||||
|
if (file == null) {
|
||||||
|
return vaults;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (String s : file.getKeys(false)) {
|
||||||
|
try {
|
||||||
|
// vault%
|
||||||
|
int number = Integer.valueOf(s.substring(4));
|
||||||
|
vaults.add(number);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
// silent
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return vaults;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteAllVaults(UUID holder) {
|
||||||
|
removeCachedPlayerVaultFile(holder);
|
||||||
|
deletePlayerVaultFile(holder);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes a players vault.
|
* Deletes a players vault.
|
||||||
*
|
*
|
||||||
@@ -187,7 +221,7 @@ public class VaultManager {
|
|||||||
* @param number The vault number.
|
* @param number The vault number.
|
||||||
* @throws IOException Uh oh!
|
* @throws IOException Uh oh!
|
||||||
*/
|
*/
|
||||||
public void deleteVault(CommandSender sender, final UUID holder, final int number) throws IOException {
|
public void deleteVault(CommandSender sender, final UUID holder, final int number) {
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@@ -232,9 +266,7 @@ public class VaultManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void removeCachedPlayerVaultFile(UUID holder) {
|
public void removeCachedPlayerVaultFile(UUID holder) {
|
||||||
if (cachedVaultFiles.containsKey(holder)) {
|
cachedVaultFiles.remove(holder);
|
||||||
cachedVaultFiles.remove(holder);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -254,6 +286,19 @@ public class VaultManager {
|
|||||||
return this.loadPlayerVaultFile(holder, true);
|
return this.loadPlayerVaultFile(holder, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Attempt to delete a vault file.
|
||||||
|
*
|
||||||
|
* @param holder UUID of the holder.
|
||||||
|
* @return true if successful, otherwise false.
|
||||||
|
*/
|
||||||
|
public void deletePlayerVaultFile(UUID holder) {
|
||||||
|
File file = new File(this.directory, holder.toString() + ".yml");
|
||||||
|
if (file.exists()) {
|
||||||
|
file.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public YamlConfiguration loadPlayerVaultFile(UUID uniqueId, boolean createIfNotFound) {
|
public YamlConfiguration loadPlayerVaultFile(UUID uniqueId, boolean createIfNotFound) {
|
||||||
if (!this.directory.exists()) {
|
if (!this.directory.exists()) {
|
||||||
this.directory.mkdir();
|
this.directory.mkdir();
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ import org.bukkit.entity.Player;
|
|||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.InventoryView;
|
import org.bukkit.inventory.InventoryView;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
@@ -70,7 +69,6 @@ public class VaultOperations {
|
|||||||
*
|
*
|
||||||
* @param sender The person to check.
|
* @param sender The person to check.
|
||||||
* @param number The vault number.
|
* @param number The vault number.
|
||||||
*
|
|
||||||
* @return Whether or not they have permission.
|
* @return Whether or not they have permission.
|
||||||
*/
|
*/
|
||||||
public static boolean checkPerms(CommandSender sender, int number) {
|
public static boolean checkPerms(CommandSender sender, int number) {
|
||||||
@@ -89,7 +87,6 @@ public class VaultOperations {
|
|||||||
* Get the max size vault a player is allowed to have.
|
* Get the max size vault a player is allowed to have.
|
||||||
*
|
*
|
||||||
* @param uuid that is having his permissions checked.
|
* @param uuid that is having his permissions checked.
|
||||||
*
|
|
||||||
* @return max size as integer. If no max size is set then it will default to 54.
|
* @return max size as integer. If no max size is set then it will default to 54.
|
||||||
*/
|
*/
|
||||||
public static int getMaxVaultSize(UUID uuid) {
|
public static int getMaxVaultSize(UUID uuid) {
|
||||||
@@ -100,7 +97,6 @@ public class VaultOperations {
|
|||||||
* Get the max size vault a player is allowed to have.
|
* Get the max size vault a player is allowed to have.
|
||||||
*
|
*
|
||||||
* @param player that is having his permissions checked.
|
* @param player that is having his permissions checked.
|
||||||
*
|
|
||||||
* @return max size as integer. If no max size is set then it will default to 54.
|
* @return max size as integer. If no max size is set then it will default to 54.
|
||||||
*/
|
*/
|
||||||
public static int getMaxVaultSize(OfflinePlayer player) {
|
public static int getMaxVaultSize(OfflinePlayer player) {
|
||||||
@@ -120,7 +116,6 @@ public class VaultOperations {
|
|||||||
*
|
*
|
||||||
* @param player The player to open to.
|
* @param player The player to open to.
|
||||||
* @param arg The vault number to open.
|
* @param arg The vault number to open.
|
||||||
*
|
|
||||||
* @return Whether or not the player was allowed to open it.
|
* @return Whether or not the player was allowed to open it.
|
||||||
*/
|
*/
|
||||||
public static boolean openOwnVault(Player player, String arg) {
|
public static boolean openOwnVault(Player player, String arg) {
|
||||||
@@ -164,7 +159,6 @@ public class VaultOperations {
|
|||||||
* @param player The player to open to.
|
* @param player The player to open to.
|
||||||
* @param arg The vault number to open.
|
* @param arg The vault number to open.
|
||||||
* @param isCommand - if player is opening via a command or not.
|
* @param isCommand - if player is opening via a command or not.
|
||||||
*
|
|
||||||
* @return Whether or not the player was allowed to open it.
|
* @return Whether or not the player was allowed to open it.
|
||||||
*/
|
*/
|
||||||
public static boolean openOwnVault(Player player, String arg, boolean isCommand) {
|
public static boolean openOwnVault(Player player, String arg, boolean isCommand) {
|
||||||
@@ -181,7 +175,6 @@ public class VaultOperations {
|
|||||||
* @param player The player to open to.
|
* @param player The player to open to.
|
||||||
* @param holder The user to whom the requested vault belongs.
|
* @param holder The user to whom the requested vault belongs.
|
||||||
* @param arg The vault number to open.
|
* @param arg The vault number to open.
|
||||||
*
|
|
||||||
* @return Whether or not the player was allowed to open it.
|
* @return Whether or not the player was allowed to open it.
|
||||||
*/
|
*/
|
||||||
public static boolean openOtherVault(Player player, UUID holder, String arg) {
|
public static boolean openOtherVault(Player player, UUID holder, String arg) {
|
||||||
@@ -241,13 +234,10 @@ public class VaultOperations {
|
|||||||
player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
|
player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
if (EconomyOperations.refundOnDelete(player, number)) {
|
||||||
if (EconomyOperations.refundOnDelete(player, number)) {
|
VaultManager.getInstance().deleteVault(player, player.getUniqueId(), number);
|
||||||
VaultManager.getInstance().deleteVault(player, player.getUniqueId(), number);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
player.sendMessage(Lang.TITLE.toString() + Lang.DELETE_VAULT_ERROR);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(Lang.TITLE.toString() + Lang.MUST_BE_NUMBER);
|
player.sendMessage(Lang.TITLE.toString() + Lang.MUST_BE_NUMBER);
|
||||||
}
|
}
|
||||||
@@ -277,11 +267,7 @@ public class VaultOperations {
|
|||||||
sender.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
|
sender.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
VaultManager.getInstance().deleteVault(sender, holder.getUniqueId(), number);
|
||||||
VaultManager.getInstance().deleteVault(sender, holder.getUniqueId(), number);
|
|
||||||
} catch (IOException e) {
|
|
||||||
sender.sendMessage(Lang.TITLE.toString() + Lang.DELETE_VAULT_ERROR);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
sender.sendMessage(Lang.TITLE.toString() + Lang.MUST_BE_NUMBER);
|
sender.sendMessage(Lang.TITLE.toString() + Lang.MUST_BE_NUMBER);
|
||||||
}
|
}
|
||||||
@@ -290,6 +276,25 @@ public class VaultOperations {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete all of a player's vaults (Currently goes to vault #100)
|
||||||
|
*
|
||||||
|
* @param sender The sender executing the deletion.
|
||||||
|
* @param holder The user to whom the deleted vault belongs.
|
||||||
|
*/
|
||||||
|
public static void deleteOtherAllVaults(CommandSender sender, UUID holder) {
|
||||||
|
if (isLocked() || holder == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sender.hasPermission("playervaults.delete.all")) {
|
||||||
|
VaultManager.getInstance().deleteAllVaults(holder);
|
||||||
|
PlayerVaults.getInstance().getLogger().warning(String.format("%s deleted ALL vaults belonging to %s", sender.getName(), holder.toString()));
|
||||||
|
} else {
|
||||||
|
sender.sendMessage(Lang.TITLE.toString() + Lang.NO_PERMS);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean isNumber(String check) {
|
private static boolean isNumber(String check) {
|
||||||
try {
|
try {
|
||||||
Integer.parseInt(check);
|
Integer.parseInt(check);
|
||||||
|
|||||||
Reference in New Issue
Block a user