Checking if a player can build

Discussion in 'Plugin Development' started by Cammy_the_block, Dec 1, 2012.

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

    Cammy_the_block

    How do I check if a player can build somewhere? If I have to do it different for every protection plugin, please post on how to do it for WorldGuard.

    Thanks in Advanceddd

    CaMmY
     
  2. Offline

    RealDope

    Code:JAVA
    1.  
    2. @EventHandler(priority = EventPriority.MONITOR)
    3. public void onBlockPlace(BlockPlaceEvent event) {
    4. if(event.isCancelled()) {
    5. // They can't build
    6. }
    7. else {
    8. // They can build
    9. }
    10. }
    11.  
     
  3. Offline

    adam753

    But how would you do it if they didn't place a block first?
     
  4. Offline

    RealDope

    What do you mean if they didn't place a block first? He asked about build rights. That listens to a blockplace after all other plugins have cancelled / uncancelled it. If he needs it to check for block breaking too he can just use the same code but BlockBreakEvent.
     
  5. Offline

    adam753

    But what if the player didn't actually set off a BlockPlaceEvent, but you have a Player and a Location and want to know, hypothetically, whether they would be allowed to place a block there?
     
  6. Offline

    Terradominik

    maybe fire a BlockPlaceEvent manually ?
     
  7. Offline

    Cammy_the_block

    Yeah cause i was trying to see if someone could build without them building.

    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  8. Offline

    toothplck1

    Code:
    public boolean checkPerms(Player player, Location loc) {
     
    WorldGuardPlugin api = (WorldGuardPlugin) getServer().getPluginManager().getPlugin("worldguard");
     
    ApplicableRegionSet regions = api.getRegionManager(loc.getWorld()).getApplicableRegions(loc);
     
    LocalPlayer lPlayer = api.wrapPlayer(player);
     
    if (regions.size() == 0){
     
    return true;
     
    }
     
    return (regions.allows(DefaultFlag.BUILD, lPlayer) ? true : false);
     
    }
    Although it would be better to just throw a manual BlockPlaceEvent for all plugins to weigh in rather than just WorldGuard
     
  9. Offline

    Cammy_the_block

    How do you "just throw a manual BlockPlaceEvent for all plugins"?

    bump

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 30, 2016
  10. Offline

    matzefratze123

    There is an api for the worldguard plugin. It has an method named canBuild();

    You can use it to check if a player can build at a location (in your case the playerlocation)

    Do something like this:

    Code:JAVA
    1. WorldGuardPlugn wg = (WorldGuardPlugin) Bukkit.getServer().getPluginManager(). getPlugin("WorldGuard")
    2.  
    3. if (wg.canBuild(*yourplayerobject*, *YourLocationObject or YourBlockObject) {
    4. //do something if player can build
    5. } else {
    6. //do something else if player can't build
    7. }


    Link to the worldguard api: http://wiki.sk89q.com/wiki/WorldGuard/Regions/API

    Sorry if something isn't right I wrote this on my mobile phone :)
     
  11. Offline

    Cammy_the_block

    I was trying to make it work for all permission plugins but thanks anyways
     
  12. Offline

    Cammy_the_block

    Where do i put the World Guard.jar?
     
  13. Offline

    mrZcr4fter

    I want to make my plugin Towny Compatible, Please anyone can Help? I was told that you can make a fake player that places a block or something like that...? Hmm dunno, help!
     
Thread Status:
Not open for further replies.

Share This Page