cannon: set count when loading wrong type of cannonballs

This commit is contained in:
Alexsuperfly
2021-04-18 17:00:39 -04:00
committed by Adam
parent 195bdd5971
commit 5bfbff492d
2 changed files with 21 additions and 0 deletions

View File

@@ -384,6 +384,15 @@ public class CannonPlugin extends Plugin
}
}
if (event.getMessage().startsWith("Your cannon contains"))
{
Matcher m = NUMBER_PATTERN.matcher(event.getMessage());
if (m.find())
{
cballsLeft = Integer.parseInt(m.group());
}
}
if (event.getMessage().startsWith("You unload your cannon and receive Cannonball")
|| event.getMessage().startsWith("You unload your cannon and receive Granite cannonball"))
{

View File

@@ -104,6 +104,18 @@ public class CannonPluginTest
Guice.createInjector(BoundFieldModule.of(this)).injectMembers(this);
}
@Test
public void addWrongTypeOfCannonballs()
{
final ChatMessage message = new ChatMessage();
message.setType(ChatMessageType.GAMEMESSAGE);
message.setMessage("Your cannon contains 20 x Cannonball.<br>You can only add cannonballs of the same kind.");
plugin.onChatMessage(message);
assertEquals(20, plugin.getCballsLeft());
}
@Test
public void addMaxCannonballs()
{