2018-03-27 01:42:26 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
|
|
|
|
|
|
|
import com.massivecraft.factions.FPlayer;
|
2018-10-23 01:42:57 +02:00
|
|
|
import com.massivecraft.factions.SavageFactions;
|
2018-03-27 01:42:26 +02:00
|
|
|
import com.massivecraft.factions.struct.Permission;
|
|
|
|
import com.massivecraft.factions.zcore.util.TL;
|
|
|
|
import net.milkbowl.vault.economy.Economy;
|
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.bukkit.inventory.Inventory;
|
|
|
|
import org.bukkit.inventory.ItemStack;
|
|
|
|
import org.bukkit.inventory.PlayerInventory;
|
2018-05-12 00:47:58 +02:00
|
|
|
import org.bukkit.inventory.meta.ItemMeta;
|
2018-03-27 01:42:26 +02:00
|
|
|
|
|
|
|
public class CmdBanner extends FCommand {
|
|
|
|
public CmdBanner() {
|
|
|
|
super();
|
|
|
|
|
|
|
|
this.aliases.add("banner");
|
|
|
|
this.aliases.add("warbanner");
|
|
|
|
|
|
|
|
this.permission = Permission.BANNER.node;
|
|
|
|
this.disableOnLock = false;
|
|
|
|
|
2018-12-21 22:46:10 +01:00
|
|
|
|
|
|
|
senderMustBePlayer = true;
|
2018-03-27 01:42:26 +02:00
|
|
|
senderMustBeMember = false;
|
|
|
|
senderMustBeModerator = false;
|
|
|
|
senderMustBeColeader = true;
|
|
|
|
senderMustBeAdmin = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void perform() {
|
2018-11-07 17:14:42 +01:00
|
|
|
if (!SavageFactions.plugin.getConfig().getBoolean("fbanners.Enabled")) {
|
2018-08-05 06:52:12 +02:00
|
|
|
msg(TL.COMMAND_BANNER_DISABLED);
|
2018-04-04 05:20:30 +02:00
|
|
|
return;
|
|
|
|
}
|
2018-11-07 17:14:42 +01:00
|
|
|
if (!fme.hasMoney(SavageFactions.plugin.getConfig().getInt("fbanners.Banner-Cost", 5000))) {
|
2018-03-29 02:33:10 +02:00
|
|
|
msg(TL.COMMAND_BANNER_NOTENOUGHMONEY);
|
|
|
|
return;
|
2018-03-27 01:42:26 +02:00
|
|
|
}
|
2018-11-07 06:38:43 +01:00
|
|
|
takeMoney(fme, SavageFactions.plugin.getConfig().getInt("fbanners.Banner-Cost", 5000));
|
2018-05-12 00:47:58 +02:00
|
|
|
|
2018-11-07 06:38:43 +01:00
|
|
|
//ItemStack warBanner = SavageFactions.plugin.createItem(Material.BANNER, 1, (short) 1, SavageFactions.plugin.getConfig().getString("fbanners.Item.Name"), SavageFactions.plugin.getConfig().getStringList("fbanners.Item.Lore"));
|
2018-05-12 00:47:58 +02:00
|
|
|
//BannerMeta bannerMeta = (BannerMeta) warBanner.getItemMeta();
|
|
|
|
ItemStack warBanner = fme.getFaction().getBanner();
|
|
|
|
if (warBanner != null) {
|
|
|
|
ItemMeta warmeta = warBanner.getItemMeta();
|
2018-11-07 06:38:43 +01:00
|
|
|
warmeta.setDisplayName(SavageFactions.plugin.color(SavageFactions.plugin.getConfig().getString("fbanners.Item.Name")));
|
|
|
|
warmeta.setLore(SavageFactions.plugin.colorList(SavageFactions.plugin.getConfig().getStringList("fbanners.Item.Lore")));
|
2018-05-12 00:47:58 +02:00
|
|
|
warBanner.setItemMeta(warmeta);
|
2018-05-12 01:13:02 +02:00
|
|
|
|
2018-05-12 00:47:58 +02:00
|
|
|
|
|
|
|
} else {
|
2018-08-11 08:14:18 +02:00
|
|
|
|
|
|
|
|
2018-11-07 06:38:43 +01:00
|
|
|
warBanner = SavageFactions.plugin.createItem(SavageFactions.plugin.BANNER, 1, (short) 1, SavageFactions.plugin.getConfig().getString("fbanners.Item.Name"), SavageFactions.plugin.getConfig().getStringList("fbanners.Item.Lore"));
|
2018-05-12 00:47:58 +02:00
|
|
|
}
|
2018-03-29 02:33:10 +02:00
|
|
|
fme.msg(TL.COMMAND_BANNER_SUCCESS);
|
2018-05-12 01:13:02 +02:00
|
|
|
warBanner.setAmount(1);
|
|
|
|
me.getInventory().addItem(warBanner);
|
2018-03-27 01:42:26 +02:00
|
|
|
}
|
|
|
|
|
2018-05-12 00:47:58 +02:00
|
|
|
|
2018-03-27 01:42:26 +02:00
|
|
|
public boolean hasMoney(FPlayer fme, int amt) {
|
2018-11-07 06:38:43 +01:00
|
|
|
Economy econ = SavageFactions.plugin.getEcon();
|
2018-04-04 05:20:30 +02:00
|
|
|
if (econ.getBalance(fme.getPlayer()) >= amt) {
|
2018-03-27 01:42:26 +02:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
fme.msg(TL.COMMAND_BANNER_NOTENOUGHMONEY);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void takeMoney(FPlayer fme, int amt) {
|
|
|
|
if (hasMoney(fme, amt)) {
|
2018-11-07 06:38:43 +01:00
|
|
|
Economy econ = SavageFactions.plugin.getEcon();
|
2018-03-27 01:42:26 +02:00
|
|
|
econ.withdrawPlayer(fme.getPlayer(), amt);
|
|
|
|
fme.sendMessage(TL.COMMAND_BANNER_MONEYTAKE.toString().replace("{amount}", amt + ""));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean inventoryContains(Inventory inventory, ItemStack item) {
|
|
|
|
int count = 0;
|
|
|
|
ItemStack[] items = inventory.getContents();
|
|
|
|
for (int i = 0; i < items.length; i++) {
|
|
|
|
if (items[i] != null && items[i].getType() == item.getType() && items[i].getDurability() == item.getDurability()) {
|
|
|
|
count += items[i].getAmount();
|
|
|
|
}
|
|
|
|
if (count >= item.getAmount()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void removeFromInventory(Inventory inventory, ItemStack item) {
|
|
|
|
int amt = item.getAmount();
|
|
|
|
ItemStack[] items = inventory.getContents();
|
|
|
|
for (int i = 0; i < items.length; i++) {
|
|
|
|
if (items[i] != null && items[i].getType() == item.getType() && items[i].getDurability() == item.getDurability()) {
|
|
|
|
if (items[i].getAmount() > amt) {
|
|
|
|
items[i].setAmount(items[i].getAmount() - amt);
|
|
|
|
break;
|
|
|
|
} else if (items[i].getAmount() == amt) {
|
|
|
|
items[i] = null;
|
|
|
|
break;
|
|
|
|
} else {
|
|
|
|
amt -= items[i].getAmount();
|
|
|
|
items[i] = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
inventory.setContents(items);
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getEmptySlots(Player p) {
|
|
|
|
PlayerInventory inventory = p.getInventory();
|
|
|
|
ItemStack[] cont = inventory.getContents();
|
|
|
|
int i = 0;
|
|
|
|
for (ItemStack item : cont)
|
|
|
|
if (item != null && item.getType() != Material.AIR) {
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
return 36 - i;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public TL getUsageTranslation() {
|
|
|
|
return TL.COMMAND_BANNER_DESCRIPTION;
|
|
|
|
}
|
|
|
|
}
|