package de._82grfl1bif.KPI_Visualizer.commands; import com.google.gson.Gson; import com.google.gson.stream.JsonReader; import de._82grfl1bif.KPI_Visualizer.data.DataHolder; import de._82grfl1bif.KPI_Visualizer.structures.Building; import de._82grfl1bif.KPI_Visualizer.structures.Structure; import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Server; import org.bukkit.block.Block; import org.bukkit.command.Command; import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import java.io.FileReader; import java.util.logging.Level; public class SetPreset implements CommandExecutor{ @Override public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { Server server = sender.getServer(); Player player = server.getPlayer(sender.getName()); Location location = player.getLocation(); if(location == null){ Bukkit.getLogger().log(Level.SEVERE,"Keine Location gefunden."); return false; } //if no Player is found if (args.length != 1){ sender.sendMessage("try with one Number behind the command."); return false; }else { Runnable t = new Runnable() { @Override public void run() { DataHolder.foundation.setLocation(location); DataHolder.generateSimpleData(Integer.parseInt(args[0])); fillPlane(server, location, DataHolder.foundation.getWidth().x, DataHolder.foundation.getWidth().y, DataHolder.foundation.getMaterial()); for (Structure structure : DataHolder.foundation.getChildren()) { Building building = (Building) structure; sender.sendMessage("bau" + building.toString()); fillQube(server, building.getLocation(), building.getWidth().x, building.getHeight(), building.getWidth().y, building.getMaterial());//Not yet ready to print foundations } } }; t.run(); } return true; } private void fillPlane(Server server, Location startLocation, int x, int z, Material material){ for (int cx = 0; cx < x; cx++ ) { for ( int cz = 0; cz < z; cz++){ Block block = server.getWorlds().get(0).getBlockAt(startLocation.clone().add(cx,0,cz)); block.setType(material); } } } private void fillQube(Server server,Location startLocation, int x, int y, int z, Material material){ for(int cy = 0; cy < y; cy++){ fillPlane(server,startLocation.clone().add(0,cy,0),x,z,material); } } private boolean evalJson(String fileName){ if(!fileName.contains(".json")){ fileName = fileName + ".json"; } //Add .json in case user forgets try(JsonReader reader = new JsonReader(new FileReader("/Users/flgr/Desktop/PaperServer/LayoutJson"+ fileName))){ Gson gson = new Gson(); }catch (Exception ex){ Bukkit.getLogger().log(Level.SEVERE, String.valueOf(ex)); return false; } return true; } }