Basically I want to make it so when the user types into the textfield /attack animal it does the attack method and takes animal as a parameter. So if player typed /attack foo it do player.attack(foo). I already have methods that perform chat so I know which player is doing the chat. I just need to know how to reconize what comes after the /attack and take it as a parameter for player.attack() which takes a Player object as an argument. These are my methods that receive input:
public void actionPerformed(ActionEvent textBox) {
String text = textField.getText();
player.chat(text);
}
Which is in my Gui class, and:
public void chat(String chat){
playerGui.printText(this.getName() + ": " + chat);
playerGui.textField.selectAll();
}
Which is in the player class. A gui instance is passed to Player() which creates the variable playerGui.
You’ll have to tweak this to fit the syntax you want the user to use, but you would probably want to change your actionPerformed method to check for the different actions the user can perform, rather than just chatting.
You will still have to verify that you are getting the right kind of arguments for each command, and I didn’t put in anything safeguard against null pointers or out-of-bounds with the string functions, but hopefully that will get you started.