Possibilité de récupérer les dernières discussion d'un joueur donné
This commit is contained in:
parent
9e74ae9973
commit
0432d10975
@ -161,7 +161,7 @@ public class CommandAnimal extends AbstractCommandExecutor {
|
||||
else
|
||||
p.sendMessage(ChatColor.GOLD+"Propriétaire : "+ChatColor.GRAY+"Non apprivoisé");
|
||||
p.sendMessage(ChatColor.GOLD+"Nom personnalisé : "+ChatColor.RESET+((animal.getCustomName() != null) ? animal.getCustomName() : ChatColor.GRAY+"Aucun"));
|
||||
p.sendMessage(ChatColor.GOLD+"Point de vie : "+ChatColor.GRAY+((int)((Damageable)animal).getHealth())+"/"+((int)((Damageable)animal).getMaxHealth())+ChatColor.GOLD+" (2 points = 1 "+ChatColor.RED+"♥"+ChatColor.GOLD+")");
|
||||
p.sendMessage(ChatColor.GOLD+"Point de vie : "+ChatColor.GRAY+((int)((Damageable)animal).getHealth())+"/"+((int)((Damageable)animal).getMaxHealth())+ChatColor.GOLD+" (2 points = 1 "+ChatColor.RED+"❤"+ChatColor.GOLD+")");
|
||||
p.sendMessage(ChatColor.GOLD+"Respiration sous l'eau : "+ChatColor.GRAY+animal.getRemainingAir()+"/"+animal.getMaximumAir());
|
||||
|
||||
if (animal instanceof Horse) {
|
||||
|
@ -58,11 +58,20 @@ public class MPMessageTable extends SQLTable<MPMessageElement> {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public List<MPMessageElement> getAllUnreadForPlayer(String player) throws SQLException {
|
||||
return getForPlayer(player, true, null);
|
||||
}
|
||||
|
||||
|
||||
public List<MPMessageElement> getForPlayer(String player, boolean onlyUnread, Integer numberLast) throws SQLException {
|
||||
if (!AbstractCommandExecutor.isValidPlayerName(player)) return null;
|
||||
|
||||
return getAll("viewerNick = '"+player+"' AND wasRead = 0", "time ASC", null, null);
|
||||
String where = "viewerNick = '"+player+"'";
|
||||
if (onlyUnread)
|
||||
where += " AND wasRead = 0";
|
||||
|
||||
return getAll(where, "time ASC", numberLast, null);
|
||||
}
|
||||
|
||||
|
||||
|
@ -62,6 +62,18 @@ public final class ORM {
|
||||
return tables.get(name);
|
||||
}
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
public synchronized static <T extends SQLTable> T getTable(Class<T> c) {
|
||||
if (c == null) return null;
|
||||
for (SQLTable table : tables.values()) {
|
||||
|
||||
if (c.isAssignableFrom(table.getClass())) {
|
||||
return c.cast(table);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -24,12 +24,15 @@ 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 org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import de.luricos.bukkit.xAuth.events.xAuthLoginEvent;
|
||||
|
||||
public class PrivateMessagesManager extends BukkitRunnable {
|
||||
@ -289,6 +292,84 @@ public class PrivateMessagesManager extends BukkitRunnable {
|
||||
|
||||
|
||||
|
||||
public List<PrivateDiscussion> getLastDiscussions(Player p, Integer nbLast) {
|
||||
try {
|
||||
// récupère les messages, triés de la plus vieille à la plus récente
|
||||
List<MPMessageElement> messages = ORM.getTable(MPMessageTable.class).getForPlayer(p.getName(), false, 1000);
|
||||
|
||||
// inverse, de la plus récente à la plus vieille
|
||||
messages = Lists.reverse(messages);
|
||||
|
||||
List<PrivateDiscussion> discussionList = new ArrayList<PrivateDiscussion>();
|
||||
|
||||
for(MPMessageElement message : messages) {
|
||||
String name;
|
||||
if (message.getDestGroup() != null)
|
||||
name = "g:"+message.getDestGroupElement().getGroupName();
|
||||
else
|
||||
name = message.getSourceNick();
|
||||
|
||||
PrivateDiscussion pvd = new PrivateDiscussion(name, (message.isRead())?0:1, new Date(message.getTime()));
|
||||
|
||||
int index;
|
||||
if ((index = discussionList.indexOf(pvd)) >= 0) {
|
||||
if (!message.isRead())
|
||||
discussionList.get(index).nbUnread++;
|
||||
}
|
||||
else
|
||||
discussionList.add(pvd);
|
||||
|
||||
}
|
||||
|
||||
if (nbLast != null && nbLast >= 0) {
|
||||
while (discussionList.size()>nbLast.intValue()) {
|
||||
discussionList.remove(discussionList.size()-1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return discussionList;
|
||||
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public class PrivateDiscussion {
|
||||
/**
|
||||
* Le pseudo du joueur ou du groupe de discussion (avec "g:" devant)
|
||||
*/
|
||||
public final String name;
|
||||
public int nbUnread;
|
||||
public Date timeLastMessage;
|
||||
|
||||
private PrivateDiscussion(String n, int unread, Date lastMess) {
|
||||
Validate.notNull(n, "n ne doit pas être null");
|
||||
name = n;
|
||||
nbUnread = unread;
|
||||
timeLastMessage = lastMess;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (o == null || !(o instanceof PrivateDiscussion))
|
||||
return false;
|
||||
|
||||
return ((PrivateDiscussion) o).name.equalsIgnoreCase(name);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -378,11 +459,12 @@ public class PrivateMessagesManager extends BukkitRunnable {
|
||||
tooltipLines.add(0, ChatColor.GRAY+"(Cliquez pour répondre)");
|
||||
|
||||
new FancyMessage("")
|
||||
.then("§6<§rmoi§6 → §r"+destAff+"§r§6>")
|
||||
.then("§d<§rmoi§d → §r"+destAff+"§r§d>")
|
||||
.suggest("/m "+destCommand+" ")
|
||||
.tooltip(tooltipLines)
|
||||
.then(" §6"+ChatColor.translateAlternateColorCodes('&', message.getMessage()).replace("§r", "§r§6"))
|
||||
.then(" §6§o"+ChatColor.translateAlternateColorCodes('&', message.getMessage()).replace("§r", "§r§6§o"))
|
||||
.color(ChatColor.GOLD)
|
||||
.style(ChatColor.ITALIC)
|
||||
.send(op.getPlayer());
|
||||
}
|
||||
else {
|
||||
@ -405,7 +487,7 @@ public class PrivateMessagesManager extends BukkitRunnable {
|
||||
tooltipLines.add(0, ChatColor.GRAY+"(Cliquez pour répondre)");
|
||||
|
||||
FancyMessage fm = new FancyMessage("")
|
||||
.then("§6<§r"+senderAff+"§r§6 → §r"+destAff+"§r§6>");
|
||||
.then("§d<§r"+senderAff+"§r§d → §r"+destAff+"§r§d>");
|
||||
if (message.getSourceNick() != null)
|
||||
fm.suggest("/m "+destCommand+" ");
|
||||
fm.tooltip(tooltipLines)
|
||||
@ -441,7 +523,7 @@ public class PrivateMessagesManager extends BukkitRunnable {
|
||||
ChatColor.GOLD+"g:"+message.getDestGroupElement().getGroupName();
|
||||
|
||||
|
||||
plugin.getServer().getConsoleSender().sendMessage("§6<§r"+senderAff+"§r§6 → §r"+destAff+"§r§6> §6"+ChatColor.translateAlternateColorCodes('&', message.getMessage()).replace("§r", "§r§6"));
|
||||
plugin.getServer().getConsoleSender().sendMessage("§d<§r"+senderAff+"§r§d → §r"+destAff+"§r§d> §6"+ChatColor.translateAlternateColorCodes('&', message.getMessage()).replace("§r", "§r§6"));
|
||||
|
||||
|
||||
} catch (SQLException e) {
|
||||
|
Loading…
Reference in New Issue
Block a user