1.15.2 api access to specific scoreboards

Discussion in 'Spigot Plugin Development' started by SkyyDaork, Feb 6, 2020.

  1. 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?
     
  2. when player runs a command, it checks players scoreboard objective "SP1", if SP1 = 1 then it triggers item give
     
  3. player.getscoreboard.getobjective("SP1")
    ?
     
  4. getscoreboard cannot be resolved or is not a field
     
  5. 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
     
  6. okay.. so whats your problem? you have the objective now..
     
  7. That it doesnt show the score in chatbar... it shows the org.bukkit.xxxxxxx. Should be showing a number, not that
     
  8. 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
     
  9. I cannot seem to get anything to stick and work, I've checked the docs and still get errors
     
  10. okay.. so show us the errors and tell us what youre doing to get the errors..
     
  11. 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"
     
  12. ? 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;
        ...
    }