Worldguard - Check if player enter / leave

Discussion in 'Plugin Development' started by splint, Jun 14, 2014.

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


    Hi all, I want to add to my music plugin a way to launch music when a player walk into a specific region. For that, I think to do like that.

    - Check the region name.
    - If the region name start with "music", search in regionmusic.yml the region name.
    - Get the associated URL.
    - Launch the music.

    That not too hard, but I have a problem: Worldguard cause some "null" errors on the checking region name.

    [GRAVE] Could not pass event PlayerMoveEvent to Spouties v0.2.1
            at org.bukkit.plugin.RegisteredListener.callEvent(
            at org.bukkit.plugin.SimplePluginManager.fireEvent(
            at org.bukkit.plugin.SimplePluginManager.callEvent(
            at net.minecraft.server.v1_6_R3.PlayerConnection.a(
            at net.minecraft.server.v1_6_R3.Packet10Flying.handle(SourceFile:136)
            at net.minecraft.server.v1_6_R3.NetworkManager.b(
            at net.minecraft.server.v1_6_R3.PlayerConnection.e(
            at org.getspout.spout.SpoutPlayerConnection.e(
            at net.minecraft.server.v1_6_R3.ServerConnection.b(SourceFile:37)
            at net.minecraft.server.v1_6_R3.DedicatedServerConnection.b(SourceFile:30)
            at net.minecraft.server.v1_6_R3.MinecraftServer.t(
            at net.minecraft.server.v1_6_R3.DedicatedServer.t(
            at net.minecraft.server.v1_6_R3.MinecraftServer.s(
    Caused by: java.lang.NullPointerException
            at com.minecamp.spouties.EnteringRegion.onPlayerMove(
            at sun.reflect.GeneratedMethodAccessor62.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            ... 15 more
    This my code:
    1. package com.minecamp.spouties;
    3. import java.util.Iterator;
    5. import org.bukkit.Server;
    6. import org.bukkit.entity.Player;
    7. import org.bukkit.event.EventHandler;
    8. import org.bukkit.event.EventPriority;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.player.PlayerMoveEvent;
    11. import org.bukkit.plugin.Plugin;
    12. import;
    14. import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
    15. import;
    16. import;
    18. public class EnteringRegion extends JavaPlugin implements Listener {
    19. private Server server;
    21. private WorldGuardPlugin getwg() {
    22. this.server = getServer();
    23. Plugin pl = server.getPluginManager().getPlugin("WorldGuard");
    24. if(pl != null) {
    25. return ((WorldGuardPlugin)pl);
    26. } else {
    27. return null;
    28. }
    29. }
    31. @EventHandler(priority = EventPriority.NORMAL)
    32. public void onPlayerMove(PlayerMoveEvent event) {
    33. Player p = event.getPlayer();
    34. if (p.getWorld().getName().equalsIgnoreCase("world") == true) {
    35. ApplicableRegionSet ar = this.getwg().getRegionManager(p.getWorld()).getApplicableRegions(p.getLocation());
    36. Iterator<ProtectedRegion> prs = ar.iterator();
    37. while (prs.hasNext()) {
    38. ProtectedRegion pr =;
    39. if (pr.getId().startsWith("music") == true) {
    40. event.getPlayer().sendMessage("That work !");
    41. }
    42. }
    43. }
    44. }
    46. }

    On my main class, I put that on my onEnable() fonction:
    1. PluginManager pm = getServer().getPluginManager();
    2. pm.registerEvents((Listener) this.listener, this);

    Thank for the future help.
  2. Offline


    Something is null on line 35. Figure out what it is. I'd assume it's the WorldGuard plugin, but maybe something else can return null there.

    Also, doing that every time a player moves is going to be extremely taxing on the server.
  3. Offline


    I would suggest doing "Ctrl + Shift + F" in your code. If I'm correct, and you're using Eclipse, it will clean up your code for you and make it much easier to read. It comes in handy when trying to read error logs. Now, to help you read the log next time you have an issue:

    1. Caused by: java.lang.NullPointerException
    2. at com.minecamp.spouties.EnteringRegion.onPlayerMove(
    3. at sun.reflect.GeneratedMethodAccessor62.invoke(Unknown Source)
    4. at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    5. at java.lang.reflect.Method.invoke(Unknown Source)
    6. at$1.execute(
    7. ... 15 more

    This is the part of the error you want to look at. You can see it says "Cause by: java.lang.NullPointerException". As you already said in the post, it is a null pointer exception. On the next line, it's giving you the package name, the class name, and the function name, then the line it's on. Here is where I'm getting that from:

    "com.minecamp.spoties" = package
    "EnteringRegion" = Class
    "onPlayerMove" is the function

    Now it's much easier to read right? Inside the () next to "onPlayerMove", you see it says "". That 35 is the line number. Much easier to read, and it isn't as spooky as what it would normally look like.

    I'm not saying you didn't know this, because you probably did. But if you didn't, here is some help next time. :)
  4. Offline


    No one know how to use Worldguard api ?
    I need help :(
  5. Offline


    Did you read any of the posts on your thread?
  6. Offline


    I just fix myself this errors, and I know the error was on line 35, because he returned null, BUT I just don't understand why, and that why I'm here ;)
Thread Status:
Not open for further replies.

Share This Page