Solved Using teams to color player names

Discussion in 'Plugin Development' started by flash110, Jun 3, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    flash110

    Hello, I was trying to create a plugin that allowed me to organize players into teams and color their name tags everywhere. It doesn't want to work in bukkit 1.8.9. I do not have the code right now because I am writing this on my phone from English class.
     
  2. Offline

    CheesyFreezy

    Do you know why it is not working?
     
  3. Offline

    flash110

    @CheesyFreezy No I do not know why, I am in Spanish class right now and I will check and try many different methods when I get home.
     
  4. Offline

    CheesyFreezy

    Can you maybe send the code, that is easier to see where the problem is.
     
  5. Offline

    mine-care

    @flash110 All we can tell you from the description you gave us is: "Something is wrong with it."
    Unfortunately we need the error (if any), the code and possibly other things to find what the issue is, and recomend fixes.
    In the mean time, forus on your classes!
     
  6. Offline

    flash110

    @CheesyFreezy and @mine-care Ok, Ill edit this comment with the code once a rewrite it really quick. Ok! I fixed it myself, some stupid mistakes, I forgot the .toString() on the color prefixes... Anyways if you need help here is the code:
    Code:
    package me.flash110;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.Team;
    
    public class Teams extends JavaPlugin implements Listener {
       
        private Scoreboard scoreboard;
       
        public void onEnable() {
            Bukkit.getPluginManager().registerEvents(this, this);
            scoreboard = getServer().getScoreboardManager().getMainScoreboard();
               initializeTeam("red", ChatColor.RED.toString());
               initializeTeam("blue", ChatColor.BLUE.toString());
        }
         
           private void initializeTeam(String teamName, String prefix) {
               if (scoreboard.getTeam(teamName) == null) {
                   scoreboard.registerNewTeam(teamName).setPrefix(prefix);
               }
           }
         
           @SuppressWarnings("deprecation")
            @EventHandler
           public void onPlayerJoin(PlayerJoinEvent e) {
              if (scoreboard.getTeam("red").getPlayers().size() < scoreboard.getTeam("blue").getPlayers().size()) {
                  scoreboard.getTeam("red").addPlayer(e.getPlayer());
              }
              else {
                  scoreboard.getTeam("blue").addPlayer(e.getPlayer());
              }
           }
    }
    
     
    Last edited: Jun 6, 2016
Thread Status:
Not open for further replies.

Share This Page