Check if Player is in WorldGuard Region Error

Discussion in 'Plugin Development' started by rmb938, May 1, 2012.

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

    rmb938

    So I have this code:

    Code:
        @EventHandler(priority = EventPriority.NORMAL)
        public void onPlayerMove(final PlayerMoveEvent event) {
            Player p = event.getPlayer();
            User u = plugin.getDb().getUser(p.getName());
            if (p.getWorld().getName().equalsIgnoreCase("world") == true) {
                ApplicableRegionSet ar = plugin.getWG().getRegionManager(p.getWorld()).getApplicableRegions(p.getLocation());
                Iterator<ProtectedRegion> prs = ar.iterator();
                while (prs.hasNext()) {
                    ProtectedRegion pr = prs.next();
                    if (pr.getId().startsWith("portal") == true) {
                        //teleport to arena!
                        }
                    }
                }
    }
    Which checks if the player is in a region that its name starts with "portal" but in game when ever a player moves I get this error:

    Code:
    20:04:20 [SEVERE] Could not pass event PlayerMoveEvent to Core
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:303)
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62)
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:459)
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:209)
            at net.minecraft.server.Packet10Flying.handle(SourceFile:126)
            at net.minecraft.server.NetworkManager.b(NetworkManager.java:229)
            at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:113)
            at org.getspout.spout.SpoutNetServerHandler.a(SpoutNetServerHandler.java
    :169)
            at net.minecraft.server.NetworkListenThread.a(NetworkListenThread.java:7
    8)
            at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:551)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:449)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    Caused by: java.lang.NullPointerException
            at java.util.zip.ZipFile.<init>(Unknown Source)
            at java.util.zip.ZipFile.<init>(Unknown Source)
            at java.util.jar.JarFile.<init>(Unknown Source)
            at java.util.jar.JarFile.<init>(Unknown Source)
            at com.sk89q.worldguard.bukkit.WorldGuardPlugin.createDefaultConfigurati
    on(WorldGuardPlugin.java:710)
            at com.sk89q.worldguard.bukkit.WorldConfiguration.<init>(WorldConfigurat
    ion.java:170)
            at com.sk89q.worldguard.bukkit.ConfigurationManager.get(ConfigurationMan
    ager.java:181)
            at com.sk89q.worldguard.bukkit.WorldGuardPlugin.getRegionManager(WorldGu
    ardPlugin.java:812)
            at com.gmail.rmb1993.core.Listeners.CorePlayerListener.onPlayerMove(Core
    PlayerListener.java:238)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
            at java.lang.reflect.Method.invoke(Unknown Source)
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:301)
            ... 11 more
    Any ideas? Thanks :)
     
    aciid likes this.
  2. Offline

    r0306

    Can you post the main class as well? I found that making your own region feature is easier than trying to use the WorldGuard API. Depending on the purpose of this plugin, you may or may not want to consider just adding a bit of code to create regions with.
     
  3. Offline

    rmb938

    Yea I may end up doing that if I can't get this to work.

    Code:
    /*
    * To change this template, choose Tools | Templates
    * and open the template in the editor.
    */
    package com.gmail.rmb1993.core;
     
    import com.gmail.rmb1993.core.Listeners.*;
    import com.gmail.rmb1993.core.commands.*;
    import com.gmail.rmb1993.core.user.User;
    import com.sk89q.worldedit.bukkit.WorldEditPlugin;
    import com.sk89q.worldguard.bukkit.WorldGuardPlugin;
    import java.util.HashMap;
    import java.util.logging.Logger;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.PluginLoader;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.getspout.spoutapi.SpoutManager;
    import org.getspout.spoutapi.keyboard.Keyboard;
     
    /**
    *
    * @author Ryan
    */
    public class Core extends JavaPlugin {
     
        Logger log;
        CorePlayerListener pl;
        CoreEntityListener el;
        CoreSpoutListener sl;
        CoreBlockListener bl;
        private WorldEditPlugin we;
        private WorldGuardPlugin wg;
        private HashMap<String, User> users = new HashMap<>();
     
        public WorldEditPlugin getWE() {
            return we;
        }
     
        public WorldGuardPlugin getWG() {
            return wg;
        }
     
        public HashMap<String, User> getUsers() {
            return users;
        }
        private DataBase db;
     
        public DataBase getDb() {
            return db;
        }
     
        public Logger getLog() {
            return log;
        }
     
        @Override
        public void onEnable() {
            we = (WorldEditPlugin) getServer().getPluginManager().getPlugin("WorldEdit");
            wg = new WorldGuardPlugin();
            db = new DataBase(this);
            Utils utils = new Utils(this);
            Utils.setupSkills();
            PluginLoader pgl = getPluginLoader();
            pl = new CorePlayerListener(this);
            el = new CoreEntityListener(this);
            sl = new CoreSpoutListener(this);
            bl = new CoreBlockListener(this);
            log = this.getLogger();
            getCommand("leave").setExecutor(new CoreLeaveCommand(this));
            getCommand("setmob").setExecutor(new CoreSetMobCommand(this));
            getCommand("shop").setExecutor(new CoreShopCommand(this));
            getCommand("portal").setExecutor(new CorePortalCommand(this));
            getCommand("link").setExecutor(new CoreLinkCommand(this));
            SpoutManager.getKeyBindingManager().registerBinding("Mob Chooser", Keyboard.KEY_K, "Open GUI for Mob Chooser", new CoreKeyMCListener(this), this);
            SpoutManager.getKeyBindingManager().registerBinding("Shop Manager", Keyboard.KEY_L, "Open GUI for Shops", new CoreKeyShopListener(this), this);
            log.info("Core plugin enabled!");
        }
     
        @Override
        public void onDisable() {
            for (Player p : getServer().getOnlinePlayers()) {
                /*User u = db.getUser(p.getName());
                u.setIsMob(false);*/
                db.saveUser(p);
            }
            db.saveConstants();
            log.info("Core plugin disabled!");
        }
    Edit: Wow I am stupid just found the problem

    Replaced

    wg = new WorldGuardPlugin();

    with

    wg = (WorldGuardPlugin) getServer().getPluginManager().getPlugin("WorldGuard");

    That is what I get for being lazy and not typing something right.
     
Thread Status:
Not open for further replies.

Share This Page