85 lines
2.8 KiB
Java
85 lines
2.8 KiB
Java
|
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.Bukkit;
|
||
|
import org.bukkit.OfflinePlayer;
|
||
|
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) {
|
||
|
me.sendMessage(TL.COMMAND_VAULTS_TOOHIGH.format(number, max));
|
||
|
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.
|
||
|
if (VaultOperations.openOtherVault(player, vaultName, String.valueOf(number))) {
|
||
|
// Success
|
||
|
PlayerVaults.getInstance().getInVault().put(player.getUniqueId().toString(), new VaultViewInfo(vaultName, number));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public TL getUsageTranslation() {
|
||
|
return TL.COMMAND_VERSION_DESCRIPTION;
|
||
|
}
|
||
|
}
|