164 lines
4.2 KiB
Java
164 lines
4.2 KiB
Java
|
package net.mc_pandacraft.java.plugin.pandacraftutils.players;
|
||
|
|
||
|
import java.util.Collections;
|
||
|
import java.util.HashSet;
|
||
|
import java.util.Set;
|
||
|
|
||
|
import net.mc_pandacraft.java.plugin.pandacraftutils.ConfigManager;
|
||
|
import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils;
|
||
|
import net.mc_pandacraft.java.plugin.pandacraftutils.plugin_interface.EssentialsInterface;
|
||
|
|
||
|
import org.bukkit.Bukkit;
|
||
|
import org.bukkit.ChatColor;
|
||
|
import org.bukkit.entity.Player;
|
||
|
|
||
|
public class OnlinePlayer {
|
||
|
private final Player player;
|
||
|
private final PandacraftUtils plugin = PandacraftUtils.getInstance();
|
||
|
|
||
|
public OnlinePlayer(Player p) {
|
||
|
player = p;
|
||
|
}
|
||
|
|
||
|
public Player getPlayer() { return player; }
|
||
|
|
||
|
|
||
|
|
||
|
/*
|
||
|
* Système AFK
|
||
|
*/
|
||
|
|
||
|
private long timeLastAction = System.currentTimeMillis();
|
||
|
private boolean afk = false;
|
||
|
|
||
|
public synchronized boolean isAfk() { return afk; }
|
||
|
|
||
|
public synchronized void setAfk(boolean a) {
|
||
|
if (afk == a)
|
||
|
return;
|
||
|
afk = a;
|
||
|
String message;
|
||
|
|
||
|
// on affiche pas le status AFK des joueurs vanish
|
||
|
if (EssentialsInterface.isPlayerVanished(player)) return;
|
||
|
|
||
|
// affichage du message
|
||
|
if (afk)
|
||
|
message = player.getDisplayName()+ChatColor.YELLOW+" est désormais AFK.";
|
||
|
else
|
||
|
message = player.getDisplayName()+ChatColor.YELLOW+" n'est plus AFK.";
|
||
|
player.getServer().broadcastMessage(message);
|
||
|
}
|
||
|
|
||
|
public void performAfkCommand() {
|
||
|
setAfk(!isAfk());
|
||
|
if (!isAfk())
|
||
|
isDoingAction();
|
||
|
}
|
||
|
|
||
|
public void adminToggleAfk() {
|
||
|
setAfk(!isAfk());
|
||
|
if (!isAfk())
|
||
|
isDoingAction();
|
||
|
}
|
||
|
|
||
|
public double getDurationSinceLastAction() {
|
||
|
return (System.currentTimeMillis() - timeLastAction)/1000D;
|
||
|
}
|
||
|
|
||
|
public void isDoingAction() {
|
||
|
timeLastAction = System.currentTimeMillis();
|
||
|
setAfk(false);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
/*
|
||
|
* Système d'analyse du chat
|
||
|
*/
|
||
|
|
||
|
private String last_message = null;
|
||
|
private long last_message_time = 0;
|
||
|
private String last_command = null;
|
||
|
private long last_command_time = 0;
|
||
|
|
||
|
private int violation_level = 0;
|
||
|
|
||
|
|
||
|
public String getLast_message() { return last_message; }
|
||
|
public void setLast_message(String last_message) { this.last_message = last_message; }
|
||
|
public long getLast_message_time() { return last_message_time; }
|
||
|
public void setLast_message_time(long last_message_time) { this.last_message_time = last_message_time; }
|
||
|
public String getLast_command() { return last_command; }
|
||
|
public void setLast_command(String last_command) { this.last_command = last_command; }
|
||
|
public long getLast_command_time() { return last_command_time; }
|
||
|
public void setLast_command_time(long last_command_time) { this.last_command_time = last_command_time; }
|
||
|
|
||
|
public void addVL(int nb)
|
||
|
{
|
||
|
violation_level += nb;
|
||
|
plugin.getLogger().info("ViolationLevel for player "+player.getDisplayName()+"§r : +"+nb+" -> "+violation_level);
|
||
|
if (violation_level >= ConfigManager.getInstance().ChatAnalysis_maxViolationLevel)
|
||
|
Bukkit.getScheduler().runTask(plugin, new Runnable() {
|
||
|
@Override
|
||
|
public void run() {
|
||
|
player.kickPlayer("Les spams/insultes/publicités sont interdits !");
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
public void removeVL(int nb)
|
||
|
{
|
||
|
violation_level -= nb;
|
||
|
if (violation_level < 0) violation_level = 0;
|
||
|
}
|
||
|
|
||
|
public int getVL() { return violation_level; }
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
/*
|
||
|
* Sélection worldEdit
|
||
|
*/
|
||
|
private boolean WE_show_selection;
|
||
|
private Set<Player> WE_other_player_selection = new HashSet<Player>();
|
||
|
|
||
|
public boolean canViewWESelection() { return WE_show_selection; }
|
||
|
public void enableViewingWESelection() { WE_show_selection = true; }
|
||
|
public void disableViewingWESelection() {
|
||
|
WE_show_selection = false;
|
||
|
WE_other_player_selection = new HashSet<Player>();
|
||
|
}
|
||
|
/**
|
||
|
* @return la liste des joueurs dont le OnlinePlayer veut voir la sélection worldedit (Cette liste retournée est immuable)
|
||
|
*/
|
||
|
public Set<Player> getPlayersForViewingOthersWESelections() { return Collections.unmodifiableSet(WE_other_player_selection); }
|
||
|
public void addPlayerForWiewingHisWESelection(Player p) {
|
||
|
if (p == null || p == player) return;
|
||
|
WE_other_player_selection.add(p);
|
||
|
}
|
||
|
public void removePlayerForWiewingHisWESelection(Player p) { WE_other_player_selection.remove(p); }
|
||
|
public boolean hasPlayerForWiewingHisWESelection(Player p) { return WE_other_player_selection.contains(p); }
|
||
|
|
||
|
|
||
|
|
||
|
}
|