WG API

Discussion in 'Plugin Development' started by Veyn12, Mar 7, 2021.

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

    Veyn12

    Hello, I am writing you from the Russian community. I need your help!

    Making a plugin: There is a "spawn" region. There is a command "/ tpa", always available to all players. There are some people on the server who have "remove.tpa" permissions in PermissionsEX. So, I want that if there are 2+ players with "remove.tpa" rights in the "spawn" region, then the "/ tpa" command will not work for anyone, it will write "There are 2 people in the region with the team blocking" ... Please help me with the code.
    I would like a complete code that checks this, since I have been trying to figure it out for the second day, but it didn’t work, the only way out is the help of the coders on Bukkit.org, who I really hope they will write the code. Once again please = (
    Thank you in advance
     
  2. Offline

    Newdel

    Sry, no spoonfeeding

    Then get the players in this region (Server? Get online players; World? Get players in world; Region in world? get players in world and check if they are inside this area) and check if they have this permission. If 2 of them do, cancel the command the player sent (just cancel it, if it's your plugin or react to the command via event
     
  3. Offline

    Veyn12

    Thank, give me good documentation for WG API please, official site me not help =(
     
  4. Offline

    davidclue

    World guard API found it with a simple google search and also I just recently used it for one of my plugins, do what Newdel said that will be the most efficient way and should not impact performance at all.

    Code:
    public static boolean isRegionProtected(Location location) {
            com.sk89q.worldedit.util.Location loc = com.sk89q.worldedit.bukkit.BukkitAdapter.adapt(location);
            com.sk89q.worldguard.protection.regions.RegionContainer container = com.sk89q.worldguard.WorldGuard.getInstance().getPlatform().getRegionContainer();
            com.sk89q.worldguard.protection.regions.RegionQuery query = container.createQuery();
            com.sk89q.worldguard.protection.ApplicableRegionSet set = query.getApplicableRegions(loc);
            if (set.size() != 0) return true;
            return false;
        }
    Put this in a utils class or even your main class doesn't really matter and then add WG API to your build path and no need to even import you can even make WG a softdepend.

    Code:
    for (Player p : world.getPlayers()) {
        if (Utils.isRegionProtected(p.getLocation())) {
            //do this
        }
    }
    You can use this to check if a player is in any region in the world, now I am not going to spoonfeed you exactly what you are trying to do because I don't feel like writing the method but this should suffice for you to understand how to use WG's API to do what you need.
     
Thread Status:
Not open for further replies.

Share This Page