Config help

Discussion in 'Spigot Plugin Development' started by Deger, Jun 7, 2016.

  1. Hello i have made a spawn/tp plugin and i set my locations in the config and get them, but how should i make a data.yml (or any xxx.yml) and store in that?

    I am pretty new so plz explain how and the smartest way to make it:)

    Code (Text):

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Location;
    import org.bukkit.World;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;

    public class Core extends JavaPlugin {

        public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
            if (!(sender instanceof Player)) {
                sender.sendMessage(ChatColor.RED + "You need to be a player to use this command!");
                return true;
            Player p = (Player) sender;
            if (label.equalsIgnoreCase("tp")) {
                if (args.length == 0) {
                    p.sendMessage(ChatColor.RED + "Please specify a player");
                    return true;
                if(args.length > 1){
                    p.sendMessage(ChatColor.RED + "Usage: /tp <playername>");
                    return true;
                Player target = Bukkit.getServer().getPlayer(args[0]);
                if(target == null){
                    p.sendMessage(ChatColor.RED + "Could not find player " + ChatColor.WHITE + "\""  + ChatColor.GREEN + args[0] + ChatColor.WHITE + "\"");
                    return true;
                return true;

            if (label.equalsIgnoreCase("setspawn")){
                getConfig().set("", p.getLocation().getWorld().getName());
                getConfig().set("spawn.x", p.getLocation().getX());
                getConfig().set("spawn.y", p.getLocation().getY());
                getConfig().set("spawn.z", p.getLocation().getZ());
                getConfig().set("spawn.yaw", p.getLocation().getYaw());
                getConfig().set("spawn.pitch", p.getLocation().getPitch());

                p.sendMessage(ChatColor.GREEN + "Spawn set!");
                return true;
                    if(getConfig().getConfigurationSection("spawn") == null){
                        p.sendMessage(ChatColor.RED + "The spawn has not yet been set!");
                        return true;
                    World w = Bukkit.getServer().getWorld(getConfig().getString(""));
                    double x = getConfig().getDouble("spawn.x");
                    double y = getConfig().getDouble("spawn.y");
                    double z = getConfig().getDouble("spawn.z");
                    double yaw = (float) getConfig().getDouble("spawn.yaw");
                    double pitch = (float) getConfig().getDouble("spawn.pitch");
                    p.teleport(new Location(w, x, y, z) );
                    return true;
            }catch(Exception e){

            return false;

  2. Did you even google before asking this? There are tons of examples of simple config out there
    • Agree Agree x 1
  3. I do not really know what to google? Could you help me