Using Permissions with BlockPlaceEvent

Discussion in 'Plugin Development' started by Willbbz, Jun 11, 2012.

  1. Offline

    Willbbz

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I'm a bit new to this but what I'm trying to achieve is to create a permission node for placing a block type which should be fairly simple but I'm kinda of making a balls of it. Hopefully someone can point me in the right direction.

    Currently I have this for the event
    Code:
        @EventHandler(priority = EventPriority.HIGH)
        public void onBlockPlace(BlockPlaceEvent event){
            if (event.isCancelled()) return;
            if(sender instanceof Player){
                if(!permCheck(Player)sender, "bp.TNT")){
            }
     
            if (event.getBlock().getType() == Material.TNT){
                event.setCancelled(true);
            }
            if (event.isCancelled()) return;
  2. Offline

    Willbbz

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I've gotten it to work now all I need to do is invert how the permissions work.
    Currently, if a player has the permission then only can they place the block. What I want to do is if they HAVE the permission they can't place the block. If they don't have the permission they can place the block

    Suggestions? I thought I was meant to use an exclamation mark to invert my statement
  3. Offline

    anerach

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Didn't test
    Code:java
    1. if(player.hasPermission("bp.TNT"))
    2. return;

    This post has been edited 1 time. It was last edited by anerach Jun 12, 2012.
  4. Offline

    Willbbz

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Didn't seem to work.

    Here's my code currently for the tnt block

    PHP:
        @EventHandler(priority EventPriority.HIGH)
        public 
    void onLavaBlockPlace(BlockPlaceEvent event){
            
    Player player event.getPlayer();
            
    Block block event.getBlockPlaced();
     
            if(
    block.getType() == Material.LAVA)
    {
                if(((
    Playerplayer).hasPermission("bp.TNT")) {
     
            }
     
            else {
     
                if ((
    player.isOp())) {
     
                }else{
     
                    
    event.setCancelled(true);
                    
    player.sendMessage(ChatColor.RED + ("You don't have permission to place this block!"));
                }
     
                
    event.setCancelled(true);
            }
              }
        }
  5. Offline

    anerach

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    This should do it.

    Code:
    @EventHandler(priority = EventPriority.HIGH)
    public void onLavaBlockPlace(BlockPlaceEvent event){
        Player player = event.getPlayer();
        Block block = event.getBlockPlaced();
        if(block.getType() != Material.LAVA)
            return;
       
        if(!player.hasPermission("bp.TNT")) {
            player.sendMessage(ChatColor.RED + "You don't have permission to place this block!");
            event.setCancelled(true);
        }
    }

    This post has been edited 2 times. It was last edited by anerach Jun 12, 2012.
  6. Offline

    Willbbz

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Awk. It didn't work and then I realized I was standing in the spawn on my test server >.<
    Working now though :)

    HTML:
        @EventHandler(priority = EventPriority.HIGH)
        public void onLavaBlockPlace(BlockPlaceEvent event){
            Player player = event.getPlayer();
            Block block = event.getBlockPlaced();
     
            if(block.getType() == Material.LAVA)
    {
            if ((player.hasPermission("bp.lava"))) {
                player.sendMessage(ChatColor.RED + "You don't have permission to place this block!");
                event.setCancelled(true);
     
            }
     
            else {
     
                player.sendMessage(ChatColor.GREEN + ("Block Was placed Successfully!!"));
                event.setCancelled(false);
            }
     
    }
              }
    Thank you for your help!

    This post has been edited 1 time. It was last edited by Willbbz Jun 12, 2012.
  7. Offline

    Willbbz

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    By default OPs have the permission bp.lava

    Is it possible to make them ignore this?
  8. Offline

    TheGreenGamerHD

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Try adding a check to see if player isOp

    something like:

    ||
    if player.isOp() && !player.hasPermission("Your.Node.Here")
    event.setCancelled(true);
    Willbbz likes this.
  9. Offline

    V10lator

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)

    This post has been edited 1 time. It was last edited by V10lator Jun 13, 2012.
  10. Offline

    Willbbz

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    I have done this and it is working as it should
    PHP:
        @EventHandler(priority EventPriority.HIGH)
        public 
    void SMOOTHSTAIRS(BlockPlaceEvent event){
            
    Player player event.getPlayer();
            
    Block block event.getBlockPlaced();
            if(
    player.isOp() || block.getType() != Material.SMOOTH_STAIRS)
                return;
       
            if(
    player.hasPermission("bp.smoothstairs")) {
                
    player.sendMessage(ChatColor.RED "You don't have permission to place this block!");
                
    event.setCancelled(true);
            }
        }
    @V10lator I'm a bit new to the using the config.yml for things other than the main, version. author + permissions.

    Currently what I'm trying to do now is to use a global permission like bp.* to give all the permissions of the plugin to the user/group. Do I have to group all the permission nodes somehow or is there a relatively quick way to grab everything?
    Currently 100+ permissions associated with this plugin

    This post has been edited 1 time. It was last edited by Willbbz Jun 13, 2012.
  11. Offline

    V10lator

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    @Willbbz 100+ permissions? Wow...
    Well,there is some child/parent system, I think, but I never worked with it. :(
  12. Offline

    Willbbz

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    You've probably deduced I'm quite new to this but I have a permission node set for every placeable block type in the game where if a group or player has the permission node it means they cannot place the block. All of the nodes follow bp.<blockname>

    Although I think this will require a system like bp.ores.diamondore so I can group all the ores together like bp.ores.*
  13. Offline

    ferrybig

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    you must add them al to your plugin.yml, because bukkit does not have sutch an list by it self

Share This Page