Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // CREAR ARENA (GUARDARLA A UN ARCHIVO YAML Y VOLVERLO A LLAMAR DESPUÉS)
- private void createArena(String arenaName, Player player) {
- WorldEditPlugin worldEdit = (WorldEditPlugin) Bukkit.getServer().getPluginManager().getPlugin("WorldEdit"); // INICIALIZAMOS WORLD EDIT
- if (worldEdit == null) { // SI NO SE ENCUENTRA
- Log.Error("WorldEdit Not Load"); // PRINT
- }else{ // SI SE ENCONTRÓ WORLD EDIT
- Selection sel = worldEdit.getSelection(player); // RECOGEMOS
- int X1 = sel.getMaximumPoint().getBlockX(); // LAS SELECCIONES
- int Y1 = sel.getMaximumPoint().getBlockY(); // DESDE X1,Y1,Z1
- int Z1 = sel.getMaximumPoint().getBlockZ(); // HASTA X2, Y2, Z2
- int X2 = sel.getMinimumPoint().getBlockX();
- int Y2 = sel.getMinimumPoint().getBlockY();
- int Z2 = sel.getMinimumPoint().getBlockZ();
- Location loc1 = new Location(sel.getWorld(),X1, Y1, Z1); // ASÍ ENCONTRAREMOS EL CUADRADO QUE HACEMOS CON WORLD EDIT
- Location loc2 = new Location(sel.getWorld(),X2, Y2, Z2);
- World world = sel.getWorld();
- String name = arenaName;
- Config saveFile = new Config(name, "NOMBREDETUPLUGIN", "Arenas"); // GUARDAMOS LA ARENA A UN ARCHIVO (VEÁSE ABAJO LA CLASE INHERENTE)
- saveFile.delete();
- saveFile.create();
- for (int x = X2; x < X1; x++) { // formula para conseguir todos los bloques en ese cuadrado
- for (int y = Y2; y < Y1; y++) {
- for (int z = Z2; z < Z1; z++) {
- Block block = world.getBlockAt(x, y, z); // recogemos cada bloque
- saveFile.getConfig().set("BLOCKS." + x + "," + y + "," + z, // lo guardamos al
- block.getType().toString() + ":" + block.getData()); // archivo de configuracion previamente creado
- }
- }
- }
- saveFile.getConfig().set("BLOCKS.WORLD", world.getName());
- saveFile.getConfig().options().copyDefaults(true);
- saveFile.save();
- }
- }
- // CARGAR UNA ARENA POR SEPARADO.
- private void loadArena(String arenaName) {
- Config saveFile = new Config(arenaName, "NOMBREDETUPLUGIN", "Arenas"); // Conseguimos el archivo de configuración
- ConfigurationSection privateSection = saveFile.getConfig().getConfigurationSection("BLOCKS"); // conseguimos las keys que habiamos creado antes
- for (String location : privateSection.getKeys(false)) { // empezamos a agarrar todos los bloques (y su data) de la configuración
- if (!location.equalsIgnoreCase("WORLD")){ // y los empezamos a colocar en donde estaban.
- String[] cords = location.split(",");
- int X = Integer.valueOf(cords[0]);
- int Y = Integer.valueOf(cords[1]);
- int Z = Integer.valueOf(cords[2]);
- String[] Blockdata = saveFile.getConfig().getString("BLOCKS." + location).split(":");
- String material = Blockdata[0];
- World getter = Bukkit.getWorld(saveFile.getConfig().getString("BLOCKS.WORLD"));
- byte data = Byte.valueOf(Blockdata[1]);
- getter.getBlockAt(X, Y, Z).setType(Material.matchMaterial(material)); // aquí donde colocamos el material
- getter.getBlockAt(X, Y, Z).setData(data); // aquí es donde colocamos la data del material
- }
- }
- }
- //Pequeña clase de configuración que hice, ustedes utilicen la suya o dejenla así, igual funciona.
- class Config(){
- File fileDir;
- File pFile;
- FileConfiguration config;
- public Config(String fileName, String pluginName) {
- this.FileDir = new File(Bukkit.getPluginManager().getPlugin(pluginName).getDataFolder(), "");
- this.pFile = new File(Bukkit.getPluginManager().getPlugin(pluginName).getDataFolder(), fileName + ".yml");
- this.config = YamlConfiguration.loadConfiguration(this.pFile);
- }
- public Config(String fileName, String pluginName, String folder) {
- try{
- this.fileDir = new File(Bukkit.getPluginManager().getPlugin(pluginName).getDatafolder() + "\\" + folder, "");
- this.pFile = new File(Bukkit.getPluginManager().getPlugin(pluginName).getDatafolder() + "\\" + folder, fileName + ".yml");
- this.config = YamlConfiguration.loadConfiguration(this.pFile);
- }catch(YAMLException event){
- event.printStackTrace();
- }
- }
- public FileConfiguration getConfig() {
- return this.config;
- }
- public void save() {
- this.config.options().copyDefaults(true);
- try {
- this.config.save(this.pFile);
- } catch (IOException var2) {
- Log.Error(var2.getMessage());
- }
- }
- public void create() {
- if(!this.fileDir.exists()) {
- this.fileDir.mkdir();
- }
- if(!this.pFile.exists()) {
- try {
- this.pFile.createNewFile();
- } catch (Exception var2) {
- Log.Error(var2.getMessage());
- }
- }
- }
- public void delete() {
- this.pFile.delete();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement