I been trying for past hour or two to work the scoreboards out and I am unable. I looked on tutorials on YouTube, on here etc. with no sucess so I decided to ask here for support; what I want is a scoreboard that will basically say: -- Test -- Konkz: 20 (The 20 is amount of Material.SUGAR in inventory) Could someone please write me the code for that so I can see how it works? Please and thank you. If anyone is having a bad day and feels like being negative, please just don't reply.
Please don't ask for code so blatantly especially without supplying any to see where you are at. However, you need to create a scoreboard and mess around with objectives and score. If you haven't already, read the documentation or go find the wikipedia on Scoreboard programming to learn what each piece means/does.
Hmm okay. I have managed to get the Scoreboard to work to somewhat what I want, to see if I can get it to work I checked how many users are online and now I have the message -- Test -- Online Players: 1 Which is what I excepted to get, but now I would like to know how to change the 'Online Players' to names and the number of players to amount of sugar found in inventory. This is the code I have used: Code:java public void scoreboard() { ScoreboardManager manager = Bukkit.getScoreboardManager(); board = manager.getNewScoreboard(); Objective objective = board.registerNewObjective("Test", "Test2"); objective.setDisplayName(ChatColor.AQUA + "-- Test --"); objective.setDisplaySlot(DisplaySlot.SIDEBAR); Team team = board.registerNewTeam("Team"); team.setDisplayName(ChatColor.RED + "t"); int a = Bukkit.getOnlinePlayers().length; Score score = objective.getScore(Bukkit.getOfflinePlayer(ChatColor.GOLD + "Online Players")); score.setScore(a); }
You would have to add a couple event listeners, like InventoryClickEvent and PlayerDropItemEvent, and update the count each time they;'re called.
Iterate through each player on the server, creating a new score object and setting the score to the amount of sugar said player has the inventory. Note that this may cause lag on lower end servers and on larger servers will flood the screen. Maurdekye To add on to what he said instead of doing that you could have a repeating runnable that checks every minute or so. EDIT by Moderator: merged posts, please use the edit button instead of double posting.
I'm sure that a couple event listeners would be much more accurate, and reduce overhead when its not necessary.
Maurdekye True and iterating every minute would be a lot more inefficient than just iterating whenever the value you want to display changes. This in mind I would create handlers for events: PlayerDropItem, PlayerQuitEvent, InventoryChangeEvent and PlayerJoin.
I'm pretty sure that InventoryChangeEvent would handle everything by itself, I didn't know that event existed before.
Maurdekye Yes, I would only change the value of the person who moved the sugar so I wouldn't have to iterate again, I picked those events so that you would never have to iterate through every player on the server.
Instead of checking for Material Sugar what I got is when as an example cobblestone block is destroyed it gives you sugar but it then can also add to the score. I'm not sure how to do that though.
Konkz You mean when a cobblestone block is broken, it drops sugar as well? That's pretty easy; Code:java @EventHandlerpublic void Break(BlockBreakEvent event) {ItemStack sugar = new ItemStack(Material.SUGAR, (int) (Math.random()*3 + 1));if (event.getBlock().getType() == Material.COBBLESTONE) event.getBlock().getWorld().dropItem(event.getBlock().getLocation(), sugar);} As for adding the sugar to the player's count, you should just leave that to the inventory event listener.
No I mean when cobblestone is broken then it adds 1 to the scoreboard Example: -- Test -- Konkz: 0 Martin: 0 Martin Destroys 1 Cobblestone -- Test -- Martin: 1 Konkz: 0