Unification des classes représentant les joueurs en-ligne (OnlinePlayer) + Création d'une classe gérant les instances des joueurs en-ligne (OnlinePlayerManager)
This commit is contained in:
parent
9b3bfe408c
commit
5e7b129c2e
@ -9,6 +9,7 @@ import net.mc_pandacraft.java.plugin.pandacraftutils.cheat_protect.creative.Crea
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.cheat_protect.no_pvp.NoPvpProtectManager;
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.login_message.LoginLogoutManager;
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.player_count_list.PacketOutServerInfoListener;
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayerManager;
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.simple_commands._command_alias.CommandAliasManager;
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.simple_commands.broadcast.CommandBroadcast;
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.simple_commands.list.CommandList;
|
||||
@ -28,7 +29,11 @@ import org.bukkit.plugin.java.JavaPlugin;
|
||||
public class PandacraftUtils extends JavaPlugin {
|
||||
|
||||
private static PandacraftUtils instance;
|
||||
public static PandacraftUtils getInstance() { return instance; }
|
||||
public static PandacraftUtils getInstance() {
|
||||
if (instance == null) (new Exception("Plugin PandacraftUtils non chargé")).printStackTrace();
|
||||
return instance;
|
||||
|
||||
}
|
||||
|
||||
//public DBConnection databaseConnection;
|
||||
|
||||
@ -70,10 +75,11 @@ public class PandacraftUtils extends JavaPlugin {
|
||||
getLogger().severe("Impossible de se connecter à la base de donnée !");
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
OnlinePlayerManager.loadNewInstance();
|
||||
|
||||
commandPlayers = new CommandList(this);
|
||||
commandSetblock = new CommandSetblock(this);
|
||||
commandAfk = new CommandAfk(this);
|
||||
commandAfk = new CommandAfk();
|
||||
commandSystem = new CommandSystem(this);
|
||||
commandPing = new CommandPing(this);
|
||||
commandMe = new CommandMe(this);
|
||||
@ -84,7 +90,7 @@ public class PandacraftUtils extends JavaPlugin {
|
||||
|
||||
commandAliasManager = new CommandAliasManager(this);
|
||||
spawnTimeManager = new SpawnTimeManager(this);
|
||||
chatAnalysisManager = new ChatAnalysisManager(this);
|
||||
chatAnalysisManager = new ChatAnalysisManager();
|
||||
creativCheatManager = new CreativCheatManager(this);
|
||||
noPvpProtectManager = new NoPvpProtectManager(this);
|
||||
loginLogoutManager = new LoginLogoutManager(this);
|
||||
@ -125,6 +131,8 @@ public class PandacraftUtils extends JavaPlugin {
|
||||
|
||||
ConfigManager.reloadConfig();
|
||||
|
||||
instance = null;
|
||||
|
||||
|
||||
//try { databaseConnection.getConnection().close(); } catch (SQLException e) { }
|
||||
}
|
||||
|
@ -1,72 +0,0 @@
|
||||
package net.mc_pandacraft.java.plugin.pandacraftutils.afk;
|
||||
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.plugin_interface.EssentialsInterface;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class AfkPlayer {
|
||||
private Player player;
|
||||
private long timeLastAction;
|
||||
private boolean afk;
|
||||
|
||||
|
||||
public AfkPlayer(Player p)
|
||||
{
|
||||
player = p;
|
||||
afk = false;
|
||||
timeLastAction = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
|
||||
public Player getPlayer() { return player; }
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
@ -3,6 +3,8 @@ package net.mc_pandacraft.java.plugin.pandacraftutils.afk;
|
||||
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.ConfigManager;
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils;
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayer;
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayerManager;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.command.Command;
|
||||
@ -17,9 +19,7 @@ import org.bukkit.event.player.PlayerDropItemEvent;
|
||||
import org.bukkit.event.player.PlayerEggThrowEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEntityEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerMoveEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.player.PlayerTeleportEvent;
|
||||
import org.bukkit.event.player.PlayerToggleFlightEvent;
|
||||
import org.bukkit.event.player.PlayerToggleSneakEvent;
|
||||
@ -27,21 +27,14 @@ import org.bukkit.event.player.PlayerToggleSprintEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
public class CommandAfk extends BukkitRunnable implements CommandExecutor, Listener {
|
||||
private PandacraftUtils plugin;
|
||||
private AfkPlayer[] players;
|
||||
private PandacraftUtils plugin = PandacraftUtils.getInstance();
|
||||
|
||||
private int timeoutAutoAfkMessage = ConfigManager.getInstance().AFK_timeoutAutoAfkMessage;
|
||||
private int timeoutAutoAfkKick = ConfigManager.getInstance().AFK_timeoutAutoAfkKick;
|
||||
|
||||
|
||||
public CommandAfk(PandacraftUtils pl)
|
||||
public CommandAfk()
|
||||
{
|
||||
plugin = pl;
|
||||
players = new AfkPlayer[plugin.getServer().getMaxPlayers()];
|
||||
|
||||
// analyse des joueurs déjà en ligne (/reload)
|
||||
for (Player p : plugin.getServer().getOnlinePlayers())
|
||||
addPlayer(p);
|
||||
|
||||
|
||||
plugin.getCommand("afk").setExecutor(this);
|
||||
@ -110,7 +103,7 @@ public class CommandAfk extends BukkitRunnable implements CommandExecutor, Liste
|
||||
if (execute_self)
|
||||
{
|
||||
Player p = (Player)sender;
|
||||
AfkPlayer ap = getAfkPlayer(p);
|
||||
OnlinePlayer ap = OnlinePlayerManager.getInstance().get(p);
|
||||
if (ap == null)
|
||||
plugin.getLogger().severe("Cant find AfkPlayer with name "+p.getName()+" when performing command /afk");
|
||||
else
|
||||
@ -119,7 +112,7 @@ public class CommandAfk extends BukkitRunnable implements CommandExecutor, Liste
|
||||
}
|
||||
else if (execute_other && other_player != null)
|
||||
{
|
||||
AfkPlayer ap = getAfkPlayer(other_player);
|
||||
OnlinePlayer ap = OnlinePlayerManager.getInstance().get(other_player);
|
||||
if (ap == null)
|
||||
plugin.getLogger().severe("Cant find AfkPlayer with name "+other_player.getName()+" when performing command /afk <player>");
|
||||
ap.adminToggleAfk();
|
||||
@ -152,7 +145,7 @@ public class CommandAfk extends BukkitRunnable implements CommandExecutor, Liste
|
||||
@Override
|
||||
public void run() {
|
||||
// methode exécutée toute les secondes
|
||||
for (AfkPlayer ap : players)
|
||||
for (OnlinePlayer ap : OnlinePlayerManager.getInstance().getAll())
|
||||
{ // parcours de tout les joueurs
|
||||
if (ap == null)
|
||||
continue;
|
||||
@ -185,17 +178,6 @@ public class CommandAfk extends BukkitRunnable implements CommandExecutor, Liste
|
||||
// ----------------------------------------
|
||||
// -------------- Evènements --------------
|
||||
// ----------------------------------------
|
||||
@EventHandler
|
||||
public void onPlayerJoin (PlayerJoinEvent event)
|
||||
{
|
||||
addPlayer(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit (PlayerQuitEvent event)
|
||||
{
|
||||
removePlayer(event.getPlayer());
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerMove (PlayerMoveEvent event)
|
||||
@ -206,7 +188,7 @@ public class CommandAfk extends BukkitRunnable implements CommandExecutor, Liste
|
||||
if ( (from.getPitch() == to.getPitch() && from.getYaw() == to.getYaw())
|
||||
|| (from.getX() == to.getX() && from.getY() == to.getY() && from.getZ() == to.getZ()))
|
||||
return;
|
||||
getAfkPlayer(event.getPlayer()).isDoingAction();
|
||||
OnlinePlayerManager.getInstance().get(event.getPlayer()).isDoingAction();
|
||||
}
|
||||
|
||||
|
||||
@ -236,7 +218,7 @@ public class CommandAfk extends BukkitRunnable implements CommandExecutor, Liste
|
||||
return;
|
||||
|
||||
|
||||
getAfkPlayer(event.getPlayer()).isDoingAction();
|
||||
OnlinePlayerManager.getInstance().get(event.getPlayer()).isDoingAction();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
@ -244,7 +226,7 @@ public class CommandAfk extends BukkitRunnable implements CommandExecutor, Liste
|
||||
{
|
||||
try
|
||||
{
|
||||
getAfkPlayer(event.getPlayer()).isDoingAction();
|
||||
OnlinePlayerManager.getInstance().get(event.getPlayer()).isDoingAction();
|
||||
}
|
||||
catch (NullPointerException e) { }
|
||||
}
|
||||
@ -254,7 +236,7 @@ public class CommandAfk extends BukkitRunnable implements CommandExecutor, Liste
|
||||
{
|
||||
try
|
||||
{
|
||||
getAfkPlayer(event.getPlayer()).isDoingAction();
|
||||
OnlinePlayerManager.getInstance().get(event.getPlayer()).isDoingAction();
|
||||
}
|
||||
catch (NullPointerException e) { }
|
||||
}
|
||||
@ -269,7 +251,7 @@ public class CommandAfk extends BukkitRunnable implements CommandExecutor, Liste
|
||||
// car un piston "téléporte" le joueur (techniquement parlant, dans le jeu) à 1 bloc de distance
|
||||
if (event.getFrom().getWorld() != event.getTo().getWorld()
|
||||
|| event.getFrom().distanceSquared(event.getTo()) > 2*2)
|
||||
getAfkPlayer(event.getPlayer()).isDoingAction();
|
||||
OnlinePlayerManager.getInstance().get(event.getPlayer()).isDoingAction();
|
||||
}
|
||||
catch (NullPointerException e) { }
|
||||
}
|
||||
@ -279,7 +261,7 @@ public class CommandAfk extends BukkitRunnable implements CommandExecutor, Liste
|
||||
{
|
||||
try
|
||||
{
|
||||
getAfkPlayer(event.getPlayer()).isDoingAction();
|
||||
OnlinePlayerManager.getInstance().get(event.getPlayer()).isDoingAction();
|
||||
}
|
||||
catch (NullPointerException e) { }
|
||||
}
|
||||
@ -288,7 +270,7 @@ public class CommandAfk extends BukkitRunnable implements CommandExecutor, Liste
|
||||
{
|
||||
try
|
||||
{
|
||||
getAfkPlayer(event.getPlayer()).isDoingAction();
|
||||
OnlinePlayerManager.getInstance().get(event.getPlayer()).isDoingAction();
|
||||
}
|
||||
catch (NullPointerException e) { }
|
||||
}
|
||||
@ -297,7 +279,7 @@ public class CommandAfk extends BukkitRunnable implements CommandExecutor, Liste
|
||||
{
|
||||
try
|
||||
{
|
||||
getAfkPlayer(event.getPlayer()).isDoingAction();
|
||||
OnlinePlayerManager.getInstance().get(event.getPlayer()).isDoingAction();
|
||||
}
|
||||
catch (NullPointerException e) { }
|
||||
}
|
||||
@ -307,7 +289,7 @@ public class CommandAfk extends BukkitRunnable implements CommandExecutor, Liste
|
||||
{
|
||||
try
|
||||
{
|
||||
getAfkPlayer(event.getPlayer()).isDoingAction();
|
||||
OnlinePlayerManager.getInstance().get(event.getPlayer()).isDoingAction();
|
||||
}
|
||||
catch (NullPointerException e) { }
|
||||
}
|
||||
@ -317,7 +299,7 @@ public class CommandAfk extends BukkitRunnable implements CommandExecutor, Liste
|
||||
{
|
||||
try
|
||||
{
|
||||
getAfkPlayer(event.getPlayer()).isDoingAction();
|
||||
OnlinePlayerManager.getInstance().get(event.getPlayer()).isDoingAction();
|
||||
}
|
||||
catch (NullPointerException e) { }
|
||||
}
|
||||
@ -327,51 +309,10 @@ public class CommandAfk extends BukkitRunnable implements CommandExecutor, Liste
|
||||
{
|
||||
try
|
||||
{
|
||||
getAfkPlayer(event.getPlayer()).isDoingAction();
|
||||
OnlinePlayerManager.getInstance().get(event.getPlayer()).isDoingAction();
|
||||
}
|
||||
catch (NullPointerException e) { }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// -----------------------------------------
|
||||
// ---------- Gestion des données ----------
|
||||
// -----------------------------------------
|
||||
public AfkPlayer getAfkPlayer(Player p)
|
||||
{
|
||||
for (AfkPlayer ap : players)
|
||||
{
|
||||
if (ap == null)
|
||||
continue;
|
||||
if (ap.getPlayer() == p)
|
||||
return ap;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
private void addPlayer(Player p)
|
||||
{
|
||||
int i=0;
|
||||
while (players[i] != null && i<players.length-1) i++;
|
||||
players[i] = new AfkPlayer(p);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void removePlayer(Player p)
|
||||
{
|
||||
|
||||
for (int i=0; i<players.length; i++)
|
||||
{
|
||||
if (players[i] == null)
|
||||
continue;
|
||||
if (players[i].getPlayer() == p)
|
||||
players[i] = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -1,41 +1,73 @@
|
||||
package net.mc_pandacraft.java.plugin.pandacraftutils.chat_analyzer;
|
||||
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.ConfigManager;
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils;
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayer;
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayerManager;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.util.NumberConversions;
|
||||
|
||||
public class ChatAnalysisManager implements Listener {
|
||||
|
||||
private ChatAnalysisPlayer[] CAPlayers;
|
||||
|
||||
private PandacraftUtils plugin;
|
||||
private PandacraftUtils plugin = PandacraftUtils.getInstance();
|
||||
|
||||
public ChatAnalysisManager(PandacraftUtils pl)
|
||||
public ChatAnalysisManager()
|
||||
{
|
||||
plugin = pl;
|
||||
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
|
||||
CAPlayers = new ChatAnalysisPlayer[plugin.getServer().getMaxPlayers()];
|
||||
|
||||
|
||||
// analyse des joueurs déjà en ligne (/reload)
|
||||
for (Player p : plugin.getServer().getOnlinePlayers())
|
||||
onPlayerJoin(new PlayerJoinEvent(p, "")); // simule l'évènement d'arrivé d'un joueur, pour le rajouter
|
||||
}
|
||||
|
||||
@EventHandler(priority=EventPriority.HIGHEST,ignoreCancelled=true)
|
||||
public void onAsyncPlayerChat(AsyncPlayerChatEvent event)
|
||||
{
|
||||
try {
|
||||
getCAPlayer(event.getPlayer()).onAsyncPlayerChat(event);
|
||||
OnlinePlayer op = OnlinePlayerManager.getInstance().get(event.getPlayer());
|
||||
if (event.getPlayer().hasPermission("pandacraft.antispam.exempt"))
|
||||
return;
|
||||
String message = event.getMessage();
|
||||
long time = System.currentTimeMillis();
|
||||
if (op.getLast_message() != null)
|
||||
{
|
||||
if (op.getLast_message().equals(message) && time - op.getLast_message_time() < ConfigManager.getInstance().ChatAnalysis_timeBeforeResendSameMessage)
|
||||
{
|
||||
event.getPlayer().sendMessage(ChatColor.RED+"Evitez de renvoyer le même message !");
|
||||
if (op.getVL() >= ConfigManager.getInstance().ChatAnalysis_maxViolationLevel/2)
|
||||
event.setCancelled(true);
|
||||
else
|
||||
event.setMessage(analyseString(message, op));
|
||||
op.addVL(5);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
long time_since_last_message = time - op.getLast_message_time();
|
||||
long timeout_needed = message.length() * ConfigManager.getInstance().ChatAnalysis_timePerCaracterForNewMessage;
|
||||
if (time_since_last_message < timeout_needed)
|
||||
{
|
||||
|
||||
event.getPlayer().sendMessage(ChatColor.RED+"Vous parlez un peu trop vite, ralentissez x)");
|
||||
op.addVL(4);
|
||||
event.setMessage(analyseString(message, op));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
message = analyseString(message, op);
|
||||
|
||||
event.setMessage(message);
|
||||
|
||||
op.removeVL(NumberConversions.floor(((time - op.getLast_message_time())/1000)/ConfigManager.getInstance().ChatAnalysis_nbSecondForOneVLDown));
|
||||
|
||||
|
||||
op.setLast_message(message);
|
||||
op.setLast_message_time(time);
|
||||
} catch (NullPointerException e) { }
|
||||
}
|
||||
|
||||
@ -43,48 +75,203 @@ public class ChatAnalysisManager implements Listener {
|
||||
public void onPlayerCommandPreprocess (PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
try {
|
||||
getCAPlayer(event.getPlayer()).onPlayerCommandPreprocess(event);
|
||||
OnlinePlayer op = OnlinePlayerManager.getInstance().get(event.getPlayer());
|
||||
if (event.getPlayer().hasPermission("pandacraft.antispam.exempt"))
|
||||
return;
|
||||
String command_line = event.getMessage();
|
||||
String[] command_line_split = event.getMessage().split(" ");
|
||||
long time = System.currentTimeMillis();
|
||||
String commande = command_line_split[0].substring(1).toLowerCase();
|
||||
|
||||
if (commande.equals("")) return;
|
||||
|
||||
// traitement du contenu des messages (si elle existe, comme MP ou /me)
|
||||
// ici, le message, c'est dès le permier paramètre
|
||||
if ((commande.equals("me")
|
||||
|| commande.equals("action")
|
||||
|| commande.equals("describe")
|
||||
|| commande.equals("r")
|
||||
|| commande.equals("reply"))
|
||||
&& command_line_split.length > 1) {
|
||||
try {
|
||||
String message = command_line.substring(1+commande.length()+1); // "/"+commande+" "
|
||||
message = analyseString(message, op);
|
||||
command_line = "/"+commande+" "+message;
|
||||
} catch (IndexOutOfBoundsException e) { }
|
||||
|
||||
}
|
||||
// ici, le message, c'est dès le deuxième paramètre
|
||||
else if((commande.equals("msg")
|
||||
|| commande.equals("m")
|
||||
|| commande.equals("tell")
|
||||
|| commande.equals("t")
|
||||
|| commande.equals("whisper")
|
||||
|| commande.equals("w"))
|
||||
&& command_line_split.length > 2) {
|
||||
try {
|
||||
String message = command_line.substring(1+commande.length()
|
||||
+1+command_line_split[1].length()
|
||||
+1); // "/"+commande+" "+pseudo+" "
|
||||
message = analyseString(message, op);
|
||||
command_line = "/"+commande+" "+command_line_split[1]+" "+message;
|
||||
} catch (IndexOutOfBoundsException e) { }
|
||||
}
|
||||
// ici, le message, c'est dès le troisième paramètre
|
||||
else if((commande.equals("mail")
|
||||
|| commande.equals("email"))
|
||||
&& command_line_split.length > 3) {
|
||||
try {
|
||||
String message = command_line.substring(1+commande.length()
|
||||
+1+command_line_split[1].length()
|
||||
+1+command_line_split[2].length()
|
||||
+1); // "/"+commande+" "+sub_command+" "+pseudo+" "
|
||||
message = analyseString(message, op);
|
||||
command_line = "/"+commande+" "+command_line_split[1]+" "+command_line_split[2]+" "+message;
|
||||
} catch (IndexOutOfBoundsException e) { }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (commande.equals("afk")
|
||||
|| commande.equals("away")
|
||||
|| commande.equals("time")
|
||||
|| commande.equals("day")
|
||||
|| commande.equals("night")
|
||||
|| commande.equals("me")
|
||||
|| commande.equals("action")
|
||||
|| commande.equals("describe")
|
||||
|| commande.equals("tpa")
|
||||
|| commande.equals("call")
|
||||
|| commande.equals("tpask")
|
||||
|| commande.equals("r")
|
||||
|| commande.equals("reply")
|
||||
|| commande.equals("msg")
|
||||
|| commande.equals("m")
|
||||
|| commande.equals("tell")
|
||||
|| commande.equals("t")
|
||||
|| commande.equals("whisper")
|
||||
|| commande.equals("w")
|
||||
|| commande.equals("mail")
|
||||
|| commande.equals("email"))
|
||||
{
|
||||
if (op.getLast_command() != null)
|
||||
{
|
||||
if (op.getLast_command().equals(command_line) && time - op.getLast_command_time() < ConfigManager.getInstance().ChatAnalysis_timeBeforeResendSameCommand)
|
||||
{
|
||||
event.getPlayer().sendMessage(ChatColor.RED+"Patientez avant de renvoyer cette commande !");
|
||||
if (op.getVL() >= ConfigManager.getInstance().ChatAnalysis_maxViolationLevel/2)
|
||||
event.setCancelled(true);
|
||||
op.addVL(5);
|
||||
event.setMessage(command_line);
|
||||
return;
|
||||
}
|
||||
}
|
||||
op.removeVL(NumberConversions.floor(((time - op.getLast_command_time())/1000)/ConfigManager.getInstance().ChatAnalysis_nbSecondForOneVLDown));
|
||||
|
||||
op.setLast_command(command_line);
|
||||
op.setLast_command_time(time);
|
||||
|
||||
event.setMessage(command_line);
|
||||
}
|
||||
} catch (NullPointerException e) { }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public ChatAnalysisPlayer getCAPlayer(Player p)
|
||||
private String analyseString(String s, OnlinePlayer op)
|
||||
{
|
||||
if (p == null || !p.isOnline())
|
||||
return null;
|
||||
for (ChatAnalysisPlayer ap : CAPlayers)
|
||||
|
||||
// évite les suites d'au moins 4 caractàres à la suite
|
||||
char[] cs = s.toCharArray();
|
||||
String r = s.substring(0, (s.length()>=3)?3:s.length());
|
||||
int nb_duplicated_char = 0;
|
||||
for (int i=3; i<cs.length; i++)
|
||||
{
|
||||
if (ap != null && ap.getPlayer() == p)
|
||||
return ap;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin (PlayerJoinEvent event)
|
||||
{
|
||||
int i=0;
|
||||
while (i<CAPlayers.length && CAPlayers[i] != null) i++;
|
||||
if (CAPlayers[i] == null) CAPlayers[i] = new ChatAnalysisPlayer(plugin, event.getPlayer());
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit (PlayerQuitEvent event)
|
||||
{
|
||||
|
||||
for (int i=0; i<CAPlayers.length; i++)
|
||||
{
|
||||
if (CAPlayers[i] == null)
|
||||
if (cs[i] == cs[i-1] && cs[i-1] == cs[i-2] && cs[i-2] == cs[i-3])
|
||||
{
|
||||
nb_duplicated_char++;
|
||||
continue;
|
||||
if (CAPlayers[i].getPlayer() == event.getPlayer())
|
||||
CAPlayers[i] = null;
|
||||
}
|
||||
|
||||
r = r.concat(String.valueOf(cs[i]));
|
||||
}
|
||||
|
||||
if (nb_duplicated_char > 0)
|
||||
{
|
||||
op.addVL(nb_duplicated_char/4+1);
|
||||
op.getPlayer().sendMessage(ChatColor.RED+"Evitez les répétitions de caractères !");
|
||||
|
||||
}
|
||||
|
||||
s = r;
|
||||
char[] sChar = s.toCharArray();
|
||||
char[] minChar = s.toLowerCase().toCharArray();
|
||||
|
||||
|
||||
// vérification des majuscules
|
||||
if (sChar.length > 5)
|
||||
{
|
||||
int nb_caps = 0;
|
||||
for (int i=0; i<sChar.length; i++)
|
||||
if (sChar[i] != minChar[i])
|
||||
nb_caps++;
|
||||
|
||||
if (nb_caps * 100 / sChar.length > 70 || nb_caps > 20)
|
||||
{
|
||||
// si plus de 70% des caractères sont majuscules
|
||||
// ou plus de 20 majuscules
|
||||
op.addVL(4);
|
||||
s = s.toLowerCase();
|
||||
op.getPlayer().sendMessage(ChatColor.RED+"Il y a trop de majuscules dans votre message, faites attention avant d'envoyer votre message ;)");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// traiter les insultes et masquage Pub ici
|
||||
|
||||
|
||||
// adresse IPv4 basique
|
||||
if (s.matches("(.*)([0-9]{1,3}\\.){3}[0-9]{1,3}(:[0-9]{1,5})?(.*)"))
|
||||
{
|
||||
s = s.replaceAll("[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}", "**.**.**.**");
|
||||
op.addVL(3);
|
||||
}
|
||||
|
||||
|
||||
// pour chaque insultes présentes dans la configuration du plugin
|
||||
for (String regex : ConfigManager.getInstance().ChatAnalysis_badWords)
|
||||
{
|
||||
if (s.matches("(?i:(.+[^a-zA-Z]|)"+regex+"(|[^a-zA-Z].+))"))
|
||||
{
|
||||
s = s.replaceAll("(?i:"+regex+")", "*****");
|
||||
op.addVL(5);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return s;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,342 +0,0 @@
|
||||
package net.mc_pandacraft.java.plugin.pandacraftutils.chat_analyzer;
|
||||
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.ConfigManager;
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.util.NumberConversions;
|
||||
|
||||
public class ChatAnalysisPlayer {
|
||||
private long time_before_resend_same_message = ConfigManager.getInstance().ChatAnalysis_timeBeforeResendSameMessage;// 30 sec
|
||||
private long time_before_resend_same_command = ConfigManager.getInstance().ChatAnalysis_timeBeforeResendSameCommand;// 30 sec
|
||||
|
||||
// définit si un message a été tapé super vite ou non
|
||||
/* pour un message reçu, on prends la durée depuis le message précédent,
|
||||
* et on le compare au produit de cette variable par le nombre de caractère du nouveau message
|
||||
* */
|
||||
private long time_per_caracter_for_new_message = ConfigManager.getInstance().ChatAnalysis_timePerCaracterForNewMessage;// 0.1 sec
|
||||
|
||||
private int max_violation_level = ConfigManager.getInstance().ChatAnalysis_maxViolationLevel;
|
||||
|
||||
private int nb_second_for_1_vl_down = ConfigManager.getInstance().ChatAnalysis_nbSecondForOneVLDown;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private Player player;
|
||||
private PandacraftUtils plugin;
|
||||
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 ChatAnalysisPlayer(PandacraftUtils pl, Player p)
|
||||
{
|
||||
player = p;
|
||||
plugin = pl;
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void addVL(int nb)
|
||||
{
|
||||
violation_level += nb;
|
||||
plugin.getLogger().info("ViolationLevel for player "+player.getDisplayName()+"§r : +"+nb+" -> "+violation_level);
|
||||
if (violation_level >= max_violation_level)
|
||||
Bukkit.getScheduler().runTaskLater(plugin, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
player.kickPlayer("Les spams/insultes/publicités sont interdits !");
|
||||
}
|
||||
}, 1L);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void removeVL(int nb)
|
||||
{
|
||||
violation_level -= nb;
|
||||
if (violation_level < 0) violation_level = 0;
|
||||
}
|
||||
|
||||
|
||||
public int getVL() { return violation_level; }
|
||||
public int getMaxVL() { return max_violation_level; }
|
||||
|
||||
|
||||
public Player getPlayer() { return player; }
|
||||
|
||||
|
||||
|
||||
public void onAsyncPlayerChat(AsyncPlayerChatEvent event)
|
||||
{
|
||||
if (event.getPlayer() != player)
|
||||
return;
|
||||
if (event.getPlayer().hasPermission("pandacraft.antispam.exempt"))
|
||||
return;
|
||||
String message = event.getMessage();
|
||||
long time = System.currentTimeMillis();
|
||||
if (last_message != null)
|
||||
{
|
||||
if (last_message.equals(message) && time - last_message_time < time_before_resend_same_message)
|
||||
{
|
||||
event.getPlayer().sendMessage(ChatColor.RED+"Evitez de renvoyer le même message !");
|
||||
if (violation_level >= max_violation_level/2)
|
||||
event.setCancelled(true);
|
||||
else
|
||||
event.setMessage(analyseString(message));
|
||||
addVL(5);
|
||||
return;
|
||||
}
|
||||
else
|
||||
{
|
||||
long time_since_last_message = time - last_message_time;
|
||||
long timeout_needed = message.length() * time_per_caracter_for_new_message;
|
||||
if (time_since_last_message < timeout_needed)
|
||||
{
|
||||
|
||||
event.getPlayer().sendMessage(ChatColor.RED+"Vous parlez un peu trop vite, ralentissez x)");
|
||||
addVL(4);
|
||||
event.setMessage(analyseString(message));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
message = analyseString(message);
|
||||
|
||||
event.setMessage(message);
|
||||
|
||||
removeVL(NumberConversions.floor(((time - last_message_time)/1000)/nb_second_for_1_vl_down));
|
||||
|
||||
|
||||
last_message = message;
|
||||
last_message_time = time;
|
||||
}
|
||||
|
||||
public void onPlayerCommandPreprocess (PlayerCommandPreprocessEvent event)
|
||||
{
|
||||
if (event.getPlayer() != player)
|
||||
return;
|
||||
if (event.getPlayer().hasPermission("pandacraft.antispam.exempt"))
|
||||
return;
|
||||
String command_line = event.getMessage();
|
||||
String[] command_line_split = event.getMessage().split(" ");
|
||||
long time = System.currentTimeMillis();
|
||||
String commande = command_line_split[0].substring(1).toLowerCase();
|
||||
|
||||
if (commande.equals("")) return;
|
||||
|
||||
// traitement du contenu des messages (si elle existe, comme MP ou /me)
|
||||
// ici, le message, c'est dès le permier paramètre
|
||||
if ((commande.equals("me")
|
||||
|| commande.equals("action")
|
||||
|| commande.equals("describe")
|
||||
|| commande.equals("r")
|
||||
|| commande.equals("reply"))
|
||||
&& command_line_split.length > 1) {
|
||||
try {
|
||||
String message = command_line.substring(1+commande.length()+1); // "/"+commande+" "
|
||||
message = analyseString(message);
|
||||
command_line = "/"+commande+" "+message;
|
||||
} catch (IndexOutOfBoundsException e) { }
|
||||
|
||||
}
|
||||
// ici, le message, c'est dès le deuxième paramètre
|
||||
else if((commande.equals("msg")
|
||||
|| commande.equals("m")
|
||||
|| commande.equals("tell")
|
||||
|| commande.equals("t")
|
||||
|| commande.equals("whisper")
|
||||
|| commande.equals("w"))
|
||||
&& command_line_split.length > 2) {
|
||||
try {
|
||||
String message = command_line.substring(1+commande.length()
|
||||
+1+command_line_split[1].length()
|
||||
+1); // "/"+commande+" "+pseudo+" "
|
||||
message = analyseString(message);
|
||||
command_line = "/"+commande+" "+command_line_split[1]+" "+message;
|
||||
} catch (IndexOutOfBoundsException e) { }
|
||||
}
|
||||
// ici, le message, c'est dès le troisième paramètre
|
||||
else if((commande.equals("mail")
|
||||
|| commande.equals("email"))
|
||||
&& command_line_split.length > 3) {
|
||||
try {
|
||||
String message = command_line.substring(1+commande.length()
|
||||
+1+command_line_split[1].length()
|
||||
+1+command_line_split[2].length()
|
||||
+1); // "/"+commande+" "+sub_command+" "+pseudo+" "
|
||||
message = analyseString(message);
|
||||
command_line = "/"+commande+" "+command_line_split[1]+" "+command_line_split[2]+" "+message;
|
||||
} catch (IndexOutOfBoundsException e) { }
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (commande.equals("afk")
|
||||
|| commande.equals("away")
|
||||
|| commande.equals("time")
|
||||
|| commande.equals("day")
|
||||
|| commande.equals("night")
|
||||
|| commande.equals("me")
|
||||
|| commande.equals("action")
|
||||
|| commande.equals("describe")
|
||||
|| commande.equals("tpa")
|
||||
|| commande.equals("call")
|
||||
|| commande.equals("tpask")
|
||||
|| commande.equals("r")
|
||||
|| commande.equals("reply")
|
||||
|| commande.equals("msg")
|
||||
|| commande.equals("m")
|
||||
|| commande.equals("tell")
|
||||
|| commande.equals("t")
|
||||
|| commande.equals("whisper")
|
||||
|| commande.equals("w")
|
||||
|| commande.equals("mail")// reste à traiter pour la censure
|
||||
|| commande.equals("email"))// reste à traiter pour la censure
|
||||
{
|
||||
if (last_command != null)
|
||||
{
|
||||
if (last_command.equals(command_line) && time - last_command_time < time_before_resend_same_command)
|
||||
{
|
||||
event.getPlayer().sendMessage(ChatColor.RED+"Patientez avant de renvoyer cette commande !");
|
||||
if (violation_level >= max_violation_level/2)
|
||||
event.setCancelled(true);
|
||||
addVL(5);
|
||||
event.setMessage(command_line);
|
||||
return;
|
||||
}
|
||||
}
|
||||
removeVL(NumberConversions.floor(((time - last_command_time)/1000)/nb_second_for_1_vl_down));
|
||||
|
||||
last_command = command_line;
|
||||
last_command_time = time;
|
||||
|
||||
event.setMessage(command_line);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private String analyseString(String s)
|
||||
{
|
||||
|
||||
// évite les suites d'au moins 4 caractàres à la suite
|
||||
char[] cs = s.toCharArray();
|
||||
String r = s.substring(0, (s.length()>=3)?3:s.length());
|
||||
int nb_duplicated_char = 0;
|
||||
for (int i=3; i<cs.length; i++)
|
||||
{
|
||||
if (cs[i] == cs[i-1] && cs[i-1] == cs[i-2] && cs[i-2] == cs[i-3])
|
||||
{
|
||||
nb_duplicated_char++;
|
||||
continue;
|
||||
}
|
||||
|
||||
r = r.concat(String.valueOf(cs[i]));
|
||||
}
|
||||
|
||||
if (nb_duplicated_char > 0)
|
||||
{
|
||||
addVL(nb_duplicated_char/4+1);
|
||||
player.sendMessage(ChatColor.RED+"Evitez les répétitions de caractères !");
|
||||
|
||||
}
|
||||
|
||||
s = r;
|
||||
char[] sChar = s.toCharArray();
|
||||
char[] minChar = s.toLowerCase().toCharArray();
|
||||
|
||||
|
||||
// vérification des majuscules
|
||||
if (sChar.length > 5)
|
||||
{
|
||||
int nb_caps = 0;
|
||||
for (int i=0; i<sChar.length; i++)
|
||||
if (sChar[i] != minChar[i])
|
||||
nb_caps++;
|
||||
|
||||
if (nb_caps * 100 / sChar.length > 70 || nb_caps > 20)
|
||||
{
|
||||
// si plus de 70% des caractères sont majuscules
|
||||
// ou plus de 20 majuscules
|
||||
addVL(4);
|
||||
s = s.toLowerCase();
|
||||
player.sendMessage(ChatColor.RED+"Il y a trop de majuscules dans votre message, faites attention avant d'envoyer votre message ;)");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// traiter les insultes et masquage Pub ici
|
||||
|
||||
|
||||
// adresse IPv4 basique
|
||||
if (s.matches("(.*)([0-9]{1,3}\\.){3}[0-9]{1,3}(:[0-9]{1,5})?(.*)"))
|
||||
{
|
||||
s = s.replaceAll("[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}", "**.**.**.**");
|
||||
addVL(3);
|
||||
}
|
||||
|
||||
|
||||
// pour chaque insultes présentes dans la configuration du plugin
|
||||
for (String regex : ConfigManager.getInstance().ChatAnalysis_badWords)
|
||||
{
|
||||
if (s.matches("(?i:(.+[^a-zA-Z]|)"+regex+"(|[^a-zA-Z].+))"))
|
||||
{
|
||||
s = s.replaceAll("(?i:"+regex+")", "*****");
|
||||
addVL(5);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return s;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,163 @@
|
||||
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); }
|
||||
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
package net.mc_pandacraft.java.plugin.pandacraftutils.players;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
|
||||
public final class OnlinePlayerManager implements Listener {
|
||||
|
||||
private static OnlinePlayerManager instance;
|
||||
|
||||
/**
|
||||
* Retourne l'unique instance de la classe. Si elle n'existe pas, on tente de créer
|
||||
* @return L'unique instance de la classe
|
||||
*/
|
||||
|
||||
public synchronized static OnlinePlayerManager getInstance() {
|
||||
if (instance == null)
|
||||
loadNewInstance();
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static void loadNewInstance() {
|
||||
instance = new OnlinePlayerManager();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
HashMap<Player, OnlinePlayer> players = new HashMap<Player, OnlinePlayer>();
|
||||
|
||||
private OnlinePlayerManager() {
|
||||
|
||||
// en cas de /reload : on ajoute les joueurs déjà en ligne
|
||||
for (Player p : PandacraftUtils.getInstance().getServer().getOnlinePlayers())
|
||||
players.put(p, new OnlinePlayer(p));
|
||||
|
||||
|
||||
PandacraftUtils.getInstance().getServer().getPluginManager().registerEvents(this, PandacraftUtils.getInstance());
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ----------------------------------------
|
||||
// -------------- Evènements --------------
|
||||
// ----------------------------------------
|
||||
@EventHandler
|
||||
public void onPlayerJoin (PlayerJoinEvent event)
|
||||
{
|
||||
players.put(event.getPlayer(), new OnlinePlayer(event.getPlayer()));
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerQuit (PlayerQuitEvent event)
|
||||
{
|
||||
players.remove(event.getPlayer());
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public OnlinePlayer get(Player p) {
|
||||
return players.get(p);
|
||||
}
|
||||
|
||||
public Collection<OnlinePlayer> getAll() {
|
||||
return players.values();
|
||||
}
|
||||
|
||||
|
||||
public boolean contains(Player p) {
|
||||
return players.containsKey(p);
|
||||
}
|
||||
|
||||
}
|
@ -2,8 +2,10 @@ package net.mc_pandacraft.java.plugin.pandacraftutils.simple_commands.list;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.ConfigManager;
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils;
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.afk.AfkPlayer;
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayer;
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayerManager;
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.plugin_interface.EssentialsInterface;
|
||||
import net.mc_pandacraft.java.util.TimeUtil;
|
||||
|
||||
@ -160,8 +162,8 @@ public class CommandList implements CommandExecutor {
|
||||
{
|
||||
try
|
||||
{
|
||||
int vl = plugin.chatAnalysisManager.getCAPlayer(p).getVL();
|
||||
int max_vl = plugin.chatAnalysisManager.getCAPlayer(p).getMaxVL();
|
||||
int vl = OnlinePlayerManager.getInstance().get(p).getVL();
|
||||
int max_vl = ConfigManager.getInstance().ChatAnalysis_maxViolationLevel;
|
||||
aff_list.add("§f"+name+"§r - §7"+vl+"/"+max_vl);
|
||||
|
||||
}
|
||||
@ -172,9 +174,9 @@ public class CommandList implements CommandExecutor {
|
||||
}
|
||||
else if (args.length > 0 && args[0].toLowerCase().equals("afk"))
|
||||
{
|
||||
AfkPlayer ap = plugin.commandAfk.getAfkPlayer(p);
|
||||
boolean afk = (ap != null && ap.isAfk());
|
||||
double afk_time = (ap != null)?ap.getDurationSinceLastAction():-1;
|
||||
OnlinePlayer op = OnlinePlayerManager.getInstance().get(p);
|
||||
boolean afk = (op != null && op.isAfk());
|
||||
double afk_time = (op != null)?op.getDurationSinceLastAction():-1;
|
||||
String afkTime;
|
||||
if (afk_time > 20)
|
||||
afkTime = TimeUtil.durationToString((long)(afk_time*1000));
|
||||
@ -193,7 +195,7 @@ public class CommandList implements CommandExecutor {
|
||||
:(p.getGameMode() == GameMode.CREATIVE)?"§bCréa§r"
|
||||
:(p.getGameMode() == GameMode.ADVENTURE)?("§8Aventure§r;vie:§7"+health+"§r;faim:§7"+eat+"§r"+((flyMode)?";§7canFly":""))
|
||||
:"§oInconnu";
|
||||
String afk = (plugin.commandAfk.getAfkPlayer(p) != null && plugin.commandAfk.getAfkPlayer(p).isAfk())?" §c(Afk)§r":"";
|
||||
String afk = (OnlinePlayerManager.getInstance().get(p) != null && OnlinePlayerManager.getInstance().get(p).isAfk())?" §c(Afk)§r":"";
|
||||
aff_list.add("§f"+name+"§r"+afk+" - §7"+world+"§r - "+gm);
|
||||
}
|
||||
else
|
||||
|
@ -1,12 +1,11 @@
|
||||
package net.mc_pandacraft.java.plugin.pandacraftutils.survival_cuboid;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils;
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayer;
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayerManager;
|
||||
import net.mc_pandacraft.java.plugin.pandacraftutils.plugin_interface.WorldEditInterface;
|
||||
import net.mc_pandacraft.java.util.bukkit.protocol.ParticleEffect;
|
||||
|
||||
@ -16,21 +15,14 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandExecutor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.sk89q.worldedit.bukkit.selections.CuboidSelection;
|
||||
|
||||
public class CommandWandSelection extends BukkitRunnable implements CommandExecutor, Listener {
|
||||
public class CommandWandSelection extends BukkitRunnable implements CommandExecutor {
|
||||
|
||||
private PandacraftUtils plugin;
|
||||
|
||||
private Map<Player, List<Player>> players = new HashMap<Player, List<Player>>();
|
||||
|
||||
|
||||
|
||||
public CommandWandSelection(PandacraftUtils pl)
|
||||
{
|
||||
@ -38,10 +30,6 @@ public class CommandWandSelection extends BukkitRunnable implements CommandExecu
|
||||
|
||||
plugin.getCommand("/selection").setExecutor(this);
|
||||
plugin.getServer().getScheduler().runTaskTimer(plugin, this, 20L, 20L);
|
||||
plugin.getServer().getPluginManager().registerEvents(this, plugin);
|
||||
|
||||
for (Player p : plugin.getServer().getOnlinePlayers())
|
||||
players.put(p, new ArrayList<Player>());
|
||||
}
|
||||
|
||||
|
||||
@ -70,6 +58,7 @@ public class CommandWandSelection extends BukkitRunnable implements CommandExecu
|
||||
}
|
||||
|
||||
Player p = (Player) sender;
|
||||
OnlinePlayer op = OnlinePlayerManager.getInstance().get(p);
|
||||
|
||||
|
||||
Player otherP = null;
|
||||
@ -84,31 +73,31 @@ public class CommandWandSelection extends BukkitRunnable implements CommandExecu
|
||||
}
|
||||
|
||||
|
||||
if (players.containsKey(p) && otherP == null)
|
||||
if (op.canViewWESelection() && otherP == null)
|
||||
{ // le joueur ne veut plus voir de cubo
|
||||
players.remove(p);
|
||||
op.disableViewingWESelection();
|
||||
sender.sendMessage(ChatColor.GREEN+"Affichage de la sélection désactivé.");
|
||||
}
|
||||
else if (players.containsKey(p))
|
||||
else if (op.canViewWESelection())
|
||||
{
|
||||
if (players.get(p).contains(otherP))
|
||||
if (op.hasPlayerForWiewingHisWESelection(otherP))
|
||||
{
|
||||
players.get(p).remove(otherP);
|
||||
op.removePlayerForWiewingHisWESelection(otherP);
|
||||
sender.sendMessage(ChatColor.GREEN+"Affichage de la sélection de "+ChatColor.GRAY+otherP.getName()+ChatColor.GREEN+" désactivé.");
|
||||
}
|
||||
else
|
||||
{
|
||||
players.get(p).add(otherP);
|
||||
op.addPlayerForWiewingHisWESelection(otherP);
|
||||
sender.sendMessage(ChatColor.GREEN+"Affichage de la sélection de "+ChatColor.GRAY+otherP.getName()+ChatColor.GREEN+" activé.");
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
players.put(p, new ArrayList<Player>());
|
||||
op.enableViewingWESelection();
|
||||
sender.sendMessage(ChatColor.GREEN+"Affichage de la sélection activé. Si vous ne voyez pas les particules, activez les dans vos options Minecraft.");
|
||||
if (otherP != null) {
|
||||
players.get(p).add(otherP);
|
||||
op.addPlayerForWiewingHisWESelection(otherP);
|
||||
sender.sendMessage(ChatColor.GREEN+"Affichage de la sélection de "+ChatColor.GRAY+otherP.getName()+ChatColor.GREEN+" activé.");
|
||||
}
|
||||
}
|
||||
@ -117,24 +106,6 @@ public class CommandWandSelection extends BukkitRunnable implements CommandExecu
|
||||
}
|
||||
|
||||
|
||||
// supprime automatiquement un joueur qui se déconnecte
|
||||
@EventHandler
|
||||
public void onPlayerQuit(PlayerQuitEvent event)
|
||||
{
|
||||
if (players.containsKey(event.getPlayer()))
|
||||
players.remove(event.getPlayer());
|
||||
}
|
||||
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerJoin(PlayerJoinEvent event)
|
||||
{
|
||||
if (!players.containsKey(event.getPlayer()))
|
||||
players.put(event.getPlayer(), new ArrayList<Player>());
|
||||
}
|
||||
|
||||
|
||||
|
||||
// pour mettre à jour l'affichage du cubo
|
||||
@Override
|
||||
public void run() {
|
||||
@ -143,23 +114,22 @@ public class CommandWandSelection extends BukkitRunnable implements CommandExecu
|
||||
try
|
||||
{
|
||||
|
||||
for (Entry<Player, List<Player>> pl : players.entrySet())
|
||||
for (OnlinePlayer op : OnlinePlayerManager.getInstance().getAll())
|
||||
{
|
||||
Player p = pl.getKey();
|
||||
Player p = op.getPlayer();
|
||||
// on vérifie que le joueur soit en ligne
|
||||
if (p == null || !p.isOnline())
|
||||
continue;
|
||||
|
||||
if (!op.canViewWESelection()) continue; // le joueur ne veut pas voir de cubo
|
||||
|
||||
CuboidSelection cubo = WorldEditInterface.getPlayerCuboSelection(p);
|
||||
|
||||
// le joueur doit être dans le même monde que sa propre sélection
|
||||
if (cubo != null && cubo.getWorld() == p.getWorld())
|
||||
drawCuboid(cubo, p, true);
|
||||
|
||||
if (pl.getValue() == null)
|
||||
continue;
|
||||
|
||||
for (Player po : pl.getValue()){
|
||||
for (Player po : op.getPlayersForViewingOthersWESelections()){
|
||||
if (po == null || !po.isOnline()) continue;
|
||||
|
||||
cubo = WorldEditInterface.getPlayerCuboSelection(po);
|
||||
|
Loading…
Reference in New Issue
Block a user