Formatted TnT Commands/Added Alias for Missions

And Few Code Clean Ups From Last Week
This commit is contained in:
Driftay 2019-08-17 15:02:38 -04:00
parent a7f0cac597
commit f497f96b94
13 changed files with 443 additions and 565 deletions

View File

@ -103,6 +103,14 @@ public class CmdHome extends FCommand {
return;
}
if (!fme.isAdminBypassing()) {
Access access = fme.getFaction().getAccess(fme, PermissableAction.HOME);
if (access != Access.ALLOW && fme.getRole() != Role.LEADER) {
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "teleport home");
return;
}
}
Faction faction = Board.getInstance().getFactionAt(new FLocation(me.getLocation()));
final Location loc = me.getLocation().clone();

View File

@ -1,166 +0,0 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.P;
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;
import org.bukkit.entity.Player;
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;
}
@Override
public void perform() {
if (!P.p.getConfig().getBoolean("ftnt.Enabled")) {
fme.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")) {
try {
Integer.parseInt(args.get(1));
} catch (NumberFormatException e) {
fme.msg(TL.COMMAND_TNT_INVALID_NUM);
return;
}
int amount = Integer.parseInt(args.get(1));
if (amount < 0) {
fme.msg(TL.COMMAND_TNT_POSITIVE);
return;
}
Inventory inv = me.getInventory();
int invTnt = 0;
for (int i = 0; i <= inv.getSize(); i++) {
if (inv.getItem(i) == null) {
continue;
}
if (inv.getItem(i).getType() == Material.TNT) {
invTnt += inv.getItem(i).getAmount();
}
}
if (amount > invTnt) {
fme.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);
return;
}
removeFromInventory(me.getInventory(), tnt);
me.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() + "")));
return;
}
if (args.get(0).equalsIgnoreCase("take") || args.get(0).equalsIgnoreCase("t")) {
try {
Integer.parseInt(args.get(1));
} catch (NumberFormatException e) {
fme.msg(TL.COMMAND_TNT_INVALID_NUM);
return;
}
int amount = Integer.parseInt(args.get(1));
if (amount < 0) {
fme.msg(TL.COMMAND_TNT_POSITIVE);
return;
}
if (fme.getFaction().getTnt() < amount) {
fme.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH);
return;
}
int fullStacks = Math.round(amount / 6);
int remainderAmt = amount - (fullStacks * 64);
if ((remainderAmt == 0 && !hasAvaliableSlot(me, fullStacks))) {
fme.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH_SPACE);
return;
}
if (!hasAvaliableSlot(me, fullStacks + 1)) {
fme.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));
if (remainderAmt != 0) me.getPlayer().getInventory().addItem(new ItemStack(XMaterial.TNT.parseMaterial(), remainderAmt));
fme.getFaction().takeTnt(amount);
me.updateInventory();
fme.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);
}
fme.sendMessage(TL.COMMAND_TNT_AMOUNT.toString().replace("{amount}", fme.getFaction().getTnt() + ""));
}
public boolean hasAvaliableSlot(Player player, int howmany) {
int check = 0;
for (ItemStack item : player.getInventory().getContents()) {
if (item == null) {
check++;
}
}
return check >= howmany;
}
public void removeFromInventory(Inventory inventory, ItemStack item) {
int amt = item.getAmount();
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()) {
if (items[i].getAmount() > amt) {
items[i].setAmount(items[i].getAmount() - amt);
break;
} else if (items[i].getAmount() == amt) {
items[i] = null;
break;
} else {
amt -= items[i].getAmount();
items[i] = null;
}
}
}
inventory.setContents(items);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_TNT_DESCRIPTION;
}
}

View File

@ -1,255 +0,0 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.P;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Dispenser;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
public class CmdTntFill extends FCommand {
public CmdTntFill() {
super();
this.aliases.add("tntfill");
this.requiredArgs.add("radius");
this.requiredArgs.add("amount");
this.permission = Permission.TNTFILL.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform() {
if (!P.p.getConfig().getBoolean("Tntfill.enabled")) {
this.fme.msg(TL.GENERIC_DISABLED);
return;
}
if (!fme.isAdminBypassing()) {
Access access = myFaction.getAccess(fme, PermissableAction.TNTFILL);
if (access != Access.ALLOW && fme.getRole() != Role.LEADER) {
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "use tnt fill");
return;
}
}
msg(TL.COMMAND_TNTFILL_HEADER);
int radius = argAsInt(0, 16);
int amount = argAsInt(1, 16);
if (radius > P.p.getConfig().getInt("Tntfill.max-radius")) {
fme.msg(TL.COMMAND_TNTFILL_RADIUSMAX.toString().replace("{max}", P.p.getConfig().getInt("Tntfill.max-radius") + ""));
return;
}
if (amount > P.p.getConfig().getInt("Tntfill.max-amount")) {
fme.msg(TL.COMMAND_TNTFILL_AMOUNTMAX.toString().replace("{max}", P.p.getConfig().getInt("Tntfill.max-amount") + ""));
return;
}
try {
Integer.parseInt(args.get(1));
} catch (NumberFormatException e) {
fme.msg(TL.COMMAND_TNT_INVALID_NUM);
return;
}
if (amount < 0) {
fme.msg(TL.COMMAND_TNT_POSITIVE);
return;
}
boolean bankMode = fme.getRole().isAtLeast(Role.MODERATOR);
Location start = me.getLocation();
int counter = 0;
for (double x = start.getX() - radius; x <= start.getX() + radius; x++) {
for (double y = start.getY() - radius; y <= start.getY() + radius; y++) {
for (double z = start.getZ() - radius; z <= start.getZ() + radius; z++) {
Location blockLoc = new Location(start.getWorld(), x, y, z);
if (blockLoc.getBlock().getState() instanceof Dispenser) {
Dispenser disp = (Dispenser) blockLoc.getBlock().getState();
Inventory dispenser = disp.getInventory();
if (canHold(dispenser, amount)) {
int fullStacks = amount / 64;
int remainderAmt = amount % 64;
if (!inventoryContains(me.getInventory(), new ItemStack(Material.TNT, amount))) {
if (!fme.getRole().isAtLeast(Role.MODERATOR)) {
fme.msg(TL.COMMAND_TNTFILL_NOTENOUGH.toString());
sendMessage(TL.COMMAND_TNTFILL_SUCCESS.toString().replace("{amount}", amount + "").replace("{dispensers}", counter + ""));
me.updateInventory();
return;
} else if (bankMode) {
//msg(TL.COMMAND_TNTFILL_MOD.toString().replace("{role}",fme.getRole().nicename));
bankMode = true;
removeFromBank(amount);
if (!inventoryContains(me.getInventory(), new ItemStack(Material.TNT, amount))) {
fme.msg(TL.COMMAND_TNTFILL_NOTENOUGH.toString());
sendMessage(TL.COMMAND_TNTFILL_SUCCESS.toString().replace("{amount}", amount + "").replace("{dispensers}", counter + ""));
me.updateInventory();
return;
}
}
}
ItemStack tnt64 = new ItemStack(Material.TNT, 64);
for (int i = 0; i <= fullStacks - 1; i++) {
dispenser.addItem(tnt64);
takeTnt(64);
}
if (remainderAmt != 0) {
ItemStack tnt = new ItemStack(Material.TNT, remainderAmt);
dispenser.addItem(tnt);
takeTnt(remainderAmt);
}
//sendMessage(TL.COMMAND_TNTFILL_SUCCESS.toString().replace("{amount}",amount + "").replace("{x}",(int) x + "").replace("{y}",(int) y + "").replace("{z}",(int) z + ""));
counter++;
}
}
}
}
}
if (bankMode) {
msg(TL.COMMAND_TNTFILL_MOD.toString().replace("{role}", fme.getRole().nicename));
}
sendMessage(TL.COMMAND_TNTFILL_SUCCESS.toString().replace("{amount}", amount + "").replace("{dispensers}", counter + ""));
me.updateInventory();
}
private void removeFromBank(int amount) {
try {
Integer.parseInt(args.get(1));
} catch (NumberFormatException e) {
fme.msg(TL.COMMAND_TNT_INVALID_NUM);
return;
}
if (amount < 0) {
fme.msg(TL.COMMAND_TNT_POSITIVE);
return;
}
if (fme.getFaction().getTnt() < amount) {
fme.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH.toString());
return;
}
int fullStacks = amount / 64;
int remainderAmt = amount % 64;
if ((remainderAmt == 0 && getEmptySlots(me) <= fullStacks)) {
fme.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH.toString());
return;
}
if (getEmptySlots(me) + 1 <= fullStacks) {
fme.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH.toString());
return;
}
ItemStack tnt64 = new ItemStack(Material.TNT, 64);
for (int i = 0; i <= fullStacks - 1; i++) {
me.getInventory().addItem(tnt64);
}
if (remainderAmt != 0) {
ItemStack tnt = new ItemStack(Material.TNT, remainderAmt);
me.getInventory().addItem(tnt);
}
fme.getFaction().takeTnt(amount);
me.updateInventory();
}
public void takeTnt(int amount) {
Inventory inv = me.getInventory();
int invTnt = 0;
for (int i = 0; i <= inv.getSize(); i++) {
if (inv.getItem(i) == null) {
continue;
}
if (inv.getItem(i).getType() == Material.TNT) {
invTnt += inv.getItem(i).getAmount();
}
}
if (amount > invTnt) {
fme.msg(TL.COMMAND_TNTFILL_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);
return;
}
removeFromInventory(me.getInventory(), tnt);
}
public boolean canHold(Inventory inventory, int amount) {
int fullStacks = amount / 64;
int remainderAmt = amount % 64;
if ((remainderAmt == 0 && getEmptySlots(me) <= fullStacks)) {
return false;
}
if (getEmptySlots(me) + 1 <= fullStacks) {
fme.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH.toString());
return false;
}
return true;
}
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 void removeFromInventory(Inventory inventory, ItemStack item) {
int amt = item.getAmount();
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()) {
if (items[i].getAmount() > amt) {
items[i].setAmount(items[i].getAmount() - amt);
break;
} else if (items[i].getAmount() == amt) {
items[i] = null;
break;
} else {
amt -= items[i].getAmount();
items[i] = null;
}
}
}
inventory.setContents(items);
}
public int getEmptySlots(Player p) {
PlayerInventory inventory = p.getInventory();
ItemStack[] cont = inventory.getContents();
int i = 0;
for (ItemStack item : cont)
if (item != null && item.getType() != Material.AIR) {
i++;
}
return 36 - i;
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_TNTFILL_DESCRIPTION;
}
}

View File

@ -13,6 +13,8 @@ import com.massivecraft.factions.cmd.relational.CmdRelationNeutral;
import com.massivecraft.factions.cmd.relational.CmdRelationTruce;
import com.massivecraft.factions.cmd.roles.CmdDemote;
import com.massivecraft.factions.cmd.roles.CmdPromote;
import com.massivecraft.factions.cmd.tnt.CmdTnt;
import com.massivecraft.factions.cmd.tnt.CmdTntFill;
import com.massivecraft.factions.missions.CmdMissions;
import com.massivecraft.factions.shop.CmdShop;
import com.massivecraft.factions.zcore.util.TL;
@ -132,8 +134,6 @@ public class FCmdRoot extends FCommand {
public CmdShop cmdShop = new CmdShop();
public CmdMissions cmdMissions = new CmdMissions();
public FCmdRoot() {
super();
this.aliases.addAll(Conf.baseCommandAliases);

View File

@ -0,0 +1,168 @@
package com.massivecraft.factions.cmd.tnt;
import com.massivecraft.factions.P;
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;
import org.bukkit.entity.Player;
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;
}
@Override
public void perform() {
if (!P.p.getConfig().getBoolean("ftnt.Enabled")) {
fme.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")) {
try {
Integer.parseInt(args.get(1));
} catch (NumberFormatException e) {
fme.msg(TL.COMMAND_TNT_INVALID_NUM);
return;
}
int amount = Integer.parseInt(args.get(1));
if (amount < 0) {
fme.msg(TL.COMMAND_TNT_POSITIVE);
return;
}
Inventory inv = me.getInventory();
int invTnt = 0;
for (int i = 0; i <= inv.getSize(); i++) {
if (inv.getItem(i) == null) {
continue;
}
if (inv.getItem(i).getType() == Material.TNT) {
invTnt += inv.getItem(i).getAmount();
}
}
if (amount > invTnt) {
fme.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);
return;
}
removeFromInventory(me.getInventory(), tnt);
me.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() + "")));
return;
}
if (args.get(0).equalsIgnoreCase("take") || args.get(0).equalsIgnoreCase("t")) {
try {
Integer.parseInt(args.get(1));
} catch (NumberFormatException e) {
fme.msg(TL.COMMAND_TNT_INVALID_NUM);
return;
}
int amount = Integer.parseInt(args.get(1));
if (amount < 0) {
fme.msg(TL.COMMAND_TNT_POSITIVE);
return;
}
if (fme.getFaction().getTnt() < amount) {
fme.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH);
return;
}
int fullStacks = Math.round(amount / 6);
int remainderAmt = amount - (fullStacks * 64);
if ((remainderAmt == 0 && !hasAvaliableSlot(me, fullStacks))) {
fme.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH_SPACE);
return;
}
if (!hasAvaliableSlot(me, fullStacks + 1)) {
fme.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));
if (remainderAmt != 0) me.getPlayer().getInventory().addItem(new ItemStack(XMaterial.TNT.parseMaterial(), remainderAmt));
fme.getFaction().takeTnt(amount);
me.updateInventory();
fme.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);
}
fme.sendMessage(TL.COMMAND_TNT_AMOUNT.toString().replace("{amount}", fme.getFaction().getTnt() + ""));
}
public boolean hasAvaliableSlot(Player player, int howmany) {
int check = 0;
for (ItemStack item : player.getInventory().getContents()) {
if (item == null) {
check++;
}
}
return check >= howmany;
}
public void removeFromInventory(Inventory inventory, ItemStack item) {
int amt = item.getAmount();
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()) {
if (items[i].getAmount() > amt) {
items[i].setAmount(items[i].getAmount() - amt);
break;
} else if (items[i].getAmount() == amt) {
items[i] = null;
break;
} else {
amt -= items[i].getAmount();
items[i] = null;
}
}
}
inventory.setContents(items);
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_TNT_DESCRIPTION;
}
}

View File

@ -0,0 +1,251 @@
package com.massivecraft.factions.cmd.tnt;
import com.massivecraft.factions.P;
import com.massivecraft.factions.cmd.FCommand;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.struct.Role;
import com.massivecraft.factions.zcore.fperms.Access;
import com.massivecraft.factions.zcore.fperms.PermissableAction;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Dispenser;
import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
public class CmdTntFill extends FCommand {
public CmdTntFill() {
super();
this.aliases.add("tntfill");
this.requiredArgs.add("radius");
this.requiredArgs.add("amount");
this.permission = Permission.TNTFILL.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeAdmin = false;
}
@Override
public void perform() {
if (!P.p.getConfig().getBoolean("Tntfill.enabled")) {
this.fme.msg(TL.GENERIC_DISABLED);
return;
}
if (!fme.isAdminBypassing()) {
Access access = myFaction.getAccess(fme, PermissableAction.TNTFILL);
if (access != Access.ALLOW && fme.getRole() != Role.LEADER) {
fme.msg(TL.GENERIC_FPERM_NOPERMISSION, "use tnt fill");
return;
}
}
msg(TL.COMMAND_TNTFILL_HEADER);
int radius = argAsInt(0, 16);
int amount = argAsInt(1, 16);
if (radius > P.p.getConfig().getInt("Tntfill.max-radius")) {
fme.msg(TL.COMMAND_TNTFILL_RADIUSMAX.toString().replace("{max}", P.p.getConfig().getInt("Tntfill.max-radius") + ""));
return;
}
if (amount > P.p.getConfig().getInt("Tntfill.max-amount")) {
fme.msg(TL.COMMAND_TNTFILL_AMOUNTMAX.toString().replace("{max}", P.p.getConfig().getInt("Tntfill.max-amount") + ""));
return;
}
try {
Integer.parseInt(args.get(1));
} catch (NumberFormatException e) {
fme.msg(TL.COMMAND_TNT_INVALID_NUM);
return;
}
if (amount < 0) {
fme.msg(TL.COMMAND_TNT_POSITIVE);
return;
}
boolean bankMode = fme.getRole().isAtLeast(Role.MODERATOR);
Location start = me.getLocation();
int counter = 0;
for (double x = start.getX() - radius; x <= start.getX() + radius; x++) {
for (double y = start.getY() - radius; y <= start.getY() + radius; y++) {
for (double z = start.getZ() - radius; z <= start.getZ() + radius; z++) {
Location blockLoc = new Location(start.getWorld(), x, y, z);
if (blockLoc.getBlock().getState() instanceof Dispenser) {
Dispenser disp = (Dispenser) blockLoc.getBlock().getState();
Inventory dispenser = disp.getInventory();
if (canHold(dispenser, amount)) {
int fullStacks = amount / 64;
int remainderAmt = amount % 64;
if (!inventoryContains(me.getInventory(), new ItemStack(Material.TNT, amount))) {
if (!fme.getRole().isAtLeast(Role.MODERATOR)) {
fme.msg(TL.COMMAND_TNTFILL_NOTENOUGH.toString());
sendMessage(TL.COMMAND_TNTFILL_SUCCESS.toString().replace("{amount}", amount + "").replace("{dispensers}", counter + ""));
me.updateInventory();
return;
} else if (bankMode) {
//msg(TL.COMMAND_TNTFILL_MOD.toString().replace("{role}",fme.getRole().nicename));
bankMode = true;
removeFromBank(amount);
if (!inventoryContains(me.getInventory(), new ItemStack(Material.TNT, amount))) {
fme.msg(TL.COMMAND_TNTFILL_NOTENOUGH.toString());
sendMessage(TL.COMMAND_TNTFILL_SUCCESS.toString().replace("{amount}", amount + "").replace("{dispensers}", counter + ""));
me.updateInventory();
return;
}
}
}
ItemStack tnt64 = new ItemStack(Material.TNT, 64);
for (int i = 0; i <= fullStacks - 1; i++) {
dispenser.addItem(tnt64);
takeTnt(64);
}
if (remainderAmt != 0) {
ItemStack tnt = new ItemStack(Material.TNT, remainderAmt);
dispenser.addItem(tnt);
takeTnt(remainderAmt);
}
counter++;
}
}
}
}
}
if (bankMode) {
msg(TL.COMMAND_TNTFILL_MOD.toString().replace("{role}", fme.getRole().nicename));
}
sendMessage(TL.COMMAND_TNTFILL_SUCCESS.toString().replace("{amount}", amount + "").replace("{dispensers}", counter + ""));
me.updateInventory();
}
private void removeFromBank(int amount) {
try {
Integer.parseInt(args.get(1));
} catch (NumberFormatException e) {
fme.msg(TL.COMMAND_TNT_INVALID_NUM);
return;
}
if (amount < 0) {
fme.msg(TL.COMMAND_TNT_POSITIVE);
return;
}
if (fme.getFaction().getTnt() < amount) {
fme.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH.toString());
return;
}
int fullStacks = amount / 64;
int remainderAmt = amount % 64;
if ((remainderAmt == 0 && getEmptySlots(me) <= fullStacks)) {
fme.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH.toString());
return;
}
if (getEmptySlots(me) + 1 <= fullStacks) {
fme.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH.toString());
return;
}
ItemStack tnt64 = new ItemStack(Material.TNT, 64);
for (int i = 0; i <= fullStacks - 1; i++) {
me.getInventory().addItem(tnt64);
}
if (remainderAmt != 0) {
ItemStack tnt = new ItemStack(Material.TNT, remainderAmt);
me.getInventory().addItem(tnt);
}
fme.getFaction().takeTnt(amount);
me.updateInventory();
}
public void takeTnt(int amount) {
Inventory inv = me.getInventory();
int invTnt = 0;
for (int i = 0; i <= inv.getSize(); i++) {
if (inv.getItem(i) == null) {
continue;
}
if (inv.getItem(i).getType() == Material.TNT) {
invTnt += inv.getItem(i).getAmount();
}
}
if (amount > invTnt) {
fme.msg(TL.COMMAND_TNTFILL_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);
return;
}
removeFromInventory(me.getInventory(), tnt);
}
public boolean canHold(Inventory inventory, int amount) {
int fullStacks = amount / 64;
int remainderAmt = amount % 64;
if ((remainderAmt == 0 && getEmptySlots(me) <= fullStacks)) {
return false;
}
if (getEmptySlots(me) + 1 <= fullStacks) {
fme.msg(TL.COMMAND_TNT_WIDTHDRAW_NOTENOUGH.toString());
return false;
}
return true;
}
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 void removeFromInventory(Inventory inventory, ItemStack item) {
int amt = item.getAmount();
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()) {
if (items[i].getAmount() > amt) {
items[i].setAmount(items[i].getAmount() - amt);
break;
} else if (items[i].getAmount() == amt) {
items[i] = null;
break;
} else {
amt -= items[i].getAmount();
items[i] = null;
}
}
}
inventory.setContents(items);
}
public int getEmptySlots(Player p) {
PlayerInventory inventory = p.getInventory();
ItemStack[] cont = inventory.getContents();
int i = 0;
for (ItemStack item : cont)
if (item != null && item.getType() != Material.AIR) {
i++;
}
return 36 - i;
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_TNTFILL_DESCRIPTION;
}
}

View File

@ -302,7 +302,6 @@ public class FactionsBlockListener implements Listener {
warBanner = P.p.createItem(XMaterial.BLACK_BANNER.parseMaterial(), 1, (short) 1, P.p.getConfig().getString("fbanners.Item.Name"), P.p.getConfig().getStringList("fbanners.Item.Lore"));
}
if (warBanner.isSimilar(bannerInHand)) {
if (fme.getFaction().isWilderness()) {
fme.msg(TL.WARBANNER_NOFACTION);
e.setCancelled(true);
@ -344,7 +343,6 @@ public class FactionsBlockListener implements Listener {
int radius = P.p.getConfig().getInt("fbanners.Banner-Effect-Radius");
List<String> effects = P.p.getConfig().getStringList("fbanners.Effects");
int affectorTask = Bukkit.getScheduler().scheduleSyncRepeatingTask(P.p, () -> {
for (Entity e1 : banner.getLocation().getWorld().getNearbyEntities(banner.getLocation(), radius, 255, radius)) {
if (e1 instanceof Player) {
Player player = (Player) e1;
@ -430,7 +428,7 @@ public class FactionsBlockListener implements Listener {
return;
if (!graceisEnabled()) {
if (e.getEntity() instanceof com.sk89q.worldedit.entity.Player) {
if (e.getEntity() instanceof Player) {
if (e.getCause() == EntityDamageEvent.DamageCause.PROJECTILE) {
e.setCancelled(true);
}
@ -462,21 +460,18 @@ public class FactionsBlockListener implements Listener {
Faction otherFaction = Board.getInstance().getFactionAt(new FLocation(target));
if (pistonFaction == otherFaction) {
if (pistonFaction == otherFaction)
return true;
}
if (otherFaction.isWilderness()) {
if (otherFaction.isWilderness())
return !Conf.wildernessDenyBuild || Conf.worldsNoWildernessProtection.contains(target.getWorld().getName());
} else if (otherFaction.isSafeZone()) {
else if (otherFaction.isSafeZone())
return !Conf.safeZoneDenyBuild;
} else if (otherFaction.isWarZone()) {
else if (otherFaction.isWarZone())
return !Conf.warZoneDenyBuild;
}
Relation rel = pistonFaction.getRelationTo(otherFaction);
return !rel.confDenyBuild(otherFaction.hasPlayersOnline());
@ -485,13 +480,13 @@ public class FactionsBlockListener implements Listener {
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onBlockBreak(BlockBreakEvent event) {
FPlayer fme = FPlayers.getInstance().getByPlayer(event.getPlayer());
if (!playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "destroy", false)) {
if (!playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock().getLocation(), "destroy", false)){
event.setCancelled(true);
return;
}
if (!fme.hasFaction()) {
if (!fme.hasFaction())
return;
}
if (event.getBlock().getType() == XMaterial.SPAWNER.parseMaterial()) {
if (!fme.isAdminBypassing()) {
Access access = fme.getFaction().getAccess(fme, PermissableAction.SPAWNER);

View File

@ -9,6 +9,8 @@ public class CmdMissions extends FCommand {
public CmdMissions() {
this.aliases.add("missions");
this.aliases.add("mission");
this.aliases.add("objectives");
this.aliases.add("objective");
this.permission = Permission.MISSIONS.node;

View File

@ -6,7 +6,6 @@ import com.massivecraft.factions.util.FactionGUI;
import com.massivecraft.factions.util.XMaterial;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.event.inventory.ClickType;

View File

@ -17,7 +17,7 @@ public class LocationTypeAdapter implements JsonSerializer<Location>, JsonDeseri
object.add("x", new JsonPrimitive(location.getX()));
object.add("y", new JsonPrimitive(location.getY()));
object.add("z", new JsonPrimitive(location.getZ()));
object.add("world", new JsonPrimitive(location.getWorld().toString()));
object.add("world", new JsonPrimitive(location.getWorld().getName()));
return object;
} catch (Exception ex) {
ex.printStackTrace();

View File

@ -42,7 +42,7 @@ public class PermissableActionFrame {
e.setCancelled(true);
if (PermissableAction.fromSlot(e.getSlot()) == action) {
Access access;
boolean success = false;
boolean success;
switch (e.getClick()) {
case LEFT:
access = Access.ALLOW;

View File

@ -125,7 +125,6 @@ public abstract class MemoryFPlayer implements FPlayer {
this.autoSafeZoneEnabled = other.autoSafeZoneEnabled;
this.autoWarZoneEnabled = other.autoWarZoneEnabled;
this.loginPvpDisabled = other.loginPvpDisabled;
this.notificationsEnabled = true;
this.powerBoost = other.powerBoost;
this.role = other.role;
this.title = other.title;
@ -181,9 +180,7 @@ public abstract class MemoryFPlayer implements FPlayer {
return true;
if (!commandCooldown.containsKey(cmd))
return true;
else if (commandCooldown.containsKey(cmd) && commandCooldown.get(cmd) <= System.currentTimeMillis())
return true;
return false;
else return commandCooldown.containsKey(cmd) && commandCooldown.get(cmd) <= System.currentTimeMillis();
}

View File

@ -613,7 +613,7 @@ frules:
############################################################
ftnt:
Enabled: true
Bank-Limit: 10000
Bank-Limit: 250000
############################################################
# +------------------------------------------------------+ #
@ -1054,127 +1054,6 @@ fupgrades:
slots:
- 22
#Potions Shop#
PotionGUISize: 3
PotionsLastHours: 6
MaxActivePotions: 2
PotionShop:
'9':
Name: "&dFire Resistance"
Lore:
- "&ffor 6 hours"
- ""
- "&d&lPrice: &f&l%price%"
PotionType: "FIRE_RESISTANCE"
Level: 0
PointCost: 100
'10':
Name: "&dStrength II"
Lore:
- "&ffor 6 hours"
- ""
- "&d&lPrice: &f&l%price%"
PotionType: "INCREASE_DAMAGE"
Level: 1
PointCost: 100
'11':
Name: "&dSpeed II"
Lore:
- "&ffor 6 hours"
- ""
- "&d&lPrice: &f&l%price%"
PotionType: "SPEED"
Level: 1
PointCost: 100
'12':
Name: "&dRegeneration"
Lore:
- "&ffor 6 hours"
- ""
- "&d&lPrice: &f&l%price%"
PotionType: "REGENERATION"
Level: 0
PointCost: 100
'13':
Name: "&dWater Breathing"
Lore:
- "&ffor 6 hours"
- ""
- "&d&lPrice: &f&l%price%"
PotionType: "WATER_BREATHING"
Level: 0
PointCost: 100
'14':
Name: "&dSaturation"
Lore:
- "&ffor 6 hours"
- ""
- "&d&lPrice: &f&l%price%"
PotionType: "SATURATION"
Level: 0
PointCost: 100
'15':
Name: "&dHaste II"
Lore:
- "&ffor 6 hours"
- ""
- "&d&lPrice: &f&l%price%"
PotionType: "FAST_DIGGING"
Level: 1
PointCost: 100
'16':
Name: "&dJump Boost II"
Lore:
- "&ffor 6 hours"
- ""
- "&d&lPrice: &f&l%price%"
PotionType: "JUMP"
Level: 1
PointCost: 100
'17':
Name: "&dHealth Boost"
Lore:
- "&ffor 6 hours"
- ""
- "&d&lPrice: &f&l%price%"
PotionType: "HEALTH_BOOST"
Level: 0
PointCost: 100
#Booster Shop#
#PlaceHolders: %faction% - %player_name% - %player_uuid%
#Booster Types:
# COMMAND - Faction Based Boosters
# COMMAND_ONLINE - Faction, Player, and Offline Player based
# COMMAND_OFFLINE - Offline Faction Members, Players, and UUID Based
# Multiple Commands Supported!
BoosterGUISize: 3 #Rows
MaxActiveBooster: 2
BoosterGUI:
'11': #Represents Whereabouts in the GUI
Material: "DIAMOND"
Name: "&aCool Booster"
Lore:
- "&ffor 30 minutes"
- ""
- "&d&lPrice: &f&l%price%"
CooldownMinutes: 30
Type: "COMMAND"
Commands: ["bc booster bought! %faction% enjoy your booster!"]
PointCost: 100
'15':
Material: "GHAST_TEAR"
Name: "&cCool Booster"
Lore:
- "&ffor 30 minutes"
- ""
- "&d&lPrice: &f&l%price%"
CooldownMinutes: 30
Type: "COMMAND_OFFLINE"
Commands: ["bc booster bought by %player_name%"] #Will broadcast that <player> bought said booster.
PointCost: 100
fbanners:
Enabled: true
Item: