Check if a player is in a protected area

Discussion in 'Plugin Development' started by Eistee², May 22, 2012.

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

    Eistee²

    Hello,
    I must check for my plugin if a player is in a protectet area which is made with World Guard or something like that is that and whether he has permission to build there ? is this possible ?when yes , how? :)

    Mfg Eistee²
     
  2. Offline

    Father Of Time

    Yes it's possible, you would utilize WorldGuard's api to do this:

    http://wiki.sk89q.com/wiki/WorldGuard/Regions/API

    Personally I found WorldGuards API to be messy and difficult to understand and decided to just make a cuboid system from the ground up; but with that said, it is possible to build off of world guard utilizing the information provided in the post above.

    Hope this helps!
     
    Eistee² likes this.
  3. Offline

    Eistee²

    Hm thanks :)
    So I look at the api and yes its a bit difficult would be nice if someone who know how to work with this can write a code like

    if(Player has permissions to build here == false){
    return;
    }
     
  4. Offline

    Father Of Time

    It's highly unlikely that anyone will be able to provide you with such example because it's not even remotely that easy I am afraid.

    WG Regions usually overlap, so you actually have to get a collection of WG regions called "applicable region set" for any specific spot, then loop through the applicable region set to do the "can build" check for each WG region in the set.

    So if you are standing in a spot with three world guard regions (say one parent and 2 child lots), you need to loop through and see if any of them disallow building, if any of them disable building then you deny construction (but don't forget to check for parent region permissions too, because if the person is denied on the lot but allowed on the parent then they should be able to build in both).

    There is a lot to take into consideration, it's not just a single check of "can you build here?".
     
  5. Offline

    Eistee²

    Hmmm
    • boolean canBuild(org.bukkit.entity.Player player, org.bukkit.Location location)​
    Looks for me like a simple check :eek: hmmm but i really need this >.<

    No one who can help me :/?

    bump I really need help :/

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

    Eistee²

  7. Offline

    Njol

    Actually it is that easy, just read the second section of the link you posted:
     
  8. Offline

    Eistee²


    Hm i tryed that but it always throws a nullpointer exception ~.~ :(

    And I dosent know how to work with that :/ would be very helpfull when someone can tell me how to make that :/
     
  9. Offline

    Njol

    You also have to read the first section of the article on how to get the worldguard reference.
     
  10. Offline

    Eistee²

    You mean

    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)) {
            return null; // Maybe you want throw an exception instead
        }
     
        return (WorldGuardPlugin) plugin;
    }
    ??
    I done this but it dosent want to work q.q and I dont know what is wrong it give always a nullpointer exception there :eek:
     
  11. Offline

    LucasEmanuel

    Well that code is throwing a null if the plugin wasnt installed on the server or it wasnt activated. Check to see if any of those are the problem.
     
  12. Offline

    Eistee²

    I has always check this when i placed a block and it throws this even when I deleted "return null" and replaced it with system.out.println() but it dosent appear anything in the consol :(
     
  13. Offline

    Lolmewn

    Try to System.out.println() if it is found.
     
  14. Offline

    Eistee²

    It break at
    Code:
    Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
    It only write something before :/
     
  15. Offline

    Lolmewn

    Well, that's just awkward. Can I see the whole class? (paste on Pastebin plz, not here)
     
  16. Offline

    Eistee²

    Sure here the on enable / on disable (sorry its a bit messy) http://pastebin.com/P85U0Zzm

    And here the part which i check in the block place event
    Code:
        Miner Miner = new Miner();
        String playername = event.getPlayer().getName();
    Player player = Bukkit.getPlayer(playername);
    Plugin wg = Bukkit.getPluginManager().getPlugin("WorldGuard");
    if(wg.isEnabled() && Miner.getWorldGuard().canBuild(player, event.getBlock().getLocation())==false){
        return;
    }

    Okay change "getServer().getPluginManager().getPlugin("WorldGuard");" to Bukkit.getPluginManager().getPlugin("WorldGuard");

    and get no error .) hope it will work with this check :p
     
  17. Offline

    Lolmewn

    Why would you do this (see below) if you can just get the player by doing Player player = event.getPlayer(); ?

    String playername = event.getPlayer().getName();
    Player player = Bukkit.getPlayer(playername);
     
  18. Offline

    Eistee²


    Hm yeah dont know I´m new with dev for bukkit :)
     
Thread Status:
Not open for further replies.

Share This Page