Fix infinite tnt glitch with /f tntfill. Thanks to Atronis for allowing me to debug on their server!

Signed-off-by: DroppingAnvil <dr0pping.4nvi1@gmail.com>
This commit is contained in:
DroppingAnvil 2019-11-01 18:38:14 -05:00
parent 9e6c91bec1
commit 9b999ffc84
1 changed files with 8 additions and 6 deletions

View File

@ -108,7 +108,7 @@ public class CmdTntFill extends FCommand {
} }
// Take TNT from the bank. // Take TNT from the bank.
removeFromBank(context, getFactionTnt); context.faction.takeTnt(getFactionTnt);
} }
fillDispensers(context.fPlayer, opDispensers, amount); fillDispensers(context.fPlayer, opDispensers, amount);
// Remove used TNT from player inventory. // Remove used TNT from player inventory.
@ -118,8 +118,9 @@ public class CmdTntFill extends FCommand {
// Actually fill every dispenser with the precise amount. // Actually fill every dispenser with the precise amount.
private void fillDispensers(FPlayer fPlayer, List<Dispenser> dispensers, int count) { private void fillDispensers(FPlayer fPlayer, List<Dispenser> dispensers, int count) {
for (Dispenser dispenser : dispensers) { for (Dispenser dispenser : dispensers) {
takeTnt(fPlayer, count); if (takeTnt(fPlayer, count)) {
dispenser.getInventory().addItem(new ItemStack(Material.TNT, count)); dispenser.getInventory().addItem(new ItemStack(Material.TNT, count));
} else {return;}
} }
} }
@ -160,7 +161,7 @@ public class CmdTntFill extends FCommand {
context.player.updateInventory(); context.player.updateInventory();
} }
private void takeTnt(FPlayer fme, int amount) { private boolean takeTnt(FPlayer fme, int amount) {
Inventory inv = fme.getPlayer().getInventory(); Inventory inv = fme.getPlayer().getInventory();
int invTnt = 0; int invTnt = 0;
for (int i = 0; i <= inv.getSize(); i++) { for (int i = 0; i <= inv.getSize(); i++) {
@ -173,14 +174,15 @@ public class CmdTntFill extends FCommand {
} }
if (amount > invTnt) { if (amount > invTnt) {
fme.msg(TL.COMMAND_TNTFILL_NOTENOUGH.toString()); fme.msg(TL.COMMAND_TNTFILL_NOTENOUGH.toString());
return; return false;
} }
ItemStack tnt = new ItemStack(Material.TNT, amount); 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.getInstance().getConfig().getInt("ftnt.Bank-Limit")) {
fme.msg(TL.COMMAND_TNT_EXCEEDLIMIT.toString()); fme.msg(TL.COMMAND_TNT_EXCEEDLIMIT.toString());
return; return false;
} }
removeFromInventory(fme.getPlayer().getInventory(), tnt); removeFromInventory(fme.getPlayer().getInventory(), tnt);
return true;
} }
// Counts the item type available in the inventory. // Counts the item type available in the inventory.