Deleting scorebored team

Discussion in 'Spigot Plugin Development' started by Technerder, Apr 27, 2017.

  1. how would I go about getting the team a player is in, removing them from the team and then deleting the team?
     
  2. Could we see the code?
     
  3. Code (Text):
    package technerder.kurion.net;

    import org.bukkit.Bukkit;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;
    import org.bukkit.scoreboard.Team;

    public class Main extends JavaPlugin {

        public void TeamsCommand(CommandSender sender, Command cmd, String label, String[] args) {

            if (label.equalsIgnoreCase("teams")) {

                if (args[0].equalsIgnoreCase("create")) {

                    ScoreboardManager Manager = Bukkit.getScoreboardManager();
                    Scoreboard board = Manager.getNewScoreboard();
                    Team team = board.registerNewTeam(args[1]);
                    team.addEntry(sender.getName());
                    team.setAllowFriendlyFire(false);

                } else {
                   
                    if (args[0].equalsIgnoreCase("disband")) {
                       
                        String team = sender.getName();
                       
                        team.unregister();

                    } else {

                        if (args[0].equalsIgnoreCase("join")) {

                        } else {

                            if (args[0].equalsIgnoreCase("leave")) {

                            }
                        }
                    }
                }
            }
        }
    }
     

  4. Code (Text):
    if (args[0].equalsIgnoreCase("disband")) {
                       
                        String team = sender.getName();
                       
                        team.unregister();
    I would check to make sure you are using the correct class imports for #getName(). You may be grabbing the command sender's name instead of using the org.bukkit.scoreboard #getName() method.
     
  5. You are trying to unregister a string... What..

    Of course that won't work. A String is not a instance of Team.
     
  6. To delete a team is to get the Scoreboard like
    ScoreboardManager manager = Bukkit.getScoreboardManager();
    Scoreboard board = manager.getMainScoreboard();

    You can use it like this.
    board.getTeam("teamname").unregister();
     
  7. ok, so
    Code (Text):
    Scoreboard scoreboard = ((Team) sender).getScoreboard();
                        scoreboard.getTeams();
    and from what https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/scoreboard/Team.html tells me im supposed to do this:
    Code (Text):
    scoreboard.unregister;
    yet it is deprecated. whats is the updated alternative for
    Code (Text):
    scoreboard.unregister;
     
  8. There is not really a updated alternative That is really the best way
    but it is really scoreboard.unregister();

    you put
    scoreboard.unregister;

    but it works when it is deprecated
     
  9. would this work?
    Code (Text):
    ScoreboardManager manager = Bukkit.getScoreboardManager();
                        Scoreboard scoreboard = manager.getMainScoreboard();
                        ((Team) scoreboard).unregister();
     
  10. sender is a CommandSender you cannot just cast that to a Team. Also you want to unregister the Team not the scoreboard.

    Code (Text):
    Player player = (Player) sender;
    Scoreboard scoreboard = player.getScoreboard();

    for (Team team : scoreboard.getTeams()) {
        team.unregister();
    }  
    Obviously check before casting to player. If you have a specific team you want to unregister it from use scoreboard.getTeam(name) otherwise this will unregister all for that player.
     
  11. @Technerder
    Not Really, you are getting the getMainScoreboard you need to get the Team to unregister
    example:
    Scoreboard board = manager.getMainScoreboard();
    board.getTeam(teamname).unregister();

    to get the player team

    Player player = (Player) sender (if using sender)

    Scoreboard board = manager.getMainScoreboard();
    board.getPlayerTeam(player).unregister();
     
  12. public void for a command?