71 lines
2.3 KiB
Java
Executable File
71 lines
2.3 KiB
Java
Executable File
package com.alttd.afkdectector;
|
|
|
|
import java.util.UUID;
|
|
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.ChatColor;
|
|
import org.bukkit.entity.Player;
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
|
|
|
public class MessageTimer extends BukkitRunnable {
|
|
|
|
private AFKDetector plugin;
|
|
private UUID uuid = null;
|
|
private int repeats;
|
|
|
|
public MessageTimer(AFKDetector plugin, UUID uuid, int repeats) {
|
|
this.plugin = plugin;
|
|
this.uuid = uuid;
|
|
this.repeats = repeats;
|
|
}
|
|
|
|
public void init() {
|
|
runTaskTimer(plugin, 0, plugin.messageDelay * 20);
|
|
}
|
|
|
|
// TODO get a better string builder
|
|
/*
|
|
private String return_placeholders(Param String ... string)
|
|
*/
|
|
private String return_placeholders(String s, Player p) {
|
|
s = s.replaceAll("%player%", p.getName()).replaceAll("%afktime%", (int) Math.floor((System.currentTimeMillis() - plugin.getPlayer(p).getstandingTime()) / 60 / 1000) +"");
|
|
return s;
|
|
}
|
|
|
|
@Override
|
|
public void run() {
|
|
Player player = Bukkit.getPlayer(uuid);
|
|
if(plugin.messageTimers.containsKey(uuid)) {
|
|
if (player == null || player.hasPermission("afkdetector.kickexempt")) {
|
|
cancel();
|
|
return;
|
|
}
|
|
if(plugin.countdownenabled) {
|
|
player.sendTitle(ChatColor.translateAlternateColorCodes('&', plugin.title1),
|
|
ChatColor.translateAlternateColorCodes('&', plugin.title2), plugin.fadein, plugin.stay, plugin.fadeout);
|
|
player.sendMessage(ChatColor.translateAlternateColorCodes('&', plugin.message));
|
|
}
|
|
repeats = repeats - 1;
|
|
|
|
if (repeats <= 0) {
|
|
if(player.isInsideVehicle()) {
|
|
player.leaveVehicle();
|
|
}
|
|
//Bukkit.dispatchCommand(Bukkit.getConsoleSender(), plugin.kickCommand.replace("%player%", player.getName()));
|
|
plugin.messageTimers.remove(player.getUniqueId());
|
|
Bukkit.dispatchCommand(Bukkit.getConsoleSender(), return_placeholders(plugin.kickCommand, player));
|
|
cancel();
|
|
}
|
|
} else {
|
|
if(player != null) {
|
|
if(!plugin.messageTimers.isEmpty()) {
|
|
if(plugin.messageTimers.containsKey(player.getUniqueId())) {
|
|
plugin.messageTimers.remove(player.getUniqueId());
|
|
}
|
|
}
|
|
cancel();
|
|
}
|
|
}
|
|
}
|
|
}
|