Add a tab completion API for chat messages. Adds BUKKIT-2607

This implementation provides access to a (mutable) list and the base
message. Also provided is a convenience method for getting the last
'token' in the provided string.

By: Wesley Wolfe <weswolf@aol.com>
This commit is contained in:
Bukkit/Spigot
2012-10-17 04:33:02 -05:00
parent 14c7734fb1
commit 8848de9887
2 changed files with 96 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
package org.bukkit.event;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import org.bukkit.event.player.PlayerChatTabCompleteEvent;
import org.bukkit.plugin.messaging.TestPlayer;
import org.junit.Test;
import com.google.common.collect.ImmutableList;
public class PlayerChatTabCompleteEventTest {
@Test
public void testGetLastToken() {
assertThat(getToken("Hello everyone!"), is("everyone!"));
assertThat(getToken(" welcome to the show..."), is("show..."));
assertThat(getToken("The whitespace is here "), is(""));
assertThat(getToken("Too much whitespace is here "), is(""));
assertThat(getToken("The_whitespace_is_missing"), is("The_whitespace_is_missing"));
assertThat(getToken(""), is(""));
assertThat(getToken(" "), is(""));
}
private String getToken(String message) {
return new PlayerChatTabCompleteEvent(TestPlayer.getInstance(), message, ImmutableList.<String>of()).getLastToken();
}
}