TntFill Logic Fixed

This commit is contained in:
Driftay 2019-11-14 04:23:35 -05:00
parent 8c7addb68e
commit ac859db55f
3 changed files with 21 additions and 30 deletions

View File

@ -4,7 +4,7 @@
<groupId>com.massivecraft</groupId>
<artifactId>Factions</artifactId>
<version>1.6.9.5-U0.2.1-2.0.5-BETA</version>
<version>1.6.9.5-U0.2.1-2.0.6-STABLE</version>
<packaging>jar</packaging>
<name>SaberFactions</name>

View File

@ -29,7 +29,7 @@ public class CmdTnt extends FCommand {
@Override
public void perform(CommandContext context) {
if (!FactionsPlugin.getInstance().getConfig().getBoolean("ftnt.Enabled")) {
if (!FactionsPlugin.instance.getConfig().getBoolean("ftnt.Enabled")) {
context.msg(TL.COMMAND_TNT_DISABLED_MSG);
return;
}
@ -62,7 +62,7 @@ public class CmdTnt extends FCommand {
return;
}
ItemStack tnt = new ItemStack(Material.TNT, amount);
if (context.faction.getTnt() + amount > FactionsPlugin.getInstance().getConfig().getInt("ftnt.Bank-Limit")) {
if (context.faction.getTnt() + amount > FactionsPlugin.instance.getConfig().getInt("ftnt.Bank-Limit")) {
context.msg(TL.COMMAND_TNT_EXCEEDLIMIT);
return;
}
@ -71,8 +71,7 @@ public class CmdTnt extends FCommand {
context.faction.addTnt(amount);
context.msg(TL.COMMAND_TNT_DEPOSIT_SUCCESS);
context.msg(TL.COMMAND_TNT_AMOUNT, context.fPlayer.getFaction().getTnt());
// context.fPlayer.sendMessage(FactionsPlugin.getInstance().color(TL.COMMAND_TNT_AMOUNT.toString().replace("{amount}", context.fPlayer.getFaction().getTnt() + "")));
context.fPlayer.sendMessage(FactionsPlugin.instance.color(TL.COMMAND_TNT_AMOUNT.toString().replace("{amount}", context.fPlayer.getFaction().getTnt() + "")));
return;
}
@ -103,10 +102,8 @@ public class CmdTnt extends FCommand {
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();
@ -116,7 +113,7 @@ public class CmdTnt extends FCommand {
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.msg(TL.COMMAND_TNT_AMOUNT, context.faction.getTnt(), context.faction.getTntBankLimit());
context.sendMessage(TL.COMMAND_TNT_AMOUNT.toString().replace("{amount}", context.faction.getTnt() + ""));
}
@ -135,7 +132,7 @@ public class CmdTnt extends FCommand {
}
public boolean hasAvaliableSlot(Player player, int howmany) {
Integer check = 0;
int check = 0;
for (ItemStack item : player.getInventory().getContents()) {
if (item == null) {
check++;
@ -169,4 +166,3 @@ public class CmdTnt extends FCommand {
return TL.COMMAND_TNT_DESCRIPTION;
}
}

View File

@ -18,9 +18,7 @@ import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.*;
public class CmdTntFill extends FCommand {
@ -40,7 +38,7 @@ public class CmdTntFill extends FCommand {
@Override
public void perform(CommandContext context) {
if (!FactionsPlugin.getInstance().getConfig().getBoolean("Tntfill.enabled")) {
if (!FactionsPlugin.instance.getConfig().getBoolean("Tntfill.enabled")) {
context.msg(TL.GENERIC_DISABLED);
return;
}
@ -62,12 +60,12 @@ public class CmdTntFill extends FCommand {
context.msg(TL.COMMAND_TNT_POSITIVE);
return;
}
if (radius > FactionsPlugin.getInstance().getConfig().getInt("Tntfill.max-radius")) {
context.msg(TL.COMMAND_TNTFILL_RADIUSMAX.toString().replace("{max}", FactionsPlugin.getInstance().getConfig().getInt("Tntfill.max-radius") + ""));
if (radius > FactionsPlugin.instance.getConfig().getInt("Tntfill.max-radius")) {
context.msg(TL.COMMAND_TNTFILL_RADIUSMAX.toString().replace("{max}", FactionsPlugin.instance.getConfig().getInt("Tntfill.max-radius") + ""));
return;
}
if (amount > FactionsPlugin.getInstance().getConfig().getInt("Tntfill.max-amount")) {
context.msg(TL.COMMAND_TNTFILL_AMOUNTMAX.toString().replace("{max}", FactionsPlugin.getInstance().getConfig().getInt("Tntfill.max-amount") + ""));
if (amount > FactionsPlugin.instance.getConfig().getInt("Tntfill.max-amount")) {
context.msg(TL.COMMAND_TNTFILL_AMOUNTMAX.toString().replace("{max}", FactionsPlugin.instance.getConfig().getInt("Tntfill.max-amount") + ""));
return;
}
@ -108,19 +106,17 @@ public class CmdTntFill extends FCommand {
}
// Take TNT from the bank.
context.faction.takeTnt(getFactionTnt);
removeFromBank(context, getFactionTnt);
}
fillDispensers(context.fPlayer, opDispensers, amount);
// Remove used TNT from player inventory.
context.sendMessage(TL.COMMAND_TNTFILL_SUCCESS.toString().replace("{amount}", requiredTnt + "").replace("{dispensers}", opDispensers.size() + ""));
}
// Actually fill every dispenser with the precise amount.
private void fillDispensers(FPlayer fPlayer, List<Dispenser> dispensers, int count) {
for (Dispenser dispenser : dispensers) {
if (takeTnt(fPlayer, count)) {
takeTnt(fPlayer, count);
dispenser.getInventory().addItem(new ItemStack(Material.TNT, count));
} else {return;}
}
}
@ -161,7 +157,7 @@ public class CmdTntFill extends FCommand {
context.player.updateInventory();
}
private boolean takeTnt(FPlayer fme, int amount) {
private void takeTnt(FPlayer fme, int amount) {
Inventory inv = fme.getPlayer().getInventory();
int invTnt = 0;
for (int i = 0; i <= inv.getSize(); i++) {
@ -174,15 +170,14 @@ public class CmdTntFill extends FCommand {
}
if (amount > invTnt) {
fme.msg(TL.COMMAND_TNTFILL_NOTENOUGH.toString());
return false;
return;
}
ItemStack tnt = new ItemStack(Material.TNT, amount);
if (fme.getFaction().getTnt() + amount > FactionsPlugin.getInstance().getConfig().getInt("ftnt.Bank-Limit")) {
if (fme.getFaction().getTnt() + amount > FactionsPlugin.instance.getConfig().getInt("ftnt.Bank-Limit")) {
fme.msg(TL.COMMAND_TNT_EXCEEDLIMIT.toString());
return false;
return;
}
removeFromInventory(fme.getPlayer().getInventory(), tnt);
return true;
}
// Counts the item type available in the inventory.