Skip to content

Commit

Permalink
Add setMessage to chat event
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-albers committed Apr 8, 2017
1 parent 6a81b14 commit a2ceba1
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/eu/the5zig/mod/event/ChatEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -36,14 +40,33 @@ 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;
}

/**
* @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;
}

Expand Down

0 comments on commit a2ceba1

Please sign in to comment.