WorldGuard API

Discussion in 'Spigot Plugin Development' started by kugick, Jun 21, 2015.

  1. Hello, I just ask because I looked arround on google, looked at the WorldGuard 6 api doc. and tried few things and not everything was working. I want to be able to do tree things with the worldguard api. First I want to be able to get the name of a region if a player is in a wg region by his location, after this I want to be able to check if a wg region exist in a region and finally I want to check if a region exist at a player location.

    There is one of the things that I am trying to do:
    Code (Text):
    package me.kugick.evolucraft.cmds;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.Plugin;

    import com.sk89q.worldedit.BlockVector;
    import com.sk89q.worldedit.bukkit.WorldEditPlugin;
    import com.sk89q.worldguard.bukkit.RegionContainer;
    import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
    import com.sk89q.worldguard.protection.managers.RegionManager;
    import com.sk89q.worldguard.protection.regions.ProtectedCuboidRegion;
    import com.sk89q.worldguard.protection.regions.ProtectedRegion;

    public class Claim implements CommandExecutor{



        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args){
            //If the player do /claim
            if(commandLabel.equalsIgnoreCase("claim")){
                //We check if the player have the permission
                if(sender.hasPermission("evolucraft.claim")){
                    //We get the player
                    Player p = (Player) sender;
                    //We get the player location.
                    World pLocation = p.getLocation().getWorld();
                    //The size of the region
                    int regionSize = 15;
                   
                    //Coordinates...
                    double X_double = (double) p.getLocation().getX();
                    double Z_double = (double) p.getLocation().getZ();
                    double x1 = X_double - regionSize;
                    double y1 = 0;
                    double z1 = Z_double - regionSize;
                    double x2 = X_double + regionSize;
                    double y2 = 255;
                    double z2 = Z_double + regionSize;
                   
                   
                        p.sendMessage(ChatColor.RED + "Une région existe déjà à cette emplacement.");

                        BlockVector min = new BlockVector(x1,y1,z1);
                        BlockVector max = new BlockVector(x2, y2, z2);
                        ProtectedRegion region = new ProtectedCuboidRegion("claim_" + p.getName(), min, max);          
                        RegionContainer container = getWorldGuard().getRegionContainer();  
                        RegionManager regions = container.get(pLocation);
                        regions.addRegion(region);
                        //We send a message who say that the region been created.
                        sender.sendMessage(ChatColor.GREEN + "Claim créé avec succès.");
                }
                //We send a message if the player didn't had the permission.
                else sender.sendMessage(ChatColor.RED + "Vous n'avez pas la permission.");
            }
            return false;
        }

       
        //WorldGuard
        @SuppressWarnings("unused")
        private WorldGuardPlugin getWorldGuard() {
            Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("WorldGuard");
            return (WorldGuardPlugin) plugin;
        }

        //WorldEdit
        @SuppressWarnings("unused")
        private WorldEditPlugin getWorldEdit() {
            Plugin plugin = Bukkit.getServer().getPluginManager().getPlugin("WorldEdit");
            return (WorldEditPlugin) plugin;
        }
    }
     
    I got the basic stuff, but now I need to check if there is already a region at the player location and near, and if there is already a region with his name..
     
  2. Creeoer

    Supporter

    RegionManager.getAppliciableRegions(Vector, Location, or ProtectedRegion) returns a set of rapplicable regions.
    You can check whether or not the player is the owner or member of these regions as well.
     
    • Agree Agree x 1
  3. I'll check when I will have the time. Thx.