Solved Help with Making this Handler Works

Discussion in 'Plugin Development' started by TECGaming360, Aug 16, 2014.

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

    TECGaming360

    Code:java
    1. }
    2. @EventHandler
    3. public void onDropItem(PlayerDropItemEvent e) {
    4. Player player = e.getPlayer();
    5. player.playSound(player.getLocation(), Sound.ORB_PICKUP, 10, 1); //plays orb sound on trying to drop
    6. if (e.getItemDrop().getItemStack().getType() == Material.getMaterial(KeepthatItem.plugin.getConfig().getString("Item 1").toUpperCase()))
    7. {
    8.  
    9. e.setCancelled(true);
    10. player.sendMessage(ChatColor.YELLOW + "[" + ChatColor.AQUA + "KeepthatItem" + ChatColor.YELLOW + "]" + ChatColor.RED + " " + KeepthatItem.plugin.getConfig().getString("Drop Message 1"));
    11. }
    12. }


    Above is the Code is partial to what i want it to do but it seems that the noise plays to every drop item. How would i make this Code play only with the Certain object. Also not be Able to drop the item?
     
  2. Offline

    xTigerRebornx

    TECGaming360 The code that plays the sound is outside the check, so its obviously going to play the sound if the code is reached, which it always is.
     
  3. Offline

    htmlman1

    Change it to this:
    Code:java
    1. public void onDropItem(PlayerDropItemEvent e) {
    2. Player player = e.getPlayer();
    3. if (e.getItemDrop().getItemStack().getType() == Material.getMaterial(KeepthatItem.plugin.getConfig().getString("Item 1").toUpperCase()))
    4. {
    5. player.playSound(player.getLocation(), Sound.ORB_PICKUP, 10, 1); //plays orb sound on trying to drop
    6. e.setCancelled(true);
    7. player.sendMessage(ChatColor.YELLOW + "[" + ChatColor.AQUA + "KeepthatItem" + ChatColor.YELLOW + "]" + ChatColor.RED + " " + KeepthatItem.plugin.getConfig().getString("Drop Message 1"));
    8. }
    9. }
     
  4. Offline

    TECGaming360

    Thank You
     
  5. Offline

    htmlman1

    No problem.
     
Thread Status:
Not open for further replies.

Share This Page