Rework operations to allow for owners of vaults to be Strings, which is more friendly to third party or group vaults. Fixes compatibility with FactionsUUID.
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
|
||||
<groupId>com.drtshock</groupId>
|
||||
<artifactId>PlayerVaultsX</artifactId>
|
||||
<version>4.0.7</version>
|
||||
<version>4.1.0</version>
|
||||
<name>PlayerVaultsX</name>
|
||||
<url>https://www.spigotmc.org/resources/51204/</url>
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ public class PlayerVaults extends JavaPlugin {
|
||||
Inventory inventory = player.getOpenInventory().getTopInventory();
|
||||
if (inventory.getViewers().size() == 1) {
|
||||
VaultViewInfo info = this.inVault.get(player.getUniqueId().toString());
|
||||
VaultManager.getInstance().saveVault(inventory, player.getUniqueId(), info.getNumber());
|
||||
VaultManager.getInstance().saveVault(inventory, player.getUniqueId().toString(), info.getNumber());
|
||||
this.openInventories.remove(info.toString());
|
||||
// try this to make sure that they can't make further edits if the process hangs.
|
||||
player.closeInventory();
|
||||
|
||||
@@ -28,20 +28,20 @@ public class DeleteCommand implements CommandExecutor {
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
OfflinePlayer player = Bukkit.getOfflinePlayer(args[0]);
|
||||
if (player == null || !player.hasPlayedBefore()) {
|
||||
sender.sendMessage(Lang.TITLE.toString() + Lang.NO_PLAYER_FOUND.toString().replaceAll("%p", args[0]));
|
||||
break;
|
||||
OfflinePlayer searchPlayer = Bukkit.getOfflinePlayer(args[0]);
|
||||
String target = args[0];
|
||||
if (searchPlayer != null && searchPlayer.hasPlayedBefore()) {
|
||||
target = searchPlayer.getUniqueId().toString();
|
||||
}
|
||||
|
||||
// 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()));
|
||||
VaultOperations.deleteOtherAllVaults(sender, target);
|
||||
sender.sendMessage(Lang.TITLE.toString() + Lang.DELETE_OTHER_VAULT_ALL.toString().replaceAll("%p", target));
|
||||
break;
|
||||
}
|
||||
|
||||
VaultOperations.deleteOtherVault(sender, player, args[1]);
|
||||
VaultOperations.deleteOtherVault(sender, target, args[1]);
|
||||
break;
|
||||
default:
|
||||
sender.sendMessage(Lang.TITLE + "/pvdel <number>");
|
||||
|
||||
@@ -33,15 +33,15 @@ public class VaultCommand implements CommandExecutor {
|
||||
switch (args.length) {
|
||||
case 1:
|
||||
if (VaultOperations.openOwnVault(player, args[0])) {
|
||||
PlayerVaults.getInstance().getInVault().put(player.getUniqueId().toString(), new VaultViewInfo(player.getUniqueId(), Integer.parseInt(args[0])));
|
||||
PlayerVaults.getInstance().getInVault().put(player.getUniqueId().toString(), new VaultViewInfo(player.getUniqueId().toString(), Integer.parseInt(args[0])));
|
||||
} else if (sender.hasPermission("playervaults.admin")) {
|
||||
OfflinePlayer searchPlayer = Bukkit.getOfflinePlayer(args[0]);
|
||||
if (searchPlayer == null || !searchPlayer.hasPlayedBefore()) {
|
||||
sender.sendMessage(Lang.TITLE.toString() + Lang.NO_PLAYER_FOUND.toString().replaceAll("%p", args[0]));
|
||||
break;
|
||||
String target = args[0];
|
||||
if (searchPlayer != null && searchPlayer.hasPlayedBefore()) {
|
||||
target = searchPlayer.getUniqueId().toString();
|
||||
}
|
||||
|
||||
YamlConfiguration file = VaultManager.getInstance().getPlayerVaultFile(searchPlayer.getUniqueId());
|
||||
YamlConfiguration file = VaultManager.getInstance().getPlayerVaultFile(target, false);
|
||||
if (file == null) {
|
||||
sender.sendMessage(Lang.TITLE.toString() + Lang.VAULT_DOES_NOT_EXIST.toString());
|
||||
} else {
|
||||
@@ -68,11 +68,15 @@ public class VaultCommand implements CommandExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
String target = args[0];
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(args[0]);
|
||||
if (offlinePlayer != null && VaultOperations.openOtherVault(player, offlinePlayer.getUniqueId(), args[1])) {
|
||||
PlayerVaults.getInstance().getInVault().put(player.getUniqueId().toString(), new VaultViewInfo(offlinePlayer.getUniqueId(), number));
|
||||
if(offlinePlayer != null && offlinePlayer.hasPlayedBefore()) {
|
||||
target = offlinePlayer.getUniqueId().toString();
|
||||
}
|
||||
if (VaultOperations.openOtherVault(player, target, args[1])) {
|
||||
PlayerVaults.getInstance().getInVault().put(player.getUniqueId().toString(), new VaultViewInfo(target, number));
|
||||
} else {
|
||||
sender.sendMessage(Lang.TITLE.toString() + Lang.NO_PLAYER_FOUND.toString().replaceAll("%p", args[0]));
|
||||
sender.sendMessage(Lang.TITLE.toString() + Lang.NO_OWNER_FOUND.toString().replaceAll("%p", args[0]));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -64,7 +64,7 @@ public class BackpackConverter implements Converter {
|
||||
continue; // No slots
|
||||
}
|
||||
|
||||
Inventory vault = vaults.getVault(uuid, intoVaultNum);
|
||||
Inventory vault = vaults.getVault(uuid.toString(), intoVaultNum);
|
||||
if (vault == null) {
|
||||
vault = plugin.getServer().createInventory(null, section.getKeys(false).size());
|
||||
}
|
||||
@@ -78,7 +78,7 @@ public class BackpackConverter implements Converter {
|
||||
// Overwrite
|
||||
vault.setItem(Integer.parseInt(key.split(" ")[1]), item);
|
||||
}
|
||||
vaults.saveVault(vault, uuid, intoVaultNum);
|
||||
vaults.saveVault(vault, uuid.toString(), intoVaultNum);
|
||||
converted++;
|
||||
|
||||
if (System.currentTimeMillis() - lastUpdate >= 1500) {
|
||||
|
||||
@@ -56,7 +56,7 @@ public class Listeners implements Listener {
|
||||
|
||||
if (inventory.getViewers().size() == 1) {
|
||||
VaultViewInfo info = plugin.getInVault().get(player.getUniqueId().toString());
|
||||
vaultManager.saveVault(inv, info.getHolderUUID(), info.getNumber());
|
||||
vaultManager.saveVault(inv, info.getVaultName(), info.getNumber());
|
||||
plugin.getOpenInventories().remove(info.toString());
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ public class Listeners implements Listener {
|
||||
if (info != null) {
|
||||
int num = info.getNumber();
|
||||
String inventoryTitle = clickedInventory.getTitle();
|
||||
String title = Lang.VAULT_TITLE.toString().replace("%number", String.valueOf(num)).replace("%p", info.getHolder());
|
||||
String title = Lang.VAULT_TITLE.toString().replace("%number", String.valueOf(num)).replace("%p", info.getVaultName());
|
||||
if (((inventoryTitle != null && inventoryTitle.equalsIgnoreCase(title)) ||event.getCurrentItem() != null)) {
|
||||
if (PlayerVaults.getInstance().isBlockedMaterial(event.getCurrentItem().getType())) {
|
||||
event.setCancelled(true);
|
||||
@@ -149,7 +149,7 @@ public class Listeners implements Listener {
|
||||
if (info != null) {
|
||||
int num = info.getNumber();
|
||||
String inventoryTitle = clickedInventory.getTitle();
|
||||
String title = Lang.VAULT_TITLE.toString().replace("%number", String.valueOf(num)).replace("%p", info.getHolder());
|
||||
String title = Lang.VAULT_TITLE.toString().replace("%number", String.valueOf(num)).replace("%p", info.getVaultName());
|
||||
if ((inventoryTitle != null && inventoryTitle.equalsIgnoreCase(title)) && event.getNewItems() != null) {
|
||||
for (ItemStack item : event.getNewItems().values()) {
|
||||
if (PlayerVaults.getInstance().isBlockedMaterial(item.getType())) {
|
||||
|
||||
@@ -102,14 +102,14 @@ public class SignListener implements Listener {
|
||||
return; // Otherwise it would try to add vault view info down there.
|
||||
}
|
||||
} else {
|
||||
Inventory inv = VaultManager.getInstance().loadOtherVault(offlinePlayer.getUniqueId(), num, VaultOperations.getMaxVaultSize(offlinePlayer));
|
||||
Inventory inv = VaultManager.getInstance().loadOtherVault(offlinePlayer.getUniqueId().toString(), num, VaultOperations.getMaxVaultSize(offlinePlayer));
|
||||
if (inv == null) {
|
||||
player.sendMessage(Lang.TITLE.toString() + Lang.VAULT_DOES_NOT_EXIST.toString());
|
||||
} else {
|
||||
player.openInventory(inv);
|
||||
}
|
||||
}
|
||||
PlayerVaults.getInstance().getInVault().put(player.getUniqueId().toString(), new VaultViewInfo(self ? player.getUniqueId() : offlinePlayer.getUniqueId(), num));
|
||||
PlayerVaults.getInstance().getInVault().put(player.getUniqueId().toString(), new VaultViewInfo(self ? player.getUniqueId().toString() : offlinePlayer.getUniqueId().toString(), num));
|
||||
event.setCancelled(true);
|
||||
player.sendMessage(Lang.TITLE.toString() + Lang.OPEN_WITH_SIGN.toString().replace("%v", String.valueOf(num)).replace("%p", owner));
|
||||
} else {
|
||||
|
||||
@@ -21,13 +21,13 @@ public class VaultPreloadListener implements Listener {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
vm.cachePlayerVaultFile(uuid);
|
||||
vm.cachePlayerVaultFile(uuid.toString());
|
||||
}
|
||||
}.runTaskAsynchronously(PlayerVaults.getInstance());
|
||||
}
|
||||
|
||||
@EventHandler(priority = EventPriority.MONITOR)
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
vm.removeCachedPlayerVaultFile(event.getPlayer().getUniqueId());
|
||||
vm.removeCachedPlayerVaultFile(event.getPlayer().getUniqueId().toString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ public final class Base64Conversion implements Runnable {
|
||||
|
||||
try {
|
||||
Inventory inventory = oldManager.getVault(holderUUID, vaultNumber);
|
||||
manager.saveVault(inventory, holderUUID, vaultNumber);
|
||||
manager.saveVault(inventory, holderUUID.toString(), vaultNumber);
|
||||
vaults++;
|
||||
} catch (Exception e) {
|
||||
logger.severe("Failed to parse vault " + vaultNumber + " for " + holderUUID);
|
||||
|
||||
@@ -44,7 +44,7 @@ public enum Lang {
|
||||
EXISTING_VAULTS("existing-vaults", "&f%p has vaults: &a%v"),
|
||||
VAULT_TITLE("vault-title", "&4Vault #%number"),
|
||||
OPEN_WITH_SIGN("open-with-sign", "&fOpening vault &a%v &fof &a%p"),
|
||||
NO_PLAYER_FOUND("no-player-found", "&cCannot find player &a%p"),
|
||||
NO_OWNER_FOUND("no-owner-found", "&cCannot find vault owner: &a%p"),
|
||||
CONVERT_PLUGIN_NOT_FOUND("plugin-not-found", "&cNo converter found for that plugin"),
|
||||
CONVERT_COMPLETE("conversion-complete", "&aConverted %converted players to PlayerVaults"),
|
||||
CONVERT_BACKGROUND("conversion-background", "&fConversion has been forked to the background. See console for updates."),
|
||||
|
||||
@@ -39,7 +39,6 @@ public class EconomyOperations {
|
||||
*
|
||||
* @param player The player to pay.
|
||||
* @param number The vault number to open.
|
||||
*
|
||||
* @return The transaction success.
|
||||
*/
|
||||
public static boolean payToOpen(Player player, int number) {
|
||||
@@ -47,7 +46,7 @@ public class EconomyOperations {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!VaultManager.getInstance().vaultExists(player.getUniqueId(), number)) {
|
||||
if (!VaultManager.getInstance().vaultExists(player.getUniqueId().toString(), number)) {
|
||||
return payToCreate(player);
|
||||
} else {
|
||||
double cost = BUKKIT_CONFIG.getDouble("economy.cost-to-open", 10);
|
||||
@@ -65,7 +64,6 @@ public class EconomyOperations {
|
||||
* Have a player pay to create a vault.
|
||||
*
|
||||
* @param player The player to pay.
|
||||
*
|
||||
* @return The transaction success
|
||||
*/
|
||||
public static boolean payToCreate(Player player) {
|
||||
@@ -88,7 +86,6 @@ public class EconomyOperations {
|
||||
*
|
||||
* @param player The player to receive the money.
|
||||
* @param number The vault number to delete.
|
||||
*
|
||||
* @return The transaction success.
|
||||
*/
|
||||
public static boolean refundOnDelete(Player player, int number) {
|
||||
|
||||
@@ -74,7 +74,7 @@ public class UUIDVaultManager {
|
||||
}
|
||||
|
||||
String title = Lang.VAULT_TITLE.toString().replace("%number", String.valueOf(number)).replace("%p", player.getName());
|
||||
VaultViewInfo info = new VaultViewInfo(player.getUniqueId(), number);
|
||||
VaultViewInfo info = new VaultViewInfo(player.getUniqueId().toString(), number);
|
||||
Inventory inv;
|
||||
if (PlayerVaults.getInstance().getOpenInventories().containsKey(info.toString())) {
|
||||
inv = PlayerVaults.getInstance().getOpenInventories().get(info.toString());
|
||||
@@ -162,7 +162,7 @@ public class UUIDVaultManager {
|
||||
public Inventory getVault(UUID holder, int number) {
|
||||
YamlConfiguration playerFile = getPlayerVaultFile(holder);
|
||||
ConfigurationSection section = playerFile.getConfigurationSection("vault" + number);
|
||||
int maxSize = VaultOperations.getMaxVaultSize(holder);
|
||||
int maxSize = VaultOperations.getMaxVaultSize(holder.toString());
|
||||
|
||||
String title = Lang.VAULT_TITLE.toString().replace("%number", String.valueOf(number));
|
||||
|
||||
@@ -238,6 +238,7 @@ public class UUIDVaultManager {
|
||||
}
|
||||
}
|
||||
|
||||
String uuid = sender instanceof Player ? ((Player)sender).getUniqueId().toString() : holder;
|
||||
PlayerVaults.getInstance().getOpenInventories().remove(new VaultViewInfo(holder, number).toString());
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public class VaultManager {
|
||||
}
|
||||
|
||||
private final File directory = PlayerVaults.getInstance().getVaultData();
|
||||
private final Map<UUID, YamlConfiguration> cachedVaultFiles = new ConcurrentHashMap<>();
|
||||
private final Map<String, YamlConfiguration> cachedVaultFiles = new ConcurrentHashMap<>();
|
||||
|
||||
/**
|
||||
* Saves the inventory to the specified player and vault number.
|
||||
@@ -40,8 +40,8 @@ public class VaultManager {
|
||||
* @param target The player of whose file to save to.
|
||||
* @param number The vault number.
|
||||
*/
|
||||
public void saveVault(Inventory inventory, UUID target, int number) {
|
||||
YamlConfiguration yaml = getPlayerVaultFile(target);
|
||||
public void saveVault(Inventory inventory, String target, int number) {
|
||||
YamlConfiguration yaml = getPlayerVaultFile(target, true);
|
||||
int size = VaultOperations.getMaxVaultSize(target);
|
||||
String serialized = Base64Serialization.toBase64(inventory, size);
|
||||
yaml.set(String.format(VAULTKEY, number), serialized);
|
||||
@@ -60,13 +60,13 @@ public class VaultManager {
|
||||
}
|
||||
|
||||
String title = Lang.VAULT_TITLE.toString().replace("%number", String.valueOf(number)).replace("%p", player.getName());
|
||||
VaultViewInfo info = new VaultViewInfo(player.getUniqueId(), number);
|
||||
VaultViewInfo info = new VaultViewInfo(player.getUniqueId().toString(), number);
|
||||
if (PlayerVaults.getInstance().getOpenInventories().containsKey(info.toString())) {
|
||||
return PlayerVaults.getInstance().getOpenInventories().get(info.toString());
|
||||
}
|
||||
|
||||
Inventory inv;
|
||||
YamlConfiguration playerFile = getPlayerVaultFile(player.getUniqueId());
|
||||
YamlConfiguration playerFile = getPlayerVaultFile(player.getUniqueId().toString(), true);
|
||||
VaultHolder vaultHolder = new VaultHolder(number);
|
||||
if (playerFile.getString(String.format(VAULTKEY, number)) == null) {
|
||||
inv = Bukkit.createInventory(vaultHolder, size, title);
|
||||
@@ -86,28 +86,32 @@ public class VaultManager {
|
||||
/**
|
||||
* Load the player's vault and return it.
|
||||
*
|
||||
* @param holder The holder of the vault.
|
||||
* @param name The holder of the vault.
|
||||
* @param number The vault number.
|
||||
*/
|
||||
public Inventory loadOtherVault(UUID holder, int number, int size) {
|
||||
public Inventory loadOtherVault(String name, int number, int size) {
|
||||
if (size % 9 != 0) {
|
||||
size = 54;
|
||||
}
|
||||
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(holder);
|
||||
String name = "null";
|
||||
if (offlinePlayer != null) {
|
||||
name = offlinePlayer.getName();
|
||||
String holder = name;
|
||||
|
||||
try {
|
||||
UUID uuid = UUID.fromString(name);
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(uuid);
|
||||
holder = offlinePlayer.getUniqueId().toString();
|
||||
} catch (Exception e) {
|
||||
// Not a player
|
||||
}
|
||||
|
||||
String title = Lang.VAULT_TITLE.toString().replace("%number", String.valueOf(number)).replace("%p", name);
|
||||
VaultViewInfo info = new VaultViewInfo(holder, number);
|
||||
String title = Lang.VAULT_TITLE.toString().replace("%number", String.valueOf(number)).replace("%p", holder);
|
||||
VaultViewInfo info = new VaultViewInfo(name, number);
|
||||
Inventory inv;
|
||||
VaultHolder vaultHolder = new VaultHolder(number);
|
||||
if (PlayerVaults.getInstance().getOpenInventories().containsKey(info.toString())) {
|
||||
inv = PlayerVaults.getInstance().getOpenInventories().get(info.toString());
|
||||
} else {
|
||||
YamlConfiguration playerFile = getPlayerVaultFile(holder);
|
||||
YamlConfiguration playerFile = getPlayerVaultFile(holder, true);
|
||||
Inventory i = getInventory(vaultHolder, playerFile, size, number, title);
|
||||
if (i == null) {
|
||||
return null;
|
||||
@@ -159,8 +163,8 @@ public class VaultManager {
|
||||
* @param number The vault number.
|
||||
* @return The inventory of the specified holder and vault number. Can be null.
|
||||
*/
|
||||
public Inventory getVault(UUID holder, int number) {
|
||||
YamlConfiguration playerFile = getPlayerVaultFile(holder);
|
||||
public Inventory getVault(String holder, int number) {
|
||||
YamlConfiguration playerFile = getPlayerVaultFile(holder, true);
|
||||
String serialized = playerFile.getString(String.format(VAULTKEY, number));
|
||||
return Base64Serialization.fromBase64(serialized);
|
||||
}
|
||||
@@ -172,13 +176,13 @@ public class VaultManager {
|
||||
* @param number vault number.
|
||||
* @return true if the vault file and vault number exist in that file, otherwise false.
|
||||
*/
|
||||
public boolean vaultExists(UUID holder, int number) {
|
||||
public boolean vaultExists(String holder, int number) {
|
||||
File file = new File(directory, holder + ".yml");
|
||||
if (!file.exists()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return getPlayerVaultFile(holder).contains(String.format(VAULTKEY, number));
|
||||
return getPlayerVaultFile(holder, true).contains(String.format(VAULTKEY, number));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -187,9 +191,9 @@ public class VaultManager {
|
||||
* @param holder
|
||||
* @return a set of Integers, which are player's vaults' numbers (fuck grammar).
|
||||
*/
|
||||
public Set<Integer> getVaultNumbers(UUID holder) {
|
||||
public Set<Integer> getVaultNumbers(String holder) {
|
||||
Set<Integer> vaults = new HashSet<>();
|
||||
YamlConfiguration file = getPlayerVaultFile(holder);
|
||||
YamlConfiguration file = getPlayerVaultFile(holder, true);
|
||||
if (file == null) {
|
||||
return vaults;
|
||||
}
|
||||
@@ -208,7 +212,7 @@ public class VaultManager {
|
||||
return vaults;
|
||||
}
|
||||
|
||||
public void deleteAllVaults(UUID holder) {
|
||||
public void deleteAllVaults(String holder) {
|
||||
removeCachedPlayerVaultFile(holder);
|
||||
deletePlayerVaultFile(holder);
|
||||
}
|
||||
@@ -221,7 +225,7 @@ public class VaultManager {
|
||||
* @param number The vault number.
|
||||
* @throws IOException Uh oh!
|
||||
*/
|
||||
public void deleteVault(CommandSender sender, final UUID holder, final int number) {
|
||||
public void deleteVault(CommandSender sender, final String holder, final int number) {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -253,11 +257,12 @@ public class VaultManager {
|
||||
}
|
||||
}
|
||||
|
||||
PlayerVaults.getInstance().getOpenInventories().remove(new VaultViewInfo(holder, number).toString());
|
||||
String vaultName = sender instanceof Player ? ((Player)sender).getUniqueId().toString() : holder;
|
||||
PlayerVaults.getInstance().getOpenInventories().remove(new VaultViewInfo(vaultName, number).toString());
|
||||
}
|
||||
|
||||
// Should only be run asynchronously
|
||||
public void cachePlayerVaultFile(UUID holder) {
|
||||
public void cachePlayerVaultFile(String holder) {
|
||||
YamlConfiguration config = this.loadPlayerVaultFile(holder, false);
|
||||
if (config != null) {
|
||||
this.cachedVaultFiles.put(holder, config);
|
||||
@@ -265,7 +270,7 @@ public class VaultManager {
|
||||
}
|
||||
}
|
||||
|
||||
public void removeCachedPlayerVaultFile(UUID holder) {
|
||||
public void removeCachedPlayerVaultFile(String holder) {
|
||||
cachedVaultFiles.remove(holder);
|
||||
}
|
||||
|
||||
@@ -275,14 +280,14 @@ public class VaultManager {
|
||||
* @param holder The vault holder.
|
||||
* @return The holder's vault config file.
|
||||
*/
|
||||
public YamlConfiguration getPlayerVaultFile(UUID holder) {
|
||||
public YamlConfiguration getPlayerVaultFile(String holder, boolean createIfNotFound) {
|
||||
if (cachedVaultFiles.containsKey(holder)) {
|
||||
return cachedVaultFiles.get(holder);
|
||||
}
|
||||
return loadPlayerVaultFile(holder);
|
||||
return loadPlayerVaultFile(holder, createIfNotFound);
|
||||
}
|
||||
|
||||
public YamlConfiguration loadPlayerVaultFile(UUID holder) {
|
||||
public YamlConfiguration loadPlayerVaultFile(String holder) {
|
||||
return this.loadPlayerVaultFile(holder, true);
|
||||
}
|
||||
|
||||
@@ -292,19 +297,19 @@ public class VaultManager {
|
||||
* @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");
|
||||
public void deletePlayerVaultFile(String holder) {
|
||||
File file = new File(this.directory, holder + ".yml");
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
public YamlConfiguration loadPlayerVaultFile(UUID uniqueId, boolean createIfNotFound) {
|
||||
public YamlConfiguration loadPlayerVaultFile(String uniqueId, boolean createIfNotFound) {
|
||||
if (!this.directory.exists()) {
|
||||
this.directory.mkdir();
|
||||
}
|
||||
|
||||
File file = new File(this.directory, uniqueId.toString() + ".yml");
|
||||
File file = new File(this.directory, uniqueId + ".yml");
|
||||
if (!file.exists()) {
|
||||
if (createIfNotFound) {
|
||||
try {
|
||||
@@ -320,21 +325,21 @@ public class VaultManager {
|
||||
return YamlConfiguration.loadConfiguration(file);
|
||||
}
|
||||
|
||||
public void saveFileSync(final UUID holder, final YamlConfiguration yaml) {
|
||||
public void saveFileSync(final String holder, final YamlConfiguration yaml) {
|
||||
if (cachedVaultFiles.containsKey(holder)) {
|
||||
cachedVaultFiles.put(holder, yaml);
|
||||
}
|
||||
|
||||
final boolean backups = PlayerVaults.getInstance().isBackupsEnabled();
|
||||
final File backupsFolder = PlayerVaults.getInstance().getBackupsFolder();
|
||||
final File file = new File(directory, holder.toString() + ".yml");
|
||||
final File file = new File(directory, holder + ".yml");
|
||||
if (file.exists() && backups) {
|
||||
file.renameTo(new File(backupsFolder, holder.toString() + ".yml"));
|
||||
file.renameTo(new File(backupsFolder, holder + ".yml"));
|
||||
}
|
||||
try {
|
||||
yaml.save(file);
|
||||
} catch (IOException e) {
|
||||
PlayerVaults.getInstance().getLogger().log(Level.SEVERE, "Failed to save vault file for: " + holder.toString(), e);
|
||||
PlayerVaults.getInstance().getLogger().log(Level.SEVERE, "Failed to save vault file for: " + holder, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -86,11 +86,18 @@ public class VaultOperations {
|
||||
/**
|
||||
* Get the max size vault a player is allowed to have.
|
||||
*
|
||||
* @param uuid that is having his permissions checked.
|
||||
* @param name that is having his permissions checked.
|
||||
* @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(String name) {
|
||||
try {
|
||||
UUID uuid = UUID.fromString(name);
|
||||
return getMaxVaultSize(Bukkit.getOfflinePlayer(uuid));
|
||||
} catch (Exception e) {
|
||||
// Not a UUID
|
||||
}
|
||||
|
||||
return 54;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,7 +156,7 @@ public class VaultOperations {
|
||||
return false; // inventory open event was cancelled.
|
||||
}
|
||||
|
||||
VaultViewInfo info = new VaultViewInfo(player.getUniqueId(), number);
|
||||
VaultViewInfo info = new VaultViewInfo(player.getUniqueId().toString(), number);
|
||||
PlayerVaults.getInstance().getOpenInventories().put(info.toString(), inv);
|
||||
|
||||
player.sendMessage(Lang.TITLE.toString() + Lang.OPEN_VAULT.toString().replace("%v", arg));
|
||||
@@ -184,11 +191,11 @@ public class VaultOperations {
|
||||
* Open another player's vault.
|
||||
*
|
||||
* @param player The player to open to.
|
||||
* @param holder The user to whom the requested vault belongs.
|
||||
* @param vaultOwner The name of the vault owner.
|
||||
* @param arg The vault number to open.
|
||||
* @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, String vaultOwner, String arg) {
|
||||
if (isLocked()) {
|
||||
return false;
|
||||
}
|
||||
@@ -206,16 +213,26 @@ public class VaultOperations {
|
||||
player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
|
||||
}
|
||||
|
||||
Inventory inv = VaultManager.getInstance().loadOtherVault(vaultOwner, number, getMaxVaultSize(vaultOwner));
|
||||
String name = vaultOwner;
|
||||
try {
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(UUID.fromString(vaultOwner));
|
||||
name = offlinePlayer.getName();
|
||||
} catch (Exception e) {
|
||||
// not a player
|
||||
}
|
||||
|
||||
Inventory inv = VaultManager.getInstance().loadOtherVault(holder, number, getMaxVaultSize(holder));
|
||||
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(holder);
|
||||
String name = offlinePlayer != null ? offlinePlayer.getName() : "";
|
||||
if (inv == null) {
|
||||
player.sendMessage(Lang.TITLE.toString() + Lang.VAULT_DOES_NOT_EXIST.toString());
|
||||
} else {
|
||||
player.openInventory(inv);
|
||||
player.sendMessage(Lang.TITLE.toString() + Lang.OPEN_OTHER_VAULT.toString().replace("%v", arg).replace("%p", name));
|
||||
PlayerVaults.debug("opening other vault", time);
|
||||
|
||||
// Need to set ViewInfo for a third party vault for the opening player.
|
||||
VaultViewInfo info = new VaultViewInfo(vaultOwner, number);
|
||||
PlayerVaults.getInstance().getInVault().put(player.getUniqueId().toString(), info);
|
||||
PlayerVaults.getInstance().getOpenInventories().put(player.getUniqueId().toString(), inv);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -246,7 +263,8 @@ public class VaultOperations {
|
||||
}
|
||||
|
||||
if (EconomyOperations.refundOnDelete(player, number)) {
|
||||
VaultManager.getInstance().deleteVault(player, player.getUniqueId(), number);
|
||||
VaultManager.getInstance().deleteVault(player, player.getUniqueId().toString(), number);
|
||||
player.sendMessage(Lang.TITLE.toString() + Lang.DELETE_VAULT.toString().replaceAll("%v", arg));
|
||||
}
|
||||
|
||||
} else {
|
||||
@@ -261,7 +279,7 @@ public class VaultOperations {
|
||||
* @param holder The user to whom the deleted vault belongs.
|
||||
* @param arg The vault number to delete.
|
||||
*/
|
||||
public static void deleteOtherVault(CommandSender sender, OfflinePlayer holder, String arg) {
|
||||
public static void deleteOtherVault(CommandSender sender, String holder, String arg) {
|
||||
if (isLocked()) {
|
||||
return;
|
||||
}
|
||||
@@ -278,7 +296,8 @@ public class VaultOperations {
|
||||
sender.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
|
||||
}
|
||||
|
||||
VaultManager.getInstance().deleteVault(sender, holder.getUniqueId(), number);
|
||||
VaultManager.getInstance().deleteVault(sender, holder, number);
|
||||
sender.sendMessage(Lang.TITLE.toString() + Lang.DELETE_OTHER_VAULT.toString().replaceAll("%v", arg).replaceAll("%p", holder));
|
||||
} else {
|
||||
sender.sendMessage(Lang.TITLE.toString() + Lang.MUST_BE_NUMBER);
|
||||
}
|
||||
@@ -293,7 +312,7 @@ public class VaultOperations {
|
||||
* @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) {
|
||||
public static void deleteOtherAllVaults(CommandSender sender, String holder) {
|
||||
if (isLocked() || holder == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -16,41 +16,22 @@
|
||||
*/
|
||||
package com.drtshock.playervaults.vaultmanagement;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* A class that stores information about a vault viewing including the holder of the vault, and the vault number.
|
||||
*/
|
||||
public class VaultViewInfo {
|
||||
|
||||
UUID uuid;
|
||||
final String holder;
|
||||
final String vaultName;
|
||||
final int number;
|
||||
|
||||
/**
|
||||
* Make a VaultViewObject.
|
||||
* Makes a VaultViewInfo object. Used for opening a vault owned by the opener.
|
||||
*
|
||||
* @param s The holder of the vault.
|
||||
* @param i The vault number.
|
||||
* @param i vault number.
|
||||
*/
|
||||
@Deprecated
|
||||
public VaultViewInfo(String s, int i) {
|
||||
this.holder = s;
|
||||
public VaultViewInfo(String vaultName, int i) {
|
||||
this.number = i;
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes a VaultViewInfo object.
|
||||
*
|
||||
* @param uuid uuid of viewer.
|
||||
* @param i vault number
|
||||
*/
|
||||
public VaultViewInfo(UUID uuid, int i) {
|
||||
this.uuid = uuid;
|
||||
this.number = i;
|
||||
this.holder = Bukkit.getOfflinePlayer(uuid).getName();
|
||||
this.vaultName = vaultName;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,18 +39,8 @@ public class VaultViewInfo {
|
||||
*
|
||||
* @return The holder of the vault.
|
||||
*/
|
||||
@Deprecated
|
||||
public String getHolder() {
|
||||
return this.holder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the vault holder's UUID.
|
||||
*
|
||||
* @return The vault holder's UUID.
|
||||
*/
|
||||
public UUID getHolderUUID() {
|
||||
return this.uuid;
|
||||
public String getVaultName() {
|
||||
return this.vaultName;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,6 +54,6 @@ public class VaultViewInfo {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.uuid + " " + this.number;
|
||||
return this.vaultName + " " + this.number;
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ cost-to-create: "&fYou were charged &c%price &ffor creating that vault."
|
||||
cost-to-open: "&fYou were charged &c%price &ffor opening that vault."
|
||||
vault-title: "&4Vault #%number"
|
||||
existing-vaults: "&f%p has vaults: &a%v"
|
||||
no-player-found: "&cCannot find player &a%p"
|
||||
no-owner-found: "&cCannot find vault owner: &a%p"
|
||||
plugin-not-found: "&cNo converter found for that plugin"
|
||||
conversion-complete: "&aConverted %converted players to PlayerVaults"
|
||||
conversion-background: "&fConversion has been forked to the background. See console for updates."
|
||||
|
||||
Reference in New Issue
Block a user