[TUT] Implementing WorldGuard in your plugin + using it in events!

Discussion in 'Resources' started by James | Buchanan, Mar 11, 2012.

Thread Status:
Not open for further replies.
  1. in your main class:
    PHP:
    public WorldGuardPlugin getWorldGuard()
        {
            
    Plugin plugin getServer().getPluginManager().getPlugin("WorldGuard");
            if ((
    plugin == null) || (!(plugin instanceof WorldGuardPlugin)))
            {
                return 
    null//throws a NullPointerException, telling the Admin that WG is not loaded.
            
    }
            return (
    WorldGuardPlugin)plugin;
        }
    the above code is setting up the WorldGuard methods, i will explain later...
    Then:
    PHP:
    public void onEnable()
    {
        
    getWorldGuard();
    }
    thats it for loading it in your plugin! now to the events!
    Heres a simple instant break tool.
    in your listener:
    PHP:
    public void event(PlayerInteractEvent ev)
    {
        
    Player p ev.getPlayer();
        
    Block b ev.getClickedBlock();
     
        if(
    ev.getAction() == Action.LEFT_CLICK_BLOCK && p.getItemInHand().getType() == Material.DIAMOND_PICKAXE)
        {
            
    //the <mainclass>.getWorldGuard() allows you to gain access to all the WG methods.
            
    if(<mainclass>.getWorldGuard().canBuild(pp.getLocation())// the constructor is: Player, Location, thats why we use: p, p.getLocation()
            
    {
                
    b.setTypeId(0); // sets the block to air
            
    }
        }
     
    }
    and thats it!
    You can use the <mainclass>.getWorldGuard() to use a whole lot of methods, like permissions and regions! Just experiment!
    i know it was very breif, but i needed to get it out there :D
     
    ThunderWaffeMC and bobbysmithyy like this.
  2. Offline

    greatman

    I think there's a error there :p
     
  3. Offline

    CXdur

    A mispell isn't an error? He mispelled it on the method too so it doesnt have anything to say I guess.
     
  4. sorry for the bad spelling, i just wanted to get this out there :p
     
  5. WorldGaurd -> WorldGuard
     
  6. Yes i realize that xD ill fix it right naow :p
     
  7. Offline

    bobbysmithyy

    Love this, just implemented it into my custom plugin!
     
Thread Status:
Not open for further replies.

Share This Page