Browse files

bugfix

  • Loading branch information...
1 parent 47929dc commit 7901aa9e882881dec2c6ab4cda5bc6ece2285316 @Kraken3 committed Jul 26, 2012
View
2 .classpath
@@ -2,7 +2,7 @@
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre6"/>
- <classpathentry kind="lib" path="C:/Users/George Constanza/Documents/GitHub/AFK-Player-GC/lib/craftbukkit-1.2.5-R3.0.jar">
+ <classpathentry kind="lib" path="C:/Users/Test1/Documents/GitHub/AFK-Player-GC/lib/craftbukkit-1.2.5-R3.0.jar">
<attributes>
<attribute name="javadoc_location" value="http://jd.bukkit.org/apidocs/"/>
</attributes>
View
BIN bin/com/github/Kraken3/AFKPGC/AFKPGC$2.class
Binary file not shown.
View
BIN bin/com/github/Kraken3/AFKPGC/AFKPGC$3.class
Binary file not shown.
View
BIN bin/com/github/Kraken3/AFKPGC/AFKPGC.class
Binary file not shown.
View
BIN bin/com/github/Kraken3/AFKPGC/Kicker.class
Binary file not shown.
View
BIN bin/com/github/Kraken3/AFKPGC/LastActivity.class
Binary file not shown.
View
BIN bin/com/github/Kraken3/AFKPGC/Message.class
Binary file not shown.
View
BIN bin/com/github/Kraken3/AFKPGC/Warning.class
Binary file not shown.
View
2 config.yml
@@ -51,3 +51,5 @@ Str11: "Configuration file error: %s"
Str12: "Configuration file incomplete - plugin doesn't know when to kick players when there are %d players online"
Str13: "Error: Inconsistency in number of players detected"
Str14: "%s kicked for being AFK for %s"
+Str15: "AFKPGC version: %s, the plugin is %s"
+Str16: "AFKPGC is alive"
View
BIN dist/AFKPGC.jar
Binary file not shown.
View
4 plugin.yml
@@ -1,9 +1,9 @@
name: AFKPGC
main: com.github.Kraken3.AFKPGC.AFKPGC
author: Kraken3
-version: 1.1
+version: 1.2.2
commands:
afkpgc:
description: AFK Player GC - mod for kicking inactive players
- usage: /afkpgc times | list | stop | reload
+ usage: /afkpgc times | list | stop | reload | info
permission-message: You don't have <permission>
View
52 src/com/github/Kraken3/AFKPGC/AFKPGC.java
@@ -32,7 +32,14 @@ public void onEnable(){
public void run() {
LastActivity.currentTime = System.currentTimeMillis();
}
- }, 0, 1L);
+ }, 0, 1L);
+
+ //Because bukkit..
+ getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
+ public void run() {
+ LastActivity.FixInconsitencies();
+ }
+ }, 0, 6000L);
Message.send(1);
}
@@ -52,21 +59,17 @@ public boolean onCommand(CommandSender sender, Command cmd, String label, String
if (cmd.getName().equalsIgnoreCase("afkpgc")){
if(args[0].equalsIgnoreCase("times")){
return onCommandTimes(player);
- } else if(args[0].equalsIgnoreCase("amistillalive")){
- if(player != null) Kicker.amIStillAlivePlayer = player.getName();
- return true;
+ } else if(args[0].equalsIgnoreCase("info")){
+ return onCommandInfo(player);
} else if(args[0].equalsIgnoreCase("reload") || args[0].equalsIgnoreCase("list") || args[0].equalsIgnoreCase("stop") ){
if(player != null && !player.isOp()) {
player.sendMessage("Only OP can do that. ");
return true;
- }
-
+ }
if(args[0].equalsIgnoreCase("reload")) return onCommandReload(player);
else if(args[0].equalsIgnoreCase("list")) return onCommandList(player, args);
- else if(args[0].equalsIgnoreCase("stop")) return onCommandStop(player);
-
-
- } else return false;
+ else if(args[0].equalsIgnoreCase("stop")) return onCommandStop(player);
+ }
}
return false;
@@ -115,6 +118,14 @@ private boolean onCommandStop(Player player){
return true;
}
+ private boolean onCommandInfo(Player player){
+ Message.send(player, 15, plugin.getDescription().getVersion(), AFKPGC.enabled ? "enabled" : "disabled");
+ if(Kicker.amIStillAlivePlayer == null) Kicker.amIStillAlivePlayer = new ArrayList<String>();
+ if(player != null) Kicker.amIStillAlivePlayer.add(player.getName());
+ else Kicker.amIStillAlivePlayer.add(null);
+ return true;
+ }
+
private boolean onCommandList(Player player, String[] args){
int p = 10;
@@ -201,4 +212,25 @@ public Warning (int time, String message){
public long timeOfLastActivity;
public long timeOflastKickerPass; //time of the last Kicker.run call, relevant for warnings
public String playerName; //useful only in onCommandList
+
+ //let's be polite.. I strongly dislike bukkit.. onPlayerQuitEvent doesn't trigger on all
+ //player log off events for some reason. This causes LastActivity.lastActivities to contain more players
+ //than there are playing on the server. FixInconsitencies() fixes this problem.
+ static public void FixInconsitencies(){
+ Map<String, LastActivity> lastActivities = LastActivity.lastActivities;
+ Player[] players = AFKPGC.plugin.getServer().getOnlinePlayers();
+ TreeSet<String> playersTree = new TreeSet<String>();
+
+ for(Player p:players) {
+ String name = p.getName();
+ if(!lastActivities.containsKey(name)) AFKPGC.addPlayer(p.getName());
+ playersTree.add(name);
+ }
+
+ String[] keySet = lastActivities.keySet().toArray(new String[0]);
+ for(String i:keySet){
+ if(!playersTree.contains(i)) AFKPGC.removerPlayer(i);
+ }
+
+ }
}
View
25 src/com/github/Kraken3/AFKPGC/Kicker.java
@@ -1,5 +1,6 @@
package com.github.Kraken3.AFKPGC;
+import java.util.List;
import java.util.Map;
import org.bukkit.entity.Player;
@@ -8,15 +9,20 @@
class Kicker implements Runnable {
public static int[] kickThresholds;
public static Warning[] warnings;
- public static String message_on_kick;
- public static String amIStillAlivePlayer; // sends a message to this player
+ public static String message_on_kick;
+ public static List<String> amIStillAlivePlayer; // sends a message to this player
+
public void run() {
if(amIStillAlivePlayer != null){
- Player p;
- if((p = AFKPGC.plugin.getServer().getPlayer(amIStillAlivePlayer)) != null){
- p.sendMessage("AFKPGC plugin is still alive");
- }
+ Player p;
+ for(String i:amIStillAlivePlayer){
+ if(i != null){
+ if((p = AFKPGC.plugin.getServer().getPlayer(i)) != null) Message.send(p,16);
+ } else {
+ Message.send(16);
+ }
+ }
amIStillAlivePlayer = null;
}
@@ -25,9 +31,10 @@ public void run() {
int numberOfPlayersOnline = LastActivity.lastActivities.size();
if(numberOfPlayersOnline == 0) return;
if(numberOfPlayersOnline > kickThresholds.length) {
- Message.send(13);
- return;
- }
+ //Message.send(13);
+ LastActivity.FixInconsitencies();
+ numberOfPlayersOnline = LastActivity.lastActivities.size();
+ }
int warningslen = warnings.length;
View
8 src/com/github/Kraken3/AFKPGC/Message.java
@@ -14,27 +14,31 @@ public static void send(Player player, String str, Object... args){
formatter.format(str, args);
if(player != null) player.sendMessage(sb.toString());
else AFKPGC.logger.info(sb.toString());
+ formatter.close();
}
public static void send(String str, Object... args){
StringBuilder sb = new StringBuilder();
Formatter formatter = new Formatter(sb, Locale.US);
formatter.format(str, args);
AFKPGC.logger.info(sb.toString());
+ formatter.close();
}
public static void warning(String str, Object... args){
StringBuilder sb = new StringBuilder();
Formatter formatter = new Formatter(sb, Locale.US);
formatter.format(str, args);
- AFKPGC.logger.log(Level.WARNING, sb.toString());
+ AFKPGC.logger.log(Level.WARNING, sb.toString());
+ formatter.close();
}
public static void error(String str, Object... args){
StringBuilder sb = new StringBuilder();
Formatter formatter = new Formatter(sb, Locale.US);
formatter.format(str, args);
- AFKPGC.logger.log(Level.SEVERE, sb.toString());
+ AFKPGC.logger.log(Level.SEVERE, sb.toString());
+ formatter.close();
}
public static void send(Player player, int str, Object... args){

0 comments on commit 7901aa9

Please sign in to comment.