Solved Get the data of a config and put in Inventory

Discussion in 'Spigot Plugin Development' started by AntonioC94, Mar 27, 2020.

  1. Hello there!

    I'm making a teleport plugin for a RPG style.
    So, The problem is that Im not really sure about how to get the data in the config and put the data in a custom inventory (The item on an "slot" and the item with the name ).

    Code (Text):

        World: world
        X: 196.47117474858277
        Y: 110.0
        Z: -66.62703968091523
        Item: minecraft:granite
    I will explain a litle bit more...

    I save in the config all the stations with a command

    Code (Text):

        public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
            if (sender instanceof Player) {
                Player player = (Player) sender;
                if (cmd.getName().equalsIgnoreCase("polvos")) {
                    if (args.length == 1) {
                        if (args[0].equalsIgnoreCase("ver")) {            }
                    if (args.length == 2) {
                        if (args[0].equalsIgnoreCase("añadir")) {
                            String nombre = args[1];
                            Location localizacion = player.getLocation();
                            ItemStack item = player.getInventory().getItemInMainHand();
                            if (item != null) {
                                main.getConfig().set("Location." + nombre + ".World", localizacion.getWorld().getName());
                                main.getConfig().set("Location." + nombre + ".X",
                                main.getConfig().set("Location." + nombre + ".Y",
                                main.getConfig().set("Location." + nombre + ".Z",
                                main.getConfig().set("Location." + nombre + ".Item",
                                player.sendMessage("Estación " + nombre + " añadida con exito");
                            } else {
                                player.sendMessage("debes tener un item en la mano");

            return true;
    So how can i add the value "nombre" (name of the station) in the menu class, to get first the item and then put in the inventory?
  2. First of all, with the item, you don't need "minecraft:item", just use "GRANITE" (or the item name)

    And do get a value from the config, and add the item to the player's inventory, you will use:
    player.getInventory().addItem(new ItemStack(Material.valueOf(config.getString<path>)), 1) or something like that
  3. thanks for the reply jeje
    I will change with the name of the item!

    I need to get the value from the config, because I need to set and save custom "warps" :C
    So, then I can look the inventory with all the locations with this

    Code (Text):

        public void bloque(PlayerInteractEvent event) {
            Player player = event.getPlayer();
            Block maceta = event.getClickedBlock();
            if (player != null) {
                if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
                    if (maceta.getType() == Material.FLOWER_POT) {
                        Block base = maceta.getRelative(BlockFace.DOWN);
                        if(base.getBlockData().getMaterial().equals(Material.BEDROCK)) {
                            player.sendMessage("Abriendo inventario");
    #3 AntonioC94, Mar 28, 2020
    Last edited: Mar 28, 2020
  4. You can use what HarleySwtfus said.

    Mine is a bad example, but you can try...
    //in the main class
    Code (Text):
    public static Plugin getPlugin() {
            return Bukkit.getServer().getPluginManager().getPlugin("PluginName");
    Put this where you want to get or set your config values
    Code (Text):

    FileConfiguration config = PluginName.getPlugin().getConfig();

    List<String> key = config.getStringList("Location.asd");
     //this gives a list with World, x, y, z & the Item

    //you can also get specific values with EX:
    int x = config.getInt("Location.asd.X"); //In the "-" put the string name, such as "World" or "Y"

    //to set a value you can do
    config.set("Location.asd.X", 5); //Again in the "-" put the string name and the next number is the desired number you want X to be.
    Hopefully this helps. :D
    • Like Like x 1