generateLayout.java 6.09 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
package de._82grfl1bif.KPI_Visualizer.commands;

import de._82grfl1bif.KPI_Visualizer.data.DataHolder;
import de._82grfl1bif.KPI_Visualizer.structures.Building;
import de._82grfl1bif.KPI_Visualizer.structures.Foundation;
import de._82grfl1bif.KPI_Visualizer.structures.Structure;
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.bukkit.scheduler.BukkitRunnable;
import org.jetbrains.annotations.NotNull;

public class generateLayout implements CommandExecutor {

    @Override
    public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
        sender.sendMessage("generating Layout");
        Server server = sender.getServer();
        Player player = server.getPlayer(sender.getName());
        Location location = player.getLocation();

        BukkitRunnable t = new BukkitRunnable() {
            @Override
            public void run() {
                DataHolder.ComplexData();
                DataHolder.foundation.setLocation(location);
                DataHolder.foundation.organizeFoundation();
                DataHolder.foundation.correctAllLocations(location);
34
                setFoundation(server, DataHolder.foundation.getLocation().clone().add(0, DataHolder.foundation.getDepth(), 0), DataHolder.foundation.getWidth().x, DataHolder.foundation.getWidth().x, DataHolder.foundation.getMaterial());
Florian Grabowski's avatar
Florian Grabowski committed
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
                setAllChildren(server, DataHolder.foundation);
            }
        };
        t.run();
        return true;
    }

    private void setFoundation(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 buildBuilding(Server server, Location startLocation, int x, int y, Material material) {
52
        setWalls(server, startLocation.clone().add(0, 1, 0), x, y, material);
Florian Grabowski's avatar
Florian Grabowski committed
53
54
    }

55
    private void setWalls(Server server, Location startLocation, int x, int y,Material material) {
Florian Grabowski's avatar
Florian Grabowski committed
56
57
58
59
        Location save = startLocation.clone();
        Location temp = startLocation.clone();
        for (int cx = 0; cx < x - 1; cx++) {// x+x Wall
            for (int cy = 0; cy < y; cy++) {
60
                server.getWorlds().get(0).getBlockAt(temp.clone().add(cx,cy,1)).setType(material);
Florian Grabowski's avatar
Florian Grabowski committed
61
62
63
64
65
            }
        }
        temp = save.clone();
        for (int cz = 0; cz < x - 1; cz++) {// z+x Wall
            for (int cy = 0; cy < y; cy++) {
66
                server.getWorlds().get(0).getBlockAt(temp.clone().add(1, cy, cz)).setType(material);
Florian Grabowski's avatar
Florian Grabowski committed
67
68
69
70
71
            }
        }
        temp = save.clone().add(0, 0, x - 1);
        for (int cx = 0; cx < x; cx++) {// x+x z+x Wall from x+x
            for (int cy = 0; cy < y; cy++) {
72
                server.getWorlds().get(0).getBlockAt(temp.clone().add(cx, cy, -1)).setType(material);
Florian Grabowski's avatar
Florian Grabowski committed
73
74
75
76
77
            }
        }
        temp = save.clone().add(x - 1, 0, 0);
        for (int cz = 0; cz < x - 1; cz++) {// x+x z+x Wall from x+z
            for (int cy = 0; cy < y; cy++) {
78
                server.getWorlds().get(0).getBlockAt(temp.clone().add(-1, cy, cz)).setType(material);
Florian Grabowski's avatar
Florian Grabowski committed
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
            }
        }

        temp = save.clone();
        for (int cx = 0; cx < x - 1; cx++) {// x+x Wall
            for (int cy = 0; cy < y; cy++) {
                server.getWorlds().get(0).getBlockAt(temp.clone().add(cx, cy, 0)).setType(Material.GLASS);
            }
        }
        temp = save.clone();
        for (int cz = 0; cz < x - 1; cz++) {// z+x Wall
            for (int cy = 0; cy < y; cy++) {
                server.getWorlds().get(0).getBlockAt(temp.clone().add(0, cy, cz)).setType(Material.GLASS);
            }
        }
        temp = save.clone().add(0, 0, x - 1);
        for (int cx = 0; cx < x; cx++) {// x+x z+x Wall from x+x
            for (int cy = 0; cy < y; cy++) {
                server.getWorlds().get(0).getBlockAt(temp.clone().add(cx, cy, 0)).setType(Material.GLASS);
            }
        }
        temp = save.clone().add(x - 1, 0, 0);
        for (int cz = 0; cz < x - 1; cz++) {// x+x z+x Wall from x+z
            for (int cy = 0; cy < y; cy++) {
                server.getWorlds().get(0).getBlockAt(temp.clone().add(0, cy, cz)).setType(Material.GLASS);
            }
        }

        temp = save.clone();
        for (int cy = 0; cy < y; cy++) {
            server.getWorlds().get(0).getBlockAt(temp.clone().add(0, cy, 0)).setType(Material.BLACKSTONE);
        }
        temp = save.clone().add(x - 1, 0, 0);
        for (int cy = 0; cy < y; cy++) {
            server.getWorlds().get(0).getBlockAt(temp.clone().add(0, cy, 0)).setType(Material.BLACKSTONE);
        }
        temp = save.clone().add(0, 0, x - 1);
        for (int cy = 0; cy < y; cy++) {
            server.getWorlds().get(0).getBlockAt(temp.clone().add(0, cy, 0)).setType(Material.BLACKSTONE);
        }
        temp = save.clone().add(x - 1, 0, x - 1);
        for (int cy = 0; cy < y; cy++) {
            server.getWorlds().get(0).getBlockAt(temp.clone().add(0, cy, 0)).setType(Material.BLACKSTONE);
        }

        save.add(0,y,0);//roof
        setFoundation(server,save,x,x,Material.BLACKSTONE);
    }

    private void setAllChildren(Server server, Foundation foundation) {
        for (Structure s : foundation.getChildren()) {
130
131
            if (s.getClass() == Foundation.class) {//TODO must be revisited to draw rectangular Foundations
                setFoundation(server, s.getLocation().clone().add(0, s.getDepth(), 0), s.getWidth().x, s.getWidth().x, s.getMaterial());
Florian Grabowski's avatar
Florian Grabowski committed
132
                setAllChildren(server, (Foundation) s);
133
134
            } else {//TODO must be revisited to draw rectangular Buildings
                buildBuilding(server, s.getLocation().clone().add(1, s.getDepth(), 1), s.getWidth().x - 2, ((Building) s).getHeight(), s.getMaterial());
Florian Grabowski's avatar
Florian Grabowski committed
135
136
137
138
139
            }
        }
    }

}