Solved Set location to teleport to when AFK

Discussion in 'Plugin Development' started by Jaaakee224, Feb 22, 2014.

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

    Jaaakee224

    I want to be able to set a location by doing a command such as /setafk, and it when a player is AFK, he will be teleport to the location. With the code below, I get an error.

    Error (I added the commands above the error to show you the problem from both commands)
    Code:java
    1. /afk
    2. 5:25:03 PM [javastacktrace] at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-42-g0551358-b3015jnks]
    3. 5:25:03 PM [javastacktrace] at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:175) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-42-g0551358-b3015jnks]
    4. 5:25:03 PM [javastacktrace] at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(CraftServer.java:683) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-42-g0551358-b3015jnks]
    5. 5:25:03 PM [javastacktrace] at net.minecraft.server.v1_7_R1.PlayerConnection.handleCommand(PlayerConnection.java:932) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-42-g0551358-b3015jnks]
    6. 5:25:03 PM [javastacktrace] at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:814) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-42-g0551358-b3015jnks]
    7. 5:25:03 PM [javastacktrace] at net.minecraft.server.v1_7_R1.PacketPlayInChat.a(PacketPlayInChat.java:28) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-42-g0551358-b3015jnks]
    8. 5:25:03 PM [javastacktrace] at net.minecraft.server.v1_7_R1.PacketPlayInChat.handle(PacketPlayInChat.java:47) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-42-g0551358-b3015jnks]
    9. 5:25:03 PM [javastacktrace] at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-42-g0551358-b3015jnks]
    10. 5:25:03 PM [javastacktrace] at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-42-g0551358-b3015jnks]
    11. 5:25:03 PM [javastacktrace] at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-42-g0551358-b3015jnks]
    12. 5:25:03 PM [javastacktrace] at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-42-g0551358-b3015jnks]
    13. 5:25:03 PM [javastacktrace] at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-42-g0551358-b3015jnks]
    14. 5:25:03 PM [javastacktrace] Caused by: java.lang.NullPointerException
    15. 5:25:03 PM [javastacktrace] at me.Jaaakee224.AFK.AFK.onCommand(AFK.java:71) ~[?:?]
    16. 5:25:03 PM [javastacktrace] at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-42-g0551358-b3015jnks]
    17.  
    18.  
    19. /setafk
    20. 5:25:25 PM [javastacktrace] at org.bukkit.command.PluginCommand.execute(PluginCommand.java:46) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-42-g0551358-b3015jnks]
    21. 5:25:25 PM [javastacktrace] at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:175) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-42-g0551358-b3015jnks]
    22. 5:25:25 PM [javastacktrace] at org.bukkit.craftbukkit.v1_7_R1.CraftServer.dispatchCommand(CraftServer.java:683) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-42-g0551358-b3015jnks]
    23. 5:25:25 PM [javastacktrace] at net.minecraft.server.v1_7_R1.PlayerConnection.handleCommand(PlayerConnection.java:932) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-42-g0551358-b3015jnks]
    24. 5:25:25 PM [javastacktrace] at net.minecraft.server.v1_7_R1.PlayerConnection.a(PlayerConnection.java:814) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-42-g0551358-b3015jnks]
    25. 5:25:25 PM [javastacktrace] at net.minecraft.server.v1_7_R1.PacketPlayInChat.a(PacketPlayInChat.java:28) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-42-g0551358-b3015jnks]
    26. 5:25:25 PM [javastacktrace] at net.minecraft.server.v1_7_R1.PacketPlayInChat.handle(PacketPlayInChat.java:47) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-42-g0551358-b3015jnks]
    27. 5:25:25 PM [javastacktrace] at net.minecraft.server.v1_7_R1.NetworkManager.a(NetworkManager.java:146) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-42-g0551358-b3015jnks]
    28. 5:25:25 PM [javastacktrace] at net.minecraft.server.v1_7_R1.MinecraftServer.u(MinecraftServer.java:655) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-42-g0551358-b3015jnks]
    29. 5:25:26 PM [javastacktrace] at net.minecraft.server.v1_7_R1.DedicatedServer.u(DedicatedServer.java:250) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-42-g0551358-b3015jnks]
    30. 5:25:26 PM [javastacktrace] at net.minecraft.server.v1_7_R1.MinecraftServer.t(MinecraftServer.java:545) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-42-g0551358-b3015jnks]
    31. 5:25:26 PM [javastacktrace] at net.minecraft.server.v1_7_R1.MinecraftServer.run(MinecraftServer.java:457) [craftbukkit.jar:git-Bukkit-1.7.2-R0.2-42-g0551358-b3015jnks]
    32. 5:25:26 PM [javastacktrace] Caused by: java.lang.NullPointerException
    33. 5:25:26 PM [javastacktrace] at me.Jaaakee224.AFK.AFK.onCommand(AFK.java:84) ~[?:?]
    34. 5:25:26 PM [javastacktrace] at org.bukkit.command.PluginCommand.execute(PluginCommand.java:44) ~[craftbukkit.jar:git-Bukkit-1.7.2-R0.2-42-g055135



    Commands Method
    Code:java
    1. Player player = (Player)sender;
    2.  
    3. @Override
    4. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    5. if(cmd.getName().equalsIgnoreCase("afk")) {
    6.  
    7. if(!(sender instanceof Player)) {
    8. Bukkit.getLogger().info("This Command can only be run by a Player!");
    9. return false;
    10. }
    11.  
    12. World w = Bukkit.getServer().getWorld(getConfig().getString("location.world"));
    13. double x = getConfig().getDouble("location.x");
    14. double y = getConfig().getDouble("location.y");
    15. double z = getConfig().getDouble("location.z");
    16. float pitch = (float) getConfig().getDouble("location.pitch");
    17. float yaw = (float) getConfig().getDouble("location.yaw");
    18. Location l = new Location(w, x, y, z);
    19. l.setPitch(pitch);
    20. l.setYaw(yaw);
    21. player.teleport(l);
    22. player.sendMessage(ChatColor.GREEN + "You are AFK, and have been sent to the pool!");
    23. if (isPlayerAfk(sender.getName())) {
    24. //this.cancelAfk(sender.getName());
    25. this.afk(sender.getName(), true);
    26. } else {
    27. //this.becomeAfk(sender.getName());
    28. this.afk(sender.getName(), false);
    29. }
    30. }
    31.  
    32. if(cmd.getName().equalsIgnoreCase("setafk")) {
    33. if(sender.hasPermission("setafk.allow")) {
    34. getConfig().set("location.world", player.getLocation().getWorld().getName());
    35. getConfig().set("location.x", Double.valueOf(player.getLocation().getX()));
    36. getConfig().set("location.y", Double.valueOf(player.getLocation().getY()));
    37. getConfig().set("location.z", Double.valueOf(player.getLocation().getZ()));
    38. getConfig().set("location.yaw", Float.valueOf(player.getLocation().getYaw()));
    39. getConfig().set("location.pitch", Float.valueOf(player.getLocation().getPitch()));
    40. saveConfig();
    41. player.sendMessage(ChatColor.GREEN + "AFK location Set!");
    42. return true;
    43. }else{
    44. player.sendMessage(ChatColor.RED + "You do not have permmison to do that!");
    45. }
    46. }
    47. return false;
    48. }


    Code:
    # Events: def. true
    # Colors: def. gray [black, dark_blue, dark_green, dark_aqua, dark_red, dark_purple, gold, gray, dark_gray, blue, green, aqua, red, light_purple, yellow, white]
    # IdleTimer: def. true, 60 sec
    # Messages: def. true (keys: {DISPLAYNAME}, {TIME})
    Events:
      move: true
      chat: true
    Colors:
      message: 'gray'
      player: 'gray'
    IdleTimer:
      enabled: true
      period: 60
    Messages:
      enabled: true
      nicknames: false
      +afk: '{DISPLAYNAME} is now AFK'
      -afk: '{DISPLAYNAME} is no longer AFK'
    location:
      world: world
      x: 1
      y: 1
      z: 1
      yaw: 1
      pitch: 1
    
     
  2. Offline

    Codex Arcanum

    What is the problem that you're having?
     
  3. Offline

    CraftCreeper6

    You could register a command to set the location, save the location to a Config. Get the config's data and teleport them to the location when they go AFK :) Hope this helps :) Otherwise I am just misunderstanding :O
     
  4. Offline

    Jaaakee224

    CraftCreeper6 Can you show me an example with code?

    Codex Arcanum
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  5. Offline

    xXMaTTHDXx

    make your simple if statment then do this:

    PHP:
    Location loc p.getLocation();
     
    getConfig().set("location.path"loc);
     
    //on my phone so could be wrong..
     
  6. Offline

    Jaaakee224

    xXMaTTHDXx How would I get the player to teleport to the location once he is AFK (use my code to explain :))

    Please use my code for telling me.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  7. Offline

    CraftCreeper6

    Sorry, i don't spoon feed plus i am on my phone :|
     
  8. Offline

    Niknea

    Jaaakee224 Check with they type the command and get their location, then put their location in the config, and get it every time a player goes AFK and teleport them to that location.
     
  9. Offline

    CraftCreeper6

    Pretty much exactly what i said ;)
     
  10. Offline

    xXMaTTHDXx

    Jaaakee224 I already gave you all you should need, when you check if the player goes afk tp them...
     
  11. Offline

    Jaaakee224

    EDIT: Not Solved. Please Help. I updated the code to say what I need help with.

    Also added config.yml

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  12. Offline

    nateracecar5

    Could you mark the lines it's giving errors on in the code, so we can help you better? I'm good with locations, so I will be glad to help with this one. :)
     
  13. Offline

    MOMOTHEREAL

    PS: You have to serialize the Location when saving it, or else you will get tons of errors xXMaTTHDXx
    *flies away*
     
Thread Status:
Not open for further replies.

Share This Page