From ac859db55f1f6dd919269811c185a6e47311eb9c Mon Sep 17 00:00:00 2001 From: Driftay Date: Thu, 14 Nov 2019 04:23:35 -0500 Subject: [PATCH] TntFill Logic Fixed --- pom.xml | 2 +- .../massivecraft/factions/cmd/tnt/CmdTnt.java | 18 +++++------ .../factions/cmd/tnt/CmdTntFill.java | 31 ++++++++----------- 3 files changed, 21 insertions(+), 30 deletions(-) diff --git a/pom.xml b/pom.xml index dc08668f..429896ff 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.massivecraft Factions - 1.6.9.5-U0.2.1-2.0.5-BETA + 1.6.9.5-U0.2.1-2.0.6-STABLE jar SaberFactions diff --git a/src/main/java/com/massivecraft/factions/cmd/tnt/CmdTnt.java b/src/main/java/com/massivecraft/factions/cmd/tnt/CmdTnt.java index 5d4df2ae..fec0fd50 100644 --- a/src/main/java/com/massivecraft/factions/cmd/tnt/CmdTnt.java +++ b/src/main/java/com/massivecraft/factions/cmd/tnt/CmdTnt.java @@ -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; } } - diff --git a/src/main/java/com/massivecraft/factions/cmd/tnt/CmdTntFill.java b/src/main/java/com/massivecraft/factions/cmd/tnt/CmdTntFill.java index 5a55ec68..95f8bd89 100644 --- a/src/main/java/com/massivecraft/factions/cmd/tnt/CmdTntFill.java +++ b/src/main/java/com/massivecraft/factions/cmd/tnt/CmdTntFill.java @@ -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 dispensers, int count) { for (Dispenser dispenser : dispensers) { - if (takeTnt(fPlayer, count)) { - dispenser.getInventory().addItem(new ItemStack(Material.TNT, count)); - } else {return;} + takeTnt(fPlayer, count); + dispenser.getInventory().addItem(new ItemStack(Material.TNT, count)); } } @@ -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.