2016-05-31 01:22:45 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
|
|
|
|
2018-03-26 23:43:15 +02:00
|
|
|
import com.massivecraft.factions.Board;
|
|
|
|
import com.massivecraft.factions.FLocation;
|
2019-09-14 21:13:01 +02:00
|
|
|
import com.massivecraft.factions.FactionsPlugin;
|
2016-05-31 01:22:45 +02:00
|
|
|
import com.massivecraft.factions.struct.Permission;
|
2018-04-25 02:32:26 +02:00
|
|
|
import com.massivecraft.factions.zcore.fperms.PermissableAction;
|
2016-05-31 01:22:45 +02:00
|
|
|
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;
|
2016-05-31 01:22:45 +02:00
|
|
|
|
|
|
|
public class CmdVault extends FCommand {
|
|
|
|
|
2019-12-02 19:55:38 +01:00
|
|
|
/**
|
|
|
|
* @author Illyria Team
|
|
|
|
*/
|
|
|
|
|
2019-09-15 11:19:06 +02:00
|
|
|
public CmdVault() {
|
|
|
|
this.aliases.add("vault");
|
2016-05-31 01:22:45 +02:00
|
|
|
|
2019-09-15 11:19:06 +02:00
|
|
|
this.requirements = new CommandRequirements.Builder(Permission.VAULT)
|
|
|
|
.playerOnly()
|
|
|
|
.memberOnly()
|
|
|
|
.withAction(PermissableAction.VAULT)
|
|
|
|
.build();
|
2018-12-21 22:46:10 +01:00
|
|
|
|
2019-09-15 11:19:06 +02:00
|
|
|
}
|
2016-05-31 01:22:45 +02:00
|
|
|
|
2019-09-15 11:19:06 +02:00
|
|
|
@Override
|
|
|
|
public void perform(CommandContext context) {
|
2018-04-25 02:32:26 +02:00
|
|
|
|
2019-09-15 11:19:06 +02:00
|
|
|
if (!FactionsPlugin.getInstance().getConfig().getBoolean("fvault.Enabled")) {
|
|
|
|
context.fPlayer.sendMessage("This command is disabled!");
|
|
|
|
return;
|
|
|
|
}
|
2016-05-31 01:22:45 +02:00
|
|
|
|
2019-09-15 11:19:06 +02:00
|
|
|
if (context.fPlayer.isInVault()) {
|
|
|
|
context.player.closeInventory();
|
|
|
|
return;
|
|
|
|
}
|
2019-09-14 21:13:01 +02:00
|
|
|
|
2019-09-15 11:19:06 +02:00
|
|
|
context.fPlayer.setInVault(true);
|
|
|
|
Location vaultLocation = context.faction.getVault();
|
|
|
|
if (vaultLocation == null) {
|
|
|
|
context.msg(TL.COMMAND_VAULT_INVALID);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
FLocation vaultFLocation = new FLocation(vaultLocation);
|
|
|
|
if (Board.getInstance().getFactionAt(vaultFLocation) != context.faction) {
|
|
|
|
context.faction.setVault(null);
|
|
|
|
context.msg(TL.COMMAND_VAULT_INVALID);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (vaultLocation.getBlock().getType() != Material.CHEST) {
|
|
|
|
context.faction.setVault(null);
|
|
|
|
context.msg(TL.COMMAND_VAULT_INVALID);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Chest chest = (Chest) vaultLocation.getBlock().getState();
|
|
|
|
Inventory chestInv = chest.getBlockInventory();
|
|
|
|
context.msg(TL.COMMAND_VAULT_OPENING);
|
|
|
|
context.player.openInventory(chestInv);
|
2016-05-31 01:22:45 +02:00
|
|
|
|
|
|
|
|
2019-09-15 11:19:06 +02:00
|
|
|
}
|
2016-05-31 01:22:45 +02:00
|
|
|
|
2019-09-15 11:19:06 +02:00
|
|
|
@Override
|
|
|
|
public TL getUsageTranslation() {
|
|
|
|
return TL.COMMAND_VAULT_DESCRIPTION;
|
|
|
|
}
|
2019-09-14 21:13:01 +02:00
|
|
|
|
|
|
|
}
|