1.1.1-STABLE

/f coords - displays your coords and current world to your faction
/f showclaims - Lists all your claims in every world
/f lowpower - lists players with power under max
/f tntfill <radius> <amount> - fills tnt in a radius and amount, hooks into /f tntbank if you're a mod or higher.

Some of these commands require permissions please see the permissions page here
https://www.prosavage.net/wiki/permissions
This commit is contained in:
Naman 2018-04-17 20:01:53 -05:00
parent 6c2ca2a468
commit aa4bbb3895
9 changed files with 385 additions and 4 deletions

View File

@ -0,0 +1,42 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.Location;
import org.bukkit.plugin.java.JavaPlugin;
public class CmdCoords extends FCommand {
public CmdCoords(){
super();
this.aliases.add("coords");
this.aliases.add("coord");
this.permission = Permission.COORD.node;
this.disableOnLock = true;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeColeader = false;
senderMustBeAdmin = false;
}
@Override
public void perform(){
Location location = fme.getPlayer().getLocation();
String message = TL.COMMAND_COORDS_MESSAGE.toString().replace("{player}",fme.getPlayer().getDisplayName()).replace("{x}",(int) location.getX() + "")
.replace("{y}",(int) location.getY() + "").replace("{z}",(int) location.getZ() + "").replace("{world}",location.getWorld().getName());
for (FPlayer fPlayer : fme.getFaction().getFPlayers()){
fPlayer.sendMessage(message);
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_COORDS_DESCRIPTION;
}
}

View File

@ -0,0 +1,43 @@
package com.massivecraft.factions.cmd;
import com.massivecraft.factions.Conf;
import com.massivecraft.factions.FPlayer;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
public class CmdLowPower extends FCommand {
public CmdLowPower(){
super();
this.aliases.add("lowpower");
this.disableOnLock = false;
senderMustBePlayer = true;
senderMustBeMember = true;
senderMustBeModerator = false;
senderMustBeColeader = true;
senderMustBeAdmin = false;
}
@Override
public void perform(){
double maxPower = Conf.powerPlayerMax;
String format = TL.COMMAND_LOWPOWER_FORMAT.toString();
msg(TL.COMMAND_LOWPOWER_HEADER.toString().replace("{maxpower}",(int) maxPower + ""));
for (FPlayer fPlayer : fme.getFaction().getFPlayers()){
if (fPlayer.getPower() < maxPower){
sendMessage(format.replace("{player}",fPlayer.getName()).replace("{player_power}",(int) fPlayer.getPower() + "").replace("{maxpower}",(int) maxPower + ""));
}
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_LOWPOWER_DESCRIPTION;
}
}

View File

@ -0,0 +1,64 @@
package com.massivecraft.factions.cmd;
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;
import com.massivecraft.factions.FLocation;
import com.massivecraft.factions.Faction;
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.zcore.util.TL;
import org.bukkit.World;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Set;
public class CmdShowClaims extends FCommand{
public CmdShowClaims(){
this.aliases.add("showclaims");
this.aliases.add("showclaim");
permission = Permission.SHOWCLAIMS.node;
this.senderMustBePlayer = true;
this.senderMustBeMember = true;
this.senderMustBeModerator = false;
this.senderMustBePlayer = true;
}
@Override
public void perform(){
sendMessage(TL.COMMAND_SHOWCLAIMS_HEADER.toString().replace("{faction}",fme.getFaction().describeTo(fme)));
ListMultimap<String,String> chunkMap = ArrayListMultimap.create();
String format = TL.COMMAND_SHOWCLAIMS_CHUNKSFORMAT.toString();
for (FLocation fLocation : fme.getFaction().getAllClaims()){
chunkMap.put(fLocation.getWorldName(),format.replace("{x}",fLocation.getX() + "").replace("{z}",fLocation.getZ() + ""));
}
for (String world : chunkMap.keySet()){
String message = TL.COMMAND_SHOWCLAIMS_FORMAT.toString().replace("{world}",world);
StringBuilder chunks = new StringBuilder("");
for (String chunkString : chunkMap.get(world)){
chunks.append(chunkString + ", ");
}
sendMessage(message.replace("{chunks}",chunks));
sendMessage("");
}
}
@Override
public TL getUsageTranslation() {
return TL.COMMAND_SHOWCLAIMS_DESCRIPTION;
}
}

View File

@ -0,0 +1,193 @@
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.util.TL;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
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(){
int radius = argAsInt(0,16);
int amount = argAsInt(1,16);
if (radius > P.p.getConfig().getInt("Tntfill.max-radius")){
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")){
msg(TL.COMMAND_TNTFILL_AMOUNTMAX.toString().replace("{max}",P.p.getConfig().getInt("Tntfill.max-amount") + ""));
return;
}
int testNumber = -1;
try {
testNumber = 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();
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)){
msg(TL.COMMAND_TNTFILL_NOTENOUGH);
return;
} else if (bankMode){
msg(TL.COMMAND_TNTFILL_MOD.toString().replace("{role}",fme.getRole().nicename));
bankMode = true;
me.performCommand("f tnt take " + amount);
if (!inventoryContains(me.getInventory(), new ItemStack(Material.TNT,amount))){
msg(TL.COMMAND_TNTFILL_NOTENOUGH);
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 + ""));
}
}
}
}
}
}
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);
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

@ -95,6 +95,10 @@ public class FCmdRoot extends FCommand {
public CmdTpBanner cmdTpBanner = new CmdTpBanner();
public CmdKillHolograms cmdKillHolograms = new CmdKillHolograms();
public CmdInspect cmdInspect = new CmdInspect();
public CmdCoords cmdCoords = new CmdCoords();
public CmdShowClaims cmdShowClaims = new CmdShowClaims();
public CmdLowPower cmdLowPower = new CmdLowPower();
public CmdTntFill cmdTntFill = new CmdTntFill();
@ -201,6 +205,10 @@ public class FCmdRoot extends FCommand {
this.addSubCommand(this.cmdBanner);
this.addSubCommand(this.cmdTpBanner);
this.addSubCommand(this.cmdKillHolograms);
this.addSubCommand(this.cmdCoords);
this.addSubCommand(this.cmdShowClaims);
this.addSubCommand(this.cmdLowPower);
this.addSubCommand(this.cmdTntFill);
if (Bukkit.getServer().getPluginManager().getPlugin("CoreProtect") != null){
P.p.log("Found CoreProtect, enabling Inspect");

View File

@ -100,6 +100,8 @@ public enum Permission {
KILLHOLOS("killholos"),
INSPECT("inspect"),
TNTFILL("tntfill"),
COORD("coords"),
SHOWCLAIMS("showclaims"),
WARP("warp");
public final String node;

View File

@ -232,6 +232,9 @@ public enum TL {
COMMAND_CONVERT_BACKEND_INVALID("&c&l[!]&7 Invalid backend"),
COMMAND_CONVERT_DESCRIPTION("Convert the plugin backend"),
COMMAND_COORDS_MESSAGE("&c&l[!] &7{player}&7's coords are &c{x}&7,&c{y}&7,&c{z}&7 in &c{world}"),
COMMAND_COORDS_DESCRIPTION("broadcast your coords to your faction"),
COMMAND_CHECKPOINT_DISABLED("&c&l[!]&7 You &ccannot&7 use checkpoint while its&c disabled&7!"),
COMMAND_CHECKPOINT_SET("&c&l[!]&7 You have &cset&7 the &cfaction checkpoint&7 at your &cLocation&7."),
COMMAND_CHECKPOINT_GO("&c&l[!]&7 &cTeleporting&7 to &cfaction checkpoint"),
@ -373,6 +376,10 @@ public enum TL {
COMMAND_LOGINS_TOGGLE("&c&l[!]&7 Set login / logout notifications for Faction members to: &c%s"),
COMMAND_LOGINS_DESCRIPTION("Toggle(?) login / logout notifications for Faction members"),
COMMAND_LOWPOWER_HEADER("&8&m--------&8<Players with power under {maxpower}&8>&8&m---------"),
COMMAND_LOWPOWER_FORMAT("&c{player} &8(&c{player_power}&8/&c{maxpower}&8)"),
COMMAND_LOWPOWER_DESCRIPTION("Shows a list of players in your faction with lower power levels"),
COMMAND_MAP_TOSHOW("to show the map"),
COMMAND_MAP_FORSHOW("for showing the map"),
COMMAND_MAP_UPDATE_ENABLED("&c&l[!]&7 Map auto update &aENABLED."),
@ -604,6 +611,11 @@ public enum TL {
COMMAND_SHOW_EXEMPT("<b>This faction is exempt and cannot be seen."),
COMMAND_SHOW_NEEDFACTION("&cYou need to join a faction to view your own!"),
COMMAND_SHOWCLAIMS_HEADER("&8&m-------------&8<{faction}'s claims&8>&8&m-------------"),
COMMAND_SHOWCLAIMS_FORMAT("&8[{world}]: {chunks}"),
COMMAND_SHOWCLAIMS_CHUNKSFORMAT("&8(&c{x}&8,&c{z}&8)"),
COMMAND_SHOWCLAIMS_DESCRIPTION("show your factions claims!"),
COMMAND_SHOWINVITES_PENDING("Players with pending invites: "),
COMMAND_SHOWINVITES_CLICKTOREVOKE("Click to revoke invite for %1$s"),
COMMAND_SHOWINVITES_DESCRIPTION("Show pending faction invites"),
@ -661,6 +673,12 @@ public enum TL {
COMMAND_TNT_POSITIVE("&cPlease use positive numbers!"),
COMMAND_TNT_DESCRIPTION("add/widthraw from faction's tnt bank"),
COMMAND_TNTFILL_SUCCESS("&c&l[!] &7Filled &c{amount}&7 Tnt in dispenser at {x} {y} {z}"),
COMMAND_TNTFILL_NOTENOUGH("&c&l[!] &7Not enough tnt in inventory."),
COMMAND_TNTFILL_RADIUSMAX("&c&l[!] &7The max radius is {max}"),
COMMAND_TNTFILL_AMOUNTMAX("&c&l[!] &7The max amount is {max}"),
COMMAND_TNTFILL_MOD("&c&l[!] &7Tnt will be used from the faction bank because you dont have the specified amount in your inventory and you are a {role}"),
COMMAND_TNTFILL_DESCRIPTION("Fill tnt into dispensers around you"),
COMMAND_UNBAN_DESCRIPTION("Unban someone from your Faction"),
COMMAND_UNBAN_NOTBANNED("&7%s &cisn't banned. Not doing anything."),

View File

@ -346,12 +346,15 @@ help:
- '&e/f join &f<name> &8- &7Join to the faction.'
- '&e/f list &8- &7List all factions.'
- '&e/f top &8- &7View the richest factions.'
- '&e/f map &8- &7Map of the surrounding area.'
- '&e/f map &8- &7Map of the surrounding area, click chunks to claim.'
- '&e/f sethome &8- &7Teleport to faction home.'
- '&e/f home &8- &7Set your faction home.'
- '&e/f ban &8- &7Ban a member from your faction.'
- '&e/f unban &8- &7Unban a member from your faction.'
- '&e/f banlist &8- &7List banned players from your faction.'
- '&e/f lowpower &8- &7List player with power under max from your faction.'
- '&e/f coords &8- &7Broadcast your location to your faction.'
- '&e/f showclaims &8- &7List all claims from your faction.'
- '&7&m--------------------&r &e/f help 2 &7&m-----------------------'
'2':
- '&7&m----------------------------------------------------'
@ -363,7 +366,9 @@ help:
- '&e/f claim &8- &7Claim a land for your faction.'
- '&e/f unclaim &8- &7Unclaim land from your faction.'
- '&e/f kick &f<playerName> &8- &7Kick player from your faction.'
- '&e/f mod &f<playerName> &8- &7Set player role in faction.'
- '&e/f mod &f<playerName> &8- &7Set player to mod role in faction.'
- '&e/f coleader &f<playerName> &8- &7Set player to coleader role in faction.'
- '&e/f leader &f<playerName> &8- &7Set player role to leader in faction.'
- '&e/f chat &f<Faction | Ally | Public> &8- &7Switch to Faction/Ally/Public chat.'
- '&e/f warp &8- &7Opens the warp menu.'
- '&e/f setwarp &8- &7Set a warp.'
@ -854,6 +859,10 @@ see-chunk:
interval: 5
Tntfill:
max-radius: 32
max-amount: 64
############################################################
# +------------------------------------------------------+ #
# | Big List of variables | #

View File

@ -1,5 +1,5 @@
name: Factions
version: ${project.version}-SF-1.1-STABLE
version: ${project.version}-SF-1.2-STABLE
main: com.massivecraft.factions.P
authors: [Olof Larsson, Brett Flannigan, drtshock, ProSavage]
softdepend: [CoreProtect, PlayerVaults, PlaceholderAPI, MVdWPlaceholderAPI, PermissionsEx, Permissions, Essentials, EssentialsChat, HeroChat, iChat, LocalAreaChat, LWC, nChat, ChatManager, CAPI, AuthMe, Vault, Spout, WorldEdit, WorldGuard, AuthDB, CaptureThePoints, CombatTag, dynmap, FactionsTop]
@ -317,3 +317,5 @@ permissions:
description: create banner
factions.killholos:
description: kill invisible holograms
factions.coords:
description: broadcast your coords to the player