Save location in config and Teleport to it

Discussion in 'Plugin Development' started by edm wasrevilosmith1999, Mar 29, 2014.

Thread Status:
Not open for further replies.
  1. Here is my code for an FFA plugin i'm working on, at the minuite I want a command to add the spawn (Which saves the players location to the config) and then a command which teleports t0 that location

    Code:java
    1. package me.revilosmith.FFA;
    2.  
    3. import java.io.File;
    4.  
    5. import org.bukkit.ChatColor;
    6. import org.bukkit.Location;
    7. import org.bukkit.command.Command;
    8. import org.bukkit.command.CommandSender;
    9. import org.bukkit.entity.Player;
    10. import org.bukkit.plugin.java.JavaPlugin;
    11.  
    12. public class Main extends JavaPlugin{
    13.  
    14. @Override
    15. public void onEnable(){
    16. if(!(new File(getDataFolder(), "config.yml")).exists()){
    17. saveDefaultConfig();
    18. }
    19. }
    20.  
    21. @Override
    22. public void onDisable(){
    23.  
    24. }
    25.  
    26. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    27.  
    28. if(cmd.getName().equalsIgnoreCase("FFA")){
    29.  
    30. Player player = (Player)sender;
    31.  
    32. if((player instanceof Player)){
    33.  
    34. if(args.length == 1){
    35.  
    36. if(args[0].equalsIgnoreCase("AddSpawn")){
    37.  
    38. if(player.hasPermission("FFA.AddSpawn")){
    39.  
    40. Location loc = player.getLocation();
    41.  
    42. getConfig().set("1.World", loc.getWorld());
    43. getConfig().set("1.World", loc.getX());
    44. getConfig().set("1.World", loc.getY());
    45. getConfig().set("1.World", loc.getZ());
    46. saveConfig();
    47.  
    48. player.sendMessage(ChatColor.AQUA + "[Minecentre] " + ChatColor.YELLOW + "You have set the spawn for FFA");
    49.  
    50. }
    51. else{
    52. player.sendMessage(ChatColor.RED + "You do not have permission to perform that command!");
    53. }
    54.  
    55. }
    56. else{
    57. player.sendMessage(ChatColor.RED + "To add a spawn to FFA, type /FFA AddSpawn");
    58. }
    59.  
    60. }
    61. else if(args.length == 0){
    62.  
    63. Player joiner = (Player)sender;
    64.  
    65. double x = getConfig().getInt("1.X");
    66. double y = getConfig().getInt("1.Z");
    67. double z = getConfig().getInt("1.Y");
    68.  
    69. Location spawn = new Location(joiner.getServer().getWorld(getConfig().getString("1.World")), x, y, z);
    70. joiner.teleport(spawn);
    71.  
    72. }
    73.  
    74. }
    75. else{
    76. sender.sendMessage(ChatColor.RED + "You must be a player to perform that command.");
    77. }
    78.  
    79. }
    80.  
    81. return true;
    82. }
    83.  
    84. }
    85.  
    86.  
     
  2. Offline

    Wolfey

    You're not setting the x, y, and z. You're just setting the World.
     
  3. Wow, i feel so stupid -.-

    Still doesn't work though

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

    Shayana

    getConfig().set("1.World", loc.getZ());
    Maybe set("l.Z") instead of this ? Same applies for all your code.
     
  5. Offline

    JBoss925

  6. Still doesn't work, Any examples of code?
     
  7. Offline

    JBoss925

  8. Did that, doesn't work

    Ok, I got it to work but here's the config the world is like this:
    Code:java
    1. '1':
    2. World: !!org.bukkit.craftbukkit.v1_7_R1.CraftWorld
    3. PVP: true
    4. ambientSpawnLimit: 15
    5. animalSpawnLimit: 15
    6. autoSave: true
    7. difficulty: EASY
    8. environment: NORMAL
    9. fullTime: 919159
    10. keepSpawnInMemory: true
    11. monsterSpawnLimit: 70
    12. thunderDuration: 8841
    13. thundering: false
    14. time: 7159
    15. waterAnimalSpawnLimit: 5
    16. weatherDuration: 25454
    17. X: -1569.703933163286
    18. Y: 90.0
    19. Z: 148.82157348943554
    20.  


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
Thread Status:
Not open for further replies.

Share This Page