[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:
    public WorldGuardPlugin getWorldGuard()
    Plugin plugin getServer().getPluginManager().getPlugin("WorldGuard");
            if ((
    plugin == null) || (!(plugin instanceof WorldGuardPlugin)))
    null//throws a NullPointerException, telling the Admin that WG is not loaded.
            return (
    the above code is setting up the WorldGuard methods, i will explain later...
    public void onEnable()
    thats it for loading it in your plugin! now to the events!
    Heres a simple instant break tool.
    in your listener:
    public void event(PlayerInteractEvent ev)
    Player p ev.getPlayer();
    Block b ev.getClickedBlock();
    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


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


    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. Offline


    WorldGaurd -> WorldGuard
  6. Yes i realize that xD ill fix it right naow :p
  7. Offline


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

Share This Page