Solved How do i add %blank% Variables on my scoreboard?

Discussion in 'Spigot Plugin Development' started by kingodk, Jun 22, 2016.

  1. Heyy guys,

    How do i add a blank space in scoreboard? with a variable of %blank%

    Code (Text):
    package bukkit.kingo.hub;

    import org.bukkit.Bukkit;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.scoreboard.DisplaySlot;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Score;
    import org.bukkit.scoreboard.ScoreboardManager;

    import net.md_5.bungee.api.ChatColor;

    public class Scoreboard implements Listener
    {
        public Scoreboard (main plugin)
        {
            plugin.getServer().getPluginManager().registerEvents(this, plugin);
        }

        @EventHandler
        public void playerJoin (PlayerJoinEvent e)
        {
            FileConfiguration config = main.getInstance().getConfig();
            Boolean sbBoolean = config.getBoolean("sb-Bool");
            String sbTitle = config.getString("sb-Title");
            String sbLine16 = config.getString("sb-line16").replace("%blank%", "");
            String sbLine15 = config.getString("sb-line15").replace("%blank%", "");
            String sbLine14 = config.getString("sb-line14").replace("%blank%", "");
            String sbLine13 = config.getString("sb-line13").replace("%blank%", "");
            String sbLine12 = config.getString("sb-line12").replace("%blank%", "");
            String sbLine11 = config.getString("sb-line11").replace("%blank%", "");
            String sbLine10 = config.getString("sb-line10").replace("%blank%", "");
            String sbLine9 = config.getString("sb-line9").replace("%blank%", "");
            String sbLine8 = config.getString("sb-line8").replace("%blank%", "");
            String sbLine7 = config.getString("sb-line7").replace("%blank%", "");
            String sbLine6 = config.getString("sb-line6").replace("%blank%", "");
            String sbLine5 = config.getString("sb-line5").replace("%blank%", "");
            String sbLine4 = config.getString("sb-line4").replace("%blank%", "");
            String sbLine3 = config.getString("sb-line3").replace("%blank%", "");
            String sbLine2 = config.getString("sb-line2").replace("%blank%", "");
            String sbLine1 = config.getString("sb-line1").replace("%blank%", "");
            String sbLine0 = config.getString("sb-line0").replace("%blank%", "");
           
            Player p = e.getPlayer();
           
            ScoreboardManager manager = Bukkit.getScoreboardManager();
            org.bukkit.scoreboard.Scoreboard sBoard = (org.bukkit.scoreboard.Scoreboard) manager.getNewScoreboard();
            Objective obj = ((org.bukkit.scoreboard.Scoreboard) sBoard).registerNewObjective("test", "dummy");
            obj.setDisplaySlot(DisplaySlot.SIDEBAR);
            obj.setDisplayName(ChatColor.translateAlternateColorCodes('&', sbTitle));
           
            Score score = obj.getScore(ChatColor.translateAlternateColorCodes('&', sbLine16));
            score.setScore(16);
            Score score1 = obj.getScore(ChatColor.translateAlternateColorCodes('&', sbLine15));
            score1.setScore(15);
            Score score2 = obj.getScore(ChatColor.translateAlternateColorCodes('&', sbLine14));
            score2.setScore(14);
            Score score3 = obj.getScore(ChatColor.translateAlternateColorCodes('&', sbLine13));
            score3.setScore(13);
            Score score4 = obj.getScore(ChatColor.translateAlternateColorCodes('&', sbLine12));
            score4.setScore(12);
            Score score5 = obj.getScore(ChatColor.translateAlternateColorCodes('&', sbLine11));
            score5.setScore(11);
            Score score6 = obj.getScore(ChatColor.translateAlternateColorCodes('&', sbLine10));
            score6.setScore(10);
            Score score7 = obj.getScore(ChatColor.translateAlternateColorCodes('&', sbLine9));
            score7.setScore(9);
            Score score8 = obj.getScore(ChatColor.translateAlternateColorCodes('&', sbLine8));
            score8.setScore(8);
            Score score9 = obj.getScore(ChatColor.translateAlternateColorCodes('&', sbLine7));
            score9.setScore(7);
            Score score10 = obj.getScore(ChatColor.translateAlternateColorCodes('&', sbLine6));
            score10.setScore(6);
            Score score11 = obj.getScore(ChatColor.translateAlternateColorCodes('&', sbLine5));
            score11.setScore(5);
            Score score12 = obj.getScore(ChatColor.translateAlternateColorCodes('&', sbLine4));
            score12.setScore(4);
            Score score13 = obj.getScore(ChatColor.translateAlternateColorCodes('&', sbLine3));
            score13.setScore(3);
            Score score14 = obj.getScore(ChatColor.translateAlternateColorCodes('&', sbLine2));
            score14.setScore(2);
            Score score15 = obj.getScore(ChatColor.translateAlternateColorCodes('&', sbLine1));
            score15.setScore(1);
            Score score16 = obj.getScore(ChatColor.translateAlternateColorCodes('&', sbLine0));
            score16.setScore(0);
           
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(main.plugin, new Runnable()
            {
                public void run ()
                {
                    if(sbBoolean)
                    {
                        p.setScoreboard(sBoard);
                    }
                    else
                    {
                       
                    }
                }
            }, 0, 20 * 10);
        }
    }
     
     
  2. You can't have 2 same texts, so if you do for line 0:
    Code (Text):
     String sbLine0 = config.getString("sb-line0").replace("%blank%", "");
    and for line 1:
    Code (Text):
     String sbLine1 = config.getString("sb-line1").replace("%blank%", " ");
    it'll work!
    You just need to add one space more at every variable: e.g. line 0: 0 spaces; line 1: 1 space; line 2: 2 spaces etc
     
  3. Like this?
    Code (Text):
            String sbLine16 = config.getString("sb-line16").replace("%blank%", "              ");
            String sbLine15 = config.getString("sb-line15").replace("%blank%", "             ");
            String sbLine14 = config.getString("sb-line14").replace("%blank%", "            ");
            String sbLine13 = config.getString("sb-line13").replace("%blank%", "           ");
            String sbLine12 = config.getString("sb-line12").replace("%blank%", "          ");
            String sbLine11 = config.getString("sb-line11").replace("%blank%", "         ");
            String sbLine10 = config.getString("sb-line10").replace("%blank%", "        ");
            String sbLine9 = config.getString("sb-line9").replace("%blank%", "         ");
            String sbLine8 = config.getString("sb-line8").replace("%blank%", "        ");
            String sbLine7 = config.getString("sb-line7").replace("%blank%", "       ");
            String sbLine6 = config.getString("sb-line6").replace("%blank%", "      ");
            String sbLine5 = config.getString("sb-line5").replace("%blank%", "     ");
            String sbLine4 = config.getString("sb-line4").replace("%blank%", "    ");
            String sbLine3 = config.getString("sb-line3").replace("%blank%", "   ");
            String sbLine2 = config.getString("sb-line2").replace("%blank%", "  ");
            String sbLine1 = config.getString("sb-line1").replace("%blank%", " ");
            String sbLine0 = config.getString("sb-line0").replace("%blank%", "");
     
    • Agree Agree x 1
  4. Thanks for the help guys!!
     
    • Like Like x 1
  5. guy* :p
     
  6. You do know there are such things as arrays and for loops to make this like 5 lines (or less). You should learn Java all the way so you can actually take advantage of these features.