Merge remote-tracking branch 'origin/1.6.x' into 1.6.x

This commit is contained in:
DroppingAnvil 2019-09-15 03:46:59 -05:00
commit b1525601a0
3 changed files with 46 additions and 40 deletions

View File

@ -3,27 +3,23 @@ package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.FactionsPlugin;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.XMaterial;
import com.massivecraft.factions.zcore.util.TL;
import net.milkbowl.vault.economy.Economy;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.List;
public class CmdBanner extends FCommand {
public CmdBanner() {
super();
this.aliases.add("banner");
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
@ -32,45 +28,39 @@ public class CmdBanner extends FCommand {
context.msg(TL.COMMAND_BANNER_DISABLED);
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))) {
context.msg(TL.COMMAND_BANNER_NOTENOUGHMONEY);
return;
}
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();
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 = context.fPlayer.getFaction().getBanner();
if (warBanner != null) {
ItemMeta warmeta = warBanner.getItemMeta();
warmeta.setDisplayName(FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fbanners.Item.Name")));
warmeta.setLore(FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fbanners.Item.Lore")));
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"));
}
ItemMeta warmeta = warBanner.getItemMeta();
warmeta.setDisplayName(FactionsPlugin.getInstance().color(FactionsPlugin.getInstance().getConfig().getString("fbanners.Item.Name")));
warmeta.setLore(FactionsPlugin.getInstance().colorList(FactionsPlugin.getInstance().getConfig().getStringList("fbanners.Item.Lore")));
warBanner.setItemMeta(warmeta);
context.msg(TL.COMMAND_BANNER_SUCCESS);
warBanner.setAmount(1);
context.player.getInventory().addItem(warBanner);
}
public boolean hasMoney(FPlayer fme, int amt) {
Economy econ = FactionsPlugin.getInstance().getEcon();
if (econ.getBalance(fme.getPlayer()) >= amt) {
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) {
if (hasMoney(fme, amt)) {
if (this.hasMoney(fme, amt)) {
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 + ""));
}
}
@ -78,9 +68,9 @@ public class CmdBanner extends FCommand {
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();
for (ItemStack item1 : items) {
if (item1 != null && item1.getType() == item.getType() && item1.getDurability() == item.getDurability()) {
count += item1.getAmount();
}
if (count >= item.getAmount()) {
return true;
@ -89,22 +79,21 @@ public class CmdBanner extends FCommand {
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++) {
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) {
}
if (items[i].getAmount() == amt) {
items[i] = null;
break;
} else {
amt -= items[i].getAmount();
items[i] = null;
}
amt -= items[i].getAmount();
items[i] = null;
}
}
inventory.setContents(items);
@ -114,14 +103,14 @@ public class CmdBanner extends FCommand {
PlayerInventory inventory = p.getInventory();
ItemStack[] cont = inventory.getContents();
int i = 0;
for (ItemStack item : cont)
for (ItemStack item : cont) {
if (item != null && item.getType() != Material.AIR) {
i++;
++i;
}
}
return 36 - i;
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_BANNER_DESCRIPTION;

View File

@ -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
public void onBannerPlace(BlockPlaceEvent e) {
if (FactionsPlugin.getInstance().mc17) {

View File

@ -200,6 +200,8 @@ public enum TL {
COMMAND_BYPASS_DESCRIPTION("Enable admin bypass mode"),
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_MONEYTAKE("&c&l[!] $&c{amount} &7has been taken from your account."),
COMMAND_BANNER_SUCCESS("&c&l[!] &7You have created a &c&lWarBanner!"),