Showing Dropping Anvil Something (Ignore)

This commit is contained in:
Driftay
2019-09-15 05:15:33 -04:00
parent e7db7170d1
commit 2feaed0aad
285 changed files with 28746 additions and 28746 deletions

View File

@@ -14,158 +14,158 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
public class CmdTnt extends FCommand {
public CmdTnt() {
super();
this.aliases.add("tnt");
this.optionalArgs.put("add/take", "");
this.optionalArgs.put("amount", "number");
public CmdTnt() {
super();
this.aliases.add("tnt");
this.optionalArgs.put("add/take", "");
this.optionalArgs.put("amount", "number");
this.requirements = new CommandRequirements.Builder(Permission.TNT)
.playerOnly()
.memberOnly()
.withAction(PermissableAction.TNTBANK)
.build();
}
this.requirements = new CommandRequirements.Builder(Permission.TNT)
.playerOnly()
.memberOnly()
.withAction(PermissableAction.TNTBANK)
.build();
}
@Override
public void perform(CommandContext context) {
if (!FactionsPlugin.getInstance().getConfig().getBoolean("ftnt.Enabled")) {
context.msg(TL.COMMAND_TNT_DISABLED_MSG);
return;
}
@Override
public void perform(CommandContext context) {
if (!FactionsPlugin.getInstance().getConfig().getBoolean("ftnt.Enabled")) {
context.msg(TL.COMMAND_TNT_DISABLED_MSG);
return;
}
if (context.args.size() == 2) {
if (context.args.get(0).equalsIgnoreCase("add") || context.args.get(0).equalsIgnoreCase("a")) {
try {
Integer.parseInt(context.args.get(1));
} catch (NumberFormatException e) {
context.msg(TL.COMMAND_TNT_INVALID_NUM);
return;
}
int amount = Integer.parseInt(context.args.get(1));
if (amount < 0) {
context.msg(TL.COMMAND_TNT_POSITIVE);
return;
}
Inventory inv = context.player.getInventory();
int invTnt = 0;
for (int i = 0; i <= inv.getSize(); i++) {
if (inv.getItem(i) == null) {
continue;
if (context.args.size() == 2) {
if (context.args.get(0).equalsIgnoreCase("add") || context.args.get(0).equalsIgnoreCase("a")) {
try {
Integer.parseInt(context.args.get(1));
} catch (NumberFormatException e) {
context.msg(TL.COMMAND_TNT_INVALID_NUM);
return;
}
if (inv.getItem(i).getType() == Material.TNT) {
invTnt += inv.getItem(i).getAmount();
int amount = Integer.parseInt(context.args.get(1));
if (amount < 0) {
context.msg(TL.COMMAND_TNT_POSITIVE);
return;
}
}
if (amount > invTnt) {
context.msg(TL.COMMAND_TNT_DEPOSIT_NOTENOUGH);
Inventory inv = context.player.getInventory();
int invTnt = 0;
for (int i = 0; i <= inv.getSize(); i++) {
if (inv.getItem(i) == null) {
continue;
}
if (inv.getItem(i).getType() == Material.TNT) {
invTnt += inv.getItem(i).getAmount();
}
}
if (amount > invTnt) {
context.msg(TL.COMMAND_TNT_DEPOSIT_NOTENOUGH);
return;
}
ItemStack tnt = new ItemStack(Material.TNT, amount);
if (context.faction.getTnt() + amount > FactionsPlugin.getInstance().getConfig().getInt("ftnt.Bank-Limit")) {
context.msg(TL.COMMAND_TNT_EXCEEDLIMIT);
return;
}
removeFromInventory(context.player.getInventory(), tnt);
context.player.updateInventory();
context.faction.addTnt(amount);
context.msg(TL.COMMAND_TNT_DEPOSIT_SUCCESS);
context.fPlayer.sendMessage(FactionsPlugin.getInstance().color(TL.COMMAND_TNT_AMOUNT.toString().replace("{amount}", context.fPlayer.getFaction().getTnt() + "")));
return;
}
ItemStack tnt = new ItemStack(Material.TNT, amount);
if (context.faction.getTnt() + amount > FactionsPlugin.getInstance().getConfig().getInt("ftnt.Bank-Limit")) {
context.msg(TL.COMMAND_TNT_EXCEEDLIMIT);
return;
}
removeFromInventory(context.player.getInventory(), tnt);
context.player.updateInventory();
context.faction.addTnt(amount);
context.msg(TL.COMMAND_TNT_DEPOSIT_SUCCESS);
context.fPlayer.sendMessage(FactionsPlugin.getInstance().color(TL.COMMAND_TNT_AMOUNT.toString().replace("{amount}", context.fPlayer.getFaction().getTnt() + "")));
return;
}
if (context.args.get(0).equalsIgnoreCase("take") || context.args.get(0).equalsIgnoreCase("t")) {
try {
Integer.parseInt(context.args.get(1));
} catch (NumberFormatException e) {
context.msg(TL.COMMAND_TNT_INVALID_NUM);
return;
}
int amount = Integer.parseInt(context.args.get(1));
if (amount < 0) {
context.msg(TL.COMMAND_TNT_POSITIVE);
return;
}
if (context.faction.getTnt() < amount) {
context.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH_TNT.toString());
return;
}
int fullStacks = Math.round(amount / 64);
int remainderAmt = amount - (fullStacks * 64);
if ((remainderAmt == 0 && !hasAvaliableSlot(context.player, fullStacks))) {
context.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH_SPACE);
return;
}
if (!hasAvaliableSlot(context.player, fullStacks + 1)) {
context.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH_SPACE);
return;
}
}
if (context.args.get(0).equalsIgnoreCase("take") || context.args.get(0).equalsIgnoreCase("t")) {
try {
Integer.parseInt(context.args.get(1));
} catch (NumberFormatException e) {
context.msg(TL.COMMAND_TNT_INVALID_NUM);
return;
}
int amount = Integer.parseInt(context.args.get(1));
if (amount < 0) {
context.msg(TL.COMMAND_TNT_POSITIVE);
return;
}
if (context.faction.getTnt() < amount) {
context.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH_TNT.toString());
return;
}
int fullStacks = Math.round(amount / 64);
int remainderAmt = amount - (fullStacks * 64);
if ((remainderAmt == 0 && !hasAvaliableSlot(context.player, fullStacks))) {
context.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH_SPACE);
return;
}
if (!hasAvaliableSlot(context.player, fullStacks + 1)) {
context.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH_SPACE);
return;
}
for (int i = 0; i <= fullStacks - 1; i++)
context.player.getInventory().addItem(new ItemStack(XMaterial.TNT.parseMaterial(), 64));
if (remainderAmt != 0)
context.player.getInventory().addItem(new ItemStack(XMaterial.TNT.parseMaterial(), remainderAmt));
for (int i = 0; i <= fullStacks - 1; i++)
context.player.getInventory().addItem(new ItemStack(XMaterial.TNT.parseMaterial(), 64));
if (remainderAmt != 0)
context.player.getInventory().addItem(new ItemStack(XMaterial.TNT.parseMaterial(), remainderAmt));
context.faction.takeTnt(amount);
context.player.updateInventory();
context.msg(TL.COMMAND_TNT_WIDTHDRAW_SUCCESS);
}
} else if (context.args.size() == 1) {
context.msg(TL.GENERIC_ARGS_TOOFEW);
context.msg(context.args.get(0).equalsIgnoreCase("take") || context.args.get(0).equalsIgnoreCase("t") ? TL.COMMAND_TNT_TAKE_DESCRIPTION : TL.COMMAND_TNT_ADD_DESCRIPTION);
}
context.sendMessage(TL.COMMAND_TNT_AMOUNT.toString().replace("{amount}", context.faction.getTnt() + ""));
}
context.faction.takeTnt(amount);
context.player.updateInventory();
context.msg(TL.COMMAND_TNT_WIDTHDRAW_SUCCESS);
}
} else if (context.args.size() == 1) {
context.msg(TL.GENERIC_ARGS_TOOFEW);
context.msg(context.args.get(0).equalsIgnoreCase("take") || context.args.get(0).equalsIgnoreCase("t") ? TL.COMMAND_TNT_TAKE_DESCRIPTION : TL.COMMAND_TNT_ADD_DESCRIPTION);
}
context.sendMessage(TL.COMMAND_TNT_AMOUNT.toString().replace("{amount}", context.faction.getTnt() + ""));
}
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 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 boolean hasAvaliableSlot(Player player, int howmany) {
Integer check = 0;
for (ItemStack item : player.getInventory().getContents()) {
if (item == null) {
check++;
}
}
return check >= howmany;
}
public boolean hasAvaliableSlot(Player player, int howmany) {
Integer check = 0;
for (ItemStack item : player.getInventory().getContents()) {
if (item == null) {
check++;
}
}
return check >= howmany;
}
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 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);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_TNT_DESCRIPTION;
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_TNT_DESCRIPTION;
}
}