You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
68 lines
2.0 KiB
68 lines
2.0 KiB
package com.entryrise.afkguard.antiafk;
|
|
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.entity.Player;
|
|
|
|
import com.entryrise.afkguard.Main;
|
|
import com.entryrise.afkguard.utils.MathUtils;
|
|
|
|
import lombok.Getter;
|
|
import lombok.Setter;
|
|
|
|
public class AFKPlayer {
|
|
|
|
private double score;
|
|
|
|
@Getter
|
|
@Setter
|
|
private int afkcycles;
|
|
|
|
public AFKPlayer() {
|
|
score = Main.config.getInt("settings.afk-detection.counter.start-score");
|
|
afkcycles = 0;
|
|
}
|
|
|
|
/*
|
|
* Returns -1 = Decrease Returns +1 = Increase Returns 0 = Stays still. (No
|
|
* usage yet)
|
|
*
|
|
* It also sets the afkcycles and makes sure it doesn't go under 0.
|
|
*/
|
|
private int calculateCycles(Player p) {
|
|
afkcycles = score > 0 ? afkcycles + 1 : Math.max(0, afkcycles - Main.config.getInt("settings.afk-detection.counter.decrease-amount"));
|
|
return score > 0 ? 1 : -1;
|
|
}
|
|
|
|
public void addScore(double increment) {
|
|
score -= increment;
|
|
}
|
|
|
|
public boolean isAfk(Player p) {
|
|
|
|
// If the player was found to be AFK, it means there was a change in cyclecount.
|
|
//
|
|
// This means we should check for actions to run.
|
|
if (calculateCycles(p) == 1) {
|
|
for (String stg : Main.config.getStringList("settings.afk-detection.punishment-table." + afkcycles)) {
|
|
String[] result = stg.split(":");
|
|
|
|
int reset = MathUtils.isInt(result[result.length - 1]) ? Integer.valueOf(result[result.length - 1])
|
|
: -1;
|
|
|
|
if (result[0].equalsIgnoreCase("cmd") && result.length >= 2 && !p.hasPermission("afkguard.bypass.cmd")) {
|
|
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), result[1].replace("%player%", p.getName()));
|
|
AFKManager.setScore(p, reset);
|
|
} else if (result[0].equalsIgnoreCase("payment") && !p.hasPermission("afkguard.bypass.payment")) {
|
|
double payment = MathUtils.isInt(result[1]) ? Integer.valueOf(result[1]) : 0;
|
|
Main.penalizePlayer(p, payment, reset);
|
|
} else if (result[0].equalsIgnoreCase("captcha") && !p.hasPermission("afkguard.bypass.captcha")) {
|
|
Main.openCapcha(p, reset);
|
|
}
|
|
}
|
|
}
|
|
|
|
score = Main.config.getDouble("settings.afk-detection.counter.start-score");
|
|
|
|
return false;
|
|
}
|
|
}
|