[WorldGuard] Check to see if a player can build/break

Discussion in 'Plugin Development' started by iMrCanuck, Dec 26, 2011.

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

    iMrCanuck

    Hello, for a personal plugin I am making I need to check if a player has permission to break a block in a region. I have looked at the WorldGuard API but there isn't a lot there to explain, so if some one could help me out that would be great.
     
  2. Offline

    tkausl

    What you can't understand?

    Code:
    import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
    import org.bukkit.plugin.Plugin;
    
    private WorldGuardPlugin getWorldGuard() {
        Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
    
        // WorldGuard may not be loaded
        if (plugin == null || !(plugin instanceof WorldGuardPlugin)) {
            //May disable Plugin
            return null; // Maybe you want throw an exception instead
        }
    
        return (WorldGuardPlugin) plugin;
    }
    Use this Method in the onEnable in your Plugin.
    Then you can use this Method:
    Code:
    boolean canBuild(org.bukkit.entity.Player player, org.bukkit.block.Block block)
    Code:
    WorldGuardPlugin wgp = getWorldGuard();
    wgp.canBuild(//Any Player, //Any Block or Location);
     
  3. Offline

    iMrCanuck

    I couldn't get that to work.
     
  4. Offline

    ItsHarry

    If you're still having problems, post the source code.
     
  5. Offline

    iMrCanuck

    That's the main class with out any of the worldguard code added in.

    Code:
    EDIT: took the code out.
    
     
  6. Offline

    tkausl

    Then try to add WorldGuard-Code and if its NOT working, Post here the Code.
     
  7. Offline

    iMrCanuck

    Hate to bump my post but I need this to finish my plugin.
     
Thread Status:
Not open for further replies.

Share This Page