1.8.8 Issues with Scoreboard Configuration

Discussion in 'Spigot Plugin Development' started by NoxuUHC, Mar 26, 2020.

  1. I am fairly new to java plugin coding, and need help with this, I am having trouble where the config.yml is cleared after I export my .jar file and the scoreboard doesn't show up because the config is empty.

    Config before export:
    [​IMG]

    Config after export:
    [​IMG]


    Completely empty..

    CODE:

    Main Class: Hub.java
    [​IMG]

    RAW CODE:
    Code (Java):
    [/B]
    package nox.HubCore;

    import org.bukkit.plugin.java.JavaPlugin;

    public class Hub extends JavaPlugin {

       
        public void onEnable() {
            getServer().getConsoleSender().sendMessage("Thank you for using our Hub Core!");
            getConfig().options().copyDefaults();
            saveConfig();
        }
    [B]   [/B]
    }
    [B]



    Scoreboard Class: Scoreboards.java
    [​IMG]

    RAW CODE:
    Code (Java):
    package nox.HubCore;

    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.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;

    public class Scoreboards extends JavaPlugin implements Listener {
       
        @EventHandler
        public void JN(PlayerJoinEvent pe) {
            @SuppressWarnings("unused")
            Player p = pe.getPlayer();
           
            ScoreboardManager sm = Bukkit.getScoreboardManager();
                Scoreboard sb = sm.getNewScoreboard();
           
            Objective o = sb.registerNewObjective("SBC", "");
                o.setDisplayName(getConfig().getString("Scoreboard Title"));
                    o.setDisplaySlot(DisplaySlot.SIDEBAR);
                   
                Score sg = o.getScore(getConfig().getString("L6"));
            sg.setScore(1);
                Score sg1 = o.getScore(getConfig().getString("L5"));
            sg1.setScore(2);
                Score sg2 = o.getScore(getConfig().getString("L4"));
            sg2.setScore(3);
                Score sg3 = o.getScore(getConfig().getString("L3"));
            sg3.setScore(4);
                Score sg4 = o.getScore(getConfig().getString("L2"));
            sg4.setScore(5);
                Score sg5 = o.getScore(getConfig().getString("L1"));
            sg5.setScore(6);
        }
       
    }
     

    Thats all, if anyone could help that'd be great.
     
  2. You forgot to assign the new scoreboard to the player.
    Add one line at the end of the method:
    Code (Java):
    p.setScoreboard(sb);