Player drop message

Discussion in 'Plugin Development' started by EvilKittyCat123, Nov 23, 2013.

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

    EvilKittyCat123

    I have a little problem that I cant fix by myself.

    When a player drops an item, and doesent have the bypass permission, they will receive a message saying they cant drop the item, and the item wont drop either. This works perfectly fine.

    But when an OP does it (Or someone with the bypass permission), the item will drop (as planned), but they receive the same message as players without the bypass permission. How do I fix this?

    Here is my code:

    Code:java
    1. @EventHandler
    2. public void onDrop(PlayerDropItemEvent event) {
    3. Player player = event.getPlayer();
    4. event.setCancelled(true);
    5. player.sendMessage(ChatColor.RED + "You are not allowed to drop items! To remove your items, type "
    6. + ChatColor.YELLOW + "/Clearme"
    7. + ChatColor.RED + ".");
    8. {
    9.  
    10. }
    11.  
    12. if(player.hasPermission("hcg.itemdrop.bypass"))
    13. event.setCancelled(false);
    14.  
     
  2. change it to
    Code:
    @EventHandler
        public void onDrop(PlayerDropItemEvent event) {
    if (!player.hasPermission(//permission){
        Player player = event.getPlayer();
        event.setCancelled(true);
        player.sendMessage(ChatColor.RED + "You are not allowed to drop items! To remove your items, type "
                + ChatColor.YELLOW + "/Clearme"
                + ChatColor.RED + ".");
    }
    }
    
    now it will run when a player does not have the permission (the ! inverses the outputted boolean)
     
  3. Offline

    Sorata_

    Look, everytime you do the drop event, you execute that player.sendMessage.

    Better:
    Code:
    @EventHandler
    public void onDrop(PlayerDropItemEvent event) {
        if (player.hasPermission("hcg.itemdrop.bypass")) {
            event.setCancelled(false);
        } else {
            Player player = event.getPlayer();
            event.setCancelled(true);
            player.sendMessage(ChatColor.RED + "You are not allowed to drop items! To remove your items, type "
            + ChatColor.YELLOW + "/Clearme"
            + ChatColor.RED + ".");
        }
    }
     
  4. Offline

    *-Emax-*

    Compressed code:

    Code:java
    1. @EventHandler
    2. public void onDrop(PlayerDropItemEvent event) {
    3. Player player = event.getPlayer();
    4. if (!player.hasPermission("hcg.itemdrop.bypass")) {
    5. event.setCancelled(true);
    6. player.sendMessage(ChatColor.RED + "You are not allowed to drop items! To remove your items, type " + ChatColor.YELLOW + "/Clearme" + ChatColor.RED + ".");
    7.  
    8. }
    9. }
     
    Chinwe likes this.
  5. Offline

    EvilKittyCat123

    I havent tested any of these fixes yet because of Minecraft "bad login" ugh,,
     
Thread Status:
Not open for further replies.

Share This Page