Correctifs du commit précédent

This commit is contained in:
Marc Baloup 2015-05-11 04:44:35 +02:00
parent dddaa83fe0
commit 10afd18f35
7 changed files with 115 additions and 11 deletions

View File

@ -96,6 +96,11 @@ commands:
usage: /tell <Joueur> <Message>
permission: pandacraft.tell
aliases: [m, msg, t, w, whisper]
mail:
description: Message privé
usage: /mail
permission: pandacraft.tell
aliases: [email]

View File

@ -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 <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+"------------------------------------",
};
sender.sendMessage(m);
return true;
}
}

View File

@ -57,6 +57,8 @@ public class PandacraftUtilsCommandsManager {
add(new CommandMuco());
add(new CommandModo());
add(new CommandGhost());
add(new CommandTell());
add(new CommandMail());
}

View File

@ -62,7 +62,7 @@ public class MPMessageTable extends SQLTable<MPMessageElement> {
public List<MPMessageElement> 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);
}

View File

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

View File

@ -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<String> users = players.getAllUniqueUsers();
for (String su : users) {
User u = players.getUser(su);
if (u.getBase() != null && u.getBase().isOnline()) continue;
List<String> 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);

View File

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