I've been attempting to get this blasted code to check a players scoreboard objective value and I cant get anything working and google is the worst for help. Does anyone know where I can find/read an example for how to check specific scoreboard objectives?
https://hub.spigotmc.org/javadocs/spigot/org/bukkit/scoreboard/Scoreboard.html and https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/scoreboard/package-summary.html would be a good start, what are you trying to do?
when player runs a command, it checks players scoreboard objective "SP1", if SP1 = 1 then it triggers item give
https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/entity/Player.html#getScoreboard-- its there. import player or import the spigot api
I have them imported, Code (Java): package itsa.me.mario; import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scoreboard.Objective; public class Test extends JavaPlugin { @Override public void onEnable() { } // Fired when plugin is disabled @Override public void onDisable() { } public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (cmd.getName().equalsIgnoreCase("objtest")) { Player p = Bukkit.getPlayer(sender.getName()); @Nullable Objective sp1 = ((Player) sender).getScoreboard().getObjective("SP1"); Objective score = sp1; p.sendMessage("Your Test Number: " + sp1); } return false; } } returns in game: Code (Text): Your Test Number: [email protected]28
That it doesnt show the score in chatbar... it shows the org.bukkit.xxxxxxx. Should be showing a number, not that
oh so you want a score, not an objective.. get the objective you need, then use objective.getscore. or just look at the javadocs for a couple seconds
This is where I am: Code (Java): import org.bukkit.Bukkit; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.scoreboard.Objective; import org.bukkit.scoreboard.Scoreboard; public class Test extends JavaPlugin { @Override public void onEnable() { } // Fired when plugin is disabled @Override public void onDisable() { } public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) { if (cmd.getName().equalsIgnoreCase("objtest")) { Player p = Bukkit.getPlayer(sender.getName()); Scoreboard obj1 = p.Objective.getScores("SP1"); p.sendMessage("Your SP1 score:" + obj1); } return false; } } I am stuck on p.Objective.getScores, as "Objectives" is throwing: "Objective cannot be resolved or is not a field"
? you're randomly dropping #getScoreboard.. you can't get an objective from a player object. you had the correct thing previously. please, i cant do the thinking for you as well. also you shouldnt be getting the player that way, just cast it as you were before. /e oh i thought you were before, guess not. Code (Java): if(sender instanceof Player) { Player player = (Player)sender; ... }