Introduced Brigadier Command System. More Formatting Coming in next commit.
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
package com.massivecraft.factions.cmd.tnt;
|
||||
|
||||
import com.massivecraft.factions.P;
|
||||
import com.massivecraft.factions.FactionsPlugin;
|
||||
import com.massivecraft.factions.cmd.CommandContext;
|
||||
import com.massivecraft.factions.cmd.CommandRequirements;
|
||||
import com.massivecraft.factions.cmd.FCommand;
|
||||
import com.massivecraft.factions.struct.Permission;
|
||||
import com.massivecraft.factions.struct.Role;
|
||||
import com.massivecraft.factions.util.XMaterial;
|
||||
import com.massivecraft.factions.zcore.fperms.Access;
|
||||
import com.massivecraft.factions.zcore.fperms.PermissableAction;
|
||||
import com.massivecraft.factions.zcore.util.TL;
|
||||
import org.bukkit.Material;
|
||||
@@ -14,54 +14,40 @@ 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");
|
||||
|
||||
|
||||
this.permission = Permission.TNT.node;
|
||||
this.disableOnLock = true;
|
||||
|
||||
senderMustBePlayer = true;
|
||||
senderMustBeMember = false;
|
||||
senderMustBeModerator = true;
|
||||
senderMustBeAdmin = false;
|
||||
|
||||
this.requirements = new CommandRequirements.Builder(Permission.TNT)
|
||||
.playerOnly()
|
||||
.memberOnly()
|
||||
.withAction(PermissableAction.TNTBANK)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void perform() {
|
||||
if (!P.p.getConfig().getBoolean("ftnt.Enabled")) {
|
||||
fme.msg(TL.COMMAND_TNT_DISABLED_MSG);
|
||||
public void perform(CommandContext context) {
|
||||
if (!FactionsPlugin.getInstance().getConfig().getBoolean("ftnt.Enabled")) {
|
||||
context.msg(TL.COMMAND_TNT_DISABLED_MSG);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!fme.isAdminBypassing()) {
|
||||
Access access = myFaction.getAccess(fme, PermissableAction.TNTBANK);
|
||||
if (access != Access.ALLOW && fme.getRole() != Role.LEADER) {
|
||||
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "use tnt bank");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (args.size() == 2) {
|
||||
if (args.get(0).equalsIgnoreCase("add") || args.get(0).equalsIgnoreCase("a")) {
|
||||
if (context.args.size() == 2) {
|
||||
if (context.args.get(0).equalsIgnoreCase("add") || context.args.get(0).equalsIgnoreCase("a")) {
|
||||
try {
|
||||
Integer.parseInt(args.get(1));
|
||||
Integer.parseInt(context.args.get(1));
|
||||
} catch (NumberFormatException e) {
|
||||
fme.msg(TL.COMMAND_TNT_INVALID_NUM);
|
||||
context.msg(TL.COMMAND_TNT_INVALID_NUM);
|
||||
return;
|
||||
}
|
||||
int amount = Integer.parseInt(args.get(1));
|
||||
int amount = Integer.parseInt(context.args.get(1));
|
||||
if (amount < 0) {
|
||||
fme.msg(TL.COMMAND_TNT_POSITIVE);
|
||||
context.msg(TL.COMMAND_TNT_POSITIVE);
|
||||
return;
|
||||
}
|
||||
Inventory inv = me.getInventory();
|
||||
Inventory inv = context.player.getInventory();
|
||||
int invTnt = 0;
|
||||
for (int i = 0; i <= inv.getSize(); i++) {
|
||||
if (inv.getItem(i) == null) {
|
||||
@@ -72,69 +58,83 @@ public class CmdTnt extends FCommand {
|
||||
}
|
||||
}
|
||||
if (amount > invTnt) {
|
||||
fme.msg(TL.COMMAND_TNT_DEPOSIT_NOTENOUGH);
|
||||
context.msg(TL.COMMAND_TNT_DEPOSIT_NOTENOUGH);
|
||||
return;
|
||||
}
|
||||
ItemStack tnt = new ItemStack(Material.TNT, amount);
|
||||
if (fme.getFaction().getTnt() + amount > P.p.getConfig().getInt("ftnt.Bank-Limit")) {
|
||||
msg(TL.COMMAND_TNT_EXCEEDLIMIT);
|
||||
if (context.faction.getTnt() + amount > FactionsPlugin.getInstance().getConfig().getInt("ftnt.Bank-Limit")) {
|
||||
context.msg(TL.COMMAND_TNT_EXCEEDLIMIT);
|
||||
return;
|
||||
}
|
||||
removeFromInventory(me.getInventory(), tnt);
|
||||
me.updateInventory();
|
||||
removeFromInventory(context.player.getInventory(), tnt);
|
||||
context.player.updateInventory();
|
||||
|
||||
fme.getFaction().addTnt(amount);
|
||||
fme.msg(TL.COMMAND_TNT_DEPOSIT_SUCCESS);
|
||||
fme.sendMessage(P.p.color(TL.COMMAND_TNT_AMOUNT.toString().replace("{amount}", fme.getFaction().getTnt() + "")));
|
||||
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 (args.get(0).equalsIgnoreCase("take") || args.get(0).equalsIgnoreCase("t")) {
|
||||
if (context.args.get(0).equalsIgnoreCase("take") || context.args.get(0).equalsIgnoreCase("t")) {
|
||||
try {
|
||||
Integer.parseInt(args.get(1));
|
||||
Integer.parseInt(context.args.get(1));
|
||||
} catch (NumberFormatException e) {
|
||||
fme.msg(TL.COMMAND_TNT_INVALID_NUM);
|
||||
context.msg(TL.COMMAND_TNT_INVALID_NUM);
|
||||
return;
|
||||
}
|
||||
int amount = Integer.parseInt(args.get(1));
|
||||
int amount = Integer.parseInt(context.args.get(1));
|
||||
if (amount < 0) {
|
||||
fme.msg(TL.COMMAND_TNT_POSITIVE);
|
||||
context.msg(TL.COMMAND_TNT_POSITIVE);
|
||||
return;
|
||||
}
|
||||
if (fme.getFaction().getTnt() < amount) {
|
||||
fme.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH);
|
||||
if (context.faction.getTnt() < amount) {
|
||||
context.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH_TNT.toString());
|
||||
return;
|
||||
}
|
||||
int fullStacks = Math.round(amount / 6);
|
||||
int fullStacks = Math.round(amount / 64);
|
||||
int remainderAmt = amount - (fullStacks * 64);
|
||||
if ((remainderAmt == 0 && !hasAvaliableSlot(me, fullStacks))) {
|
||||
fme.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH_SPACE);
|
||||
if ((remainderAmt == 0 && !hasAvaliableSlot(context.player, fullStacks))) {
|
||||
context.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH_SPACE);
|
||||
return;
|
||||
}
|
||||
if (!hasAvaliableSlot(me, fullStacks + 1)) {
|
||||
fme.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH_SPACE);
|
||||
if (!hasAvaliableSlot(context.player, fullStacks + 1)) {
|
||||
context.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH_SPACE);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i <= fullStacks - 1; i++)
|
||||
me.getPlayer().getInventory().addItem(new ItemStack(XMaterial.TNT.parseMaterial(), 64));
|
||||
context.player.getInventory().addItem(new ItemStack(XMaterial.TNT.parseMaterial(), 64));
|
||||
if (remainderAmt != 0)
|
||||
me.getPlayer().getInventory().addItem(new ItemStack(XMaterial.TNT.parseMaterial(), remainderAmt));
|
||||
context.player.getInventory().addItem(new ItemStack(XMaterial.TNT.parseMaterial(), remainderAmt));
|
||||
|
||||
fme.getFaction().takeTnt(amount);
|
||||
me.updateInventory();
|
||||
fme.msg(TL.COMMAND_TNT_WIDTHDRAW_SUCCESS);
|
||||
context.faction.takeTnt(amount);
|
||||
context.player.updateInventory();
|
||||
context.msg(TL.COMMAND_TNT_WIDTHDRAW_SUCCESS);
|
||||
}
|
||||
} else if (args.size() == 1) {
|
||||
fme.msg(TL.GENERIC_ARGS_TOOFEW);
|
||||
fme.msg(args.get(0).equalsIgnoreCase("take") || args.get(0).equalsIgnoreCase("t") ? TL.COMMAND_TNT_TAKE_DESCRIPTION : TL.COMMAND_TNT_ADD_DESCRIPTION);
|
||||
} 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);
|
||||
}
|
||||
fme.sendMessage(TL.COMMAND_TNT_AMOUNT.toString().replace("{amount}", fme.getFaction().getTnt() + ""));
|
||||
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 hasAvaliableSlot(Player player, int howmany) {
|
||||
int check = 0;
|
||||
Integer check = 0;
|
||||
for (ItemStack item : player.getInventory().getContents()) {
|
||||
if (item == null) {
|
||||
check++;
|
||||
@@ -168,3 +168,4 @@ public class CmdTnt extends FCommand {
|
||||
return TL.COMMAND_TNT_DESCRIPTION;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user