Permalink
Browse files

v0.0.3.3 - kick, mute, cleanup

  • Loading branch information...
1 parent 79258af commit 4aea8d8051c69e4ed1591c451a34aa64efadc1b2 @slipcor committed Jan 12, 2012
View
1 README
@@ -1,5 +1,6 @@
CHANGELOG
+v0.0.3 - +kick ; +mute
v0.0.2 - config options, unbanning
v0.0.1 - independant ban manager
v0.0.0 - basic functionality
View
30 plugin.yml
@@ -1,7 +1,7 @@
name: BanVote
author: slipcor
main: net.slipcor.banvote.BanVotePlugin
-version: 0.0.2.2
+version: 0.0.3.3
website: http://dev.bukkit.org/server-mods/banvote
commands:
banvote:
@@ -11,15 +11,35 @@ commands:
/banvote [playername] [reason] | start vote
/banvote [+|yes|true] | vote for ban
/banvote [-|no|false] | vote against ban
- unbanvote:
- description: unban a player
+ mutevote:
+ description: vote for muting a player
usage: |
- /unbanvote [#] | unban vote #
- /unbanvote list | list all bans
+ /mutevote help | detailed usage help
+ /mutevote [playername] [reason] | start vote
+ /mutevote [+|yes|true] | vote for mute
+ /mutevote [-|no|false] | vote against mute
+ kickvote:
+ description: vote for kicking a player
+ usage: |
+ /kickvote help | detailed usage help
+ /kickvote [playername] [reason] | start vote
+ /kickvote [+|yes|true] | vote for kick
+ /kickvote [-|no|false] | vote against kick
+ release:
+ description: unban/mute a player
+ usage: |
+ /release [#] | unban vote #
+ /release list | list all bans/mutes
permissions:
banvote.admin:
description: Allows you to unban
default: op
banvote.vote:
description: Allows you to vote
+ default: true
+ mutevote.vote:
+ description: Allows you to vote
+ default: true
+ kickvote.vote:
+ description: Allows you to vote
default: true
View
117 src/net/slipcor/banvote/BanVoteClass.java
@@ -12,7 +12,7 @@
/**
* ban vote class
*
- * @version v0.0.0
+ * @version v0.0.3
*
* @author slipcor
*
@@ -35,6 +35,7 @@
private static int coolMinutes;
private static boolean calcPublic;
+ private String type;
private voteState state;
private String voter;
private String target;
@@ -54,34 +55,66 @@
* @param sReason
* the reason given for banning
*/
- public BanVoteClass(Player pTarget, Player player, String sReason) {
+ public BanVoteClass(Player pTarget, Player player, String sReason,
+ byte bType) {
voter = player.getName();
target = pTarget.getName();
state = voteState.MUTETARGET;
+ type = parse(bType);
+
BanVotePlugin.brc(ChatColor.GREEN + player.getName() + ChatColor.GOLD
- + " started a ban vote against " + ChatColor.RED
+ + " started a " + type + " vote against " + ChatColor.RED
+ pTarget.getName() + ChatColor.GOLD + ".");
- BanVotePlugin.brc(ChatColor.GOLD + "Ban reason: " + ChatColor.WHITE
+ BanVotePlugin.brc(ChatColor.GOLD + type + " reason: " + ChatColor.WHITE
+ sReason);
- BanVotePlugin.brc(ChatColor.GOLD + "Say " + ChatColor.GREEN
- + "/banvote yes" + ChatColor.GOLD + " for banning, "
- + ChatColor.RED + "/banvote no" + ChatColor.GOLD
- + " to vote against ban.");
+ BanVotePlugin.brc(ChatColor.GOLD + "Say " + ChatColor.GREEN + "/"
+ + type + "vote yes" + ChatColor.GOLD + " for banning, "
+ + ChatColor.RED + "/" + type + "vote no" + ChatColor.GOLD
+ + " to vote against " + type + ".");
BanVotePlugin.brc(ChatColor.GOLD + "Muting " + ChatColor.RED
+ pTarget.getName() + ChatColor.GOLD + " for " + stageSeconds
- + " seconds to discuss the ban vote.");
- BanVotePlugin.log.i("ban vote started: [voter: " + player.getName()
- + "], [target: " + pTarget.getName() + "], reason: " + sReason);
+ + " seconds to discuss the " + type + " vote.");
+ BanVotePlugin.log.i("" + type + " vote started: [voter: "
+ + player.getName() + "], [target: " + pTarget.getName()
+ + "], reason: " + sReason);
int interval = 20 * Math.round(stageSeconds / 2); // half a minute
- BanVotePlugin.db.i("banVote interval: " + interval + " ticks");
+ BanVotePlugin.db.i("" + type + "Vote interval: " + interval + " ticks");
RUN_ID = Bukkit
.getServer()
.getScheduler()
.scheduleSyncRepeatingTask(BanVotePlugin.instance,
new BanVoteRunnable(this), interval, interval);
}
+
+ /**
+ * parse ban vote type: byte to string
+ * @param bType the input byte
+ * @return the output string
+ */
+ protected static String parse(byte bType) {
+ if (bType == 1) {
+ return "kick";
+ } else if (bType == 2) {
+ return "ban";
+ }
+ return "mute";
+ }
+
+ /**
+ * parse ban vote type: byte to string
+ * @param bType the input byte
+ * @return the output string
+ */
+ protected static byte parse(String sType) {
+ if (sType.equals("kick")) {
+ return 1;
+ } else if (sType.equals("ban")) {
+ return 2;
+ }
+ return 0;
+ }
/**
* hand over vote state
@@ -119,8 +152,14 @@ protected String getVoter() {
HashSet<String> afk = new HashSet<String>();
try {
+ if (BanVotePlugin.instance.getServer().getPluginManager()
+ .getPlugin("SimpleAFK") == null) {
+ return afk;
+ }
+
SimpleAFK plugin = (SimpleAFK) BanVotePlugin.instance.getServer()
.getPluginManager().getPlugin("SimpleAFK");
+
for (Player p : plugin.afkPlayers.keySet()) {
if (yes.contains(p.getName())) {
continue;
@@ -187,8 +226,9 @@ protected void advance() {
state = voteState.MUTEVOTER;
BanVotePlugin.brc(ChatColor.GOLD + "Muting " + ChatColor.GREEN
+ voter + ChatColor.GOLD + " for " + stageSeconds
- + " seconds, so " + target + " can explain.");
- BanVotePlugin.log.i("ban vote: stage 2 - muting the voter");
+ + " seconds, so " + ChatColor.RED + target + ChatColor.GOLD + " can explain.");
+ BanVotePlugin.log.i("" + type
+ + " vote: stage 2 - muting the voter");
} else {
BanVotePlugin.brc(ChatColor.GOLD
+ String.valueOf(Math.round(stageSeconds / 2))
@@ -238,7 +278,7 @@ private void calculateResult() {
if (calcPublic) {
- BanVotePlugin.brc(yes.size() + " ban votes = "
+ BanVotePlugin.brc(yes.size() + " " + type + " votes = "
+ (yes.size() * yesValue) + " :: " + getNames(yes));
BanVotePlugin.brc(afk.size() + " afk votes = "
+ (afk.size() * afkValue) + " :: " + getNames(afk));
@@ -249,7 +289,7 @@ private void calculateResult() {
BanVotePlugin.brc("------------------");
BanVotePlugin.brc("Final vote tally = " + result);
} else {
- BanVotePlugin.log.i(yes.size() + " ban votes = "
+ BanVotePlugin.log.i(yes.size() + " " + type + " votes = "
+ (yes.size() * yesValue) + " :: " + getNames(yes));
BanVotePlugin.log.i(afk.size() + " afk votes = "
+ (afk.size() * afkValue) + " :: " + getNames(afk));
@@ -263,37 +303,42 @@ private void calculateResult() {
if (result > validMin) {
// ban successful
- BanVotePlugin.brc(ChatColor.GOLD + "Ban vote on " + ChatColor.RED
- + target + ChatColor.GOLD + " gave a clear result.");
+ BanVotePlugin.brc(ChatColor.GOLD + "" + type + " vote on "
+ + ChatColor.RED + target + ChatColor.GOLD
+ + " gave a clear result.");
BanVotePlugin.brc(ChatColor.GOLD + "It " + ChatColor.GREEN
+ "succeeded" + ChatColor.GOLD + " with a score of "
+ Math.round(result) + ".");
- BanVotePlugin.brc(ChatColor.GOLD + "Banning " + ChatColor.RED
- + target + ChatColor.GOLD + ".");
+ if (type.equals("ban")) {
+ BanVotePlugin.brc(ChatColor.GOLD + "Banning " + ChatColor.RED
+ + target + ChatColor.GOLD + ".");
+ }
state = voteState.POSITIVE;
BanVotePlugin.log.i(target + " tempban = " + result * posMinutes);
commitBan(target, Math.round(result * posMinutes));
} else if (result < validMax) {
// ban failed
- BanVotePlugin.brc(ChatColor.GOLD + "Ban vote on " + ChatColor.RED
- + target + ChatColor.GOLD + " gave a clear result.");
+ BanVotePlugin.brc(ChatColor.GOLD + "" + type + " vote on "
+ + ChatColor.RED + target + ChatColor.GOLD
+ + " gave a clear result.");
BanVotePlugin.brc(ChatColor.GOLD + "It " + ChatColor.RED + "failed"
+ ChatColor.GOLD + " with a score of " + Math.round(result)
+ ".");
- BanVotePlugin.brc(ChatColor.GOLD + "Banning " + ChatColor.GREEN
- + voter + ChatColor.GOLD + ".");
+ if (type.equals("ban")) {
+ BanVotePlugin.brc(ChatColor.GOLD + "Banning " + ChatColor.GREEN
+ + voter + ChatColor.GOLD + ".");
+ }
state = voteState.NEGATIVE;
BanVotePlugin.log.i(voter + " tempban = " + result * negMinutes);
commitBan(voter, Math.round(result * negMinutes));
} else {
// community failed
- BanVotePlugin
- .brc(ChatColor.GOLD + "Ban vote on " + ChatColor.RED
- + target + ChatColor.GOLD
- + " did not give a clear result.");
+ BanVotePlugin.brc(ChatColor.GOLD + "" + type + " vote on "
+ + ChatColor.RED + target + ChatColor.GOLD
+ + " did not give a clear result.");
state = voteState.NULL;
}
@@ -304,20 +349,32 @@ private void calculateResult() {
}
/**
- * actually commit the ban command, calculate ban count to maybe perm ban
+ * actually commit the ban/mute/kick command, TODO calculate ban/mute count to maybe perm ban
*
* @param target
* playername to be banned
* @param i
* value in minutes to be banned
*/
private void commitBan(String sBanTarget, int i) {
+ byte b = 0;
+ if (type.equals("kick")) {
+ b = 1;
+ } else if (type.equals("ban")) {
+ b = 2;
+ }
i = Math.abs(i);
BanVotePlugin.instance.bbm.add(voter + ":" + target + ":"
+ Math.round(System.currentTimeMillis() / 1000) + ":" + i + ":"
- + target.equals(sBanTarget));
+ + target.equals(sBanTarget) + ":" + b);
BanVotePlugin.db.i("committing ban on " + target + " for " + i
+ " minutes");
+ if (b == 0) {
+ BanVotePlugin
+ .brc("Muting " + sBanTarget + " for " + i + " minutes");
+ BanVotePlugin.db.i("NOT kicking");
+ return;
+ }
try {
Bukkit.getPlayer(sBanTarget).kickPlayer(
"You have been vote-banned for " + i + " minutes!");
View
6 src/net/slipcor/banvote/BanVoteManager.java
@@ -8,7 +8,7 @@
/**
* ban vote manager class
*
- * @version v0.0.1
+ * @version v0.0.3
*
* @author slipcor
*
@@ -75,7 +75,7 @@ private boolean isPossible(Player pTarget) {
* @param player
* the player trying to vote
*/
- protected void init(String sTarget, String[] args, Player player) {
+ protected void init(String sTarget, String[] args, Player player, byte b) {
BanVotePlugin.db.i("vote init: " + player.getName() + " => " + sTarget);
BanVotePlugin.db.i("args: "
+ BanVotePlugin.instance.parseStringArray(args));
@@ -99,7 +99,7 @@ protected void init(String sTarget, String[] args, Player player) {
}
BanVotePlugin.db.i("possibility check positive");
votes.add(new BanVoteClass(pTarget, player, BanVotePlugin.instance
- .parseStringArray(args)));
+ .parseStringArray(args), b));
}
/**
View
36 src/net/slipcor/banvote/BanVotePlayerListener.java
@@ -1,6 +1,7 @@
package net.slipcor.banvote;
import org.bukkit.ChatColor;
+import org.bukkit.entity.Player;
import org.bukkit.event.player.PlayerChatEvent;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
import org.bukkit.event.player.PlayerListener;
@@ -9,7 +10,7 @@
/**
* ban vote player listener class
*
- * @version v0.0.1
+ * @version v0.0.3
*
* @author slipcor
*
@@ -21,25 +22,34 @@
public void onPlayerCommandPreprocess(PlayerCommandPreprocessEvent event) {
BanVotePlugin.db.i("onPlayerCommandPreprocess: "
+ event.getPlayer().getName());
- if (BanVotePlugin.instance.bm
- .isChatBlocked(event.getPlayer().getName())) {
- BanVotePlugin.db.i("cancelling event...");
- event.setCancelled(true);
- BanVotePlugin.msg(event.getPlayer(), ChatColor.GOLD
- + "You are muted, please wait.");
+ if (isAllowed(event.getPlayer())) {
+ return;
}
+ event.setCancelled(true);
}
@Override
public void onPlayerChat(PlayerChatEvent event) {
BanVotePlugin.db.i("onPlayerChat: " + event.getPlayer().getName());
- if (BanVotePlugin.instance.bm
- .isChatBlocked(event.getPlayer().getName())) {
- BanVotePlugin.db.i("cancelling event...");
- event.setCancelled(true);
- BanVotePlugin.msg(event.getPlayer(), ChatColor.GOLD
- + "You are muted, please wait.");
+ if (isAllowed(event.getPlayer())) {
+ return;
}
+ event.setCancelled(true);
+ }
+
+ /**
+ * is a given player allowed to chat/use commands?
+ * @param p the player to check
+ * @return true if the player may talk/use commands, false otherwise
+ */
+ private boolean isAllowed(Player p) {
+ if ((BanVotePlugin.instance.bm.isChatBlocked(p.getName()))
+ || (BanVotePlugin.instance.bbm.isMuted(p.getName()))) {
+ BanVotePlugin
+ .msg(p, ChatColor.GOLD + "You are muted, please wait.");
+ return false;
+ }
+ return true;
}
@Override
View
55 src/net/slipcor/banvote/BanVotePlugin.java
@@ -15,7 +15,7 @@
/**
* plugin class
*
- * @version v0.0.1
+ * @version v0.0.3
*
* @author slipcor
*
@@ -24,7 +24,7 @@
public class BanVotePlugin extends JavaPlugin {
protected static BanVotePlugin instance;
protected final BanVoteManager bm = new BanVoteManager();
- protected final BanVoteBanManager bbm = new BanVoteBanManager();
+ protected final BanVoteResultManager bbm = new BanVoteResultManager();
protected final BanVotePlayerListener pl = new BanVotePlayerListener();
protected static BanVoteDebugger db;
@@ -87,20 +87,29 @@ public boolean onCommand(CommandSender sender, Command cmd, String sCmd,
sender.sendMessage("[BanVote] Commands only usable ingame!");
return true;
}
-
+ byte b = 0;
Player player = (Player) sender;
- if (!sCmd.equals("banvote")) {
- if (sCmd.equals("unbanvote")) {
+ if (!sCmd.equals("banvote") && !sCmd.equals("mutevote")
+ && !sCmd.equals("kickvote")) {
+ if (sCmd.equals("release")) {
return onAdminCommand(player, args);
} else {
return false;
}
}
- db.i("onCommand: banvote command");
+ if (sCmd.startsWith("ban")) {
+ b = 2;
+ } else if (sCmd.startsWith("kick")) {
+ b = 1;
+ }
+
+ String type = BanVoteClass.parse(b);
+
+ db.i("onCommand: " + type + "vote command");
- if (!player.hasPermission("banvote.vote")) {
+ if (!player.hasPermission("" + type + "vote.vote")) {
BanVotePlugin.msg(player, ChatColor.RED
+ "You don't have permission!");
return true;
@@ -113,26 +122,27 @@ public boolean onCommand(CommandSender sender, Command cmd, String sCmd,
db.i("onCommand: args: " + parseStringArray(args));
if (args.length > 1) {
- bm.init(args[0], args, player);
+ bm.init(args[0], args, player, b);
return true;
}
if (args[0].equalsIgnoreCase("help")) {
- msg(player, ChatColor.GOLD
- + "To start a vote to ban a player type: ");
- msg(player, ChatColor.AQUA + "/banvote [playername] [reason]fuc");
+ msg(player, ChatColor.GOLD + "To start a vote to " + type
+ + " a player type: ");
+ msg(player, ChatColor.AQUA + "/" + type
+ + "vote [playername] [reason]");
msg(player, ChatColor.GOLD + "Once started, type "
- + ChatColor.GREEN + "/banvote [+|yes|true]"
+ + ChatColor.GREEN + "/" + type + "vote [+|yes|true]"
+ ChatColor.GOLD + " to vote to ban");
- msg(player, ChatColor.GOLD + "or " + ChatColor.RED
- + "/banvote [-|no|false]" + ChatColor.GOLD
- + " to vote not to ban.");
+ msg(player, ChatColor.GOLD + "or " + ChatColor.RED + "/" + type
+ + "vote [-|no|false]" + ChatColor.GOLD + " to vote not to "
+ + type + ".");
msg(player, ChatColor.GOLD + "A vote against counts as "
+ ChatColor.RED + "-4" + ChatColor.GOLD
- + " votes towards a ban");
+ + " votes towards a " + type + "");
msg(player, ChatColor.GOLD + "A non-vote counts as "
+ ChatColor.RED + "-0.25" + ChatColor.GOLD
- + " votes towards a ban");
+ + " votes towards a " + type + "");
return true;
}
@@ -161,11 +171,12 @@ private boolean onAdminCommand(Player player, String[] args) {
}
if (args[0].equals("list")) {
- for (int i : bbm.bans.keySet()) {
- BanVoteBan ban = bbm.bans.get(i);
- BanVotePlugin.msg(player, ChatColor.GOLD + "#" + i + ": " + ban.getInfo());
+ for (int i : bbm.results.keySet()) {
+ BanVoteResult ban = bbm.results.get(i);
+ BanVotePlugin.msg(player,
+ ChatColor.GOLD + "#" + i + ": " + ban.getInfo());
}
- if (bbm.bans.size() < 1) {
+ if (bbm.results.size() < 1) {
BanVotePlugin.msg(player, ChatColor.GOLD + "No bans active!");
}
return true;
@@ -174,7 +185,7 @@ private boolean onAdminCommand(Player player, String[] args) {
String banPlayer = "";
try {
int i = Integer.parseInt(args[0]);
- banPlayer = bbm.bans.get(i).getBanned();
+ banPlayer = bbm.results.get(i).getResultPlayerName();
bbm.remove(i);
} catch (Exception e) {
BanVotePlugin.msg(player, ChatColor.RED
View
60 src/net/slipcor/banvote/BanVoteBan.java → src/net/slipcor/banvote/BanVoteResult.java
@@ -3,23 +3,28 @@
import org.bukkit.ChatColor;
/**
- * ban vote ban class
+ * ban vote result class
*
- * @version v0.0.1
+ * -
+ *
+ * the actual ban/mute resulting from a vote
+ *
+ * @version v0.0.3
*
* @author slipcor
*
*/
-public class BanVoteBan {
+public class BanVoteResult {
private final long timestamp;
private final String voter;
private final String target;
private final int interval;
private final boolean result;
+ private final byte type; // 0 = mute ; 1 = kick ; 2 = ban
/**
- * construct a ban vote ban instance
+ * construct a ban vote result instance
*
* @param uid
* the case unique ID
@@ -33,50 +38,75 @@
* ban length (in minutes)
* @param bResult
* true: target banned, false:
+ * @param bType
+ * 0 = mute ; 1 = kick ; 2 = ban
*/
- public BanVoteBan(int uid, String sVoter, String sTarget, long lTimestamp,
- int iInterval, boolean bResult) {
+ public BanVoteResult(int uid, String sVoter, String sTarget, long lTimestamp,
+ int iInterval, boolean bResult, byte bType) {
voter = sVoter;
target = sTarget;
timestamp = lTimestamp;
interval = iInterval;
result = bResult;
+ type = bType;
BanVotePlugin.instance.getConfig().set("bans.b" + uid, getContents());
BanVotePlugin.instance.saveConfig();
}
/**
- * check who was banned
+ * check who was banned/muted
*
* @return result true: target, else: voter name
*/
- protected String getBanned() {
+ protected String getResultPlayerName() {
return result ? target : voter;
}
/**
- * check if the ban has expired
+ * check if the ban/mute has expired
*
- * @return true if the ban has expired, false otherwise
+ * @return true if the ban/mute has expired, false otherwise
*/
protected boolean over() {
- BanVotePlugin.db.i(timestamp + (interval*60) + " < " + System.currentTimeMillis() / 1000);
- return (timestamp + (interval*60)) < System.currentTimeMillis() / 1000;
+ BanVotePlugin.db.i(timestamp + (interval * 60) + " < "
+ + System.currentTimeMillis() / 1000);
+ return (timestamp + (interval * 60)) < System.currentTimeMillis() / 1000;
}
/**
- * combine the ban information to a string
+ * combine the ban/mute information to a string
*
* @return a string of all information, joined with ":"
*/
private String getContents() {
return voter + ":" + target + ":" + timestamp + ":" + interval + ":"
- + result;
+ + result + ":" + type;
}
+ /**
+ * print voter, target and result
+ *
+ * @return a string containing voter, target, banned, interval
+ */
public String getInfo() {
+ String s = "mute";
+ if (type == 1) {
+ s = "kick";
+ } else if (type == 2) {
+ s = "ban";
+ }
+
return ChatColor.GREEN + voter + ChatColor.GOLD + " => "
- + ChatColor.RED + target + ChatColor.GOLD + "; banned: "
+ + ChatColor.RED + target + ChatColor.GOLD + "; " + s + ": "
+ (result ? target : voter) + " (" + interval + " mins)";
}
+
+ /**
+ * get the ban type
+ *
+ * @return 0 (mute), 1 (kick), 2 (ban)
+ */
+ public byte getType() {
+ return type;
+ }
}
View
68 ...et/slipcor/banvote/BanVoteBanManager.java → ...slipcor/banvote/BanVoteResultManager.java
@@ -4,19 +4,19 @@
import java.util.HashSet;
/**
- * ban vote manager class
+ * ban vote result manager class
*
- * @version v0.0.1
+ * @version v0.0.3
*
* @author slipcor
*
*/
-public class BanVoteBanManager {
- HashMap<Integer, BanVoteBan> bans = new HashMap<Integer, BanVoteBan>();
+public class BanVoteResultManager {
+ HashMap<Integer, BanVoteResult> results = new HashMap<Integer, BanVoteResult>();
/**
- * add a string to the bans
+ * add a string to the bans/mutes
*
* @param s
* ban string
@@ -25,11 +25,12 @@ protected void add(String s) {
BanVotePlugin.db.i("banning : " + s);
String[] args = s.split(":");
int i = getFreeID();
- bans.put(
+ results.put(
i,
- new BanVoteBan(i, args[0], args[1], Long.parseLong(args[2]),
+ new BanVoteResult(i, args[0], args[1], Long.parseLong(args[2]),
Integer.parseInt(args[3]), args[4]
- .equalsIgnoreCase("true")));
+ .equalsIgnoreCase("true"), Byte
+ .parseByte(args[5])));
}
/**
@@ -39,7 +40,7 @@ protected void add(String s) {
*/
private int getFreeID() {
int i = 0;
- while (bans.get(++i) != null)
+ while (results.get(++i) != null)
;
return i;
}
@@ -48,23 +49,23 @@ private int getFreeID() {
* check if a given UID can be removed and do it
*
* @param i
- * the ban UID
- * @return true if the ban was removed, false otherwise
+ * the ban/mute UID
+ * @return true if the ban/mute was removed, false otherwise
*/
protected boolean checkRemove(int i) {
- if (bans.get(i) != null && bans.get(i).over()) {
+ if (results.get(i) != null && results.get(i).over()) {
remove(i);
return true;
}
return false;
}
/**
- * check all bans if they can be removed and do when possible
+ * check all bans/mutes if they can be removed and do that if possible
*/
protected void checkRemove() {
HashSet<Integer> uids = new HashSet<Integer>();
- for (int i : bans.keySet()) {
+ for (int i : results.keySet()) {
uids.add(i);
}
for (int i : uids) {
@@ -73,27 +74,32 @@ protected void checkRemove() {
}
/**
- * remove a given UID from the bans
+ * remove a given UID from the bans/mutes
*
* @param i
* the ban UID to remove
*/
protected void remove(int i) {
- bans.remove(i);
+ results.remove(i);
BanVotePlugin.instance.getConfig().set("bans.b" + i, null);
BanVotePlugin.instance.saveConfig();
}
/**
- * read a map of UID => banned player name
+ * read a map of UID => banned/muted player name
*
+ * @param b
+ * banned = true; muted = false
* @return a map of all band UIDs mapped to the banned player name
*/
- protected HashMap<Integer, String> getList() {
+ protected HashMap<Integer, String> getList(boolean b) {
HashMap<Integer, String> result = new HashMap<Integer, String>();
- for (int i : bans.keySet()) {
- result.put(i, bans.get(i).getBanned());
+ for (int i : results.keySet()) {
+ if ((results.get(i).getType() == 2 && b)
+ || (results.get(i).getType() == 0 && !b))
+
+ result.put(i, results.get(i).getResultPlayerName());
}
return result;
@@ -107,7 +113,27 @@ protected void remove(int i) {
* @return true if a ban is active, false otherwise
*/
protected boolean isBanned(String sPlayer) {
- HashMap<Integer, String> map = getList();
+ HashMap<Integer, String> map = getList(true);
+
+ for (int i : map.keySet()) {
+ if (map.get(i).equals(sPlayer)) {
+ if (!checkRemove(i)) {
+ return true;
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * check if a given player name is muted
+ *
+ * @param sPlayer
+ * the player name to check
+ * @return true if a mute is active, false otherwise
+ */
+ protected boolean isMuted(String sPlayer) {
+ HashMap<Integer, String> map = getList(false);
for (int i : map.keySet()) {
if (map.get(i).equals(sPlayer)) {

0 comments on commit 4aea8d8

Please sign in to comment.