Browse Source

Made input for getUseMessage() case insensitive

remotes/origin/fight-engine
fdai7430 2 years ago
parent
commit
d47b77c1ea
  1. 4
      src/main/java/org/bitbiome/commands/UseCommand.java
  2. 3
      src/test/java/org/bitbiome/commands/UseCommandTest.java

4
src/main/java/org/bitbiome/commands/UseCommand.java

@ -49,7 +49,7 @@ private boolean combat = false;
for(int i = 0; i<inv.size(); i++) { for(int i = 0; i<inv.size(); i++) {
Item item = inv.get(i); Item item = inv.get(i);
if(item.getName().equals(itemName)) {
if(item.getName().toLowerCase().equals(itemName.toLowerCase())) {
if(!item.doesDamage()) if(!item.doesDamage())
return "You can't attack with this."; return "You can't attack with this.";
if(message.length == 1) if(message.length == 1)
@ -59,7 +59,7 @@ private boolean combat = false;
ArrayList<Mob> mobs = loc.getMobList(); ArrayList<Mob> mobs = loc.getMobList();
for(int j = 0; j<mobs.size(); j++) { for(int j = 0; j<mobs.size(); j++) {
Mob mob = mobs.get(j); Mob mob = mobs.get(j);
if(mob.getName().equals(targetName))
if(mob.getName().toLowerCase().equals(targetName.toLowerCase()))
return useItem(item, mob, loc); return useItem(item, mob, loc);
} }
return "That target is not available."; return "That target is not available.";

3
src/test/java/org/bitbiome/commands/UseCommandTest.java

@ -47,8 +47,11 @@ public class UseCommandTest {
assertEquals("You can't attack with this.", com.getUseMessage("Fell", engine)); assertEquals("You can't attack with this.", com.getUseMessage("Fell", engine));
engine.getPlayer().addToInventory(new Item("Heiliges Schwert der Erzengel", true, 3000)); engine.getPlayer().addToInventory(new Item("Heiliges Schwert der Erzengel", true, 3000));
assertEquals("That target is not available.", com.getUseMessage("Heiliges Schwert der Erzengel on Wolf", engine)); assertEquals("That target is not available.", com.getUseMessage("Heiliges Schwert der Erzengel on Wolf", engine));
assertEquals("That target is not available.", com.getUseMessage("hEiLiGeS sChWeRt DeR eRzEnGeL on WoLf", engine));
engine.getPlayer().getLocation().getMobList().add(new Mob("Wolf", false, 11, 10)); engine.getPlayer().getLocation().getMobList().add(new Mob("Wolf", false, 11, 10));
assertEquals("You killed Wolf with Heiliges Schwert der Erzengel", com.getUseMessage("Heiliges Schwert der Erzengel on Wolf", engine)); assertEquals("You killed Wolf with Heiliges Schwert der Erzengel", com.getUseMessage("Heiliges Schwert der Erzengel on Wolf", engine));
assertEquals("That target is not available.", com.getUseMessage("Heiliges Schwert der Erzengel on Wolf", engine)); assertEquals("That target is not available.", com.getUseMessage("Heiliges Schwert der Erzengel on Wolf", engine));
engine.getPlayer().getLocation().getMobList().add(new Mob("Wolf", false, 11, 10));
assertEquals("You killed Wolf with Heiliges Schwert der Erzengel", com.getUseMessage("hEiLiGeS sChWeRt DeR eRzEnGeL on WoLf", engine));
} }
} }
Loading…
Cancel
Save