How to Create variables in config.yml

Discussion in 'Spigot Plugin Help' started by DeadSpark, Mar 22, 2020.

  1. I just started making spigot plugin but I need help making config variables couls someone tell me the code to convert variables from config into something else like making a check for var {nick} and then converting it to player display name 'player.getDisplayName()'
     
  2. If you do all in main class, just use
    Code (Java):

    @Override
    public void onEnable() {
     saveDefaultConfig();
     Bukkit.getPluginManager().registerEvents(this, this);
    }

    @EventHandler
    public void onPlayerJoin(PlayerJoinEvent e) {
     Player p = e.getPlayer();
     getConfig().set(p.getName(), "some_data");
    saveConfig();
    }

     
     
  3. Oh TY Ill try that out within a few seconds and let you know
     
  4. @ilya50 is that alright?
    I actually didnt understood the concept of "some_data"

    upload_2020-3-22_14-20-2.png
     
  5. What do you want to save in config? The question was how to save the data in the config, but what data was not indicated
     
  6. What i actually want is to use variables in config like my code is

    main class:
    Code (Java):
     @EventHandler
        public void OnBedEnter(PlayerBedEnterEvent event) {

            Player player = event.getPlayer();
            if (player.hasPermission("betterbedtime.enterbedmsg")) {

                String bedentermsg = getConfig().getString("bedentermessage");
                assert bedentermsg != null;
                player.sendMessage(ChatColor.translateAlternateColorCodes('&', bedentermsg));

            }

        }
    Config:
    Code (YAML):
    # Configuration version 1.4

    # Custom Message that will be typed when player goes to bed
    # Supports '&" color codes
    bedentermessage
    : '&2Hey, &aYou are going to sleep?'
    so i want a way to add the {nick} usable in config.yml and when plugin detects the variable it converts it to player.getDisplayName()
     
  7. Config:
    Code (YAML):
    # Configuration version 1.4

    # Custom Message that will be typed when player goes to bed
    # Supports '&" color codes
    bedentermessage
    : '&2Hey {player}, &aYou are going to sleep?'
    Code:
    Code (Java):
        @EventHandler
        public void OnBedEnter(PlayerBedEnterEvent event) {

         Player player = event.getPlayer();
         if (player.hasPermission("betterbedtime.enterbedmsg")) {

          String bedentermsg = getConfig().getString("bedentermessage")
           .replace("{player}", player.getName());
          player.sendMessage(ChatColor.translateAlternateColorCodes('&', bedentermsg));

         }

        }
     
    • Informative Informative x 1
  8. TY really appreciated