Saber-Factions/src/main/java/com/massivecraft/factions/cmd/CmdVault.java

80 lines
2.3 KiB
Java
Raw Normal View History

package com.massivecraft.factions.cmd;
2018-03-26 23:43:15 +02:00
import com.massivecraft.factions.Board;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.SavageFactions;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL;
2018-03-26 23:43:15 +02:00
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Chest;
import org.bukkit.inventory.Inventory;
public class CmdVault extends FCommand {
public CmdVault() {
this.aliases.add("vault");
//this.requiredArgs.add("");
2018-03-26 23:43:15 +02:00
this.permission = Permission.VAULT.node;
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeAdmin = false;
2018-12-21 22:46:10 +01:00
}
2018-07-12 18:11:07 +02:00
@Override
public void perform() {
if (!SavageFactions.plugin.getConfig().getBoolean("fvault.Enabled")) {
2018-03-26 23:43:15 +02:00
fme.sendMessage("This command is disabled!");
return;
}
2018-07-12 18:11:07 +02:00
Access access = fme.getFaction().getAccess(fme, PermissableAction.VAULT);
if (access.equals(Access.DENY)) {
fme.msg(TL.GENERIC_NOPERMISSION, "vault");
2018-07-11 15:33:43 +02:00
return;
}
2018-07-12 18:11:07 +02:00
if (fme.isInVault()) {
2018-03-26 23:43:15 +02:00
me.closeInventory();
return;
}
2018-03-26 23:43:15 +02:00
fme.setInVault(true);
Location vaultLocation = fme.getFaction().getVault();
2018-07-12 18:11:07 +02:00
if (vaultLocation == null) {
2018-03-26 23:43:15 +02:00
fme.msg(TL.COMMAND_VAULT_INVALID);
return;
}
2018-07-12 18:11:07 +02:00
FLocation vaultFLocation = new FLocation(vaultLocation);
if (Board.getInstance().getFactionAt(vaultFLocation) != fme.getFaction()) {
2018-03-26 23:43:15 +02:00
fme.getFaction().setVault(null);
fme.msg(TL.COMMAND_VAULT_INVALID);
return;
}
2018-07-12 18:11:07 +02:00
if (vaultLocation.getBlock().getType() != Material.CHEST) {
2018-03-26 23:43:15 +02:00
fme.getFaction().setVault(null);
fme.msg(TL.COMMAND_VAULT_INVALID);
return;
}
2018-07-12 18:11:07 +02:00
Chest chest = (Chest) vaultLocation.getBlock().getState();
Inventory chestInv = chest.getBlockInventory();
fme.msg(TL.COMMAND_VAULT_OPENING);
me.openInventory(chestInv);
}
@Override
public TL getUsageTranslation() {
2016-05-31 01:25:27 +02:00
return TL.COMMAND_VAULT_DESCRIPTION;
}
}