Reformat
This commit is contained in:
@@ -0,0 +1,14 @@
|
|||||||
|
package com.drtshock.playervaults.commands;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class DeleteCommand implements CommandExecutor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package com.drtshock.playervaults.commands;
|
||||||
|
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
|
||||||
|
public class SignCommand implements CommandExecutor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package com.drtshock.playervaults.commands;
|
||||||
|
|
||||||
|
import com.drtshock.playervaults.util.Lang;
|
||||||
|
import com.drtshock.playervaults.vaults.VaultManagement;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.command.Command;
|
||||||
|
import org.bukkit.command.CommandExecutor;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
|
||||||
|
public class VaultCommand implements CommandExecutor {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
|
||||||
|
if (!(sender instanceof Player)) {
|
||||||
|
sender.sendMessage(Lang.PLAYER_ONLY.toString());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Player player = (Player) sender;
|
||||||
|
if (args.length > 2) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
String vaultNumber = args.length == 1 ? args[0] : "1"; // so they can do /pv and open the first vault.
|
||||||
|
try {
|
||||||
|
Integer.valueOf(vaultNumber);
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
openOtherVault(player, args[0], Integer.valueOf(args[1])); // TODO: better logic for checking args.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Integer num = Integer.valueOf(vaultNumber);
|
||||||
|
Inventory inv = VaultManagement.
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void openOtherVault(Player player, String target, int num) {
|
||||||
|
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(target);
|
||||||
|
if (offlinePlayer == null) {
|
||||||
|
player.sendMessage(Lang.TITLE.toString() + Lang.VAULT_DOES_NOT_EXIST.toString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Inventory vault = VaultManagement.getVault(offlinePlayer, num);
|
||||||
|
if (vault == null) {
|
||||||
|
player.sendMessage(Lang.TITLE.toString() + Lang.VAULT_DOES_NOT_EXIST.toString());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
player.openInventory(vault); // TODO: Don't allow same vault to be opened multiple times.
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package com.drtshock.playervaults.util;
|
||||||
|
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
public class PermissionChecks {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if a player can open a request vault.
|
||||||
|
*
|
||||||
|
* @param player - player in question.
|
||||||
|
* @param number - vault number in question
|
||||||
|
*
|
||||||
|
* @return - true if permitted, otherwise false.
|
||||||
|
*/
|
||||||
|
public static boolean canOpenVault(Player player, int number) {
|
||||||
|
if (player.isOp() && player.hasPermission("playervaults.admin") && player.hasPermission("playervaults.amount." + String.valueOf(number))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
for (int x = number; x <= 99; x++) {
|
||||||
|
if (player.hasPermission("playervaults.amount." + String.valueOf(x))) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the max size vault a player is allowed to have.
|
||||||
|
*
|
||||||
|
* @param player that is having his permissions checked.
|
||||||
|
*
|
||||||
|
* @return max size as int. If no max size is set then it will default to 54.
|
||||||
|
*/
|
||||||
|
public static int getMaxVaultSize(Player player) {
|
||||||
|
if (player == null) {
|
||||||
|
return 54;
|
||||||
|
}
|
||||||
|
for (int i = 6; i != 0; i--) {
|
||||||
|
if (player.hasPermission("playervaults.size." + i)) {
|
||||||
|
return i * 9;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 54;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -109,7 +109,7 @@ public class Serialization {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, Object> serialize(ConfigurationSerializable cs) {
|
public static Map<String, Object> serialize(ConfigurationSerializable cs) {
|
||||||
Map<String,Object> returnVal = handleSerialization(cs.serialize());
|
Map<String, Object> returnVal = handleSerialization(cs.serialize());
|
||||||
returnVal.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY, ConfigurationSerialization.getAlias(cs.getClass()));
|
returnVal.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY, ConfigurationSerialization.getAlias(cs.getClass()));
|
||||||
return returnVal;
|
return returnVal;
|
||||||
}
|
}
|
||||||
@@ -129,13 +129,14 @@ public class Serialization {
|
|||||||
newList.add(object);
|
newList.add(object);
|
||||||
}
|
}
|
||||||
entry.setValue(newList);
|
entry.setValue(newList);
|
||||||
} else if (entry.getValue() instanceof Map<?,?>) {
|
} else if (entry.getValue() instanceof Map<?, ?>) {
|
||||||
// unchecked cast here. If you're serializing to a non-standard Map you deserve ClassCastExceptions
|
// unchecked cast here. If you're serializing to a non-standard Map you deserve ClassCastExceptions
|
||||||
entry.setValue(handleSerialization((Map<String, Object>) entry.getValue()));
|
entry.setValue(handleSerialization((Map<String, Object>) entry.getValue()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return serialized;
|
return serialized;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Map<String, Object> recreateMap(Map<String, Object> original) {
|
public static Map<String, Object> recreateMap(Map<String, Object> original) {
|
||||||
Map<String, Object> map = new HashMap<String, Object>();
|
Map<String, Object> map = new HashMap<String, Object>();
|
||||||
map.putAll(original);
|
map.putAll(original);
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
package com.drtshock.playervaults.vaults;
|
||||||
|
|
||||||
|
import com.drtshock.playervaults.PlayerVaults;
|
||||||
|
import com.drtshock.playervaults.util.Lang;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.configuration.serialization.ConfigurationSerializable;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles files for Vaults.
|
||||||
|
*/
|
||||||
|
public class VaultFiles {
|
||||||
|
|
||||||
|
public static YamlConfiguration getVaultFile(OfflinePlayer player) {
|
||||||
|
return getVaultFile(player.getUniqueId());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static YamlConfiguration getVaultFile(UUID uuid) {
|
||||||
|
File file = new File(PlayerVaults.getInstance().getDataFolder(), "files" + File.separator + uuid.toString() + ".yml");
|
||||||
|
if (!file.exists()) file.mkdirs();
|
||||||
|
return YamlConfiguration.loadConfiguration(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean serializeVault(Inventory inventory, UUID owner, int vaultNumber) {
|
||||||
|
YamlConfiguration yaml = getVaultFile(owner);
|
||||||
|
List<ConfigurationSerializable> items = new ArrayList<>();
|
||||||
|
for (ItemStack is : inventory.getContents()) {
|
||||||
|
items.add(is);
|
||||||
|
}
|
||||||
|
for (int i = 0; i <= items.size(); i++) {
|
||||||
|
yaml.set("vault" + vaultNumber + "." + i, items.get(i));
|
||||||
|
}
|
||||||
|
saveFile(owner);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Inventory deserializeVault(UUID owner, int vaultNumber) {
|
||||||
|
YamlConfiguration yaml = getVaultFile(owner);
|
||||||
|
Inventory inv = Bukkit.createInventory(null, 54, Lang.VAULT_TITLE.toString()); // TODO get correct size.
|
||||||
|
for (int i = 0; i <= 54; i++) {
|
||||||
|
ItemStack is = yaml.getItemStack("vault" + vaultNumber + "." + i);
|
||||||
|
if (is != null) inv.addItem(is);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void saveFile(UUID uuid) {
|
||||||
|
File file = new File(PlayerVaults.getInstance().getDataFolder(), "files" + File.separator + uuid.toString() + ".yml");
|
||||||
|
if (!file.exists()) file.mkdirs();
|
||||||
|
saveFile(file, YamlConfiguration.loadConfiguration(file));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void saveFile(File file, YamlConfiguration yaml) {
|
||||||
|
try {
|
||||||
|
yaml.save(file);
|
||||||
|
} catch (IOException e) {
|
||||||
|
PlayerVaults.getInstance().getLogger().log(Level.SEVERE, "Failed to save file: " + file.toString());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package com.drtshock.playervaults.vaults;
|
||||||
|
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.inventory.Inventory;
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles opening and getting Vaults.
|
||||||
|
*/
|
||||||
|
public class VaultManagement {
|
||||||
|
|
||||||
|
public static Inventory getVault(OfflinePlayer player, int num) {
|
||||||
|
UUID uuid = player.getUniqueId();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void saveVault(Inventory inv, OfflinePlayer player, int num) {
|
||||||
|
saveVault(inv, player.getUniqueId(), num);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void saveVault(Inventory inv, UUID owner, int num) {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user