TntFill Logic Fixed
This commit is contained in:
parent
8c7addb68e
commit
ac859db55f
2
pom.xml
2
pom.xml
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
<groupId>com.massivecraft</groupId>
|
<groupId>com.massivecraft</groupId>
|
||||||
<artifactId>Factions</artifactId>
|
<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>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
<name>SaberFactions</name>
|
<name>SaberFactions</name>
|
||||||
|
@ -29,7 +29,7 @@ public class CmdTnt extends FCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void perform(CommandContext context) {
|
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);
|
context.msg(TL.COMMAND_TNT_DISABLED_MSG);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -62,7 +62,7 @@ public class CmdTnt extends FCommand {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ItemStack tnt = new ItemStack(Material.TNT, amount);
|
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);
|
context.msg(TL.COMMAND_TNT_EXCEEDLIMIT);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -71,8 +71,7 @@ public class CmdTnt extends FCommand {
|
|||||||
|
|
||||||
context.faction.addTnt(amount);
|
context.faction.addTnt(amount);
|
||||||
context.msg(TL.COMMAND_TNT_DEPOSIT_SUCCESS);
|
context.msg(TL.COMMAND_TNT_DEPOSIT_SUCCESS);
|
||||||
context.msg(TL.COMMAND_TNT_AMOUNT, context.fPlayer.getFaction().getTnt());
|
context.fPlayer.sendMessage(FactionsPlugin.instance.color(TL.COMMAND_TNT_AMOUNT.toString().replace("{amount}", context.fPlayer.getFaction().getTnt() + "")));
|
||||||
// context.fPlayer.sendMessage(FactionsPlugin.getInstance().color(TL.COMMAND_TNT_AMOUNT.toString().replace("{amount}", context.fPlayer.getFaction().getTnt() + "")));
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -103,10 +102,8 @@ public class CmdTnt extends FCommand {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i <= fullStacks - 1; i++)
|
for (int i = 0; i <= fullStacks - 1; i++) context.player.getInventory().addItem(new ItemStack(XMaterial.TNT.parseMaterial(), 64));
|
||||||
context.player.getInventory().addItem(new ItemStack(XMaterial.TNT.parseMaterial(), 64));
|
if (remainderAmt != 0) context.player.getInventory().addItem(new ItemStack(XMaterial.TNT.parseMaterial(), remainderAmt));
|
||||||
if (remainderAmt != 0)
|
|
||||||
context.player.getInventory().addItem(new ItemStack(XMaterial.TNT.parseMaterial(), remainderAmt));
|
|
||||||
|
|
||||||
context.faction.takeTnt(amount);
|
context.faction.takeTnt(amount);
|
||||||
context.player.updateInventory();
|
context.player.updateInventory();
|
||||||
@ -116,7 +113,7 @@ public class CmdTnt extends FCommand {
|
|||||||
context.msg(TL.GENERIC_ARGS_TOOFEW);
|
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(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) {
|
public boolean hasAvaliableSlot(Player player, int howmany) {
|
||||||
Integer check = 0;
|
int check = 0;
|
||||||
for (ItemStack item : player.getInventory().getContents()) {
|
for (ItemStack item : player.getInventory().getContents()) {
|
||||||
if (item == null) {
|
if (item == null) {
|
||||||
check++;
|
check++;
|
||||||
@ -169,4 +166,3 @@ public class CmdTnt extends FCommand {
|
|||||||
return TL.COMMAND_TNT_DESCRIPTION;
|
return TL.COMMAND_TNT_DESCRIPTION;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,9 +18,7 @@ import org.bukkit.inventory.Inventory;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.PlayerInventory;
|
import org.bukkit.inventory.PlayerInventory;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class CmdTntFill extends FCommand {
|
public class CmdTntFill extends FCommand {
|
||||||
|
|
||||||
@ -40,7 +38,7 @@ public class CmdTntFill extends FCommand {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void perform(CommandContext context) {
|
public void perform(CommandContext context) {
|
||||||
if (!FactionsPlugin.getInstance().getConfig().getBoolean("Tntfill.enabled")) {
|
if (!FactionsPlugin.instance.getConfig().getBoolean("Tntfill.enabled")) {
|
||||||
context.msg(TL.GENERIC_DISABLED);
|
context.msg(TL.GENERIC_DISABLED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -62,12 +60,12 @@ public class CmdTntFill extends FCommand {
|
|||||||
context.msg(TL.COMMAND_TNT_POSITIVE);
|
context.msg(TL.COMMAND_TNT_POSITIVE);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (radius > 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.getInstance().getConfig().getInt("Tntfill.max-radius") + ""));
|
context.msg(TL.COMMAND_TNTFILL_RADIUSMAX.toString().replace("{max}", FactionsPlugin.instance.getConfig().getInt("Tntfill.max-radius") + ""));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (amount > 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.getInstance().getConfig().getInt("Tntfill.max-amount") + ""));
|
context.msg(TL.COMMAND_TNTFILL_AMOUNTMAX.toString().replace("{max}", FactionsPlugin.instance.getConfig().getInt("Tntfill.max-amount") + ""));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,19 +106,17 @@ public class CmdTntFill extends FCommand {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Take TNT from the bank.
|
// Take TNT from the bank.
|
||||||
context.faction.takeTnt(getFactionTnt);
|
removeFromBank(context, getFactionTnt);
|
||||||
}
|
}
|
||||||
fillDispensers(context.fPlayer, opDispensers, amount);
|
fillDispensers(context.fPlayer, opDispensers, amount);
|
||||||
// Remove used TNT from player inventory.
|
// Remove used TNT from player inventory.
|
||||||
context.sendMessage(TL.COMMAND_TNTFILL_SUCCESS.toString().replace("{amount}", requiredTnt + "").replace("{dispensers}", opDispensers.size() + ""));
|
context.sendMessage(TL.COMMAND_TNTFILL_SUCCESS.toString().replace("{amount}", requiredTnt + "").replace("{dispensers}", opDispensers.size() + ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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) {
|
||||||
if (takeTnt(fPlayer, count)) {
|
takeTnt(fPlayer, count);
|
||||||
dispenser.getInventory().addItem(new ItemStack(Material.TNT, count));
|
dispenser.getInventory().addItem(new ItemStack(Material.TNT, count));
|
||||||
} else {return;}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,7 +157,7 @@ public class CmdTntFill extends FCommand {
|
|||||||
context.player.updateInventory();
|
context.player.updateInventory();
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean takeTnt(FPlayer fme, int amount) {
|
private void 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++) {
|
||||||
@ -174,15 +170,14 @@ 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 false;
|
return;
|
||||||
}
|
}
|
||||||
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.instance.getConfig().getInt("ftnt.Bank-Limit")) {
|
||||||
fme.msg(TL.COMMAND_TNT_EXCEEDLIMIT.toString());
|
fme.msg(TL.COMMAND_TNT_EXCEEDLIMIT.toString());
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
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.
|
||||||
|
Loading…
Reference in New Issue
Block a user