001 package org.bukkit.event.player;
002
003 import java.util.Collection;
004
005 import org.apache.commons.lang.Validate;
006 import org.bukkit.entity.Player;
007 import org.bukkit.event.HandlerList;
008
009 /**
010 * Called when a player attempts to tab-complete a chat message.
011 */
012 public class PlayerChatTabCompleteEvent extends PlayerEvent {
013 private static final HandlerList handlers = new HandlerList();
014 private final String message;
015 private final String lastToken;
016 private final Collection<String> completions;
017
018 public PlayerChatTabCompleteEvent(final Player who, final String message, final Collection<String> completions) {
019 super(who);
020 Validate.notNull(message, "Message cannot be null");
021 Validate.notNull(completions, "Completions cannot be null");
022 this.message = message;
023 int i = message.lastIndexOf(' ');
024 if (i < 0) {
025 this.lastToken = message;
026 } else {
027 this.lastToken = message.substring(i + 1);
028 }
029 this.completions = completions;
030 }
031
032 /**
033 * Gets the chat message being tab-completed.
034 *
035 * @return the chat message
036 */
037 public String getChatMessage() {
038 return message;
039 }
040
041 /**
042 * Gets the last 'token' of the message being tab-completed.
043 * <p>
044 * The token is the substring starting with the character after the last
045 * space in the message.
046 *
047 * @return The last token for the chat message
048 */
049 public String getLastToken() {
050 return lastToken;
051 }
052
053 /**
054 * This is the collection of completions for this event.
055 *
056 * @return the current completions
057 */
058 public Collection<String> getTabCompletions() {
059 return completions;
060 }
061
062 @Override
063 public HandlerList getHandlers() {
064 return handlers;
065 }
066
067 public static HandlerList getHandlerList() {
068 return handlers;
069 }
070 }