diff --git a/resources/plugin.yml b/resources/plugin.yml index e0ab1dd..c44f7b4 100644 --- a/resources/plugin.yml +++ b/resources/plugin.yml @@ -96,6 +96,11 @@ commands: usage: /tell permission: pandacraft.tell aliases: [m, msg, t, w, whisper] + mail: + description: Message privé + usage: /mail + permission: pandacraft.tell + aliases: [email] diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandMail.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandMail.java new file mode 100644 index 0000000..900eeb0 --- /dev/null +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/CommandMail.java @@ -0,0 +1,27 @@ +package net.mc_pandacraft.java.plugin.pandacraftutils.commands; + +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; + +public class CommandMail extends AbstractCommandExecutor { + + public CommandMail() { + super("mail"); + } + + @Override + public boolean onCommand(CommandSender sender, Command cmd, String label, + String[] args) { + String[] m = new String[] { + 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+"------------------------------------", + }; + + sender.sendMessage(m); + return true; + } + +} 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 6db74a2..01dfa2e 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/PandacraftUtilsCommandsManager.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/commands/PandacraftUtilsCommandsManager.java @@ -57,6 +57,8 @@ public class PandacraftUtilsCommandsManager { add(new CommandMuco()); add(new CommandModo()); add(new CommandGhost()); + add(new CommandTell()); + add(new CommandMail()); } diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPMessageTable.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPMessageTable.java index 29221ef..3e5a042 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPMessageTable.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/MPMessageTable.java @@ -62,7 +62,7 @@ public class MPMessageTable extends SQLTable { public List getAllUnreadForPlayer(String player) throws SQLException { if (!AbstractCommandExecutor.isValidPlayerName(player)) return null; - return getAll("viewerNick = "+player+" AND read = 0", "time ASC", null, null); + return getAll("viewerNick = '"+player+"' AND wasRead = 0", "time ASC", null, null); } diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/SQLElement.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/SQLElement.java index d5bbf1e..6024661 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/SQLElement.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/data_model/SQLElement.java @@ -2,6 +2,7 @@ package net.mc_pandacraft.java.plugin.pandacraftutils.data_model; import java.sql.Connection; import java.sql.PreparedStatement; +import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; @@ -87,9 +88,16 @@ public abstract class SQLElement { st.setString(i+1, values[i]); } - id = st.executeUpdate(); - st.close(); + st.executeUpdate(); + + ResultSet rs = st.getGeneratedKeys(); + if(rs.next()) + { + id = rs.getInt(1); + } + saved = true; + st.close(); } } catch (SQLException e) { e.printStackTrace(); 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 47d019b..3f7b07e 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/PrivateMessagesManager.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/PrivateMessagesManager.java @@ -7,6 +7,7 @@ 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; @@ -21,6 +22,7 @@ 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; @@ -28,6 +30,9 @@ 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; + public class PrivateMessagesManager extends BukkitRunnable { private PandacraftUtils plugin = PandacraftUtils.getInstance(); @@ -36,6 +41,46 @@ public class PrivateMessagesManager extends BukkitRunnable { public PrivateMessagesManager() { plugin.getServer().getScheduler().runTaskTimer(plugin, this, 2L, 10L); + + + + + // récupération des /mail + plugin.getServer().getScheduler().runTaskLater(plugin, new Runnable() { + + @Override + public void run() { + UserMap players = EssentialsInterface.getPlugin().getUserMap(); + plugin.getLogger().info("Importing player's /mail from Essentials data ..."); + if (players == null) return; + plugin.getLogger().info("There are "+players.getUniqueUsers()+" players files in Essentials/userdata"); + Set users = players.getAllUniqueUsers(); + + for (String su : users) { + User u = players.getUser(su); + if (u.getBase() != null && u.getBase().isOnline()) continue; + List mails = u.getMails(); + if (mails.isEmpty()) continue; + + for (String mail : mails) { + String[] split = mail.split(":", 2); + + String sourceName = split[0].trim(); + String message = split[1].trim(); + + try { + inputMessage(new MessageSender(sourceName), u.getName(), message); + } catch (MessageSendingException e) { + plugin.getLogger().severe(e.getMessage()); + } + } + + u.setMails(null); + } + players.reloadConfig(); + } + + }, 1L); } @@ -67,6 +112,13 @@ public class PrivateMessagesManager extends BukkitRunnable { } + + + + + + + } catch (SQLException e) { plugin.getLogger().severe("Impossible de récupérer les messages privés de la base de donnée"); e.printStackTrace(); @@ -171,7 +223,7 @@ public class PrivateMessagesManager extends BukkitRunnable { tryDisplayMessage(el); } - MPMessageElement elCible = new MPMessageElement(time, secKey, destUserName, sender.senderName, message, true, true); + MPMessageElement elCible = new MPMessageElement(time, secKey, destUserName, sender.senderName, message, false, true); elCible.setDestNick(destUserName); elCible.save(); tryDisplayMessage(elCible); @@ -179,8 +231,11 @@ public class PrivateMessagesManager extends BukkitRunnable { tryDisplayMessageToConsole(elCible); - if (sender.isPlayer()) - OnlinePlayerManager.get(plugin.getServer().getPlayer(sender.senderName)).setLastMessageTarget(destUserName); + if (sender.isPlayer()) { + OnlinePlayer op = OnlinePlayerManager.get(plugin.getServer().getPlayer(sender.senderName)); + if (op != null) + op.setLastMessageTarget(destUserName); + } } @@ -272,7 +327,10 @@ public class PrivateMessagesManager extends BukkitRunnable { if (dispToSender) { String destAff = (message.getDestGroup() == null)? - new OffPlayer(message.getDestNick()).getDisplayName(): + ( (message.getDestNick().equalsIgnoreCase(message.getViewerNick())) ? + "moi": + new OffPlayer(message.getDestNick()).getDisplayName() + ): "g:"+message.getDestGroupElement().getGroupName(); String destCommand = (message.getDestGroup() == null)? @@ -280,11 +338,12 @@ public class PrivateMessagesManager extends BukkitRunnable { "g:"+message.getDestGroupElement().getGroupName(); - new FancyMessage() + 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 { @@ -304,11 +363,12 @@ public class PrivateMessagesManager extends BukkitRunnable { "g:"+message.getDestGroupElement().getGroupName(); - new FancyMessage() + new FancyMessage("") .then("§6<§r"+senderAff+"§r§6 → §r"+destAff+"§r§6>") .suggest("/m "+destCommand+" ") .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); diff --git a/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/staff/StaffQueueManager.java b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/staff/StaffQueueManager.java index ae398a4..c6e43c4 100644 --- a/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/staff/StaffQueueManager.java +++ b/src/net/mc_pandacraft/java/plugin/pandacraftutils/modules/staff/StaffQueueManager.java @@ -326,7 +326,8 @@ public class StaffQueueManager { el.setMessage(message); el.save(); - } catch (SQLException e) { + } catch (Exception e) { + plugin.getLogger().severe("Impossible de récupérer l'élément en base de donnée : id="+dbId); e.printStackTrace(); } @@ -345,7 +346,8 @@ public class StaffQueueManager { el.setStaffPlayer(staffPlayer); el.save(); - } catch (SQLException e) { + } catch (Exception e) { + plugin.getLogger().severe("Impossible de récupérer l'élément en base de donnée : id="+dbId); e.printStackTrace(); }