Solved PlayerRespawnEvent Help

Discussion in 'Plugin Development' started by Theodossis, Sep 28, 2012.

  1. Offline

    Theodossis

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    I got this code:
    Code:
    @EventHandler
    public void onRespawn(PlayerRespawnEvent e) {
    int len = Bukkit.getServer().getOnlinePlayers().lenght;
    int x = this.getConfig().getInt("Spawns.spawn" + len + ".x");
    int y = this.getConfig().getInt("Spawns.spawn" + len + ".y");
    int z = this.getConfig().getInt("Spawns.spawn" + len + ".z");
    String world = this.getConfig().getString("Spawns.spawn" + len + ".world");
    e.setRespawnLocation(new Location(Bukkit.getServer().getWorld(world), x, y, z));
    }
    But on respawn it teleports me to x: 0 y:64 z:0 while i have setted the spawns....(The "len" works cause i am using it on other event in my plugin)
    Please help!

    This post has been edited 1 time. It was last edited by Theodossis Sep 28, 2012.
  2. Offline

    blackwolf12333

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Are you sure you did set the Spawns.spawn(len).x, y and z? because i don't see any real problems with your code.
  3. Offline

    Firefly

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    .length is spelled wrong.
    kroltan and MCForger like this.
  4. Offline

    brord

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    pfffs lol, we all missed that xD
    krazytraynz likes this.
  5. Offline

    Theodossis

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    That's all my event:
    Code:
    @EventHandler
        public void onRespawn(PlayerRespawnEvent e) {
            Player p = e.getPlayer();
            if (getConfig().getBoolean("Players." + p.getName() + ".VIP") == true) {
                int len = Bukkit.getServer().getOnlinePlayers().length;
                int x = this.getConfig().getInt("Spawns.spawn" + len + ".x");
                int y = this.getConfig().getInt("Spawns.spawn" + len + ".y");
                int z = this.getConfig().getInt("Spawns.spawn" + len + ".z");
                e.setRespawnLocation(new Location(Bukkit.getServer().getWorld("TheoWorld"), x, y, z));
                p.getInventory().addItem(new ItemStack(Material.BOW, 1));
                p.getInventory().addItem(new ItemStack(Material.ARROW, 64));
                p.getInventory().addItem(new ItemStack(Material.ARROW, 64));
                p.getInventory().addItem(new ItemStack(Material.EGG, 1));
                p.getInventory().addItem(new ItemStack(Material.SNOW_BALL, 2));
                p.getInventory().setHelmet(new ItemStack(Material.LEATHER_HELMET));
                p.getInventory().setChestplate(new ItemStack(Material.LEATHER_CHESTPLATE));
                p.getInventory().setLeggings(new ItemStack(Material.LEATHER_LEGGINGS));
                p.getInventory().setBoots(new ItemStack(Material.LEATHER_BOOTS));
            }
            if (getConfig().getBoolean("Players." + p.getName() + ".VIP") == false) {
                int len = Bukkit.getServer().getOnlinePlayers().length;
                int x = this.getConfig().getInt("Spawns.spawn" + len + ".x");
                int y = this.getConfig().getInt("Spawns.spawn" + len + ".y");
                int z = this.getConfig().getInt("Spawns.spawn" + len + ".z");
                e.setRespawnLocation(new Location(Bukkit.getServer().getWorld("TheoWorld"), x, y, z));
                p.getInventory().addItem(new ItemStack(Material.BOW, 1));
                p.getInventory().addItem(new ItemStack(Material.ARROW, 64));
            }
        }
  6. Offline

    brord

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    So if im not mistaking, you have different x, y, z coords for every different amounth of players?
  7. Offline

    Theodossis

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Yes, but it still teleports me to x: 0 y:64 z:0

    This post has been edited 1 time. It was last edited by Theodossis Sep 29, 2012.
  8. Offline

    brord

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Which are the coordinates of? what amounth of players?
    Have you tried printing the output of x, y and z?
  9. Offline

    Theodossis

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    This is my error:
    Code:
    2012-09-30 16:41:27 [SEVERE] Could not pass event PlayerRespawnEvent to CoDMod
    org.bukkit.event.EventException
        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:341)
        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:477)
        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:462)
        at net.minecraft.server.ServerConfigurationManagerAbstract.moveToWorld(ServerConfigurationManagerAbstract.java:363)
        at net.minecraft.server.ServerConfigurationManagerAbstract.moveToWorld(ServerConfigurationManagerAbstract.java:321)
        at net.minecraft.server.NetServerHandler.a(NetServerHandler.java:1076)
        at net.minecraft.server.Packet205ClientCommand.handle(SourceFile:30)
        at net.minecraft.server.NetworkManager.b(NetworkManager.java:276)
        at net.minecraft.server.NetServerHandler.d(NetServerHandler.java:111)
        at net.minecraft.server.ServerConnection.b(SourceFile:35)
        at net.minecraft.server.DedicatedServerConnection.b(SourceFile:30)
        at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:578)
        at net.minecraft.server.DedicatedServer.q(DedicatedServer.java:213)
        at net.minecraft.server.MinecraftServer.p(MinecraftServer.java:474)
        at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:406)
        at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    Caused by: java.lang.NullPointerException
        at org.bukkit.craftbukkit.CraftServer.getWorld(CraftServer.java:791)
        at me.Theodossis.CoDMod.CoDMod.onRespawn(CoDMod.java:237)
        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.java:339)
        ... 16 more
    This is code:
    Code:
    @EventHandler
        public void onRespawn(PlayerRespawnEvent e) {
            Player p = e.getPlayer();
            if (getConfig().getBoolean("Players." + p.getName() + ".VIP") == true) {
                p.getInventory().addItem(new ItemStack(Material.BOW, 1));
                p.getInventory().addItem(new ItemStack(Material.ARROW, 64));
                p.getInventory().addItem(new ItemStack(Material.ARROW, 64));
                p.getInventory().addItem(new ItemStack(Material.EGG, 1));
                p.getInventory().addItem(new ItemStack(Material.SNOW_BALL, 2));
                p.getInventory().setHelmet(new ItemStack(Material.LEATHER_HELMET));
                p.getInventory().setChestplate(new ItemStack(Material.LEATHER_CHESTPLATE));
                p.getInventory().setLeggings(new ItemStack(Material.LEATHER_LEGGINGS));
                p.getInventory().setBoots(new ItemStack(Material.LEATHER_BOOTS));
                int len = Bukkit.getServer().getOnlinePlayers().length;
                int x = this.getConfig().getInt("Spawns.spawn" + len + ".x");
                int y = this.getConfig().getInt("Spawns.spawn" + len + ".y");
                int z = this.getConfig().getInt("Spawns.spawn" + len + ".z");
                String world = this.getConfig().getString("Spawns.spawn" + len + ".world");
                Location loc = new Location(Bukkit.getServer().getWorld(world), x, y, z);
                System.out.println(loc);
            }
            if (getConfig().getBoolean("Players." + p.getName() + ".VIP") == false) {
                p.getInventory().addItem(new ItemStack(Material.BOW, 1));
                p.getInventory().addItem(new ItemStack(Material.ARROW, 64));
                int len = Bukkit.getServer().getOnlinePlayers().length;
                int x = this.getConfig().getInt("Spawns.spawn" + len + ".x");
                int y = this.getConfig().getInt("Spawns.spawn" + len + ".y");
                int z = this.getConfig().getInt("Spawns.spawn" + len + ".z");
                String world = this.getConfig().getString("Spawns.spawn" + len + ".world");
                Location loc = new Location(Bukkit.getServer().getWorld(world), x, y, z);
                System.out.println(loc);
            }
        }
  10. Offline

    brord

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    If you replace the second IF with else, its much more efficient.
    Otherwise, it looks into IF 1, lets say its true.
    It sets the data to that corresponding if, and continues
    Reads through the next if -> false but it still reads it.
    When you place else, it skips everything under the first match, so if the first if is true, it just stops.
    Makes it faster.

    Anyways, any chance you can post your config?
  11. Offline

    Theodossis

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Here is my config:
    Code:
    Spawns:
      spawn1:
        x: 156
        y: 75
        z: 260
        world: TheoWorld
      spawn2:
        x: 149
        y: 72
        z: 261
        world: TheoWorld
      spawn3:
        x: 157
        y: 74
        z: 262
        world: TheoWorld
    

    This post has been edited 1 time. It was last edited by Theodossis Oct 1, 2012.
  12. Offline

    Firefly

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Try outputting the value of len to the console and see what you get.
  13. Offline

    FTWinston

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Code:
    Caused by: java.lang.NullPointerException
        at org.bukkit.craftbukkit.CraftServer.getWorld(CraftServer.java:791)
        at me.Theodossis.CoDMod.CoDMod.onRespawn(CoDMod.java:237)
    The crash is caused by what you pass to the getWorld function. It's probably null, because for whatever reason, you're trying to get the name of an invalid config. Print out the name of the config you're trying to get, to see what's going wrong with that.
  14. Offline

    Theodossis

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    Haha i fixed it :p
  15. Offline

    Shockwave317

    dev.bukkit.org profile:
    CFUSERNAME
    My Plugins (CFCOUNT)
    Minecraft account:
    MCUSERNAME
    How because I have been turning my head inside out on how to set-up multiple spawns for 2 groups of people! I could get 1 spawn set then the other brings up a error...

Share This Page