The whole source code: Code: package net.nubpro.project.plugin.hp; import java.util.logging.Logger; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; public class Hp extends JavaPlugin{ private Player player; private static final Logger log = Logger.getLogger("Minecraft"); public void onDisable() { log.info("[Health]Plugin had been disabled"); } public void onEnable() { log.info("[Health]Plugin had been enabled"); } public boolean onCommand(CommandSender sender, Command cmd, String cmdLabel, String[] args) { int health = player.getHealth(); if ((sender instanceof Player)){ if (cmd.getName().equalsIgnoreCase("hp")) { sender.sendMessage(health); } return false; } return false; } } A error occurs when I used "int"! See below: Code: int health = player.getHealth(); A error occurs when using "int" It keep telling me to change "int" to string due sender.sendMessage(health); cannot support int Code: int health = player.getHealth(); if ((sender instanceof Player)){ if (cmd.getName().equalsIgnoreCase("hp")) { sender.sendMessage(health); So I decide to change to string but getHealth(); doesnt support string Code: String health = player.getHealth(); It's making me MAD! Is there anyway to fix this?
String health = player.getHealth().toString(); This is like very basic stuff, you should know this O_O.
int doesn't have a toString method inherited from a superclass. It's a primitive data type. If you want to cast it as a string (but retain its use as an int) cast it as Integer. Code: Integer health = player.getHealth(); sender.sendMessage(health.toString()); alternatively: int health = player.getHealth(); sender.sendMessage("" + health);
Integer is a type (just like int) that stores data, it just wraps the int in a class with some methods to utilize the data in more than just one way (ie as an int) the expression: Code: Integer health = player.getHealth(); Means (simply) to create a variable named "health" of type "Integer," and assign it the value returned by "player.getHealth()" java.lang.Integer
@nubpro This seems to work for me: Code: public boolean onCommand(CommandSender sender, Command cmd, String cmdLabel, String[] args){ if (cmd.getName().equalsIgnoreCase("hp")){ if (sender instanceof Player){ Player player = (Player) sender; int health = player.getHealth(); player.sendMessage(String.valueOf(health)); return true; } } return false; } EDIT: Nevermind, you figured it out.