From a170a0f4adf84ec084b65221860a2f83302a6744 Mon Sep 17 00:00:00 2001 From: drtshock Date: Tue, 14 Oct 2014 13:30:05 -0500 Subject: [PATCH] /f showinvites for ability to see pending invites for current faction. Adds feature in ticket #76 --- .../massivecraft/factions/cmd/CmdShow.java | 24 ++++++++--------- .../factions/cmd/CmdShowInvites.java | 27 +++++++++++++++++++ .../massivecraft/factions/cmd/FCmdRoot.java | 2 ++ .../factions/struct/Permission.java | 1 + 4 files changed, 42 insertions(+), 12 deletions(-) create mode 100644 src/main/java/com/massivecraft/factions/cmd/CmdShowInvites.java diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdShow.java b/src/main/java/com/massivecraft/factions/cmd/CmdShow.java index 67f8653d..b200b33c 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdShow.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdShow.java @@ -114,17 +114,17 @@ public class CmdShow extends FCommand { enemyList = enemyList.substring(0, enemyList.length() - 2); } - if(allyList.length() > 2048) { + if (allyList.length() > 2048) { String[] lines = splitString(allyList, 2048, 256000); - for (int i=0; i < lines.length; i++) { + for (int i = 0; i < lines.length; i++) { sendMessage(lines[i]); } } else { sendMessage(allyList); } - if(enemyList.length() > 2048) { + if (enemyList.length() > 2048) { String[] lines = splitString(enemyList, 2048, 256000); - for (int i=0; i < lines.length; i++) { + for (int i = 0; i < lines.length; i++) { sendMessage(lines[i]); } } else { @@ -166,17 +166,17 @@ public class CmdShow extends FCommand { offlineList = offlineList.substring(0, offlineList.length() - 2); } - if(onlineList.length() > 2048) { + if (onlineList.length() > 2048) { String[] lines = splitString(onlineList, 2048, 256000); - for (int i=0; i < lines.length; i++) { + for (int i = 0; i < lines.length; i++) { sendMessage(lines[i]); } } else { sendMessage(onlineList); } - if(offlineList.length() > 2048) { + if (offlineList.length() > 2048) { String[] lines = splitString(offlineList, 2048, 256000); - for (int i=0; i < lines.length; i++) { + for (int i = 0; i < lines.length; i++) { sendMessage(lines[i]); } } else { @@ -186,11 +186,11 @@ public class CmdShow extends FCommand { private String[] splitString(String text, int chunkSize, int maxLength) { char[] data = text.toCharArray(); - int len = Math.min(data.length,maxLength); - String[] result = new String[(len+chunkSize-1)/chunkSize]; + int len = Math.min(data.length, maxLength); + String[] result = new String[(len + chunkSize - 1) / chunkSize]; int linha = 0; - for (int i=0; i < len; i+=chunkSize) { - result[linha] = new String(data, i, Math.min(chunkSize,len-i)); + for (int i = 0; i < len; i += chunkSize) { + result[linha] = new String(data, i, Math.min(chunkSize, len - i)); linha++; } return result; diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdShowInvites.java b/src/main/java/com/massivecraft/factions/cmd/CmdShowInvites.java new file mode 100644 index 00000000..77166972 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/cmd/CmdShowInvites.java @@ -0,0 +1,27 @@ +package com.massivecraft.factions.cmd; + +import com.massivecraft.factions.FPlayer; +import com.massivecraft.factions.FPlayers; +import com.massivecraft.factions.struct.Permission; + +public class CmdShowInvites extends FCommand { + + public CmdShowInvites() { + super(); + aliases.add("showinvites"); + permission = Permission.SHOW_INVITES.node; + + senderMustBePlayer = true; + senderMustBeMember = true; + } + + @Override + public void perform() { + StringBuilder sb = new StringBuilder(); + for (String id : myFaction.getInvites()) { + FPlayer fp = FPlayers.i.get(id); + sb.append(fp != null ? fp.getName() : id).append(" "); + } + msg("Players with pending invites: %s", sb.toString().trim()); + } +} diff --git a/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java b/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java index ef0cb5e3..54e7aaae 100644 --- a/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java +++ b/src/main/java/com/massivecraft/factions/cmd/FCmdRoot.java @@ -52,6 +52,7 @@ public class FCmdRoot extends FCommand { public CmdVersion cmdVersion = new CmdVersion(); public CmdWarunclaimall cmdWarunclaimall = new CmdWarunclaimall(); public CmdSB cmdSB = new CmdSB(); + public CmdShowInvites cmdShowInvites = new CmdShowInvites(); public FCmdRoot() { super(); @@ -120,6 +121,7 @@ public class FCmdRoot extends FCommand { this.addSubCommand(this.cmdVersion); this.addSubCommand(this.cmdWarunclaimall); this.addSubCommand(this.cmdSB); + this.addSubCommand(this.cmdShowInvites); } @Override diff --git a/src/main/java/com/massivecraft/factions/struct/Permission.java b/src/main/java/com/massivecraft/factions/struct/Permission.java index 40c62ffc..c252c88c 100644 --- a/src/main/java/com/massivecraft/factions/struct/Permission.java +++ b/src/main/java/com/massivecraft/factions/struct/Permission.java @@ -50,6 +50,7 @@ public enum Permission { SET_PEACEFUL("setpeaceful"), SET_PERMANENT("setpermanent"), SET_PERMANENTPOWER("setpermanentpower"), + SHOW_INVITES("showinvites"), POWERBOOST("powerboost"), POWER("power"), POWER_ANY("power.any"),