Add score on right click

Discussion in 'Plugin Development' started by S431, Jun 24, 2017.

Thread Status:
Not open for further replies.
  1. I'd like to add a score to the player's team when he/she right-clicks an item.but I'm having trouble adding the score to the scoreboard.What should I do?
    Code:
    public class PlayerInteract implements Listener{
        @EventHandler
    public void onPlayerInteract(PlayerInteractEvent e){
        Player p = e.getPlayer();
         Material mat =p.getItemInHand().getType();
         if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK){
             if(mat == Material.RED_ROSE){
                 Bukkit.broadcastMessage(ChatColor.RED + "You right clicked a rose.Plus 1!");
                 if(mat == Material.BLAZE_POWDER){
                     Bukkit.broadcastMessage(ChatColor.RED + "You right clicked a blaze powder.Plus 1!");
                     if(mat == Material.CROPS){
                         Bukkit.broadcastMessage(ChatColor.RED + "You right clicked a crop.Plus 1!");
                         if(mat == Material.CLAY){
                             Bukkit.broadcastMessage(ChatColor.RED + "You right clicked clay.Plus 1!");
                             if(mat == Material.FEATHER){
                                 Bukkit.broadcastMessage(ChatColor.RED + "You right clicked a feather.Plus 1!");
                                 if(mat == Material.RED_MUSHROOM){
                                     Bukkit.broadcastMessage(ChatColor.RED + "You right clicked a red mushroom Plus1!");
                                 }
                                 if(mat == Material.EMERALD){
                                     Bukkit.broadcastMessage(ChatColor.RED + "You right clicked an emerald Plus 1!");
                                 }
                             }
                         }
                     }
                 }
             }
         }
             }
       
    }
     
  2. Offline

    Zombie_Striker

    @S431
    1. Get the player's scoreboard using player#getScoreboard()
    2. Get all the teams, loop through them, and find the one with that player in it.
    3. When you do, add +1 to the score.
     
  3. Offline

    timtower Administrator Administrator Moderator

    @S431 Don't nest your material checks.
     
    Zombie_Striker likes this.
Thread Status:
Not open for further replies.

Share This Page