1.15.2 Issue with grabbing the players score from scoreboard

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

  1. Been searching for how to pull a specific score from a players scoreboard for a few hours now and im now in a standstill trying to figure out what went wrong here? I'm working on getting the command to check a players score on "totrun" and see if it is either 0 or 1. Im getting at "p.getObjective(@NotNull String name);"
    Code (Text):
    The method getObjective() is undefined for the type Player
    Code (Java):
    package com.testrigz.myplugin;

    import java.util.ArrayList;
    import java.util.List;
    import java.util.Random;

    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.meta.ItemMeta;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Score;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;

    public class Spigots extends JavaPlugin{
        // Fired when plugin is first enabled
        @Override
        public void onEnable() {
        }
        // Fired when plugin is disabled
        @Override
        public void onDisable() {

        }
       
        @Override
        public boolean onCommand(CommandSender sender,
                                 Command command,
                                 String label,
                                 String[] args) {
            if (command.getName().equalsIgnoreCase("runchex")) {
                Random rand = new Random();
                Player p = (Player) sender;
                int random;
                random = rand.nextInt(6);
                Object spscore = p.getObjective(@NotNull String name);
                if (spscore == 1) {
                    sender.sendMessage("You have been awarded Endero");
                    p.getInventory().addItem(demo());
                    return true;
                }
                else {
                    sender.sendMessage("You havent completed this challenge yet");
                }
                return true;
            }
            return false;
        }
        private ItemStack demo() {
            ItemStack item = new ItemStack(Material.DIAMOND_SWORD, 1, (short) 12);
            ItemMeta meta = item.getItemMeta();
            meta.setDisplayName("Endero");
            {
                List<String> lore = new ArrayList<String>();
                lore.add("Use it wisely...");
                meta.setLore(lore);
            }
            item.setItemMeta(meta);
            return item;
        }

    }
    Anyone able to help me before I rip all my hair out in frustration?
     
  2. Player#getScoreboard()
    Scoreboard#getObjectibe()