I would like to get the position and the id of the block Code (Text): ##################################### # # # # # POSITION MINERAI BREAK # # # # # ##################################### block: 1: x: 55 y: 34 z: 75 id: STONE I would like it to appear this way and I would like to know if it is also possible to withdraw part of what is written Thanks for watching
Keep some kind of internal counter for you to index by - going by your design, listen on BlockBreakEvent, get your config, write to "block.<next id>" with the x, y, z Location and the Material type of the block and save.
Thanks, but when i try that : Code (Java): // Reading from the config String name = plugin.getConfig().getString("player-name"); // Writing to the config plugin.getConfig().set("player-name", name); nothing happens :/
Try saving it, you are just writing to the cached version of the configuration (step 1) and not the actual file. JavaPlugin#saveConfig
have try that Code (Java): String name = plugin.getConfig().getString("player-name"); plugin.getConfig().set("player-name", name); main.saveConfig(); nothing happens yet
Just realized you are getting a field from the config then saving it exactly back. What are you expecting to happen exactly? Does the config even contain "player-name"?
I managed to find how to recover the positions of the blocks in my config file with this Code (Java): int i = 1; while (i <= 500){ if(plugin.getConfig().getString("Amethyst."+i) == null){ plugin.getConfig().set("Amethyst."+i, ""); plugin.getConfig().set("Amethyst."+i+".block.x", e.getBlock().getLocation().getX()); plugin.getConfig().set("Amethyst."+i+".block.y", e.getBlock().getLocation().getY()); plugin.getConfig().set("Amethyst."+i+".block.z", e.getBlock().getLocation().getZ()); plugin.saveConfig(); break; } i=i+1; I would like to know how to do now to be able to delete one of the blocks in my config.yml file Code (Text): Amethyst: '1': block: x: 27.0 y: 191.0 z: 0.0 '2': block: x: 25.0 y: 191.0 z: 5.0 '3': block: x: 24.0 y: 191.0 z: 8.0 for example block 2 how can i remove it from the file by executing a line of code please
It does exactly what i expected thank you, but how can I put my variable "i" instead of 2 Code (Java): int i = 1; while (i <= 500){ if(plugin.getConfig().getString("Amethyst."+i) == null){ plugin.getConfig().set("Amethyst."+i+".block.x", e.getBlock().getLocation().getX()); plugin.getConfig().set("Amethyst."+i+".block.y", e.getBlock().getLocation().getY()); plugin.getConfig().set("Amethyst."+i+".block.z", e.getBlock().getLocation().getZ()); plugin.saveConfig(); Bukkit.getScheduler().runTaskLater(plugin, () -> e.getBlock().setType(Material.YELLOW_GLAZED_TERRACOTTA), 20 * 10); Bukkit.getScheduler().runTaskLater(plugin, () -> plugin.getConfig().getConfigurationSection("Amethyst").set(i+"", null), 20 * 10); Bukkit.getScheduler().runTaskLater(plugin, () -> plugin.saveConfig(), 20 * 10); break; } i=i+1; } i need use int and string in the same time
it's good have use that Code (Java): int i = 1; while (i <= 500){ if(plugin.getConfig().getString("Amethyst."+i) == null){ plugin.getConfig().set("Amethyst."+i+".block.x", e.getBlock().getLocation().getX()); plugin.getConfig().set("Amethyst."+i+".block.y", e.getBlock().getLocation().getY()); plugin.getConfig().set("Amethyst."+i+".block.z", e.getBlock().getLocation().getZ()); plugin.saveConfig(); String i2 = String.valueOf(i); Bukkit.getScheduler().runTaskLater(plugin, () -> e.getBlock().setType(Material.YELLOW_GLAZED_TERRACOTTA), 20 * 10); Bukkit.getScheduler().runTaskLater(plugin, () -> plugin.getConfig().getConfigurationSection("Amethyst").set(i2, null), 20 * 10); Bukkit.getScheduler().runTaskLater(plugin, () -> plugin.saveConfig(), 20 * 10); break; } i=i+1; }