So here's my Bukkit plugin code
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.scoreboard.*;
import org.bukkit.Bukkit;
//import org.bukkit.*;
public class GetScore extends JavaPlugin{
@Override
public void onEnable() {
// TODO Insert logic to be performed when the plugin is enabled
}
@Override
public void onDisable() {
// TODO Insert logic to be performed when the plugin is disabled
}
@Override
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
if (cmd.getName().equalsIgnoreCase("getscore")) { // If the player typed /basic then do the following...
// doSomething
ScoreboardManager manager = Bukkit.getScoreboardManager();
Scoreboard board = manager.getMainScoreboard();
//Scoreboard sb = new Scoreboard();
Objective objective = board.getObjective("Kill");
Score score = objective.getScore("John");
//sender.sendMessage(score.toString());
sender.sendMessage(score.toString());
return true;
} //If this has happened the function will return true.
// If this hasn't happened the value of false will be returned.
return false;
}
}
The thing is plugin compiles without errors,but when i type /getscore I get this: org.bukkit.craftbukkit.v1_7_R4.scoreboard.CraftScore@16f690c Of course this is not what I wanted,It should output John's score on objective Kill.Which is 38
The default value of toString()
is as follows:
getClass().getName() + '@' + Integer.toHexString(hashCode())
You'll have to provide an override for Score
's toString() method and in there, return the appropriate value.