[Now with NPE's!]Teleport player to "the end"? Then back to spwan in 5 minutes

Discussion in 'Plugin Development' started by calebbfmv, Aug 10, 2012.

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

    travja

    OK, for the PlayerRespawnEvent, do what you were doing and teleport them to the End. Then schedule a task that is 5 mins long, inside there, teleport them to the main world.
     
  2. Offline

    calebbfmv

    Erm, hmm. I myself have not worked with timers and such, but how might I go about doing that?

    It always says "initialize variable" blah blah blah GRRRRRRRRRRR

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  3. Offline

    travja

    Make sure your event is set up right, something like this: p
    Code:java
    1. public void onRespawn(PlayerRespawnEvent event){
    2. final Player p = event.getPlayer();
    3. event.setRespawnLocation(endcoords);
    4. //NOTE: you need to input your coords here
    5. getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
    6. public void run(){
    7. p.teleport(getServer().getWorld(overworld name..).getSpawn());
    8. //NOTE: you need to enter your worlds name here
    9. }
    10. }, 6000L);
    11. }


    That will make them respawn in the end and teleport them to the overworld spawn after 5 mins.
     
  4. Offline

    calebbfmv

    Dude, thanks.
     
  5. Offline

    travja

    Welcome!
     
    calebbfmv likes this.
  6. Offline

    calebbfmv

  7. Offline

    travja

  8. Offline

    calebbfmv

    travja
    Code:
    16:33:41 [WARNING] Task of 'CH Limbo' generated an exception
    java.lang.NullPointerException
            at com.craft.hammer.Lim.Bo$1.run(Bo.java:37)
            at org.bukkit.craftbukkit.scheduler.CraftScheduler.mainThreadHeartbeat(C
    raftScheduler.java:126)
            at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:512)
            at net.minecraft.server.DedicatedServer.q(DedicatedServer.java:212)
            at net.minecraft.server.MinecraftServer.p(MinecraftServer.java:476)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:408)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    16:33:59 [WARNING] Task of 'CH Limbo' generated an exception
    java.lang.NullPointerException
            at com.craft.hammer.Lim.Bo$2.run(Bo.java:70)
            at org.bukkit.craftbukkit.scheduler.CraftScheduler.mainThreadHeartbeat(C
    raftScheduler.java:126)
            at net.minecraft.server.MinecraftServer.q(MinecraftServer.java:512)
            at net.minecraft.server.DedicatedServer.q(DedicatedServer.java:212)
            at net.minecraft.server.MinecraftServer.p(MinecraftServer.java:476)
            at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:408)
            at net.minecraft.server.ThreadServerApplication.run(SourceFile:539)
    
     
  9. Offline

    travja

    Can you give me your class?
     
  10. Offline

    calebbfmv

    Code:
    package com.craft.hammer.Lim;
     
    import java.util.logging.Logger;
     
    import org.bukkit.Location;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerRespawnEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Bo extends JavaPlugin implements Listener {
     
    public Logger log = Logger.getLogger("Minecraft");
     
            @Override
            public void onEnable() {
      log.info("================================");
      log.info("CraftHammer Limbo is now enabled");
      log.info("================================");
      getServer().getPluginManager().registerEvents(this, this);
            }
    
     
            @Override
            public void onDisable() {
            log.info("=================================");
            log.info("CraftHammer Limbo is now disbaled");
            log.info("=================================");
            }
         // X29 Y135 Z-64 main world
            // end X-5 Y67 Z -5
            @EventHandler
            public void onRespawn(PlayerRespawnEvent event){
                final Player p = event.getPlayer();
                Location loc = new Location(getServer().getWorld("world_the_end"), -5, 67, -5);
                event.setRespawnLocation(loc);
                getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
                public void run(){
                p.teleport(getServer().getWorld("world").getSpawnLocation());
                }
                }, 6000L);
                }
    }
    
     
  11. Offline

    travja

    What line is line 70?
     
  12. Offline

    Jogy34

    I think you have to load the world first. Try doing:
    Code:
    World w = getServer().createWorld(new WorldCreator("world_the_end"));
    
    before you try to teleport to it and use 'w' as the world.
    the createWorld method will either create or load a world so make sure that you have the right name otherwise you will be using a completely new world
     
  13. Offline

    calebbfmv

    No, I can teleport to the nether just fine, it is teleporting BACK that is difficult/is not working.

    There is no line 70.... Dah Faq is up with this?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  14. Offline

    Jogy34

    That is really weird.
    It is calling 2 errors at 2 different locations:
    Code:
    at com.craft.hammer.Lim.Bo$1.run(Bo.java:37)
    at com.craft.hammer.Lim.Bo$2.run(Bo.java:70)
    
    It's saying they are at line 37 and 70 but it only goes up to line 41. It is also saying that there is another run method in (presumably) another scheduled event on line 70.
     
  15. Offline

    calebbfmv

    I see that, 37 is setRespawn(loc) thing and line 70? Da FAQQQ
     
  16. Offline

    travja

    The respawn location is null... Make sure it's set to something...
     
  17. Offline

    calebbfmv

    Um, It isn't
     
  18. Offline

    travja

    can you give me the loc object?
     
  19. Offline

    calebbfmv

    Code:
    Location loc = new Location(getServer().getWorld("world_the_end"), -5, 67, -5);
    
     
  20. Offline

    travja

    There you go, it can't find the world "world_the_end"
     
  21. Offline

    calebbfmv

    *facepalm* yes it can, the problem is teleporting BACK.
     
  22. Offline

    travja

    Can you post your most recent code? Sorry for not understanding.. *facepunch...*
     
  23. Offline

    calebbfmv

    Code:
    package com.craft.hammer.Lim;
     
    import java.util.logging.Logger;
     
    import org.bukkit.Location;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerRespawnEvent;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Bo extends JavaPlugin implements Listener {
     
    public Logger log = Logger.getLogger("Minecraft");
     
            @Override
            public void onEnable() {
      log.info("================================");
      log.info("CraftHammer Limbo is now enabled");
      log.info("================================");
      getServer().getPluginManager().registerEvents(this, this);
            }
    
     
            @Override
            public void onDisable() {
            log.info("=================================");
            log.info("CraftHammer Limbo is now disbaled");
            log.info("=================================");
            }
         // X29 Y135 Z-64 main world
            // end X-5 Y67 Z -5
            @EventHandler
            public void onRespawn(PlayerRespawnEvent event){
                final Player p = event.getPlayer();
                Location loc = new Location(getServer().getWorld("world_the_end"), -5, 67, -5);
                event.setRespawnLocation(loc);
                getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
                public void run(){
                p.teleport(getServer().getWorld("world").getSpawnLocation());
                }
                }, 6000L);
                }
     }
    
     
  24. Offline

    travja

    I don't know.. but I can mess around with some code tomorrow to try and help you, in the mean time, good luck!
     
  25. Offline

    calebbfmv

    Cool, I am going yo slepp. as you can tell :p I need it. Night and thanks:

    PS: This is still not solved for everyone out there...

    Bumpidy bumpidy bump buh bump!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  26. Offline

    travja

    Here is what I got to work:
    Code:java
    1. package me.Travja.DeathPenalty;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.Location;
    7. import org.bukkit.entity.Player;
    8. import org.bukkit.event.EventHandler;
    9. import org.bukkit.event.Listener;
    10. import org.bukkit.event.player.PlayerRespawnEvent;
    11. import org.bukkit.plugin.java.JavaPlugin;
    12.  
    13. public class Main extends JavaPlugin implements Listener{
    14. public Logger log;
    15. public void onEnable(){
    16. log = this.getLogger();
    17. log.info("DeathPenalty has been Enabled!!");
    18. this.getServer().getPluginManager().registerEvents(this, this);
    19. }
    20. public void onDisable(){
    21. log.info("DeathPenalty has been Disabled!!");
    22. }
    23. @EventHandler
    24. public void onRespawn(PlayerRespawnEvent event){
    25. final Player p = event.getPlayer();
    26. Location loc = Bukkit.getServer().getWorld("world_the_end").getSpawnLocation();
    27. event.setRespawnLocation(loc);
    28. getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable(){
    29. public void run(){
    30. Location loc = Bukkit.getServer().getWorld("world").getSpawnLocation();
    31. p.teleport(loc);
    32. }
    33. }, 6000L);
    34.  
    35. }
    36. }


    And plugin.yml:
    Code:
    name: DeathPenalty
    main: me.Travja.DeathPenalty.Main
    version: 1.0
    description: Just a Death Pentalty plugin
    author: travja
     
  27. Offline

    calebbfmv

    Yeah it dont work. crap
     
  28. Offline

    travja

    That worked perfectly fine for me. I got tele'd to the end and back in 5 mins.
     
  29. Offline

    calebbfmv

    Odd it didn't work for me.............. Anyway i shall figure it out
     
  30. Offline

    GuntherDW

    Make sure that you do not have an older version of the plugin inside your plugins/ folder. Looks like you have an older backup or the likes inside of that folder :p.
     
Thread Status:
Not open for further replies.

Share This Page