Help with scoreboards ( java)

Status
This thread has been locked.

NUJABES__

Feedback score
0
Posts
2
Reactions
0
Resources
0
Hello. I am new to java, and do not possess any extensive knowledge to the programming language. I have a scoreboard that displays this upon the PlayerJoinEvent activating.

It displays something like this

Your stats
Pearls: 0
Blocks: 0

This scoreboard updates the amount of blocks you have broken and the amount of enderpearls you have thrown each time you break/throw one. The block break event works fine, but i cannot get the playerinteractevent to update the enderpearls each time you throw it.
Here's my code
 

NUJABES__

Feedback score
0
Posts
2
Reactions
0
Resources
0
  1. public class SecondPlugin extends JavaPlugin implements Listener {

  2. @Override
  3. public void onEnable() {
  4. System.out.println("OnEnable has been called.");
  5. getServer().getPluginManager().registerEvents(this, this);
  6. }

  7. @Override
  8. public void onDisable() {
  9. System.out.println("OnDisable has been called.");
  10. }

  11. @EventHandler (priority = EventPriority.NORMAL)
  12. public void onPlayerJoin(PlayerJoinEvent e) {

  13. //scoreboard
  14. Scoreboard board = getServer().getScoreboardManager().getNewScoreboard();
  15. Objective objective = board.registerNewObjective("blocks","pearl");
  16. objective.setDisplaySlot(DisplaySlot.SIDEBAR);
  17. objective.setDisplayName(ChatColor.GREEN + "Your stats");
  18. Score score = objective.getScore(ChatColor.AQUA+"Blocks:");
  19. Score score1 = objective.getScore(ChatColor.AQUA+"Pearls:");




  20. score.setScore(0);
  21. score1.setScore(0);
  22. e.getPlayer().setScoreboard(board);



  23. }
  24. @EventHandler
  25. public void onBreak(BlockBreakEvent e) {
  26. Scoreboard board = e.getPlayer().getScoreboard();
  27. Objective objective = board.getObjective("blocks");
  28. objective.getScore(ChatColor.AQUA + "Blocks:").setScore(objective.getScore(ChatColor.AQUA + "Blocks:").getScore()+1 );


  29. }
  30. @EventHandler
  31. public void onPearl(PlayerInteractEvent event){
  32. Player player = event.getPlayer();
  33. if(event.getAction()== Action.RIGHT_CLICK_AIR ||event.getAction()== Action.RIGHT_CLICK_BLOCK){
  34. if (player.getItemInHand().getType()== Material.ENDER_PEARL){
  35. Scoreboard board = event.getPlayer().getScoreboard();
  36. Objective objective = board.getObjective ( "pearl");

  37. objective.getScore(ChatColor.AQUA+"Pearls:").setScore(objective.getScore(ChatColor.AQUA+"Pearls:").getScore()+1 );



  38. }

  39. }
  40. }



  41. }
 

Brendan Curry

Premium
Feedback score
0
Posts
0
Reactions
6
Resources
0
Make sure the PlayerInteractEvent is even firing in the first place. I would add (priority = EventPriority.LOWEST, ignoreCancelled=true) to the top of your onPearl method. That should fix it.
 

SimonM

Java Developer
Premium
Feedback score
12
Posts
190
Reactions
58
Resources
0
Format your code.. and if you "do not possess any extensive knowledge" I suggest you learn java before you work with the bukkit api.
 
Status
This thread has been locked.
Top