Scoreboard

Discussion in 'Plugin Development' started by LiamHBest, Mar 31, 2020.

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

    LiamHBest

    Hey! Im a new developer that is trying to code a scoreboard plugin. I have run in to some problems that i cant fix. When someone joins a specific world i want the "Lobby: " score on the scoreboard to change depending on which world they joined. But then when a player is switching world I also want the "Lobby: " score to change depending on which world they switched to! I have tried to do this in every way but I cant figure out how! Both the scoreboard just tries to override each other! I will send my code here!
    Im a new developer so please dont blame me for my bad code and only using one class!
    Thanks! :)
    Code:
    package me.liamhbest.scoreboardTest;
    
    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.HandlerList;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerChangedWorldEvent;
    import org.bukkit.event.player.PlayerJoinEvent;
    import org.bukkit.plugin.Plugin;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.scoreboard.DisplaySlot;
    import org.bukkit.scoreboard.Objective;
    import org.bukkit.scoreboard.Score;
    import org.bukkit.scoreboard.Scoreboard;
    import org.bukkit.scoreboard.ScoreboardManager;
    
    import me.clip.placeholderapi.PlaceholderAPI;
    
    public class Test extends JavaPlugin implements Listener {
    
        static Plugin plugin;
    
        public void onEnable() {
            plugin = this;
            Bukkit.getServer().getPluginManager().registerEvents(this, this);
        }
    
    
        @EventHandler
        public void PlayerJoin(PlayerJoinEvent e) {
            final Player p = e.getPlayer();
            ScoreboardManager manager = Bukkit.getScoreboardManager();
            final Scoreboard board = manager.getNewScoreboard();
            Objective objective = board.registerNewObjective("test", "dummy");
            objective.setDisplaySlot(DisplaySlot.SIDEBAR);
            objective.setDisplayName(ChatColor.GOLD + "" + ChatColor.BOLD + "ALFACRAFT" + ChatColor.GRAY + " " + ChatColor.ITALIC + "");
        
            Score score = objective.getScore(ChatColor.GREEN + " ");
            score.setScore(12);
        
            Score score1 = objective.getScore(ChatColor.AQUA + "Rank: " + ChatColor.WHITE + "PLAYERS RANK");
            score1.setScore(11);
        
            Score score2 = objective.getScore(ChatColor.AQUA + "Level: " + ChatColor.WHITE + "PLAYERS LEVEL");
            score2.setScore(10);
        
            Score score3 = objective.getScore(ChatColor.AQUA + "Gems: " + ChatColor.WHITE + "PLAYERS GEMS");
            score3.setScore(9);
        
            Score score4 = objective.getScore(ChatColor.WHITE + "  ");
            score4.setScore(8);
        
            Score score5 = objective.getScore(ChatColor.AQUA + "Mystery Boxes: " + PlaceholderAPI.setPlaceholders(p, ChatColor.WHITE + "%gadgetsmenu_mystery_boxes%"));
            score5.setScore(7);
        
            Score score6 = objective.getScore(ChatColor.AQUA + "Mystery Dust: " + PlaceholderAPI.setPlaceholders(p, ChatColor.WHITE + "%gadgetsmenu_mystery_dust%"));
            score6.setScore(6);
    
            Score score7 = objective.getScore(ChatColor.AQUA + "");
            score7.setScore(5);
        
            Score score8 = objective.getScore(ChatColor.AQUA + "Players Online: " + ChatColor.WHITE + (Bukkit.getOnlinePlayers().size()));
            score8.setScore(4);
        
            if (p.getWorld().getName().equalsIgnoreCase("world")) {
                Score scoreworld = objective.getScore(ChatColor.AQUA + "Lobby: " + ChatColor.WHITE + "#1");
                scoreworld.setScore(3);
            }
        
        
            if (p.getWorld().getName().equalsIgnoreCase("hub1_main")) {
                Score scorehub1 = objective.getScore(ChatColor.AQUA + "Lobby: " + ChatColor.WHITE + "#2");
                scorehub1.setScore(3);
            }
        
            Score score10 = objective.getScore(ChatColor.AQUA + " ");
            score10.setScore(2);
        
            Score score11 = objective.getScore(ChatColor.YELLOW + "www.alfacraft.buycraft.net");
            score11.setScore(1);
        
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Test.plugin, new Runnable() {
                public void run() {
    
        
            p.setScoreboard(board);
                
                }
            },0, 10 * 2); {
            
            }
    
    
    
        }
        
    
        @EventHandler
        public void onWorldSwitch(PlayerChangedWorldEvent event) {
            final Player p = event.getPlayer();
            ScoreboardManager manager = Bukkit.getScoreboardManager();
            final Scoreboard board1 = manager.getNewScoreboard();
            Objective objective = board1.registerNewObjective("test", "dummy");
            objective.setDisplaySlot(DisplaySlot.SIDEBAR);
            objective.setDisplayName(ChatColor.GOLD + "" + ChatColor.BOLD + "ALFACRAFT" + ChatColor.GRAY + " " + ChatColor.ITALIC + "");
        
            Score score = objective.getScore(ChatColor.GREEN + " ");
            score.setScore(12);
        
            Score score1 = objective.getScore(ChatColor.AQUA + "Rank: " + ChatColor.WHITE + "PLAYERS RANK");
            score1.setScore(11);
         
            Score score2 = objective.getScore(ChatColor.AQUA + "Level: " + ChatColor.WHITE + "PLAYERS LEVEL");
            score2.setScore(10);
        
            Score score3 = objective.getScore(ChatColor.AQUA + "Gems: " + ChatColor.WHITE + "PLAYERS GEMS");
            score3.setScore(9);
        
            Score score4 = objective.getScore(ChatColor.WHITE + "  ");
            score4.setScore(8);
        
            Score score5 = objective.getScore(ChatColor.AQUA + "Mystery Boxes: " + PlaceholderAPI.setPlaceholders(p, ChatColor.WHITE + "%gadgetsmenu_mystery_boxes%"));
            score5.setScore(7);
        
            Score score6 = objective.getScore(ChatColor.AQUA + "Mystery Dust: " + PlaceholderAPI.setPlaceholders(p, ChatColor.WHITE + "%gadgetsmenu_mystery_dust%"));
            score6.setScore(6);
    
            Score score7 = objective.getScore(ChatColor.AQUA + "");
            score7.setScore(5);
        
            Score score8 = objective.getScore(ChatColor.AQUA + "Players Online: " + ChatColor.WHITE + (Bukkit.getOnlinePlayers().size()));
            score8.setScore(4);
        
            if (p.getWorld().getName().equalsIgnoreCase("world")) {
                Score scoreworldA = objective.getScore(ChatColor.AQUA + "Lobby: " + ChatColor.WHITE + "#1");
                scoreworldA.setScore(3);
            }
        
            if (p.getWorld().getName().equalsIgnoreCase("hub1_main")) {
                Score scorehub1A = objective.getScore(ChatColor.AQUA + "Lobby: " + ChatColor.WHITE + "#2");
                scorehub1A.setScore(3);
            }
        
            Score score10 = objective.getScore(ChatColor.AQUA + " ");
            score10.setScore(2);
        
            Score score11 = objective.getScore(ChatColor.YELLOW + "www.alfacraft.buycraft.net");
            score11.setScore(1);
        
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(Test.plugin, new Runnable() {
                public void run() {
    
        
            p.setScoreboard(board1);
                
                
                }
            },0, 10 * 2); {
            
            }
    
    
        
        }
    
    
    
    }
    
    
    
    
     
    Last edited: Mar 31, 2020
  2. @LiamHBest You're creating a new scoreboard everytime the events are called. You should create it in the onEnable.
     
  3. Offline

    LiamHBest

    Okay but can I make a new scoreboard and at the same time delete the old one, like a loop?
     
  4. Offline

    LiamHBest

    I dont know?? Im new the coding so i dont really know any good methods? But what i want to do in total is when you join the server I want the scoreboard to start working and I want it to set the score depending on which world i joined, but then I also want the score to be set to another thing when i switch world, but they just start to override each other, can I fix it in someway??
     
  5. Online

    timtower Administrator Moderator

    @LiamHBest Get the old scoreboard and modify the values instead.
     
  6. Offline

    LiamHBest

    Okay! Im new to developing so I will see what I can do that is not so complecated! But what you says sounds like its not to hard with the help of some youtube videos, forums and some hours behind the computer! But thanks for the answer! Is there any other way to do it??
     
  7. @LiamHBest Recreating the scoreboard causes flicker, if you don't want any flicker, you'll have to set the values.
     
Thread Status:
Not open for further replies.

Share This Page