I am making a scoreboard and need to set the score of a scoreboard as text. The scoreboard is for ranks and it won't let me set the score as a string, so I can enter the players ranks. How would I fix this/do this?
Dragonphase Ok then would I be able to set the display name to the rank of each player by setting that to a string?
@Dragonphase ok but when I try to set the display name as a string I get this error on the player join event (that is where I put the setup scoreboard): and my code is (THE ERROR IS MAINLY CAUSED AT line 65 the rank.setDisplayName): Code:java package me.Cockatoo2X.Main; import java.io.File;import java.io.IOException;import java.util.UUID; import org.bukkit.Bukkit;import org.bukkit.ChatColor;import org.bukkit.configuration.file.YamlConfiguration;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.Scoreboard; public class Main extends JavaPlugin implements Listener{ File folder = new File(this.getDataFolder() + File.separator);File playersdata = new File(this.getDataFolder() + File.separator + "Players.yml");YamlConfiguration playerConfig = YamlConfiguration.loadConfiguration(playersdata); private Scoreboard sb; public void onEnable() {Bukkit.getServer().getPluginManager().registerEvents(this, this);getLogger().info("Mage Academy Enabled!"); if(!folder.exists()){folder.mkdir();if (!(playersdata.exists())) {try {playersdata.createNewFile(); } catch (IOException e) { }}}} public void onDisable() {getLogger().info("Mage Academy Disabled!");pcSave();} @EventHandlerpublic void onPlayerJoin (final PlayerJoinEvent e){Player p = e.getPlayer();UUID pID = p.getUniqueId(); playerConfig.set("Players." + pID + ".Current Username:.", p.getName()); pcSave(); if (!(playerConfig.contains("Players." + pID + ".Rank"))){playerConfig.set("Players." + pID + ".Rank", "Apprentice");pcSave();} String pRank = playerConfig.getString("Players." + pID + ".Rank"); pcSave(); //CREATE ALL SCOREBOARD STUFFsb = Bukkit.getScoreboardManager().getNewScoreboard();Objective rank = sb.registerNewObjective("rank", "dummy");rank.setDisplayName(pRank);rank.setDisplaySlot(DisplaySlot.BELOW_NAME); p.setScoreboard(getScoreboard()); p.sendMessage(ChatColor.RED + "WELCOME TO THE MAGE ACADEMY!"); } public void pcSave(){try {playerConfig.save(playersdata);} catch(IOException e) { }} public Scoreboard getScoreboard(){return this.sb;} }
cockatoo2 Code:java playerConfig.set("Players." + pID + ".Current Username:.", p.getName()); That's not how configs work.
stormneo7 Dragonphase First of all I am trying to fix a scoreboard problem and secondly that is a custom config.yml defined somewhere else in my code but as I said earlier how can I fix the problem I just listed, (my next post above this one)
Do you know how to debug errors?... Your error's coming from that line. I suggest that you look carefully. Quoting your error: Caused by: java.lang.IllegalArgumentException: Cannot set to an empty path Secondly, how're you concluding that the error's with your scoreboard? You can't. Your code malfunctions before it even GETS to the scoreboard part, stopping the script entirely.
stormneo7 I know it is coming from that line and that is what I need help fixing I have tried rearranging my code and asked other bukkit devs for help like timtower but we can't figure it out. So can you help me fix that line?
Explain to me what the dots [.] do inside a configuration path. If you know what they do, you should have no problem finding your issue.
stormneo7 the dots in a config path help separate the paths. Like: Players: UUID:Name:Rank:Different UUID:They are used to create separate sections. But I don't know how that would help
playerConfig.set("Players." + pID + ".Current Username:.", p.getName()); Now read the path you're trying to set. You should figure out why Caused by: java.lang.IllegalArgumentException: Cannot set to an empty path was thrown. If you still can't, I'll explain it.
Dammit I give up. I'll explain it now. Code: at me.Cockatoo2X.Main.Main.onPlayerJoin(Main.java:54) ~[?:?] Caused by: java.lang.IllegalArgumentException: Cannot set to an empty path This was your error log. The problem occurs at Main.java class in line 54. I don't know where you got 65 from. Line 54 is Code:java playerConfig.set("Players." + pID + ".Current Username:.", p.getName()); Your path for the variable is Code: "Players." + pID + ".Current Username:." Do you not see what's wrong with that? Why do you have a :. at the end of the path? That basically means you're trying to set Players => [UUID] => CurrentUsername: => null That's where your error triggers. Your path ends up nowhere due to the '.' at the end. Your code cuts off before you even reach the scoreboard coding.
stormneo7 ok let my try that stormneo7 Yeah...It worked and I feel like an idiot... Now let me ask one more question you will find dumb, How do I have 2 or More chat colors combined? Like Bold Red and Magic? EDIT by Moderator: merged posts, please use the edit button instead of double posting.
cockatoo2 Minecraft uses the § symbol to identify colour. So you could do p.sendMessage("§4§lHi"); Another option is (ChatColor.RED + "" + ChatColor.BOLD + "Hi");