McMMOChatEvent: added a field to hold the dispatching plugin

Currently, there is no sane way to detect which plugin dispatched
an McMMOChatEvent. This is problematic for plugins using the ChatAPI
while also listening for McMMOChatEvents as it leads to a message loop
being created.

A "simple" solution is to store a reference to the dispatching plugin in
the McMMOChatEvent. This allows for a plugin to determine if it is an
event dispatched by itself, or some other plugin. In addition, this can
allow for better control within third party plugins to determine where
McMMOChatEvents are dispatched from.

This patch is backwards with existing interfaces.
This commit is contained in:
jgeboski
2013-01-26 18:19:13 -05:00
committed by NuclearW
parent a8fa625b5c
commit 251c152efa
5 changed files with 81 additions and 9 deletions

View File

@ -1,10 +1,16 @@
package com.gmail.nossr50.events.chat;
import org.bukkit.plugin.Plugin;
/**
* Called when a chat is sent to the admin chat channel
*/
public class McMMOAdminChatEvent extends McMMOChatEvent {
public McMMOAdminChatEvent(Plugin plugin, String sender, String message) {
super(plugin, sender, message);
}
public McMMOAdminChatEvent(String sender, String message) {
super(sender, message);
this(null, sender, message);
}
}

View File

@ -3,17 +3,33 @@ package com.gmail.nossr50.events.chat;
import org.bukkit.event.Cancellable;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.plugin.Plugin;
import com.gmail.nossr50.mcMMO;
public class McMMOChatEvent extends Event implements Cancellable {
private boolean cancelled;
private Plugin plugin;
private String sender;
private String message;
protected McMMOChatEvent(String sender, String message) {
protected McMMOChatEvent(Plugin plugin, String sender, String message) {
if (plugin == null) {
plugin = mcMMO.p;
}
this.plugin = plugin;
this.sender = sender;
this.message = message;
}
/**
* @return The plugin responsible for this event
*/
public Plugin getPlugin() {
return plugin;
}
/**
* @return String name of the player who sent the chat, or "Console"
*/

View File

@ -1,16 +1,22 @@
package com.gmail.nossr50.events.chat;
import org.bukkit.plugin.Plugin;
/**
* Called when a chat is sent to a party channel
*/
public class McMMOPartyChatEvent extends McMMOChatEvent {
private String party;
public McMMOPartyChatEvent(String sender, String party, String message) {
super(sender, message);
public McMMOPartyChatEvent(Plugin plugin, String sender, String party, String message) {
super(plugin, sender, message);
this.party = party;
}
public McMMOPartyChatEvent(String sender, String party, String message) {
this(null, sender, party, message);
}
/**
* @return String name of the party the message will be sent to
*/