WorldGuard Region Events
Description
WorldGuard Region Events allows modders to trigger function if a player enters or leaves a region. It adds four events that you can use to trigger your functions: RegionEnterEvent, RegionEnteredEvent, RegionLeaveEvent and RegionLeftEvent. They can be used just as any other Bukkit event (for more information look here .)
The RegionEnteredEvent and RegionLeftEvent are triggered a short time after a player entered/left a region so you cannot cancel them, but use the to check the flags of the regions the player is in.
The JavaDoc of WGRegionEvents can be found here.
Example
If you don't want to create a plugin ignore this
To send a player a text whenever he enters a region:
import com.mewin.WGRegionEvents.events.RegionEnterEvent; ... @EventHandler public void onRegionEnter(RegionEnterEvent e) { e.getPlayer().sendMessage("You just entered " + e.getRegion().getId()); }
Or to quit players from escaping from jail:
import com.mewin.WGRegionEvents.events.RegionLeaveEvent ... @EventHandler public void onRegionLeave(RegionLeaveEvent e) { if (e.getRegion().getId().equals("jail") && e.isCancellable()) // you cannot cancel the event if the player left the region because he died { e.setCancelled(true); e.getPlayer().sendMessage("You cannot leave the jail!"); } }
@der_mewin
Haha, oops! I should always know to look for other branches.
It's worth noting that we were originally running the stock version off of DBO, but I guess may have gotten a downgrade once I started working from master.
I'll give it a pull and compare with the changes I've made so far- thanks!
@TheDroneWolf
EDIT: ok, I just updated the master branch to match the content of the test branch and will remove the test branch ^^
EDIT 2.: btw, if you want you may add your name to the plugin.yml file ;)
Hi NathanWolf,
I am actually not working much on my projects anymore and appreciate all the work you are doing :) . If you want you can create a pull request on GitHub, but you should apply all your changes to the test-branch of the plugin as it is still ahead of master (as I could not merge them yet). For example this branch is already mavenized what could have saved you some work ;) .
Hello!
EDIT: The CME's may not be your plugin, could have been jumping to conclusions there... but please read regardless and let me know what you think!
We ran into some really nasty CME's on our server (hard server crash) that I believe *may* stem back to WGRE + WGRC.
It appears as though WGRE sends the "left" and "entered" events asynchronously- and these are the events WGRC uses, meaning commands get executed asynchronouosly. This is kinda bad if so! I'm surprised no one else has run into the issue.
Is this plugin still in active development? I would love to submit a PR to address this and other issues:
And of course let me know if you think I'm jumping to conclusions here- but we had consistent issues with multiple CME crashes per day, and once changing WGRC to use the synchronous version of events, the problem went away.
I'm not sure if the "isAsynchronous" check works, but I think at the very least you should make it *really* clear that some of these events may be called from a separate thread. Personally I don't think you ought to be using async at all, and I've removed it from my branch completely - but maybe it could be a config option?
Another nice feature, if I were submitting pulls, would be a config option to turn off any of the 4 events for performance. On our server we really only care about "enter" at least for now.
I bring this all up because we've been closely investigating server lag, and WG's PME event (aka WGRE's PME event) is highly in the lead, often taking up 40% of the CPU time (we have the builtin WG PME disabled)
This all said, I love your plugin (and WGRC and WGCF)- these are all SO great, and I'm baffled as to why they are not core features of WorldGuard yet. Thanks for putting this out there, and let me know if I can help!
- NathanWolf (via an alt account, my DBO account is broken, long story)
@Valon750
Yes, thats correct ;) .
@EventHandler
public void onRegionEnter (RegionEnterEvent e) {
e.getPlayer().sendMessage("You just entered " + e.getRegion().getId());
}
That's the code I'm using (basically copy+pasted from the above site) and it doesnt do anything in game. No console errors, no message sent to the player.
be sure that your plugin implements Listener, and that you have the line
getServer().getPluginManager().registerEvents(this, this);
in your onEnable() method, hope it helps ^.^
@como89
Thank you. :)
@catprowler
It's work perfect in 1.7.2 version :) I test it.
Hi there, will there be an update for 1.7.2? Thank you.
@xXBadeye
Thank you for the report, I updated the link to the most current version.
@Pie_Man_456
You can use the RegionLeaveEvent and test if getMovementWay returns MovementWay.DISCONNECT.
@como89 How would I get the player's region when they leave the server
@xXBadeye
The new link for the javadoc : http://mewin.bplaced.net/javadoc/WGRegionEvents/
Huh. Strange, the javadoc link does not work :/ So, i can just implement it to my libarys aswell as worldguard itself into eclipse/my project, and i can use the events? Do i have to put your jar into my plugins folder in my server or just putting it as a libary in my project?
@adamwbb
What doesnt work?
@EvlCreeperReaper The plugin is just an api for plugin developers. It does not do anything on its own, but some other plugins use it to detect players who enter/leave a region.
Hi,
This plugin doesn't generate a config, or has any commands in /help. It is required for RegionJukebox, yet that plugin works fine. I'm doing everything correctly, so...could you please look into finding this if it's a bug or something? Also, in my console, it says it enables this plugin, and my server is 1.6.4 Dev (Also didn't work w/ 1.6.2 Rec).
Thanks!
it doesnt work for me
@lANTHONYl
I have the same problem
@lANTHONYl
The only thing it does is adding/removing regions from an arraylist and sending an event when a player moves ...
@der_mewin
I know, you've got a lot of projects going on here bud. I've been trying to not be a nuisance about it. Best i can gather is that there is some conflict between WGRegionEvents and one (or more) of the 60 other plugins we're using. Does WGRegionEvents make any calls to WG that use the snycChunkLoad events?
@lANTHONYl
I'm sorry, I hope you understand it is not easy to manage 22 projects alone ;)
I don't know what causes the issue as I never had it. If you have any idea how to fix this please tell me :/ .