Builder.java 4.34 KB
Newer Older
1
2
3
4
5
6
7
8
9
package de._82grfl1bif.KPI_Visualizer.structures;

import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.block.Block;

public class Builder {

Florian Grabowski's avatar
Florian Grabowski committed
10
11
12
13
14
15
16
    Server server;

    public Builder(Server server) {
        this.server = server;
    }

    public void setFoundation(Location startLocation, int x, int z, Material material) {
17
18
19
20
21
22
23
24
        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);
            }
        }
    }

Florian Grabowski's avatar
Florian Grabowski committed
25
    public void fillQube(Location startLocation, int x, int y, int z, Material material) {
26
        for (int cy = 0; cy < y; cy++) {
Florian Grabowski's avatar
Florian Grabowski committed
27
            setFoundation(startLocation.clone().add(0, cy, 0), x, z, material);
28
29
30
        }
    }

Florian Grabowski's avatar
Florian Grabowski committed
31
32
33
    private void setWalls(Location startLocation, int x, int y, int z, Material innerMaterial, Material glassMaterial) {
        Location temp = startLocation.clone().add(0,0,1);
        for (int cz = 0; cz < z - 2; cz++) {//00-0Z
34
            for (int cy = 0; cy < y; cy++) {
Florian Grabowski's avatar
Florian Grabowski committed
35
36
                server.getWorlds().get(0).getBlockAt(temp.clone().add(1, cy, cz)).setType(innerMaterial);
                server.getWorlds().get(0).getBlockAt(temp.clone().add(0, cy, cz)).setType(glassMaterial);
37
38
            }
        }
Florian Grabowski's avatar
Florian Grabowski committed
39
40
        temp = startLocation.clone().add(1,0,0);
        for (int cx = 0; cx < x - 2; cx++) {//00-0X
41
            for (int cy = 0; cy < y; cy++) {
Florian Grabowski's avatar
Florian Grabowski committed
42
43
                server.getWorlds().get(0).getBlockAt(temp.clone().add(cx, cy, 1)).setType(innerMaterial);
                server.getWorlds().get(0).getBlockAt(temp.clone().add(cx, cy, 0)).setType(glassMaterial);
44
45
            }
        }
Florian Grabowski's avatar
Florian Grabowski committed
46
47
        temp = startLocation.clone().add(1, 0, z - 1);
        for (int cx = 0; cx < x - 2; cx++) {//0Z-ZX
48
            for (int cy = 0; cy < y; cy++) {
Florian Grabowski's avatar
Florian Grabowski committed
49
50
                server.getWorlds().get(0).getBlockAt(temp.clone().add(cx, cy, -1)).setType(innerMaterial);
                server.getWorlds().get(0).getBlockAt(temp.clone().add(cx, cy, 0)).setType(glassMaterial);
51
52
53

            }
        }
Florian Grabowski's avatar
Florian Grabowski committed
54
55
        temp = startLocation.clone().add(x - 1, 0, 1);
        for (int cz = 0; cz < z - 2; cz++) {//0X-XZ
56
            for (int cy = 0; cy < y; cy++) {
Florian Grabowski's avatar
Florian Grabowski committed
57
58
59
                server.getWorlds().get(0).getBlockAt(temp.clone().add(-1, cy, cz)).setType(innerMaterial);
                server.getWorlds().get(0).getBlockAt(temp.clone().add(0, cy, cz)).setType(glassMaterial);

60
61
            }
        }
Florian Grabowski's avatar
Florian Grabowski committed
62
    }
63

Florian Grabowski's avatar
Florian Grabowski committed
64
65
    private void setCorners(Location startLocation, int x, int y, int z, Material facade) {
        Location temp = startLocation.clone();
66
        for (int cy = 0; cy < y; cy++) {
Florian Grabowski's avatar
Florian Grabowski committed
67
            server.getWorlds().get(0).getBlockAt(temp.clone().add(0, cy, 0)).setType(facade);
68
        }
Florian Grabowski's avatar
Florian Grabowski committed
69
        temp = startLocation.clone().add(x - 1, 0, 0);
70
        for (int cy = 0; cy < y; cy++) {
Florian Grabowski's avatar
Florian Grabowski committed
71
            server.getWorlds().get(0).getBlockAt(temp.clone().add(0, cy, 0)).setType(facade);
72
        }
Florian Grabowski's avatar
Florian Grabowski committed
73
        temp = startLocation.clone().add(0, 0, z - 1);
74
        for (int cy = 0; cy < y; cy++) {
Florian Grabowski's avatar
Florian Grabowski committed
75
            server.getWorlds().get(0).getBlockAt(temp.clone().add(0, cy, 0)).setType(facade);
76
        }
Florian Grabowski's avatar
Florian Grabowski committed
77
        temp = startLocation.clone().add(x - 1, 0, z - 1);
78
        for (int cy = 0; cy < y; cy++) {
Florian Grabowski's avatar
Florian Grabowski committed
79
            server.getWorlds().get(0).getBlockAt(temp.clone().add(0, cy, 0)).setType(facade);
80
81
82
        }
    }

Florian Grabowski's avatar
Florian Grabowski committed
83
84
85
86
    public void buildBuilding(Location startLocation, int x, int y, int z, Material material) {
        setWalls(startLocation, x, y, z, material, Material.GLASS);
        setCorners(startLocation, x, y, z, Material.BLACKSTONE);
        setFoundation(startLocation.clone().add(0, y, 0), x, z, Material.BLACKSTONE);//roof
87
88
    }

Florian Grabowski's avatar
Florian Grabowski committed
89
90
91
92
93
94
95
96
97
98
    public void setAllChildren(Foundation foundation) {
        for (Structure s : foundation.getChildren()) {
            if (s.getClass() == Foundation.class) {//TODO must be revisited to draw rectangular Foundations
                this.setFoundation(s.getLocation().clone().add(0, s.getDepth(), 0), s.getWidth().x, s.getWidth().x, s.getMaterial());
                setAllChildren((Foundation) s);
            } else {//TODO must be revisited to draw rectangular Buildings
                this.buildBuilding(s.getLocation().clone().add(1, s.getDepth(), 1), s.getWidth().x - 2, ((Building) s).getHeight(),s.getWidth().x-2, s.getMaterial());
            }
        }
    }
99
}