Masquage des messages privés avant le /login + ajout des informations dans le tooltip des messages privés
This commit is contained in:
parent
19960a6dfe
commit
a5d5ff78fd
@ -3,7 +3,7 @@ package net.mc_pandacraft.java.plugin.pandacraftutils.modules;
|
|||||||
import java.sql.Date;
|
import java.sql.Date;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.util.Arrays;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
@ -17,6 +17,8 @@ import net.mc_pandacraft.java.plugin.pandacraftutils.data_model.MPGroupUserEleme
|
|||||||
import net.mc_pandacraft.java.plugin.pandacraftutils.data_model.MPGroupUserTable;
|
import net.mc_pandacraft.java.plugin.pandacraftutils.data_model.MPGroupUserTable;
|
||||||
import net.mc_pandacraft.java.plugin.pandacraftutils.data_model.MPMessageElement;
|
import net.mc_pandacraft.java.plugin.pandacraftutils.data_model.MPMessageElement;
|
||||||
import net.mc_pandacraft.java.plugin.pandacraftutils.data_model.MPMessageTable;
|
import net.mc_pandacraft.java.plugin.pandacraftutils.data_model.MPMessageTable;
|
||||||
|
import net.mc_pandacraft.java.plugin.pandacraftutils.data_model.MPWebSessionElement;
|
||||||
|
import net.mc_pandacraft.java.plugin.pandacraftutils.data_model.MPWebSessionTable;
|
||||||
import net.mc_pandacraft.java.plugin.pandacraftutils.data_model.ORM;
|
import net.mc_pandacraft.java.plugin.pandacraftutils.data_model.ORM;
|
||||||
import net.mc_pandacraft.java.plugin.pandacraftutils.players.OffPlayer;
|
import net.mc_pandacraft.java.plugin.pandacraftutils.players.OffPlayer;
|
||||||
import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayer;
|
import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayer;
|
||||||
@ -34,6 +36,9 @@ public class PrivateMessagesManager extends BukkitRunnable {
|
|||||||
private PandacraftUtils plugin = PandacraftUtils.getInstance();
|
private PandacraftUtils plugin = PandacraftUtils.getInstance();
|
||||||
|
|
||||||
|
|
||||||
|
private static final long TIMEOUT_WEB_SESSION = 10000; // msec
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public PrivateMessagesManager()
|
public PrivateMessagesManager()
|
||||||
{
|
{
|
||||||
@ -299,10 +304,6 @@ public class PrivateMessagesManager extends BukkitRunnable {
|
|||||||
|
|
||||||
OnlinePlayer op = OnlinePlayerManager.get(new OffPlayer(message.getViewerNick()).getBukkitOnlinePlayer());
|
OnlinePlayer op = OnlinePlayerManager.get(new OffPlayer(message.getViewerNick()).getBukkitOnlinePlayer());
|
||||||
|
|
||||||
if (op == null) return; // la cible n'est pas en ligne
|
|
||||||
|
|
||||||
if (!op.isAuthenticated()) return; // la cible n'a pas fait son /login
|
|
||||||
|
|
||||||
MessageSender sender = new MessageSender(message.getSourceNick());
|
MessageSender sender = new MessageSender(message.getSourceNick());
|
||||||
|
|
||||||
boolean isIgnoring = sender.isPlayer() && op.getEssentialsUser().isIgnoredPlayer(new OffPlayer(message.getSourceNick()).getEssentialsUser());
|
boolean isIgnoring = sender.isPlayer() && op.getEssentialsUser().isIgnoredPlayer(new OffPlayer(message.getSourceNick()).getEssentialsUser());
|
||||||
@ -310,83 +311,109 @@ public class PrivateMessagesManager extends BukkitRunnable {
|
|||||||
|
|
||||||
if (isIgnoring) {
|
if (isIgnoring) {
|
||||||
message.delete();
|
message.delete();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (op == null) return; // la cible n'est pas en ligne
|
||||||
|
|
||||||
|
if (!op.isAuthenticated()) return; // la cible n'a pas fait son /login
|
||||||
|
|
||||||
|
|
||||||
|
message.setRead(true);
|
||||||
|
message.save();
|
||||||
|
|
||||||
|
// le message est affiché sur l'écran de la source du message
|
||||||
|
boolean dispToSender = (message.getViewerNick().equalsIgnoreCase(message.getSourceNick()));
|
||||||
|
|
||||||
|
// -------
|
||||||
|
// tooltip
|
||||||
|
// -------
|
||||||
|
|
||||||
|
Date d = new Date(message.getTime());
|
||||||
|
DateFormat date = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.FRANCE);
|
||||||
|
DateFormat hour = DateFormat.getTimeInstance(DateFormat.MEDIUM, Locale.FRANCE);
|
||||||
|
|
||||||
|
String affDate = date.format(d) + " à " + hour.format(d);
|
||||||
|
|
||||||
|
List<String> tooltipLines = new ArrayList<String>();
|
||||||
|
tooltipLines.add(ChatColor.GRAY+affDate);
|
||||||
|
tooltipLines.add(ChatColor.GRAY+"de "+ChatColor.RESET+new OffPlayer(message.getSourceNick()).getDisplayName()+ChatColor.GRAY+" ("+displayablePlayerStatus(getPlayerStatut(message.getSourceNick()))+ChatColor.GRAY+")");
|
||||||
|
if (message.getDestGroup() == null) // vers un joueur
|
||||||
|
tooltipLines.add(ChatColor.GRAY+"vers "+ChatColor.RESET+new OffPlayer(message.getDestNick()).getDisplayName()+ChatColor.GRAY+" ("+displayablePlayerStatus(getPlayerStatut(message.getDestNick()))+ChatColor.GRAY+")");
|
||||||
|
else { // vers un groupe
|
||||||
|
MPGroupElement groupEl = message.getDestGroupElement();
|
||||||
|
|
||||||
|
tooltipLines.add(ChatColor.GRAY+"vers le groupe "+ChatColor.GOLD+groupEl.getGroupName());
|
||||||
|
|
||||||
|
List<MPGroupUserElement> groupUsers = groupEl.getUsers();
|
||||||
|
|
||||||
|
for (MPGroupUserElement gUser : groupUsers) {
|
||||||
|
if (!gUser.getPlayerName().equalsIgnoreCase(message.getSourceNick()))
|
||||||
|
tooltipLines.add(ChatColor.GRAY+"- "+ChatColor.RESET+new OffPlayer(gUser.getPlayerName()).getDisplayName()+ChatColor.GRAY+" ("+displayablePlayerStatus(getPlayerStatut(gUser.getPlayerName()))+ChatColor.GRAY+")");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------
|
||||||
|
|
||||||
|
|
||||||
|
if (dispToSender) {
|
||||||
|
|
||||||
|
String destAff = (message.getDestGroup() == null)?
|
||||||
|
( (message.getDestNick().equalsIgnoreCase(message.getViewerNick())) ?
|
||||||
|
"moi":
|
||||||
|
new OffPlayer(message.getDestNick()).getDisplayName()
|
||||||
|
):
|
||||||
|
"g:"+message.getDestGroupElement().getGroupName();
|
||||||
|
|
||||||
|
String destCommand = (message.getDestGroup() == null)?
|
||||||
|
message.getDestNick():
|
||||||
|
"g:"+message.getDestGroupElement().getGroupName();
|
||||||
|
|
||||||
|
tooltipLines.add(0, ChatColor.GRAY+"(Cliquez pour répondre)");
|
||||||
|
|
||||||
|
new FancyMessage("")
|
||||||
|
.then("§6<§rmoi§6 → §r"+destAff+"§r§6>")
|
||||||
|
.suggest("/m "+destCommand+" ")
|
||||||
|
.tooltip(tooltipLines)
|
||||||
|
.then(" §6"+ChatColor.translateAlternateColorCodes('&', message.getMessage()))
|
||||||
|
.color(ChatColor.GOLD)
|
||||||
|
.send(op.getPlayer());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
message.setRead(true);
|
|
||||||
message.save();
|
|
||||||
|
|
||||||
// le message est affiché sur l'écran de la source du message
|
|
||||||
boolean dispToSender = (message.getViewerNick().equalsIgnoreCase(message.getSourceNick()));
|
|
||||||
|
|
||||||
|
|
||||||
Date d = new Date(message.getTime());
|
String senderAff = new MessageSender(message.getSourceNick()).getDisplayName();
|
||||||
DateFormat date = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.FRANCE);
|
|
||||||
DateFormat hour = DateFormat.getTimeInstance(DateFormat.MEDIUM, Locale.FRANCE);
|
|
||||||
|
|
||||||
String affDate = date.format(d) + " à " + hour.format(d);
|
|
||||||
|
|
||||||
|
|
||||||
List<String> tooltipLines = Arrays.asList(new String[] {
|
String destAff = (message.getDestGroup() == null)?
|
||||||
ChatColor.GRAY+"(Cliquez pour répondre)",
|
((message.getDestNick().equalsIgnoreCase(message.getViewerNick()))?
|
||||||
ChatColor.GRAY+affDate,
|
"moi":
|
||||||
});
|
new OffPlayer(message.getDestNick()).getDisplayName()):
|
||||||
|
"g:"+message.getDestGroupElement().getGroupName();
|
||||||
|
|
||||||
|
String destCommand = (message.getDestGroup() == null)?
|
||||||
|
message.getSourceNick():
|
||||||
|
"g:"+message.getDestGroupElement().getGroupName();
|
||||||
|
|
||||||
if (dispToSender) {
|
if (message.getSourceNick() != null)
|
||||||
|
tooltipLines.add(0, ChatColor.GRAY+"(Cliquez pour répondre)");
|
||||||
String destAff = (message.getDestGroup() == null)?
|
|
||||||
( (message.getDestNick().equalsIgnoreCase(message.getViewerNick())) ?
|
|
||||||
"moi":
|
|
||||||
new OffPlayer(message.getDestNick()).getDisplayName()
|
|
||||||
):
|
|
||||||
"g:"+message.getDestGroupElement().getGroupName();
|
|
||||||
|
|
||||||
String destCommand = (message.getDestGroup() == null)?
|
|
||||||
message.getDestNick():
|
|
||||||
"g:"+message.getDestGroupElement().getGroupName();
|
|
||||||
|
|
||||||
|
|
||||||
new FancyMessage("")
|
|
||||||
.then("§6<§rmoi§6 → §r"+destAff+"§r§6>")
|
|
||||||
.suggest("/m "+destCommand+" ")
|
|
||||||
.tooltip(tooltipLines)
|
|
||||||
.then(" §6"+ChatColor.translateAlternateColorCodes('&', message.getMessage()))
|
|
||||||
.color(ChatColor.GOLD)
|
|
||||||
.send(op.getPlayer());
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
|
|
||||||
|
|
||||||
String senderAff = new MessageSender(message.getSourceNick()).getDisplayName();
|
|
||||||
|
|
||||||
|
|
||||||
String destAff = (message.getDestGroup() == null)?
|
|
||||||
((message.getDestNick().equalsIgnoreCase(message.getViewerNick()))?
|
|
||||||
"moi":
|
|
||||||
new OffPlayer(message.getDestNick()).getDisplayName()):
|
|
||||||
"g:"+message.getDestGroupElement().getGroupName();
|
|
||||||
|
|
||||||
String destCommand = (message.getDestGroup() == null)?
|
|
||||||
message.getSourceNick():
|
|
||||||
"g:"+message.getDestGroupElement().getGroupName();
|
|
||||||
|
|
||||||
|
|
||||||
FancyMessage fm = new FancyMessage("")
|
|
||||||
.then("§6<§r"+senderAff+"§r§6 → §r"+destAff+"§r§6>");
|
|
||||||
if (message.getSourceNick() != null)
|
|
||||||
fm.suggest("/m "+destCommand+" ");
|
|
||||||
fm.tooltip(tooltipLines)
|
|
||||||
.then(" §6"+ChatColor.translateAlternateColorCodes('&', message.getMessage()))
|
|
||||||
.color(ChatColor.GOLD)
|
|
||||||
.send(op.getPlayer());
|
|
||||||
|
|
||||||
// op.getPlayer().playSound(op.getPlayer().getLocation(), Sound.ORB_PICKUP, 1, 0.3F);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
FancyMessage fm = new FancyMessage("")
|
||||||
|
.then("§6<§r"+senderAff+"§r§6 → §r"+destAff+"§r§6>");
|
||||||
|
if (message.getSourceNick() != null)
|
||||||
|
fm.suggest("/m "+destCommand+" ");
|
||||||
|
fm.tooltip(tooltipLines)
|
||||||
|
.then(" §6"+ChatColor.translateAlternateColorCodes('&', message.getMessage()))
|
||||||
|
.color(ChatColor.GOLD)
|
||||||
|
.send(op.getPlayer());
|
||||||
|
|
||||||
|
// op.getPlayer().playSound(op.getPlayer().getLocation(), Sound.ORB_PICKUP, 1, 0.3F);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
plugin.getLogger().severe("Impossible d'afficher un message");
|
plugin.getLogger().severe("Impossible d'afficher un message");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@ -458,6 +485,55 @@ public class PrivateMessagesManager extends BukkitRunnable {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private PlayerStatut getPlayerStatut(String playerName) {
|
||||||
|
if (!AbstractCommandExecutor.isValidPlayerName(playerName))
|
||||||
|
return PlayerStatut.OFFLINE;
|
||||||
|
OnlinePlayer op = OnlinePlayerManager.get(playerName);
|
||||||
|
if (op != null)
|
||||||
|
return op.isAfk() ? PlayerStatut.AFK_IG : PlayerStatut.ONLINE_IG;
|
||||||
|
|
||||||
|
try {
|
||||||
|
MPWebSessionElement webSession = ((MPWebSessionTable)ORM.getTable("mp_web_session")).getFirst("playerName LIKE '"+playerName+"'", null);
|
||||||
|
|
||||||
|
if (webSession != null) {
|
||||||
|
long lastWebActivity = webSession.getLastWebActivity();
|
||||||
|
|
||||||
|
if (System.currentTimeMillis() - lastWebActivity < TIMEOUT_WEB_SESSION)
|
||||||
|
return PlayerStatut.ONLINE_WEB;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return PlayerStatut.OFFLINE;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private String displayablePlayerStatus(PlayerStatut ps) {
|
||||||
|
if (ps == PlayerStatut.ONLINE_IG)
|
||||||
|
return ChatColor.GREEN+"En ligne, IG";
|
||||||
|
if (ps == PlayerStatut.AFK_IG)
|
||||||
|
return ChatColor.YELLOW+"AFK, IG";
|
||||||
|
if (ps == PlayerStatut.ONLINE_WEB)
|
||||||
|
return ChatColor.GOLD+"En ligne, web";
|
||||||
|
if (ps == PlayerStatut.OFFLINE)
|
||||||
|
return ChatColor.GRAY+"Hors ligne";
|
||||||
|
return ChatColor.WHITE+"N/A";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public enum PlayerStatut {
|
||||||
|
ONLINE_IG, AFK_IG, ONLINE_WEB, OFFLINE
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static class MessageSender {
|
public static class MessageSender {
|
||||||
public final String senderName;
|
public final String senderName;
|
||||||
|
@ -9,6 +9,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils;
|
import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
@ -79,6 +80,15 @@ public final class OnlinePlayerManager {
|
|||||||
return getInstance().players.get(p);
|
return getInstance().players.get(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Insensible à la casse
|
||||||
|
* @param p le pseudo du joueur recherché
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static OnlinePlayer get(String p) {
|
||||||
|
return get(Bukkit.getServer().getPlayerExact(p));
|
||||||
|
}
|
||||||
|
|
||||||
public synchronized static List<OnlinePlayer> getAll() {
|
public synchronized static List<OnlinePlayer> getAll() {
|
||||||
return new ArrayList<OnlinePlayer>(getInstance().players.values());
|
return new ArrayList<OnlinePlayer>(getInstance().players.values());
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user