if a location is in a world guard region?

Discussion in 'Plugin Development' started by 15987632, Oct 6, 2014.

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

    15987632

    can somebody tell me a way to get if a location is in a world guard region? I am trying to code a simple plugin that stops water from flowing into a world guard region but still be able to flow inside of a world guard region and i need this.
     
  2. Offline

    fireblast709

  3. Offline

    15987632

    fireblast709 i already looked at the api before but it confused me a bit. Would it be sorta like this?

    Code:java
    1. WorldGuardPlugin worldGuard = getWorldGuard();
    2. Vector pt = toVector(block); // This also takes a location
    3.  
    4. RegionManager regionManager = worldGuard.getRegionManager(world);
    5. if (regionManager.getApplicableRegions(pt) != null){
    6. // stuff here
    7.  
    8. }
     
  4. Offline

    fireblast709

    15987632 assuming you have defined a getWorldGuard() method and a toVector(Block) method (and that this method returns a WE Vector instead of a Bukkit Vector - you can use Locations in getApplicableRegions() as well), then yes.
     
  5. Offline

    15987632

    fireblast709 kk thanks :D

    fireblast709 it doesn't work this is what i have

    Code:java
    1. package me.trevor.bukkit;
    2.  
    3. import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
    4. import com.sk89q.worldguard.protection.managers.RegionManager;
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.Location;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.Listener;
    9. import org.bukkit.event.block.BlockFromToEvent;
    10. import org.bukkit.plugin.Plugin;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class Main extends JavaPlugin implements Listener{
    14.  
    15. @Override
    16. public void onEnable() {
    17. Bukkit.getPluginManager().registerEvents(this, this);
    18. }
    19.  
    20.  
    21. private WorldGuardPlugin getWorldGuard() {
    22. Plugin plugin = getServer().getPluginManager().getPlugin("WorldGuard");
    23.  
    24. // WorldGuard may not be loaded
    25. if (plugin == null || !(plugin instanceof WorldGuardPlugin)) {
    26. return null; // Maybe you want throw an exception instead
    27. }
    28.  
    29. return (WorldGuardPlugin) plugin;
    30. }
    31.  
    32.  
    33. @EventHandler
    34. public void onLiquidFlow(BlockFromToEvent e){
    35. Location to = e.getToBlock().getLocation();
    36. Location from = e.getBlock().getLocation();
    37.  
    38.  
    39. WorldGuardPlugin worldGuard = getWorldGuard();
    40. RegionManager regionManager = worldGuard.getRegionManager(e.getBlock().getWorld());
    41. System.out.print("1");
    42. if (regionManager.getApplicableRegions(to) != null && regionManager.getApplicableRegions(from) == null){
    43. e.setCancelled(true);
    44. System.out.print("2");
    45. }
    46.  
    47. }
    48. }
    49.  


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

    fireblast709

    15987632 got any debug messages? Do note that getApplicableRegions(Location) never returns null. You need to check if the size is either 0 or 1 (depending on whether it includes the global region)
     
  7. Offline

    15987632

    fireblast709 thanks a ton! what you said here helps me finish the plugin
     
Thread Status:
Not open for further replies.

Share This Page