diff --git a/src/eu/the5zig/mod/event/ChatEvent.java b/src/eu/the5zig/mod/event/ChatEvent.java index 28c1505..fc8cf82 100644 --- a/src/eu/the5zig/mod/event/ChatEvent.java +++ b/src/eu/the5zig/mod/event/ChatEvent.java @@ -24,6 +24,10 @@ public class ChatEvent extends Event implements Cancelable { /** * The message of the server. */ + private String originalMessage; + /** + * Can be changed by plugins. + */ private String message; /** * An object that represents a minecraft internal chat component. Used internally to send messages to the second chat. @@ -36,7 +40,7 @@ public class ChatEvent extends Event implements Cancelable { private boolean cancelled; public ChatEvent(String message, Object chatComponent) { - this.message = message; + this.originalMessage = message; this.chatComponent = chatComponent; } @@ -44,6 +48,25 @@ public ChatEvent(String message, Object chatComponent) { * @return the chat message that has been received. */ public String getMessage() { + return originalMessage; + } + + /** + * Changes the chat message. The message will be only changed if {@link #isCancelled()} is {@code false}. + * Note, that {@link #getMessage()} still returns the original message to maintain compatibility. + * + * @param message the new message. + */ + public void setMessage(String message) { + if (message == null || !message.equals(originalMessage)) { + this.message = message; + } + } + + /** + * @return the chat message that has been changed by plugins or {@code null}, if the chat message has not been changed. + */ + public String getAlteredMessage() { return message; }