Saving Location in Config

Discussion in 'Spigot Plugin Development' started by DeathZonePT, Jun 7, 2015.

  1. How do i have multi location in the config with commands?

    this is for a lobby command!!
     
  2. you...just do it? What is the problem you need help with ("I don't know how to do this" is not a valid answer!)
     
  3. i ask for help id don't want to help please just ignore this post!

    OBS: sorry for the bad english
     
  4. I've never seen something so vaguely explained. If you can tell the Forums what you want we might be able to help you.

    Edit: Oh My God...
     
  5. I am asking for an actual issue to help with. If you can give me a more precise description, I can actually help.
     
    • Agree Agree x 1
    • Funny Funny x 1
  6. i want to make a warp system but i dont know how to save multiple locations in tha config
     
  7. Just save them under a different key. For example 'lobby.one' and 'lobby.two'.
     
    • Like Like x 1
  8. but i want to make it with commands like "lobby save <namee or ID>"
     
  9. Could you post the code? Just to let me get the feel of what you're trying to do.
    Please.
     
  10. Code (Text):
    package com.DeathZone.CMD;

    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;

    import com.DeathZone.Core;
    import com.DeathZone.Utils.Teleport;

    public class LobbyCommand implements CommandExecutor {
     
        private Core plugin;
     
        public LobbyCommand(Core plugin) {
            this.plugin = plugin;
        }

        @Override
        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
         
            if (!(sender instanceof Player)) {
                sender.sendMessage("§cYou are not a Player!");
                return true;
            }
         
            if (cmd.getName().equalsIgnoreCase("lobby")) {
             
                Player p = (Player) sender;
             
                if(plugin.getConfig().getBoolean("bungee") == true) {
                    plugin.api.sendToServer(p, "lobby");
                }
                else {
                 
                    new Teleport(p, loc, 5).teleport(plugin);
                }
                return true;
            }
         
            return false;
        }
    }
     
  11. Do that.
     
  12. Did it work?
    Lol?
     
    #14 ItsWill, Jun 7, 2015
    Last edited: Jun 7, 2015
  13. wait im working on that and on the rest of the plugin :D
     
  14. You need to define the coords with double and two floats for the yaw postion and pitch position.
     
    • Agree Agree x 1
  15. Yeah.
     
  16. I know how to work with locs
     
  17. Use StringList to save location on your config...
     
  18. You can use this:

    Save:
    Code (Text):

    if(cmd.getName().equalsIgnoreCase("set")) {
         getConfig().set("lobby.world", p.getLocation().getWorld().getName());
         getConfig().set("lobby.x", p.getLocation().getX());
         getConfig().set("lobby.y", p.getLocation().getY());
         getConfig().set("lobby.z", p.getLocation().getZ());
         saveConfig();
         reloadConfig();
    }
     
    Load:
    Code (Text):

    World w = getServer().getWorld(getConfig().getString("lobby.world"));
    double x = getConfig().getDouble("lobby.x");
    double y = getConfig().getDouble("lobby.y");
    double z = getConfig().getDouble("lobby.z");
    p.teleport(new Location(w, x, y, z));
     
     
    • Winner Winner x 1