Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Add API to use 1.7 chat features. Adds BUKKIT-5245 #8

Open
wants to merge 72 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
72 commits
Select commit Hold shift + click to select a range
dff7352
First draft
Ribesg Jul 17, 2014
0c577dc
More draft
Ribesg Jul 21, 2014
5375e34
Append a Message to another one
Ribesg Jul 21, 2014
a844dc3
Prevent modifying parts
Ribesg Jul 25, 2014
6c4cd36
Make Part mutable, add some methods
Ribesg Jul 25, 2014
d45527f
Implement new API
Ribesg Jul 25, 2014
734978a
Move hover data outside of Part, move inner classes outside of Message
Ribesg Jul 25, 2014
6ae81e6
Add test material & little modifications
Ribesg Jul 25, 2014
5ec90a0
Add equals() and hashCode() everywhere
Ribesg Jul 25, 2014
8af1389
Clean tabs and stuff
Ribesg Jul 26, 2014
9fe76be
Make Click & Hover immutable
Ribesg Jul 30, 2014
7df8f44
Ensure stored String[] and ItemStack are not modified
Ribesg Jul 30, 2014
f457284
Handle null value in String[]
Ribesg Jul 30, 2014
b4abdef
Add .toString() to Message and Part
Ribesg Jul 30, 2014
db58a06
Don't print "null" for Achievement or Item parts
Ribesg Jul 30, 2014
074bde3
Add 2 millions methods
Ribesg Aug 7, 2014
8d74fcb
Document the Click class
Ribesg Aug 7, 2014
090dc73
Document the Hover class
Ribesg Aug 7, 2014
73e4a63
Add basic Javadoc for Message and Part
Ribesg Aug 22, 2014
9f814e4
Add JavaDucks for Message static constructors
Ribesg Aug 25, 2014
33e6fae
Add JavaDucks for Message append(...) methods
Ribesg Aug 25, 2014
d98d04e
Add JavaDucks for Message insert(...) methods
Ribesg Aug 25, 2014
ae2c82e
Added some javadocs
ST-DDT Aug 29, 2014
c929fc3
Use Messages in Events too.
ST-DDT Aug 30, 2014
270c9f3
Added Deprecation annotation to all string message related methods
ST-DDT Aug 30, 2014
a26aae7
Merge pull request #8 from ST-DDT/BUKKIT-5245-v2_javadocs
Ribesg Aug 30, 2014
0a356c0
Merge pull request #7 from ST-DDT/BUKKIT-5245-v2_events
Ribesg Aug 30, 2014
91f1321
Update PlayerDeathEvent
ST-DDT Aug 31, 2014
ec799c8
Update AsyncPlayerChatEvent
ST-DDT Aug 31, 2014
e1bb1e7
Added AsyncPlayerChatEvent#getFormatedMessage
ST-DDT Aug 31, 2014
6c3dbf2
Update PlayerLoginEvent
ST-DDT Aug 31, 2014
d8b1861
Update AsyncPlayerPreLoginEvent
ST-DDT Aug 31, 2014
9a1d7b1
Use setters to centralize logic and ternary for one line statements.
ST-DDT Sep 1, 2014
34799da
Improve jd formating
ST-DDT Sep 1, 2014
7b13b43
Formating
ST-DDT Sep 1, 2014
7f1e301
Replace '!=' with 'does not match' in jd, add additional javadocs
ST-DDT Sep 2, 2014
caed86c
Lowercase Null.
ST-DDT Sep 2, 2014
f62d47b
Add support for '%s' in format
ST-DDT Sep 2, 2014
5f89c99
Fixed indentation in AsyncPlayerChatEvent
ST-DDT Sep 2, 2014
210c99f
Added clone method
ST-DDT Sep 2, 2014
869402e
Improve cloning
ST-DDT Sep 2, 2014
51bdb2e
Ternary
ST-DDT Sep 2, 2014
33044d5
Added missing deprecation javadocs + added ServerListPingEvent
ST-DDT Sep 3, 2014
48bc47a
Added support for Player.kick(Message) and updated PlayerKickEvent ac…
ST-DDT Sep 3, 2014
a0111e0
Added Player.chat(Message)
ST-DDT Sep 3, 2014
83d7145
Messages cannot be a command
ST-DDT Sep 3, 2014
119cde4
Merge pull request #10 from ST-DDT/BUKKIT-5245-v2_clone
bendem Sep 3, 2014
5f1c443
Fixed typos and minor improvements
ST-DDT Sep 3, 2014
00b7652
Fixed some more typos
ST-DDT Sep 3, 2014
7e1908f
Made Click implement ConfigurationSerializable, add toString
ST-DDT Sep 4, 2014
a9927d1
Made Hover implement ConfigurationSerializable, add toString, fix equals
ST-DDT Sep 4, 2014
10c879d
Made Message implement ConfigurationSerializable
ST-DDT Sep 4, 2014
4d595ac
Made Part implement ConfigurationSerializable
ST-DDT Sep 4, 2014
05fe519
Merge pull request #11 from ST-DDT/BUKKIT-5245-v2_config
Ribesg Sep 5, 2014
6f279f3
Merge pull request #9 from ST-DDT/BUKKIT-5245-v2_events
Ribesg Sep 5, 2014
057b8eb
Remove useless brackets
ST-DDT Sep 5, 2014
b11d0a3
Clone the parts before adding it to the formated message
ST-DDT Sep 5, 2014
ec5be3d
Merge pull request #12 from ST-DDT/BUKKIT-5245-v2_clone
Ribesg Sep 5, 2014
f9c611d
Merge pull request #13 from ST-DDT/BUKKIT-5245-v2_bugfix
Ribesg Sep 5, 2014
ade1877
Merge constructors
ST-DDT Sep 6, 2014
8c1e88f
Added some missing validation
ST-DDT Sep 6, 2014
d20d306
Merge pull request #14 from ST-DDT/BUKKIT-5245-v2_events
Ribesg Sep 6, 2014
830aad1
Merge pull request #15 from ST-DDT/BUKKIT-5245-v2_validation
Ribesg Sep 6, 2014
1d1875d
Add tests for clone methods, fixed whitespace issues.
ST-DDT Sep 6, 2014
5fb2d36
Merge pull request #16 from ST-DDT/BUKKIT-5245-v2_test
Ribesg Sep 6, 2014
c80cfd7
Minor improvements
ST-DDT Sep 16, 2014
9aea521
Merge pull request #17 from ST-DDT/BUKKIT-5245-v2_improvements
Ribesg Sep 17, 2014
ce341e8
Added MC 1.8 features
ST-DDT Sep 19, 2014
a42dc5b
Fixed javadocs errors
ST-DDT Sep 20, 2014
04b84b6
Merge pull request #18 from ST-DDT/v1.8_features
Ribesg Oct 1, 2014
79252ca
Bugfix Message
ST-DDT Nov 6, 2014
ec23ace
Merge pull request #19 from ST-DDT/BUKKIT-5245-v2
bendem Nov 6, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update AsyncPlayerChatEvent
ST-DDT committed Aug 31, 2014
commit ec799c8ac98d8a16a286afa663b14c8f21a63924
134 changes: 99 additions & 35 deletions src/main/java/org/bukkit/event/player/AsyncPlayerChatEvent.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package org.bukkit.event.player;

import java.util.IllegalFormatException;
import java.util.Set;
import java.util.UUID;

import org.apache.commons.lang.Validate;
import org.bukkit.chat.Message;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.HandlerList;
@@ -26,81 +28,143 @@
public class AsyncPlayerChatEvent extends PlayerEvent implements Cancellable {
private static final HandlerList handlers = new HandlerList();
private boolean cancel = false;
private String message;
private Message senderDetails;
private Message message;
private String format = "<%1$s> %2$s";
private final Set<Player> recipients;

/**
*
* Creates a new AsyncPlayerChatEvent for the given player with the given
* message sent to all recipients after the event finished being processed.
*
* @param async This changes the event to a synchronous state.
* @param who the chat sender
* @param message the message sent
* @param players the players to receive the message. This may be a lazy
* or unmodifiable collection.
* @param players the players to receive the message. This may be a lazy or
* unmodifiable collection.
*/
public AsyncPlayerChatEvent(final boolean async, final Player who, final String message, final Set<Player> players) {
public AsyncPlayerChatEvent(final boolean async, final Player who, final Message message, final Set<Player> players) {
super(who, async);
Validate.notNull(message, "Message cannot be Null!");
this.senderDetails = Message.of(who.getDisplayName(), who.getUniqueId().toString());
this.message = message;
recipients = players;
}

/**
* Gets the message that the player is attempting to send. This message
* will be used with {@link #getFormat()}.
* Creates a new AsyncPlayerChatEvent for the given player with the given
* message sent to all recipients after the event finished being processed.
*
* @param async This changes the event to a synchronous state.
* @param who the chat sender
* @param message the message sent
* @param players the players to receive the message. This may be a lazy or
* unmodifiable collection.
*/
@Deprecated
public AsyncPlayerChatEvent(final boolean async, final Player who, final String message, final Set<Player> players) {
super(who, async);
this.senderDetails = Message.of(who.getDisplayName(), who.getUniqueId().toString());
this.message = Message.of(message);
recipients = players;
}

/**
* Gets the sender details that the will be shown along with the message.
* This sender details will by default contain the player name and will show
* the senders {@link UUID} on hover.
*
* @return Message the player is attempting to send
* @return Message the player details to show
*/
public Message getSenderDetails() {
return senderDetails;
}

/**
* Sets the sender details that the will be shown along with the message.
* The player's name will <b>NOT</b> be injected automatically and should be
* set before this method is called. Must not be null.
*
* @param senderDetails the player details to show
*/
public void setSenderDetails(Message senderDetails) {
Validate.notNull(senderDetails, "SenderDetails cannot be null!");
this.senderDetails = senderDetails;
}

/**
* Gets the message that the player is attempting to send. This message will
* be used with {@link #getFormat()}. May contain color codes.
*
* @return the player is attempting to send
* @deprecated This event now uses {@link Message} to send the message. Use
* {@link #getChatMessage()} instead.
*/
@Deprecated
public String getMessage() {
return message.toString();
}

/**
* Sets the message that the player will send. This message will be used
* with {@link #getFormat()}. Can contain color codes.
*
* @param message new message that the player will send
* @deprecated This event now uses {@link Message} to send the message. Use
* {@link #setChatMessage(Message)} instead.
*/
@Deprecated
public void setMessage(String message) {
Validate.notNull("Message cannot be Null!");
this.message = Message.of(message);
}

/**
* Gets the message that the player is attempting to send. This message will
* be used with {@link #getFormat()}.
*
* @return Message the player is attempting to send
*/
public Message getChatMessage() {
return message;
}

/**
* Sets the message that the player will send. This message will be used
* with {@link #getFormat()}.
*
* @param message New message that the player will send
* @param message new message that the player will send
*/
public void setMessage(String message) {
public void setChatMessage(Message message) {
Validate.notNull(message, "Message cannot be Null!");
this.message = message;
}

/**
* Gets the format to use to display this chat message.
* <p>
* When this event finishes execution, the first format parameter is the
* {@link Player#getDisplayName()} and the second parameter is {@link
* #getMessage()}
* When this event finishes execution, the first format parameter %1$s is
* the {@link #getSenderDetails()} and the second parameter %2$s is
* {@link #getMessage()}. Defaults to "&lt%1$s&gt %2$s".
*
* @return {@link String#format(String, Object...)} compatible format
* string
* @return the format string used to format the message
*/
public String getFormat() {
return format;
}

/**
* Sets the format to use to display this chat message.
* Sets the format used to display this chat message.
* <p>
* When this event finishes execution, the first format parameter is the
* {@link Player#getDisplayName()} and the second parameter is {@link
* #getMessage()}
* When this event finishes execution, the first format parameter %1$s is
* the {@link #getSenderDetails()} and the second parameter %1$s is
* {@link #getMessage()}. It is not required to have those parameters in the
* format, but their use is recommended.
*
* @param format {@link String#format(String, Object...)} compatible
* format string
* @throws IllegalFormatException if the underlying API throws the
* exception
* @throws NullPointerException if format is null
* @see String#format(String, Object...)
* @param format the message format to use. Cannot be Null.
*/
public void setFormat(final String format) throws IllegalFormatException, NullPointerException {
// Oh for a better way to do this!
try {
String.format(format, player, message);
} catch (RuntimeException ex) {
ex.fillInStackTrace();
throw ex;
}

public void setFormat(final String format) {
Validate.notNull(format, "Format cannot be Null!");
this.format = format;
}