Teleport Config Help

Discussion in 'Plugin Development' started by Ambamore2000, Jan 6, 2014.

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

    Ambamore2000

    So, I am trying to make it so when you change the config, you get teleported to THAT exact coordinates.
    Code:
    Code:java
    1. package me.Ambamore2000.Factions_Wild;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    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. Logger pluginLogger = Bukkit.getLogger();
    15.  
    16. @Override
    17. public void onEnable(){
    18. pluginLogger.info(getName() + " has been enabled!");
    19. pluginLogger.warning("Enabling " + getName());
    20. getConfig().options().copyDefaults(true);
    21. saveConfig();
    22. }
    23. @Override
    24. public void onDisable(){
    25. pluginLogger.info(getName() + "has been disabled!");
    26. }
    27. public boolean onCommand(CommandSender theSender, Command cmd, String commandLabel, String[] args) {
    28. Player thePlayer = (Player) theSender;
    29. if(cmd.getName().equalsIgnoreCase("wild")){
    30. if (args.length >= 0);
    31. thePlayer.sendMessage(ChatColor.GRAY + "<" + ChatColor.RED + "Factions" + ChatColor.GRAY + ">" + ChatColor.GREEN + " You have been teleported to the wild. Good luck!");
    32. double X = getConfig().getDouble("X-Coord");
    33. double Y = getConfig().getDouble("Y-Coord");
    34. double Z = getConfig().getDouble("Z-Coord");
    35. thePlayer.teleport();
    36. }
    37. return false;
    38. }
    39. }
    40.  

    What I have in config.yml:
    Code:java
    1. # Made By Ambamore2000
    2. # (X, Y, Z)
    3. X, Y, Z
    4. # Remove The X, Y, Z and replace with numbers.

    Pl()XH@lP
     
  2. Offline

    _Filip

  3. Offline

    Ambamore2000

  4. Offline

    ROKLGAMES

    Save each value when you set a coordinate, for example.
    Code:java
    1. public void locToString(Location loc){
    2. String coord = (loc.getWorld().getName()+";"+loc.getX()+";"+loc.getX()+";"+loc.getZ());
    3. this.getConfig().set("locations.loc",coord);
    4. }


    then to get it out of the config do it the opposite way. I think that's what you're looking for :)
     
  5. Offline

    Ambamore2000

    Ehh, do you know how the config.yml is supposed to look like?
     
  6. Offline

    ROKLGAMES

    It would look something like this:
    Code:
    #Made by blah
    loactions:
      coord:'world;300.43534;115.345345;-225.3453453'
     
  7. Offline

    _Filip

  8. Offline

    ROKLGAMES

    swampshark19 i think he's looking how to save the loc, not how to make a conf.
     
  9. Offline

    Ambamore2000

    At first, that helped me, but I was wondering how ROKLGAMES would do it for HIS code. :3 Thanks anyways, I never knew there was that. :confused:

    ROKLGAMES
    I got this so far:
    Code:java
    1. public void locToString(Location loc){
    2. String coord = (loc.getWorld().getName()+";"+loc.getX()+";"+loc.getX()+";"+loc.getZ());
    3. this.getConfig().set("locations.loc",coord);
    4. }
    5. public boolean onCommand(CommandSender theSender, Command cmd, String commandLabel, String[] args) {
    6. Player thePlayer = (Player) theSender;
    7. if(cmd.getName().equalsIgnoreCase("wild")){
    8. if (args.length >= 0);
    9. thePlayer.sendMessage(ChatColor.GRAY + "<" + ChatColor.RED + "Factions" + ChatColor.GRAY + ">" + ChatColor.GREEN + " You have been teleported to the wild. Good luck!");
    10. double X = getConfig().getDouble("X-Coord");
    11. double Y = getConfig().getDouble("Y-Coord");
    12. double Z = getConfig().getDouble("Z-Coord");
    13. thePlayer.teleport(arg0);
    14. }
    15. return false;
    16. }

    and
    Code:
    #Made by Ambamore2000
    loactions:
      coord:'world;x;y;z'
    #Format = coord:worldname;x;y;z'
    I don't get what I put in the arg0.

    ...

    ROKLGAMES
    It doesn't work. ;(

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

    ROKLGAMES

    Make a function that does the opposite of what i did, name it "stringToLocation".
     
Thread Status:
Not open for further replies.

Share This Page