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!"); } }
-
View User Profile
-
Send Message
Posted Feb 16, 2013@der_mewin Awesome thanks for the help and the great plugin!
-
View User Profile
-
Send Message
Posted Feb 16, 20131. You can use the getMovementWay() method to retrieve the way how the player entered/left the region (walked, teleported, died, etc.).
2. If you do not want the plugin to spam the message, you could use a Map to save the time when the message was displayed to the player the last time and only send it if there is enough time between the two messages.
3. I think I will add a reference to the "parent event" to my events. This would allow you to access the getTo() and getFrom() methods of this event.
-
View User Profile
-
Send Message
Posted Feb 16, 2013@der_mewin
3 questions then.. one, I noticed something in your code called getMovementWay() - what does this do?
And, any suggestions on how I can use your jail example as is, but just send one message to the player so it doesn't spam when they are trying to get back out.
in order to more properly bounce a player off a border i did some reading, and it's suggested to use event.getTo() and getFrom() - do you think you could add those to your RegionEnterEvent?
-
View User Profile
-
Send Message
Posted Feb 16, 2013@tremor77
As it is a very basic example there are of course many things you could do better. Basically you should not get stuck at the border with this example but should be teleported back when you try to leave the region. Sometimes you appear to get stuck, but it should be possible to get out of this by walking back into the region.
-
View User Profile
-
Send Message
Posted Feb 15, 2013using your jail example - how do you avoid player just getting stuck on the region border.. i walk to it, e.setcancelled.. never ending loop stuck in place getting, you cannot leave the jail a million times.
-
View User Profile
-
Send Message
Posted Feb 13, 2013@ImpactCP
It should work with MultiVerse as it uses the WG API to retrieve the regions a player is in and it also triggers on teleport. I'll take a look at it.
-
View User Profile
-
Send Message
Posted Feb 12, 2013Hello, can you build a multiverse support?
my Problem:
In World A - Region B there i give a player a some permissions.
Now he change the World (via Multiverse)
Problem now: The LeaveEvent (from your other plugins) like "Server-Leave-Command" dont work.
Is there any way? :)
-
View User Profile
-
Send Message
Posted Feb 3, 2013I just wanted to say I think this is the greatest thing ever. :) Thank you.
-
View User Profile
-
Send Message
Posted Jan 31, 2013@shadvalentine
Because it hasn't updated to CB 1.4.7...
-
View User Profile
-
Send Message
Posted Jan 26, 2013errors on 1.4.7
http://pastebin.com/eRx9rXA7
-
View User Profile
-
Send Message
Posted Jan 26, 2013I was wondering if somehow could i make it so when a player enters the region it moves them to a "Channel" where anyone in that region could hear them but when they leave that region they leave the "Channel" and revert to local chat.
-
View User Profile
-
Send Message
Posted Nov 16, 2012@der_mewin
Hi, sorry for lack of reply. Turns out that the internet consists of a cardboard box with the word internet at work. Maybe a mobile broadband dongle or two.
I shall give the github version a go and get back to you.
Thanks, Stool
-
View User Profile
-
Send Message
Posted Nov 13, 2012@Stoolbend
I tried to fix it, maybe you could try the new version before I upload it :). I uploaded it to GitHub.
-
View User Profile
-
Send Message
Posted Nov 11, 2012Hi,
I am making a plugin that uses the events thrown off by WGRegionEvents but it is causing problems with WorldGuard (5.6.5) and whenever my plugin teleports a player from one region to another.
Obligatory stack trace is here: https://gist.github.com/4055290
Problem seems to be caused by line 117 in WGRegionEventsListener, which after de-compiling and taking a look in eclipse will cause eclipse to moan "Type mismatch: cannot convert from element type Object to ProtectedRegion" for the regions variable on line 117.
Server is using 1.4.2 R0.2 and latest versions of WorldGuard, WorldEdit and PEX.
Just being detailed, trying to help.