Another question D:

Discussion in 'Plugin Development' started by InspectorFacepalm, May 31, 2013.

Thread Status:
Not open for further replies.
  1. So I got another question, this will probably be my last question for a couple of days l;
    Is there any way to make it so you can't drop your sharpness 1 diamond sword :/
    If anyone can help I will love them forever<3
     
  2. Offline

    Pink__Slime

    PlayerDropItemEvent. Check if it's a diamond sword then check if it's enchanted with Sharpness 1.
     
  3. Offline

    Zach_1919

  4. Thanks zach and pink, I actually don't know how to do it with enchants but I'll try to find out about it
    Pink__Slime do you know how to do it D:
    or Zach_1919
     
  5. Offline

    Pink__Slime

    InspectorFacepalm
    Try this
    Code:java
    1. @EventHandler
    2. public void swordDrop(PlayerDropItemEvent event){
    3. Player player = event.getPlayer();
    4. if(event.getItemDrop().getItemStack().getType().equals(Material.DIAMOND_SWORD)){
    5. ItemStack sword = event.getItemDrop().getItemStack();
    6. if(sword.containsEnchantment(new EnchantmentWrapper(16))){
    7. if(sword.getEnchantmentLevel(new EnchantmentWrapper(16)) == 1){
    8. event.setCancelled(true);
    9. player.sendMessage("You cannot drop this");
    10. }
    11. }
    12. }
    13. }
     
  6. Doesn't work :/
     
  7. Offline

    chasechocolate

    InspectorFacepalm any errors? Did you register your events? Maybe try checking if(sword.getEnchantmentLevel(Enchantment.DAMAGE_ALL) == 1) instead of using EnchantmentWrappers.
     
  8. I already registered the events and that doesn't work D;
     
  9. Offline

    bfgbfggf

    o.o ANY event work with your code? Sooo... you can;t spawn a pig, and also use that event? Check other events :D
     
    InspectorFacepalm likes this.
  10. Other events work, i finally figured out the pig spawn thing, It was because I was doing something wrong xD

    This one doesn't work tho. D:
     
  11. Offline

    UnlikeAny

    As these people suggested, this code works just fine:
    Code:
        @EventHandler
        public void swordDrop(PlayerDropItemEvent event) {
            Player player = event.getPlayer();
           
            if (event.getItemDrop().getItemStack().getType().equals(Material.DIAMOND_SWORD)) {
                ItemStack sword = event.getItemDrop().getItemStack();
                if (sword.getEnchantmentLevel(Enchantment.DAMAGE_ALL) == 1) {
                    event.setCancelled(true);
                    player.sendMessage("You cannot drop this");
                }
            }
        }
    I bet you are trying to drop diamond sword that is enchanted more than 1 lvl.
     
Thread Status:
Not open for further replies.

Share This Page