Correctifs et dernières fonctionnalités de la messagerie privée

This commit is contained in:
Marc Baloup 2015-05-12 01:25:40 +02:00
parent 10afd18f35
commit 19960a6dfe
10 changed files with 150 additions and 68 deletions

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml version="1.0" encoding="UTF-8" standalone="no"?>
<jardesc> <jardesc>
<jar path="PandacraftUtils/jar_export/PandacraftUtils-4.2.jar"/> <jar path="PandacraftUtils/jar_export/PandacraftUtils-4.3.jar"/>
<options buildIfNeeded="true" compress="true" descriptionLocation="/PandacraftUtils/make_jar.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="false" overwrite="false" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/> <options buildIfNeeded="true" compress="true" descriptionLocation="/PandacraftUtils/make_jar.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="false" overwrite="false" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
<storedRefactorings deprecationInfo="true" structuralOnly="false"/> <storedRefactorings deprecationInfo="true" structuralOnly="false"/>
<selectedProjects/> <selectedProjects/>

View File

@ -1,6 +1,6 @@
name: PandacraftUtils name: PandacraftUtils
main: net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils main: net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils
version: 4.2 version: 4.3
@ -96,6 +96,11 @@ commands:
usage: /tell <Joueur> <Message> usage: /tell <Joueur> <Message>
permission: pandacraft.tell permission: pandacraft.tell
aliases: [m, msg, t, w, whisper] 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 <Message>
permission: pandacraft.tell
aliases: [r]
mail: mail:
description: Message privé description: Message privé
usage: /mail usage: /mail

View File

@ -14,10 +14,10 @@ public class CommandMail extends AbstractCommandExecutor {
public boolean onCommand(CommandSender sender, Command cmd, String label, public boolean onCommand(CommandSender sender, Command cmd, String label,
String[] args) { String[] args) {
String[] m = new String[] { String[] m = new String[] {
ChatColor.GOLD+"---------- Messagerie privée ----------", ChatColor.GOLD+"--------------- Messagerie privée ---------------",
ChatColor.GRAY+"/m <Pseudo> <Message>"+ChatColor.GOLD+" pour envoyer un message à un joueur même quand il est hors-ligne", ChatColor.GRAY+"/m <Pseudo> <Message>"+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.GRAY+"/m"+ChatColor.GOLD+" pour lire vos messages non lus",
ChatColor.GOLD+"------------------------------------", ChatColor.GOLD+"----------------------------------------------",
}; };
sender.sendMessage(m); sender.sendMessage(m);

View File

@ -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());
}
}
}

View File

@ -59,6 +59,7 @@ public class PandacraftUtilsCommandsManager {
add(new CommandGhost()); add(new CommandGhost());
add(new CommandTell()); add(new CommandTell());
add(new CommandMail()); add(new CommandMail());
add(new CommandReply());
} }

View File

@ -31,6 +31,10 @@ public class XAuthListener implements Listener {
public void onxAuthLogin(xAuthLoginEvent event) { public void onxAuthLogin(xAuthLoginEvent event) {
plugin.vanillaMessageManager.onxAuthLogin(event); plugin.vanillaMessageManager.onxAuthLogin(event);
} }
@EventHandler(ignoreCancelled=false,priority=EventPriority.HIGHEST)
public void onxAuthLogin_Highest(xAuthLoginEvent event) {
plugin.privateMessagesManager.onxAuthLogin(event);
}

View File

@ -7,7 +7,6 @@ import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Random; import java.util.Random;
import java.util.Set;
import mkremins.fanciful.FancyMessage; import mkremins.fanciful.FancyMessage;
import net.mc_pandacraft.java.plugin.pandacraftutils.PandacraftUtils; 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.OffPlayer;
import net.mc_pandacraft.java.plugin.pandacraftutils.players.OnlinePlayer; 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.players.OnlinePlayerManager;
import net.mc_pandacraft.java.plugin.pandacraftutils.plugin_interface.EssentialsInterface;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
@ -30,8 +28,7 @@ import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import com.earth2me.essentials.User; import de.luricos.bukkit.xAuth.events.xAuthLoginEvent;
import com.earth2me.essentials.UserMap;
public class PrivateMessagesManager extends BukkitRunnable { public class PrivateMessagesManager extends BukkitRunnable {
private PandacraftUtils plugin = PandacraftUtils.getInstance(); private PandacraftUtils plugin = PandacraftUtils.getInstance();
@ -46,6 +43,7 @@ public class PrivateMessagesManager extends BukkitRunnable {
// récupération des /mail // récupération des /mail
/*
plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() { plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() {
@Override @Override
@ -81,6 +79,7 @@ public class PrivateMessagesManager extends BukkitRunnable {
} }
}, 1L); }, 1L);
*/
} }
@ -139,6 +138,8 @@ public class PrivateMessagesManager extends BukkitRunnable {
*/ */
public void respondMessage(MessageSender sender, String message) throws MessageSendingException { public void respondMessage(MessageSender sender, String message) throws MessageSendingException {
OnlinePlayer op = OnlinePlayerManager.get(Bukkit.getPlayer(sender.senderName)); 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) if (op.getLastMessageTarget() == null)
throw new MessageSendingException("Vous n'avez pas encore envoyé de message. Utilisez /msg"); throw new MessageSendingException("Vous n'avez pas encore envoyé de message. Utilisez /msg");
inputMessage(sender, op.getLastMessageTarget(), message); inputMessage(sender, op.getLastMessageTarget(), message);
@ -190,9 +191,11 @@ public class PrivateMessagesManager extends BukkitRunnable {
tryDisplayMessageToConsole(messEl); tryDisplayMessageToConsole(messEl);
} }
if (sender.isPlayer()) if (sender.isPlayer()) {
OnlinePlayerManager.get(plugin.getServer().getPlayer(sender.senderName)).setLastMessageTarget("g:"+groupEl.getGroupName()); OnlinePlayer op = OnlinePlayerManager.get(plugin.getServer().getPlayer(sender.senderName));
if (op != null)
op.setLastMessageTarget("g:"+groupEl.getGroupName());
}
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
@ -205,8 +208,11 @@ public class PrivateMessagesManager extends BukkitRunnable {
} }
else { else {
// joueur // joueur
if (!AbstractCommandExecutor.isValidPlayerName(dest))
throw new MessageSendingException("Le pseudo n'est pas valide");
OffPlayer offP = new OffPlayer(dest); OffPlayer offP = new OffPlayer(dest);
if (offP.getBukkitOfflinePlayer() == null) { if (!offP.hasPlayedBefore()) {
throw new MessageSendingException("Le joueur n'a jamais existé"); 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 == 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,7 +318,7 @@ public class PrivateMessagesManager extends BukkitRunnable {
// le message est affiché sur l'écran de la source du message // le message est affiché sur l'écran de la source du message
boolean dispToSender = (message.getViewerNick().equalsIgnoreCase(message.getSourceNick())); boolean dispToSender = (message.getViewerNick().equalsIgnoreCase(message.getSourceNick()));
Date d = new Date(message.getTime()); Date d = new Date(message.getTime());
DateFormat date = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.FRANCE); DateFormat date = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.FRANCE);
DateFormat hour = DateFormat.getTimeInstance(DateFormat.MEDIUM, Locale.FRANCE); DateFormat hour = DateFormat.getTimeInstance(DateFormat.MEDIUM, Locale.FRANCE);
@ -337,7 +345,7 @@ public class PrivateMessagesManager extends BukkitRunnable {
message.getDestNick(): message.getDestNick():
"g:"+message.getDestGroupElement().getGroupName(); "g:"+message.getDestGroupElement().getGroupName();
new FancyMessage("") new FancyMessage("")
.then("§6<§rmoi§6 → §r"+destAff+"§r§6>") .then("§6<§rmoi§6 → §r"+destAff+"§r§6>")
.suggest("/m "+destCommand+" ") .suggest("/m "+destCommand+" ")
@ -363,10 +371,11 @@ public class PrivateMessagesManager extends BukkitRunnable {
"g:"+message.getDestGroupElement().getGroupName(); "g:"+message.getDestGroupElement().getGroupName();
new FancyMessage("") FancyMessage fm = new FancyMessage("")
.then("§6<§r"+senderAff+"§r§6 → §r"+destAff+"§r§6>") .then("§6<§r"+senderAff+"§r§6 → §r"+destAff+"§r§6>");
.suggest("/m "+destCommand+" ") if (message.getSourceNick() != null)
.tooltip(tooltipLines) fm.suggest("/m "+destCommand+" ");
fm.tooltip(tooltipLines)
.then(" §6"+ChatColor.translateAlternateColorCodes('&', message.getMessage())) .then(" §6"+ChatColor.translateAlternateColorCodes('&', message.getMessage()))
.color(ChatColor.GOLD) .color(ChatColor.GOLD)
.send(op.getPlayer()); .send(op.getPlayer());
@ -420,6 +429,33 @@ public class PrivateMessagesManager extends BukkitRunnable {
public void onxAuthLogin(xAuthLoginEvent event) {
try {
List<MPMessageElement> 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();
}
}

View File

@ -1,16 +1,8 @@
package net.mc_pandacraft.java.plugin.pandacraftutils.network_api.request_executors; package net.mc_pandacraft.java.plugin.pandacraftutils.network_api.request_executors;
import org.bukkit.ChatColor; import net.mc_pandacraft.java.plugin.pandacraftutils.modules.PrivateMessagesManager.MessageSender;
import org.bukkit.command.CommandSender; import net.mc_pandacraft.java.plugin.pandacraftutils.modules.PrivateMessagesManager.MessageSendingException;
import org.bukkit.entity.Player;
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.Console;
import net.mc_pandacraft.java.plugin.pandacraftutils.network_api.Response; 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 { public class RequestExecutorPrivateMessage extends AbstractRequestExecutor {
@ -26,51 +18,21 @@ public class RequestExecutorPrivateMessage extends AbstractRequestExecutor {
return new Response(false, "bad_data : at least two space"); 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(); try {
cibleName = cible.getName(); plugin.privateMessagesManager.inputMessage(new MessageSender(sourceName), cibleName, message);
} } catch (MessageSendingException e) {
else { plugin.getLogger().warning(e.getMessage());
Player p = plugin.getServer().getPlayer(dataSplit[1]); return new Response(false, e.getMessage());
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();
} }
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, ""); return new Response(true, "");
} }

View File

@ -84,6 +84,12 @@ public class OffPlayer {
public boolean hasPlayedBefore() {
return (getBukkitOfflinePlayer() != null && getEssentialsUser() != null);
}
public User getEssentialsUser() { public User getEssentialsUser() {
User u = EssentialsInterface.getPlugin().getOfflineUser(playerName); User u = EssentialsInterface.getPlugin().getOfflineUser(playerName);

View File

@ -39,7 +39,11 @@ public class OnlinePlayer extends OffPlayer {
public OfflinePlayer getBukkitOfflinePlayer() { public OfflinePlayer getBukkitOfflinePlayer() {
return getPlayer(); return getPlayer();
} }
@Override
public boolean hasPlayedBefore() {
return true;
}
/* /*