Skip to content

Commit

Permalink
v0.0.3.3 - kick, mute, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
slipcor committed Jan 12, 2012
1 parent 79258af commit 4aea8d8
Show file tree
Hide file tree
Showing 8 changed files with 264 additions and 109 deletions.
1 change: 1 addition & 0 deletions 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
30 changes: 25 additions & 5 deletions 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:
Expand All @@ -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
117 changes: 87 additions & 30 deletions src/net/slipcor/banvote/BanVoteClass.java
Expand Up @@ -12,7 +12,7 @@
/**
* ban vote class
*
* @version v0.0.0
* @version v0.0.3
*
* @author slipcor
*
Expand All @@ -35,6 +35,7 @@ protected static enum voteState {
private static int coolMinutes;
private static boolean calcPublic;

private String type;
private voteState state;
private String voter;
private String target;
Expand All @@ -54,34 +55,66 @@ protected static enum voteState {
* @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
Expand Down Expand Up @@ -119,8 +152,14 @@ private HashSet<String> getAfk() {
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;
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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));
Expand All @@ -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));
Expand All @@ -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;
}
Expand All @@ -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!");
Expand Down
6 changes: 3 additions & 3 deletions src/net/slipcor/banvote/BanVoteManager.java
Expand Up @@ -8,7 +8,7 @@
/**
* ban vote manager class
*
* @version v0.0.1
* @version v0.0.3
*
* @author slipcor
*
Expand Down Expand Up @@ -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));
Expand All @@ -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));
}

/**
Expand Down
36 changes: 23 additions & 13 deletions 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;
Expand All @@ -9,7 +10,7 @@
/**
* ban vote player listener class
*
* @version v0.0.1
* @version v0.0.3
*
* @author slipcor
*
Expand All @@ -21,25 +22,34 @@ public class BanVotePlayerListener extends PlayerListener {
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
Expand Down

0 comments on commit 4aea8d8

Please sign in to comment.