How can I read out a value in Minecraft with a plugin?

Cr
- in Plugins
4

I would like to make a plugin by using a value that the player has entered in the plugin, so that I can e.g. Make / health 20 and then the maximum life number is set to 20.

Would be nice if someone could help me.

Ay

I'll help you:

First you create a class for the command:

@Override
public boolean onCommand (CommandSender commandSender, Command command, String s, String [] strings) {

if (! (commandSender instanceof Player)) return true;
final Player player = (Player) commandSender;

if (strings.length! = 1) {
player.sendMessage ("§4Use / health [health]");
return true;
}

try {

int healthValue = Integer.parseInt (strings [0]);
player.setMaxHealth (healthValue);
player.sendMessage ("§2Your maximum life is now:" + healthValue);

} catch (NumberFormatException exception) {
player.sendMessage ("§4You have to enter a number!");
}

return false;
}

the method you need is Integer # parseInt, which converts a data type into an integer. And of course a NumberFormatException, since the player can also specify a string.

Cr

Thanks, I'll try it out later.

Cr

Worked.

Ay

I'm happy ^^