From 19960a6dfe989ef5f78d7f6b9f84f89662acfef3 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Tue, 12 May 2015 01:25:40 +0200 Subject: [PATCH] =?UTF-8?q?Correctifs=20et=20derni=C3=A8res=20fonctionnali?= =?UTF-8?q?t=C3=A9s=20de=20la=20messagerie=20priv=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- make_jar.jardesc | 2 +- resources/plugin.yml | 7 +- .../pandacraftutils/commands/CommandMail.java | 4 +- .../commands/CommandReply.java | 64 +++++++++++++++++++ .../PandacraftUtilsCommandsManager.java | 1 + .../listener/XAuthListener.java | 4 ++ .../modules/PrivateMessagesManager.java | 64 +++++++++++++++---- .../RequestExecutorPrivateMessage.java | 60 ++++------------- .../pandacraftutils/players/OffPlayer.java | 6 ++ .../pandacraftutils/players/OnlinePlayer.java | 6 +- 10 files changed, 150 insertions(+), 68 deletions(-) create mode 100644 src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandReply.java diff --git a/make_jar.jardesc b/make_jar.jardesc index 0aa0889..8ad80c1 100644 --- a/make_jar.jardesc +++ b/make_jar.jardesc @@ -1,6 +1,6 @@ - + diff --git a/resources/plugin.yml b/resources/plugin.yml index c44f7b4..2ca636a 100644 --- a/resources/plugin.yml +++ b/resources/plugin.yml @@ -1,6 +1,6 @@ name: PandacraftUtils main: net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils -version: 4.2 +version: 4.3 @@ -96,6 +96,11 @@ commands: usage: /tell permission: pandacraft.tell aliases: [m, msg, t, w, whisper] + reply: + description: Envoyer un message privé au dernier joueur auquel vous avez déjà envoyé un message + usage: /reply + permission: pandacraft.tell + aliases: [r] mail: description: Message privé usage: /mail diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandMail.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandMail.java index 900eeb0..7e15d1b 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandMail.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandMail.java @@ -14,10 +14,10 @@ public class CommandMail extends AbstractCommandExecutor { public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { String[] m = new String[] { - ChatColor.GOLD+"---------- Messagerie privée ----------", + ChatColor.GOLD+"--------------- Messagerie privée ---------------", ChatColor.GRAY+"/m "+ChatColor.GOLD+" pour envoyer un message à un joueur même quand il est hors-ligne", ChatColor.GRAY+"/m"+ChatColor.GOLD+" pour lire vos messages non lus", - ChatColor.GOLD+"------------------------------------", + ChatColor.GOLD+"----------------------------------------------", }; sender.sendMessage(m); diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandReply.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandReply.java new file mode 100644 index 0000000..6e1ccd7 --- /dev/null +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandReply.java @@ -0,0 +1,64 @@ +package net.mc_pandacraft.java.plugin.pandacraftutils.commands; + +import net.mc_pandacraft.java.plugin.pandacraftutils.modules.PrivateMessagesManager.MessageSender; +import net.mc_pandacraft.java.plugin.pandacraftutils.modules.PrivateMessagesManager.MessageSendingException; +import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayer; +import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayerManager; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +public class CommandReply extends AbstractCommandExecutor { + + public CommandReply() { + super("reply"); + } + + + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, + String[] args) { + + if (args.length == 0 && sender instanceof Player) { + OnlinePlayer op = OnlinePlayerManager.get((Player) sender); + String lastTarget = op.getLastMessageTarget(); + if (lastTarget == null) + sender.sendMessage(ChatColor.RED+"Vous n'avez pas encore envoyé de message"); + else + sender.sendMessage(ChatColor.GRAY+"/"+label+ChatColor.GOLD+" pour envoyer un message à "+ChatColor.GRAY+lastTarget); + return true; + } + + if (!(sender instanceof Player)) { + sender.sendMessage(ChatColor.RED+"Seul un joueur en ligne peut utiliser la commande /"+label); + return false; + } + + + onCommandReply(sender, getLastParam(args, 0)); + return true; + + + } + + + + private void onCommandReply(CommandSender sender, String message) { + + if (sender instanceof Player && OnlinePlayerManager.get((Player) sender).getEssentialsUser().isMuted()) { + sender.sendMessage(ChatColor.RED+"Vous ne pouvez pas envoyer de message quand vous êtes muet"); + return; + } + + try { + plugin.privateMessagesManager.respondMessage(new MessageSender(sender), message); + } catch (MessageSendingException e) { + sender.sendMessage(ChatColor.RED+e.getMessage()); + } + + } + +} diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/PandacraftUtilsCommandsManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/PandacraftUtilsCommandsManager.java index 01dfa2e..7e28c08 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/PandacraftUtilsCommandsManager.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/PandacraftUtilsCommandsManager.java @@ -59,6 +59,7 @@ public class PandacraftUtilsCommandsManager { add(new CommandGhost()); add(new CommandTell()); add(new CommandMail()); + add(new CommandReply()); } diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/listener/XAuthListener.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/listener/XAuthListener.java index 471cbeb..3cc4eb2 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/listener/XAuthListener.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/listener/XAuthListener.java @@ -31,6 +31,10 @@ public class XAuthListener implements Listener { public void onxAuthLogin(xAuthLoginEvent event) { plugin.vanillaMessageManager.onxAuthLogin(event); } + @EventHandler(ignoreCancelled=false,priority=EventPriority.HIGHEST) + public void onxAuthLogin_Highest(xAuthLoginEvent event) { + plugin.privateMessagesManager.onxAuthLogin(event); + } diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/PrivateMessagesManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/PrivateMessagesManager.java index 3f7b07e..a4d402b 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/PrivateMessagesManager.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/PrivateMessagesManager.java @@ -7,7 +7,6 @@ import java.util.Arrays; import java.util.List; import java.util.Locale; import java.util.Random; -import java.util.Set; import mkremins.fanciful.FancyMessage; import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils; @@ -22,7 +21,6 @@ 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.OnlinePlayer; import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayerManager; -import net.mc_pandacraft.java.plugin.pandacraftutils.plugin_interface.EssentialsInterface; import org.bukkit.Bukkit; import org.bukkit.ChatColor; @@ -30,8 +28,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitRunnable; -import com.earth2me.essentials.User; -import com.earth2me.essentials.UserMap; +import de.luricos.bukkit.xAuth.events.xAuthLoginEvent; public class PrivateMessagesManager extends BukkitRunnable { private PandacraftUtils plugin = PandacraftUtils.getInstance(); @@ -46,6 +43,7 @@ public class PrivateMessagesManager extends BukkitRunnable { // récupération des /mail + /* plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() { @Override @@ -81,6 +79,7 @@ public class PrivateMessagesManager extends BukkitRunnable { } }, 1L); + */ } @@ -139,6 +138,8 @@ public class PrivateMessagesManager extends BukkitRunnable { */ public void respondMessage(MessageSender sender, String message) throws MessageSendingException { OnlinePlayer op = OnlinePlayerManager.get(Bukkit.getPlayer(sender.senderName)); + if (op == null) + throw new MessageSendingException("Seul les joueurs en ligne peuvent utiliser /r"); if (op.getLastMessageTarget() == null) throw new MessageSendingException("Vous n'avez pas encore envoyé de message. Utilisez /msg"); inputMessage(sender, op.getLastMessageTarget(), message); @@ -190,9 +191,11 @@ public class PrivateMessagesManager extends BukkitRunnable { tryDisplayMessageToConsole(messEl); } - if (sender.isPlayer()) - OnlinePlayerManager.get(plugin.getServer().getPlayer(sender.senderName)).setLastMessageTarget("g:"+groupEl.getGroupName()); - + if (sender.isPlayer()) { + OnlinePlayer op = OnlinePlayerManager.get(plugin.getServer().getPlayer(sender.senderName)); + if (op != null) + op.setLastMessageTarget("g:"+groupEl.getGroupName()); + } } catch (SQLException e) { e.printStackTrace(); @@ -205,8 +208,11 @@ public class PrivateMessagesManager extends BukkitRunnable { } else { // joueur + if (!AbstractCommandExecutor.isValidPlayerName(dest)) + throw new MessageSendingException("Le pseudo n'est pas valide"); + OffPlayer offP = new OffPlayer(dest); - if (offP.getBukkitOfflinePlayer() == null) { + if (!offP.hasPlayedBefore()) { throw new MessageSendingException("Le joueur n'a jamais existé"); } @@ -295,6 +301,8 @@ public class PrivateMessagesManager extends BukkitRunnable { 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()); boolean isIgnoring = sender.isPlayer() && op.getEssentialsUser().isIgnoredPlayer(new OffPlayer(message.getSourceNick()).getEssentialsUser()); @@ -310,7 +318,7 @@ public class PrivateMessagesManager extends BukkitRunnable { // 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()); DateFormat date = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.FRANCE); DateFormat hour = DateFormat.getTimeInstance(DateFormat.MEDIUM, Locale.FRANCE); @@ -337,7 +345,7 @@ public class PrivateMessagesManager extends BukkitRunnable { message.getDestNick(): "g:"+message.getDestGroupElement().getGroupName(); - + new FancyMessage("") .then("§6<§rmoi§6 → §r"+destAff+"§r§6>") .suggest("/m "+destCommand+" ") @@ -363,10 +371,11 @@ public class PrivateMessagesManager extends BukkitRunnable { "g:"+message.getDestGroupElement().getGroupName(); - new FancyMessage("") - .then("§6<§r"+senderAff+"§r§6 → §r"+destAff+"§r§6>") - .suggest("/m "+destCommand+" ") - .tooltip(tooltipLines) + 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()); @@ -420,6 +429,33 @@ public class PrivateMessagesManager extends BukkitRunnable { + public void onxAuthLogin(xAuthLoginEvent event) { + try { + List messages = ((MPMessageTable)ORM.getTable("mp_message")).getAllUnreadForPlayer(event.getPlayer().getName()); + + if (messages.size() == 0) return; + + String[] m = new String[] { + ChatColor.GOLD+"--------------- Messagerie privée ---------------", + ChatColor.GOLD+"Vous avez "+messages.size()+" message"+((messages.size()>1)?"s":"")+" non lu"+((messages.size()>1)?"s":""), + ChatColor.GOLD+"Faites "+ChatColor.GRAY+"/m"+ChatColor.GOLD+" pour voir le"+((messages.size()>1)?"s":"")+" message"+((messages.size()>1)?"s":""), + ChatColor.GOLD+"----------------------------------------------", + }; + + + event.getPlayer().sendMessage(m); + + + } catch(SQLException e) { + e.printStackTrace(); + } + } + + + + + + diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/network_api/request_executors/RequestExecutorPrivateMessage.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/network_api/request_executors/RequestExecutorPrivateMessage.java index 9fd00b6..e332110 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/network_api/request_executors/RequestExecutorPrivateMessage.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/network_api/request_executors/RequestExecutorPrivateMessage.java @@ -1,16 +1,8 @@ package net.mc_pandacraft.java.plugin.pandacraftutils.network_api.request_executors; -import org.bukkit.ChatColor; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -import com.earth2me.essentials.CommandSource; -import com.earth2me.essentials.Console; - +import net.mc_pandacraft.java.plugin.pandacraftutils.modules.PrivateMessagesManager.MessageSender; +import net.mc_pandacraft.java.plugin.pandacraftutils.modules.PrivateMessagesManager.MessageSendingException; import net.mc_pandacraft.java.plugin.pandacraftutils.network_api.Response; -import net.mc_pandacraft.java.plugin.pandacraftutils.players.OffPlayer; -import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayerManager; -import net.mc_pandacraft.java.plugin.pandacraftutils.plugin_interface.EssentialsInterface; public class RequestExecutorPrivateMessage extends AbstractRequestExecutor { @@ -26,51 +18,21 @@ public class RequestExecutorPrivateMessage extends AbstractRequestExecutor { return new Response(false, "bad_data : at least two space"); + String sourceName = dataSplit[0]; + String cibleName = dataSplit[1]; + String message = dataSplit[2]; - CommandSender cible; - String cibleName; - if (dataSplit[1].equalsIgnoreCase("console")) { - cible = plugin.getServer().getConsoleSender(); - cibleName = cible.getName(); - } - else { - Player p = plugin.getServer().getPlayer(dataSplit[1]); - - if (p == null || !p.isOnline()) { - plugin.getLogger().warning(ChatColor.RED+dataSplit[1]+" n'est pas en ligne"); - return new Response(false, "user_doest_not_online"); - } - - cible = p; - cibleName = p.getDisplayName(); + + try { + plugin.privateMessagesManager.inputMessage(new MessageSender(sourceName), cibleName, message); + } catch (MessageSendingException e) { + plugin.getLogger().warning(e.getMessage()); + return new Response(false, e.getMessage()); } - String displayName = "["+ChatColor.GRAY+"Console"+ChatColor.GOLD+"]"+ (new OffPlayer(dataSplit[0]).getDisplayName()); - - - String finalMessageToUser = ChatColor.GOLD+"["+displayName+ChatColor.GOLD+" -> moi] "+ChatColor.RESET+dataSplit[2]; - String finalMessageToConsole = ChatColor.GOLD+"["+displayName+ChatColor.GOLD+" -> "+cibleName+ChatColor.GOLD+"] "+ChatColor.RESET+dataSplit[2]; - - plugin.getServer().getConsoleSender().sendMessage(ChatColor.translateAlternateColorCodes('&', finalMessageToConsole)); - - - - if (cible instanceof Player) { - Player p = (Player) cible; - p.sendMessage(ChatColor.translateAlternateColorCodes('&', finalMessageToUser)); - - if (!OnlinePlayerManager.get(p).hasReceiveMessageFromNetworkAPI()) { - p.sendMessage(ChatColor.GREEN+"Répondez à un message venant de la console avec "+ChatColor.GRAY+"/m console"); - } - EssentialsInterface.getPlayer(p).setReplyTo(new CommandSource(plugin.getServer().getConsoleSender())); - } - - - Console.getConsoleReplyTo().setReplyTo(new CommandSource(cible)); - return new Response(true, ""); } diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/players/OffPlayer.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/players/OffPlayer.java index dab36a6..cfb7a60 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/players/OffPlayer.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/players/OffPlayer.java @@ -84,6 +84,12 @@ public class OffPlayer { + public boolean hasPlayedBefore() { + return (getBukkitOfflinePlayer() != null && getEssentialsUser() != null); + } + + + public User getEssentialsUser() { User u = EssentialsInterface.getPlugin().getOfflineUser(playerName); diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/players/OnlinePlayer.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/players/OnlinePlayer.java index dcd459d..d1c5830 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/players/OnlinePlayer.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/players/OnlinePlayer.java @@ -39,7 +39,11 @@ public class OnlinePlayer extends OffPlayer { public OfflinePlayer getBukkitOfflinePlayer() { return getPlayer(); } - + + @Override + public boolean hasPlayedBefore() { + return true; + } /*