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

Commit

Permalink
Fix CommandHelper#getRawCommand() misbehaving with sub-commands (Fixes
Browse files Browse the repository at this point in the history
…#9), Add corresponding test to prevent this from happening again
  • Loading branch information
literalplus committed Sep 20, 2014
1 parent b891cd1 commit cc1dc2f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
4 changes: 4 additions & 0 deletions common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@
<groupId>net.cubespace</groupId>
<artifactId>Yamler-Core</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static String getRawCommand(String chatMessage) {
if (spaceIndex == -1) { //If no space found
chatMessage = chatMessage.substring(1); //Just remove slash
} else { //If we have a space
chatMessage = chatMessage.substring(1, spaceIndex - 1); //Get the first word of the message and remove slash
chatMessage = chatMessage.substring(1, spaceIndex); //Get the first word of the message and remove slash
}

return removeModPrefix(chatMessage); //Return the raw command name!
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.github.xxyy.cmdblocker.common.util;

import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

/**
* Tests the CommandHelper class for compliance with the JavaDoc declarations
*
* @author <a href="http://xxyy.github.io/">xxyy</a>
* @since 20/09/14
*/
public class CommandHelperTest {
@Test
public void testGetRawCommand() {
assertThat(CommandHelper.getRawCommand("/help"), is("help"));
assertThat(CommandHelper.getRawCommand("/help test"), is("help"));
assertThat(CommandHelper.getRawCommand("/minecraft:help"), is("help"));
assertThat(CommandHelper.getRawCommand("/minecraft:help test"), is("help"));
assertThat(CommandHelper.getRawCommand("/bukkit:help"), is("help"));
assertThat(CommandHelper.getRawCommand("/bukkit:help something multiple arguments wow"), is("help"));
}
}
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@
<artifactId>Yamler-Core</artifactId>
<version>2.2.3-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down

0 comments on commit cc1dc2f

Please sign in to comment.