2016-05-31 01:22:45 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
|
|
|
|
|
|
|
import com.drtshock.playervaults.PlayerVaults;
|
|
|
|
import com.drtshock.playervaults.util.Lang;
|
|
|
|
import com.drtshock.playervaults.vaultmanagement.UUIDVaultManager;
|
|
|
|
import com.drtshock.playervaults.vaultmanagement.VaultOperations;
|
|
|
|
import com.drtshock.playervaults.vaultmanagement.VaultViewInfo;
|
|
|
|
import com.massivecraft.factions.Conf;
|
|
|
|
import com.massivecraft.factions.struct.Permission;
|
|
|
|
import com.massivecraft.factions.zcore.util.TL;
|
|
|
|
import org.bukkit.configuration.file.YamlConfiguration;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
public class CmdVault extends FCommand {
|
|
|
|
|
|
|
|
public CmdVault() {
|
|
|
|
this.aliases.add("vault");
|
|
|
|
|
|
|
|
//this.requiredArgs.add("");
|
|
|
|
this.optionalArgs.put("number", "number");
|
|
|
|
|
|
|
|
this.permission = Permission.VAULT.node;
|
|
|
|
this.disableOnLock = false;
|
|
|
|
|
|
|
|
senderMustBePlayer = true;
|
|
|
|
senderMustBeMember = true;
|
|
|
|
senderMustBeModerator = false;
|
|
|
|
senderMustBeAdmin = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void perform() {
|
|
|
|
/*
|
|
|
|
/f vault <number>
|
|
|
|
*/
|
|
|
|
|
|
|
|
int number = argAsInt(0, 0); // Default to 0 or show on 0
|
|
|
|
|
|
|
|
Player player = me;
|
|
|
|
|
|
|
|
if (PlayerVaults.getInstance().getInVault().containsKey(player.getUniqueId().toString())) {
|
|
|
|
return; // Already in a vault so they must be trying to dupe.
|
|
|
|
}
|
|
|
|
|
|
|
|
int max = myFaction.getMaxVaults();
|
|
|
|
if (number > max) {
|
2016-05-31 01:25:27 +02:00
|
|
|
me.sendMessage(TL.COMMAND_VAULT_TOOHIGH.format(number, max));
|
2016-05-31 01:22:45 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Something like faction-id
|
|
|
|
String vaultName = String.format(Conf.vaultPrefix, myFaction.getId());
|
|
|
|
|
|
|
|
if (number < 1) {
|
|
|
|
// Message about which vaults that Faction has.
|
|
|
|
// List the target
|
|
|
|
YamlConfiguration file = UUIDVaultManager.getInstance().getPlayerVaultFile(vaultName);
|
|
|
|
if (file == null) {
|
|
|
|
sender.sendMessage(Lang.TITLE.toString() + Lang.VAULT_DOES_NOT_EXIST.toString());
|
|
|
|
} else {
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
for (String key : file.getKeys(false)) {
|
|
|
|
sb.append(key.replace("vault", "")).append(" ");
|
|
|
|
}
|
|
|
|
|
|
|
|
sender.sendMessage(Lang.TITLE.toString() + Lang.EXISTING_VAULTS.toString().replaceAll("%p", fme.getTag()).replaceAll("%v", sb.toString().trim()));
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
} // end listing vaults.
|
|
|
|
|
|
|
|
// Attempt to open vault.
|
2018-02-01 02:03:55 +01:00
|
|
|
if (VaultOperations.openOtherVault(player, null, String.valueOf(number))) {
|
2016-05-31 01:22:45 +02:00
|
|
|
// Success
|
|
|
|
PlayerVaults.getInstance().getInVault().put(player.getUniqueId().toString(), new VaultViewInfo(vaultName, number));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TL getUsageTranslation() {
|
2016-05-31 01:25:27 +02:00
|
|
|
return TL.COMMAND_VAULT_DESCRIPTION;
|
2016-05-31 01:22:45 +02:00
|
|
|
}
|
|
|
|
}
|