Bukkit-API  1.7.9-R0.2
The inofficial Bukkit-API
PlayerChatTabCompleteEvent.java
1 package org.bukkit.event.player;
2 
3 import java.util.Collection;
4 
5 import org.apache.commons.lang.Validate;
6 import org.bukkit.entity.Player;
8 
9 /**
10  * Called when a player attempts to tab-complete a chat message.
11  */
13  private static final HandlerList handlers = new HandlerList();
14  private final String message;
15  private final String lastToken;
16  private final Collection<String> completions;
17 
18  public PlayerChatTabCompleteEvent(final Player who, final String message, final Collection<String> completions) {
19  super(who);
20  Validate.notNull(message, "Message cannot be null");
21  Validate.notNull(completions, "Completions cannot be null");
22  this.message = message;
23  int i = message.lastIndexOf(' ');
24  if (i < 0) {
25  this.lastToken = message;
26  } else {
27  this.lastToken = message.substring(i + 1);
28  }
29  this.completions = completions;
30  }
31 
32  /**
33  * Gets the chat message being tab-completed.
34  *
35  * @return the chat message
36  */
37  public String getChatMessage() {
38  return message;
39  }
40 
41  /**
42  * Gets the last 'token' of the message being tab-completed.
43  * <p>
44  * The token is the substring starting with the character after the last
45  * space in the message.
46  *
47  * @return The last token for the chat message
48  */
49  public String getLastToken() {
50  return lastToken;
51  }
52 
53  /**
54  * This is the collection of completions for this event.
55  *
56  * @return the current completions
57  */
58  public Collection<String> getTabCompletions() {
59  return completions;
60  }
61 
62  @Override
63  public HandlerList getHandlers() {
64  return handlers;
65  }
66 
67  public static HandlerList getHandlerList() {
68  return handlers;
69  }
70 }