SetPreset.java 3.32 KB
Newer Older
Florian Grabowski's avatar
Florian Grabowski committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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]));
44
                    fillPlane(server, location, DataHolder.foundation.getWidth().x, DataHolder.foundation.getWidth().y, DataHolder.foundation.getMaterial());
Florian Grabowski's avatar
Florian Grabowski committed
45
46
47
                    for (Structure structure : DataHolder.foundation.getChildren()) {
                        Building building = (Building) structure;
                        sender.sendMessage("bau" + building.toString());
48
                        fillQube(server, building.getLocation(), building.getWidth().x, building.getHeight(), building.getWidth().y, building.getMaterial());//Not yet ready to print foundations
Florian Grabowski's avatar
Florian Grabowski committed
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
                    }
                }
            };
            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;
    }

}