Check which region the player is?

Discussion in 'Plugin Development' started by zDubsCrazy, May 20, 2014.

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


    I need to check which region the player is using the WorldGuard API. But do not know how to do this, I wanted something like:
    1. @EventHandler
    2. public void onEnterFeast(PlayerMoveEvent event) {
    4. if(player.getRegion().equals("region")) {
    5. player.sendMessage("You came to feast");
    6. arraylist.add(player.getName());
    7. }
    8. }

    But obviously it does not exist. Hope you can help me!

  2. Offline


    zDubsCrazy I think there's something already within the plugin itself to make a region enter message. I think you have to do /region flag [name] enter (The "enter" thing may be different) [message] ... You can do this with any region. But, there may be a way to do this. I myself have never used the WorldGuard API.
  3. Offline


  4. Offline


    zDubsCrazy Epicballzy 'enter' needs to be 'greeting', then the command is as follows: /region flag <name> greeting Message to say when someone enters.

    If you want to do something that is not already in WorldGuard you can get the regions that the player is in with the following:
    1. ApplicableRegionSet regions = worldGuard.getRegionManager(player.getWorld()).getApplicableRegions(event.getPlayer().getLocation());
    2. for(ProtectedRegion r : regions) {
    3. // do something with the found region(s)
    4. }

    The variable 'worldGuard' has to reference the instance of the WorldGuardPlugin class. You can get that with this code:
    1. getServer().getPluginManager().getPlugin("WorldGuard");

    You have to save that and check if it is not null. Also you want to add a 'depend: [WorldGuard]' section in your plugin.yml if you do not already have that.
Thread Status:
Not open for further replies.

Share This Page