Make recipient event work for console. Add in some more debug in mstore.

This commit is contained in:
Olof Larsson 2013-09-06 11:35:07 +02:00
parent f78872c157
commit ac3ff4590e
3 changed files with 37 additions and 8 deletions

View File

@ -68,11 +68,11 @@ public class InternalListener implements Listener
for (CommandSender recipient : recipients) for (CommandSender recipient : recipients)
{ {
// Run the event for this unique recipient // Run the event for this unique recipient
MCorePlayerToRecipientChatEvent event = new MCorePlayerToRecipientChatEvent(sender, recipient, message, format); MCorePlayerToRecipientChatEvent recipientEvent = new MCorePlayerToRecipientChatEvent(sender, recipient, message, format);
event.run(); recipientEvent.run();
// Format and send with the format and message from this recipient's own event. // Format and send with the format and message from this recipient's own event.
String recipientMessage = String.format(event.getFormat(), sender.getDisplayName(), event.getMessage()); String recipientMessage = String.format(recipientEvent.getFormat(), sender.getDisplayName(), recipientEvent.getMessage());
recipient.sendMessage(recipientMessage); recipient.sendMessage(recipientMessage);
} }
} }
@ -84,16 +84,32 @@ public class InternalListener implements Listener
if (!MCoreConf.get().isUsingRecipientChatEvent()) return; if (!MCoreConf.get().isUsingRecipientChatEvent()) return;
// Prepare vars // Prepare vars
MCorePlayerToRecipientChatEvent recipientEvent;
final Player sender = event.getPlayer(); final Player sender = event.getPlayer();
String message = event.getMessage(); String message = event.getMessage();
String format = event.getFormat(); String format = event.getFormat();
// Pick the recipients to avoid the message getting sent without canceling the event. // Pick the recipients to avoid the message getting sent without canceling the event.
Set<CommandSender> recipients = new HashSet<CommandSender>(event.getRecipients()); Set<Player> players = new HashSet<Player>(event.getRecipients());
event.getRecipients().clear(); event.getRecipients().clear();
// Do it! // For each of the players
recipientChat(sender, message, format, recipients); for (Player recipient : players)
{
// Run the event for this unique recipient
recipientEvent = new MCorePlayerToRecipientChatEvent(sender, recipient, message, format);
recipientEvent.run();
// Format and send with the format and message from this recipient's own event.
String recipientMessage = String.format(recipientEvent.getFormat(), sender.getDisplayName(), recipientEvent.getMessage());
recipient.sendMessage(recipientMessage);
}
// For the console
recipientEvent = new MCorePlayerToRecipientChatEvent(sender, Bukkit.getConsoleSender(), message, format);
recipientEvent.run();
event.setMessage(recipientEvent.getMessage());
event.setFormat(recipientEvent.getFormat());
} }
// -------------------------------------------- // // -------------------------------------------- //

View File

@ -609,7 +609,20 @@ public class Coll<E> implements CollInterface<E>
protected boolean examineHasLocalAlter(String id, E entity) protected boolean examineHasLocalAlter(String id, E entity)
{ {
JsonElement lastRaw = this.lastRaw.get(id); JsonElement lastRaw = this.lastRaw.get(id);
JsonElement currentRaw = this.getGson().toJsonTree(entity, this.getEntityClass()); JsonElement currentRaw = null;
try
{
currentRaw = this.getGson().toJsonTree(entity, this.getEntityClass());
}
catch (Exception e)
{
MCore.get().log(Txt.parse("<b>Database examineHasLocalAlter failed convert current entity to JSON tree."));
MCore.get().log(Txt.parse("<k>Error: <v>%s", e.getMessage()));
MCore.get().log(Txt.parse("<k>Entity: <v>%s", id));
MCore.get().log(Txt.parse("<k>Collection: <v>%s", this.getName()));
throw e;
}
return !MStore.equal(lastRaw, currentRaw); return !MStore.equal(lastRaw, currentRaw);
} }