how would I go about getting the team a player is in, removing them from the team and then deleting the team?
If you look through the Spigot API there are some useful methods on this. Read through them and I'm certain you'll find what you need https://hub.spigotmc.org/javadocs/bukkit/org/bukkit/scoreboard/Team.html
I appreciate the link, however i have looked throught it and tried to use .unregister() however i cant seem to get it to work.
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")) { } } } } } } }
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.
You are trying to unregister a string... What.. Of course that won't work. A String is not a instance of Team.
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();
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;
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
would this work? Code (Text): ScoreboardManager manager = Bukkit.getScoreboardManager(); Scoreboard scoreboard = manager.getMainScoreboard(); ((Team) scoreboard).unregister();
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.
@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();