Removing from scoreboard

Discussion in 'Spigot Plugin Development' started by _Wiildanimal_, Jun 25, 2016.

Thread Status:
Not open for further replies.
  1. Hi, I would like the player to get removed from whatever scoreboard they are in upon quit.
    Code (Text):
    package me.arraying.nametags;

    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.event.player.PlayerQuitEvent;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.Team;

    import net.md_5.bungee.api.ChatColor;

    public class ListenerClass implements Listener {
     
        private MainClass pl;
     
        public ListenerClass(MainClass plugin) {
            plugin.getServer().getPluginManager().registerEvents(this, plugin);
            this.pl = plugin;
        }
     
        Scoreboard board = Bukkit.getScoreboardManager().getMainScoreboard();
        Team team = null;
     
        @EventHandler
        public void onJoin(PlayerJoinEvent e){
         
            Player player = e.getPlayer();
            String name = player.getName();
         
            if(player.hasPermission("nametag.owner")){
             
                if(board.getTeam("Owner") == null){
                 
                    team = board.registerNewTeam("Owner");
                 
                }
                else{
                 
                    team = board.getTeam("Owner");
                 
                }
                team.setPrefix(ChatColor.translateAlternateColorCodes('&', pl.getConfig().getString("owner")));
                team.addEntry(name);
             
            }
         
            if(player.hasPermission("nametag.admin")){
             
                if(board.getTeam("Admin") == null){
                 
                    team = board.registerNewTeam("Admin");
                 
                }
                else{
                 
                    team = board.getTeam("Admin");
                 
                }
                team.setPrefix(ChatColor.translateAlternateColorCodes('&', pl.getConfig().getString("admin")));
                team.addEntry(name);
             
            }
         
            if(player.hasPermission("nametag.mod")){
             
                if(board.getTeam("Mod") == null){
                 
                    team = board.registerNewTeam("Mod");
                 
                }
                else{
                 
                    team = board.getTeam("Mod");
                 
                }
                team.setPrefix(ChatColor.translateAlternateColorCodes('&', pl.getConfig().getString("mod")));
                team.addEntry(name);
             
            }
         
            if(player.hasPermission("nametag.helper")){
             
                if(board.getTeam("Helper") == null){
                 
                    team = board.registerNewTeam("Helper");
                 
                }
                else{
                 
                    team = board.getTeam("Helper");
                 
                }
                team.setPrefix(ChatColor.translateAlternateColorCodes('&', pl.getConfig().getString("helper")));
                team.addEntry(name);
             
            }
         
            if(player.hasPermission("nametag.platinum")){
             
                if(board.getTeam("Platinum") == null){
                 
                    team = board.registerNewTeam("Platinum");
                 
                }
                else{
                 
                    team = board.getTeam("Platinum");
                 
                }
                team.setPrefix(ChatColor.translateAlternateColorCodes('&', pl.getConfig().getString("platinum")));
                team.addEntry(name);
             
            }
         
        }
     
        public void onQuit(PlayerQuitEvent e){
         
            Player player = e.getPlayer();
            String name = player.getName();
         
            team.removeEntry(name);
         
        }
     
    }
    I have tried adding teams.getTeam("Platinum"); before removeEntry, didn't work.
     
    #1 _Wiildanimal_, Jun 25, 2016
    Last edited: Jun 25, 2016
Thread Status:
Not open for further replies.