Player Interact Event

Discussion in 'Plugin Development' started by BurnerDiamond, Jan 25, 2015.

Thread Status:
Not open for further replies.
  1. Offline

    BurnerDiamond

    Not sure why it's not shooting the paintball. But everything seems in order!

    Code:
    package torax.events;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.entity.Snowball;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    
    public class GunInteractEvent implements Listener {
       
        @EventHandler
        public void onGunInteract(PlayerInteractEvent e) {
            Player p = e.getPlayer();
            if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
                if(p.getItemInHand().equals(Material.DIAMOND_BARDING != null)) {
                        if(p.getItemInHand().getItemMeta().getDisplayName().equals(ChatColor.YELLOW + "" + ChatColor.BOLD + "MACHINE GUN")) {
                            p.launchProjectile(Snowball.class);
                       
                           
                    }
                }
            }
           
        }
    
    }
     
  2. Offline

    Skionz

    Regablith and Konato_K like this.
  3. Offline

    PreFiXAUT

    Everything in Order? You're comparing "p.getItemInHand()" so an ItemStack with an Material...oh wait. Not even this. You're comparing it with a boolean which doesn't make ANY sence at all. Rethink this entirely please.
     
  4. Offline

    567legodude

  5. Offline

    Skionz

  6. Offline

    567legodude

    @Skionz Sorry, clicked the wrong person, I fixed it.
     
  7. Offline

    BurnerDiamond

    Ooops. Dumb mistake!

    Is it possible for me to name a snowball entity? To where it hits a player. It deals a certain amount of damage?
     
    Last edited by a moderator: Jan 26, 2015
  8. Offline

    InfamousSheep

    Save the Projectile in a HashMap with an int value as the damage. When the snowball hits an entity, get the int value from the HashMap by using the Projectile as the key, then remove it from the map.
     
  9. Offline

    BurnerDiamond

  10. Offline

    InfamousSheep

    I'm not going to code it for you... but here's a rough start:

    Code:
    public HashMap<Snowball, Integer> snowballs = new HashMap<Snowball, Integer>();
    
    Snowball snowball = player.launchProjectile(Snowball.class);
    snowballs.add(snowball);
    
     
  11. Offline

    SuperOriginal

     
  12. Offline

    BurnerDiamond

    @InfamousSheep

    Oops. I meant do you have any tutorials in hashmaps?
     
  13. Offline

    Burnett

  14. Offline

    BurnerDiamond

Thread Status:
Not open for further replies.

Share This Page