WorldEdit & WorldGuard API [Need Help]

Discussion in 'Plugin Development' started by Josh014, Mar 29, 2014.

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

    Josh014

    Hello,
    I want to protect an area. I use WorldEdit to select the area and I use WorldGuard to protect it. I saw this method on the forums;

    Method code:
    Code:java
    1. public static void addProtectedRegion(Player player, World world, int x, int y, int z, int radius, int delay, Map flags)
    2. {
    3. // get the region manager
    4. RegionManager rm = worldGuard.getRegionManager(world);
    5.  
    6. // make a cuboid with two points to create a 3d cube in the world
    7. BlockVector b1 = new BlockVector(x + radius + 1, y + radius + 1, z + radius + 1);
    8. BlockVector b2 = new BlockVector(x - radius - 1, y - radius - 1, z - radius - 1);
    9.  
    10. // create the protected region
    11. ProtectedCuboidRegion pr = new ProtectedCuboidRegion(/* fill in a name here */, b1, b2);
    12. DefaultDomain dd = new DefaultDomain();
    13.  
    14. // add the player to the region
    15. dd.addPlayer(player.getName());
    16.  
    17. // set the player as the owner
    18. pr.setOwners(dd);
    19.  
    20. // set the flags
    21. if (flags == null)
    22. {
    23. flags = new HashMap();
    24. flags.put(DefaultFlag.BUILD, State.DENY);
    25. flags.put(DefaultFlag.CREEPER_EXPLOSIONS, State.DENY);
    26. //
    27. // put more flag definitions here
    28. //
    29. }
    30.  
    31. pr.setFlags(flags);
    32. try
    33. {
    34. rm.save();
    35. }
    36. catch (Exception exp)
    37. { }
    38. }


    What I use to get the WorldGuard plugin is this:

    Code:
    Code:java
    1. public static WorldGuardPlugin getWorldGuard(JavaPlugin plugin) {
    2. Plugin p = plugin.getServer().getPluginManager()
    3. .getPlugin("WorldGuard");
    4.  
    5. if ((p == null) || (!(p instanceof WorldGuardPlugin))) {
    6. return null;
    7. }
    8.  
    9. return (WorldGuardPlugin) p;
    10. }


    And my question is how can I get my selection of WorldEdit and use it to protect an area with WorldGuard?

    This is my onCommand:

    onCommand code:
    Code:java
    1. @Override
    2. public boolean onCommand(CommandSender sender, Command command,
    3. String label, String[] args) {
    4. if (!(sender instanceof Player)) {
    5. sender.sendMessage("This is an ingame command!");
    6. return true;
    7. }
    8.  
    9. Player p = (Player) sender;
    10.  
    11. if (label.equalsIgnoreCase("wetest")) {
    12. Selection s;
    13. s = getWorldEdit().getSelection(p);
    14.  
    15. if (s == null) {
    16. sender.sendMessage("Make a selection first!");
    17. return false;
    18. }
    19.  
    20. sender.sendMessage("Worked :D");
    21.  
    22. }
    23.  
    24. return false;
    25. }
     
  2. Offline

    Josh014

    Bump,
     
  3. Offline

    Dragonphase

  4. Offline

    Josh014

  5. Offline

    Josh014

    I'm still open for help btw.
     
Thread Status:
Not open for further replies.

Share This Page