Correctifs et dernières fonctionnalités de la messagerie privée
This commit is contained in:
parent
10afd18f35
commit
19960a6dfe
@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<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"/>
|
||||
<storedRefactorings deprecationInfo="true" structuralOnly="false"/>
|
||||
<selectedProjects/>
|
||||
|
@ -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 <Joueur> <Message>
|
||||
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 <Message>
|
||||
permission: pandacraft.tell
|
||||
aliases: [r]
|
||||
mail:
|
||||
description: Message privé
|
||||
usage: /mail
|
||||
|
@ -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 <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.GOLD+"------------------------------------",
|
||||
ChatColor.GOLD+"----------------------------------------------",
|
||||
};
|
||||
|
||||
sender.sendMessage(m);
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -59,6 +59,7 @@ public class PandacraftUtilsCommandsManager {
|
||||
add(new CommandGhost());
|
||||
add(new CommandTell());
|
||||
add(new CommandMail());
|
||||
add(new CommandReply());
|
||||
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -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());
|
||||
@ -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<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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -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, "");
|
||||
}
|
||||
|
@ -84,6 +84,12 @@ public class OffPlayer {
|
||||
|
||||
|
||||
|
||||
public boolean hasPlayedBefore() {
|
||||
return (getBukkitOfflinePlayer() != null && getEssentialsUser() != null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public User getEssentialsUser() {
|
||||
User u = EssentialsInterface.getPlugin().getOfflineUser(playerName);
|
||||
|
@ -40,6 +40,10 @@ public class OnlinePlayer extends OffPlayer {
|
||||
return getPlayer();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPlayedBefore() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user