commit
b4b226e4f0
@ -3,27 +3,23 @@ package com.massivecraft.factions.cmd;
|
|||||||
import com.massivecraft.factions.FPlayer;
|
import com.massivecraft.factions.FPlayer;
|
||||||
import com.massivecraft.factions.FactionsPlugin;
|
import com.massivecraft.factions.FactionsPlugin;
|
||||||
import com.massivecraft.factions.struct.Permission;
|
import com.massivecraft.factions.struct.Permission;
|
||||||
import com.massivecraft.factions.util.XMaterial;
|
|
||||||
import com.massivecraft.factions.zcore.util.TL;
|
import com.massivecraft.factions.zcore.util.TL;
|
||||||
import net.milkbowl.vault.economy.Economy;
|
import net.milkbowl.vault.economy.Economy;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.OfflinePlayer;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class CmdBanner extends FCommand {
|
public class CmdBanner extends FCommand {
|
||||||
public CmdBanner() {
|
public CmdBanner() {
|
||||||
super();
|
|
||||||
|
|
||||||
this.aliases.add("banner");
|
this.aliases.add("banner");
|
||||||
this.aliases.add("warbanner");
|
this.aliases.add("warbanner");
|
||||||
|
this.requirements = new CommandRequirements.Builder(Permission.BANNER).playerOnly().memberOnly().build();
|
||||||
this.requirements = new CommandRequirements.Builder(Permission.BANNER)
|
|
||||||
.playerOnly()
|
|
||||||
.memberOnly()
|
|
||||||
.build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -32,45 +28,39 @@ public class CmdBanner extends FCommand {
|
|||||||
context.msg(TL.COMMAND_BANNER_DISABLED);
|
context.msg(TL.COMMAND_BANNER_DISABLED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (context.faction.getBanner() == null) {
|
||||||
|
context.msg(TL.COMMAND_BANNER_NOBANNER);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (!context.fPlayer.hasMoney(FactionsPlugin.getInstance().getConfig().getInt("fbanners.Banner-Cost", 5000))) {
|
if (!context.fPlayer.hasMoney(FactionsPlugin.getInstance().getConfig().getInt("fbanners.Banner-Cost", 5000))) {
|
||||||
context.msg(TL.COMMAND_BANNER_NOTENOUGHMONEY);
|
context.msg(TL.COMMAND_BANNER_NOTENOUGHMONEY);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
takeMoney(context.fPlayer, FactionsPlugin.getInstance().getConfig().getInt("fbanners.Banner-Cost", 5000));
|
this.takeMoney(context.fPlayer, FactionsPlugin.getInstance().getConfig().getInt("fbanners.Banner-Cost", 5000));
|
||||||
|
this.takeMoney(context.fPlayer, FactionsPlugin.getInstance().getConfig().getInt("fbanners.Banner-Cost", 5000));
|
||||||
//ItemStack warBanner = FactionsPlugin.getInstance().createItem(Material.BANNER, 1, (short) 1, FactionsPlugin.getInstance().getConfig().getString("fbanners.Item.Name"), FactionsPlugin.getInstance().getConfig().getStringList("fbanners.Item.Lore"));
|
|
||||||
//BannerMeta bannerMeta = (BannerMeta) warBanner.getItemMeta();
|
|
||||||
ItemStack warBanner = context.fPlayer.getFaction().getBanner();
|
ItemStack warBanner = context.fPlayer.getFaction().getBanner();
|
||||||
if (warBanner != null) {
|
ItemMeta warmeta = warBanner.getItemMeta();
|
||||||
ItemMeta warmeta = warBanner.getItemMeta();
|
warmeta.setDisplayName(FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fbanners.Item.Name")));
|
||||||
warmeta.setDisplayName(FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fbanners.Item.Name")));
|
warmeta.setLore(FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fbanners.Item.Lore")));
|
||||||
warmeta.setLore(FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fbanners.Item.Lore")));
|
warBanner.setItemMeta(warmeta);
|
||||||
warBanner.setItemMeta(warmeta);
|
|
||||||
|
|
||||||
|
|
||||||
} else {
|
|
||||||
warBanner = FactionsPlugin.getInstance().createItem(XMaterial.BLACK_BANNER.parseMaterial(), 1, (short) 1, FactionsPlugin.getInstance().getConfig().getString("fbanners.Item.Name"), FactionsPlugin.getInstance().getConfig().getStringList("fbanners.Item.Lore"));
|
|
||||||
}
|
|
||||||
context.msg(TL.COMMAND_BANNER_SUCCESS);
|
context.msg(TL.COMMAND_BANNER_SUCCESS);
|
||||||
warBanner.setAmount(1);
|
warBanner.setAmount(1);
|
||||||
context.player.getInventory().addItem(warBanner);
|
context.player.getInventory().addItem(warBanner);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean hasMoney(FPlayer fme, int amt) {
|
public boolean hasMoney(FPlayer fme, int amt) {
|
||||||
Economy econ = FactionsPlugin.getInstance().getEcon();
|
Economy econ = FactionsPlugin.getInstance().getEcon();
|
||||||
if (econ.getBalance(fme.getPlayer()) >= amt) {
|
if (econ.getBalance(fme.getPlayer()) >= amt) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
|
||||||
fme.msg(TL.COMMAND_BANNER_NOTENOUGHMONEY);
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
fme.msg(TL.COMMAND_BANNER_NOTENOUGHMONEY);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void takeMoney(FPlayer fme, int amt) {
|
public void takeMoney(FPlayer fme, int amt) {
|
||||||
if (hasMoney(fme, amt)) {
|
if (this.hasMoney(fme, amt)) {
|
||||||
Economy econ = FactionsPlugin.getInstance().getEcon();
|
Economy econ = FactionsPlugin.getInstance().getEcon();
|
||||||
econ.withdrawPlayer(fme.getPlayer(), amt);
|
econ.withdrawPlayer(fme.getPlayer(), (double) amt);
|
||||||
fme.sendMessage(TL.COMMAND_BANNER_MONEYTAKE.toString().replace("{amount}", amt + ""));
|
fme.sendMessage(TL.COMMAND_BANNER_MONEYTAKE.toString().replace("{amount}", amt + ""));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -78,9 +68,9 @@ public class CmdBanner extends FCommand {
|
|||||||
public boolean inventoryContains(Inventory inventory, ItemStack item) {
|
public boolean inventoryContains(Inventory inventory, ItemStack item) {
|
||||||
int count = 0;
|
int count = 0;
|
||||||
ItemStack[] items = inventory.getContents();
|
ItemStack[] items = inventory.getContents();
|
||||||
for (int i = 0; i < items.length; i++) {
|
for (ItemStack item1 : items) {
|
||||||
if (items[i] != null && items[i].getType() == item.getType() && items[i].getDurability() == item.getDurability()) {
|
if (item1 != null && item1.getType() == item.getType() && item1.getDurability() == item.getDurability()) {
|
||||||
count += items[i].getAmount();
|
count += item1.getAmount();
|
||||||
}
|
}
|
||||||
if (count >= item.getAmount()) {
|
if (count >= item.getAmount()) {
|
||||||
return true;
|
return true;
|
||||||
@ -89,22 +79,21 @@ public class CmdBanner extends FCommand {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void removeFromInventory(Inventory inventory, ItemStack item) {
|
public void removeFromInventory(Inventory inventory, ItemStack item) {
|
||||||
int amt = item.getAmount();
|
int amt = item.getAmount();
|
||||||
ItemStack[] items = inventory.getContents();
|
ItemStack[] items = inventory.getContents();
|
||||||
for (int i = 0; i < items.length; i++) {
|
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] != null && items[i].getType() == item.getType() && items[i].getDurability() == item.getDurability()) {
|
||||||
if (items[i].getAmount() > amt) {
|
if (items[i].getAmount() > amt) {
|
||||||
items[i].setAmount(items[i].getAmount() - amt);
|
items[i].setAmount(items[i].getAmount() - amt);
|
||||||
break;
|
break;
|
||||||
} else if (items[i].getAmount() == amt) {
|
}
|
||||||
|
if (items[i].getAmount() == amt) {
|
||||||
items[i] = null;
|
items[i] = null;
|
||||||
break;
|
break;
|
||||||
} else {
|
|
||||||
amt -= items[i].getAmount();
|
|
||||||
items[i] = null;
|
|
||||||
}
|
}
|
||||||
|
amt -= items[i].getAmount();
|
||||||
|
items[i] = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
inventory.setContents(items);
|
inventory.setContents(items);
|
||||||
@ -114,14 +103,14 @@ public class CmdBanner extends FCommand {
|
|||||||
PlayerInventory inventory = p.getInventory();
|
PlayerInventory inventory = p.getInventory();
|
||||||
ItemStack[] cont = inventory.getContents();
|
ItemStack[] cont = inventory.getContents();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (ItemStack item : cont)
|
for (ItemStack item : cont) {
|
||||||
if (item != null && item.getType() != Material.AIR) {
|
if (item != null && item.getType() != Material.AIR) {
|
||||||
i++;
|
++i;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return 36 - i;
|
return 36 - i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TL getUsageTranslation() {
|
public TL getUsageTranslation() {
|
||||||
return TL.COMMAND_BANNER_DESCRIPTION;
|
return TL.COMMAND_BANNER_DESCRIPTION;
|
||||||
|
@ -327,6 +327,21 @@ public class FactionsBlockListener implements Listener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@EventHandler
|
||||||
|
public void onBannerBreak(BlockBreakEvent e){
|
||||||
|
FPlayer fme = FPlayers.getInstance().getByPlayer(e.getPlayer());
|
||||||
|
if (FactionsPlugin.getInstance().mc17) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(bannerLocations.containsValue(e.getBlock().getLocation())){
|
||||||
|
if(e.getBlock().getType().name().contains("BANNER")) {
|
||||||
|
e.setCancelled(true);
|
||||||
|
fme.msg(TL.BANNER_CANNOT_BREAK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onBannerPlace(BlockPlaceEvent e) {
|
public void onBannerPlace(BlockPlaceEvent e) {
|
||||||
if (FactionsPlugin.getInstance().mc17) {
|
if (FactionsPlugin.getInstance().mc17) {
|
||||||
|
@ -200,6 +200,8 @@ public enum TL {
|
|||||||
COMMAND_BYPASS_DESCRIPTION("Enable admin bypass mode"),
|
COMMAND_BYPASS_DESCRIPTION("Enable admin bypass mode"),
|
||||||
|
|
||||||
COMMAND_BANNER_DESCRIPTION("Turn a held banner into a war banner"),
|
COMMAND_BANNER_DESCRIPTION("Turn a held banner into a war banner"),
|
||||||
|
BANNER_CANNOT_BREAK("&c&l[!] &7You may not break a faction banner!"),
|
||||||
|
COMMAND_BANNER_NOBANNER("&c&l[!] &cPlease set a banner using /f setbanner"),
|
||||||
COMMAND_BANNER_NOTENOUGHMONEY("&c&l[!] &7You do&c not&7 have enough money"),
|
COMMAND_BANNER_NOTENOUGHMONEY("&c&l[!] &7You do&c not&7 have enough money"),
|
||||||
COMMAND_BANNER_MONEYTAKE("&c&l[!] $&c{amount} &7has been taken from your account."),
|
COMMAND_BANNER_MONEYTAKE("&c&l[!] $&c{amount} &7has been taken from your account."),
|
||||||
COMMAND_BANNER_SUCCESS("&c&l[!] &7You have created a &c&lWarBanner!"),
|
COMMAND_BANNER_SUCCESS("&c&l[!] &7You have created a &c&lWarBanner!"),
|
||||||
|
Loading…
Reference in New Issue
Block a user