Adding players to scoreboard teams

Discussion in 'Spigot Plugin Development' started by Marvin566, Oct 13, 2017.

  1. I can't seem to add myself to a team, what's wrong with this code?
    Code (Text):
    import org.bukkit.Bukkit;
    import org.bukkit.OfflinePlayer;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;
    import org.bukkit.scoreboard.Team;

    import net.md_5.bungee.api.ChatColor;

    public class Team implements CommandExecutor {

        static CommandSender s;
        static ScoreboardManager sm = Bukkit.getScoreboardManager();
        static Scoreboard scoreboard = sm.getNewScoreboard();

        public boolean onCommand(CommandSender sender, Command command, String label, String args[]) {
            s = sender;
                    if (s instanceof Player) {
                        Player player = (Player) s;
                        Team Prisoners = scoreboard.registerNewTeam("Prisoners");
                        Prisoners.addPlayer(player);
                        //Prisoners.addEntry(player.getName());
                        s.sendMessage(ChatColor.GREEN+"You are in the team!");
                    }
            return false;
        }
    }
     
     
  2. Just this line is wrong
    Code (Text):
    Team Prisoners = scoreboard.registerNewTeam("Prisoners");
    Change it for
    Code (Text):
    org.bukkit.scoreboard.Team Prisoners = scoreboard.registerNewTeam("Prisoners");
    Your code is wrong because the 'Team' you means refer to your class and not to the scoreboard Team !
     
  3. The class has another name, I just changed it in the post. Anyway, it doesn't work, org.bukkit.scoreboard.Team is already imported and still, I can't add myself there
     
  4. I have tested out your code and it's working for me with the line you set as a comment !
    Code (Text):
        static CommandSender s;
        static ScoreboardManager sm = Bukkit.getScoreboardManager();
        static Scoreboard scoreboard = sm.getNewScoreboard();

        public boolean onCommand(CommandSender sender, Command command, String label, String args[]) {
            s = sender;
            if (s instanceof Player) {
                Player player = (Player) s;
                org.bukkit.scoreboard.Team Prisoners = scoreboard.registerNewTeam("Prisoners");
                Prisoners.addEntry(player.getName());
                s.sendMessage(ChatColor.GREEN+"You are in the team!");
               
                System.out.println(Prisoners.getEntries());
            }
            return false;
        }
     
  5. I can't find the team and players in it when I use "/scoreboard teams list". They are stored in minecraft's scoreboard teams, right?
     
  6. Yes, what function do you use ?
    EDIT: i get all the teams like that
    Code (Text):
                for(org.bukkit.scoreboard.Team t : scoreboard.getTeams())
                    System.out.println(t.getName()+": "+t.getEntries());
     
  7. Well, I actually got the team and it's entries, but I still don't know why the team doesn't show up when I use minecraft scoreboard command. Any suggestions?
    [​IMG]
     
  8. I'm not a master at scoreboard so i don't know that point... I Hope i helped you with your problem :)
     
  9. Thanks for your time. The thing is, I wanted to make teams to change players' collision option. I can't get it to work with this code neither I want to use commands
     

Share This Page