Background: I used to program on the 3 Kingdoms MUD.
You are going to rapidly find that you don't want to use this kind of logic for command loop handling. I suggest that you look at using a Map<string, IGameCommand>
- where IGameCommand
provides the actual doing-work part.
Usage would look like this:
// might be other things you want in this interface later, as well...
interface IGameCommand
{
void Invoke(string commandline);
}
if (myMap.containsKey(op1))
{
myMap[op1].Invoke(op1);
}
This method is much easier to read and lets you merge a global dictionary of commands with commands added by the location and carried items of the player MUCH more easily. (Yes, this is a bit deeper into Java than you seem to be. When you're ready to use the tools I'm recommending here, you'll find you're starting to get good at Java. When you're ready to argue about what I've glossed over.... you'll be answering people's questions on SO.)