Commit bad6607d authored by Florian Grabowski's avatar Florian Grabowski
Browse files

IDP Update

parent 92fedcf1
package de._82grfl1bif.KPI_Visualizer.helpers;
import java.awt.Point;
public class Shape {
protected Point bottomLeftCorner;
protected Point topRightCorner;
protected int xEdgeLength;
protected Shape(){}
}
package de._82grfl1bif.KPI_Visualizer;
import de._82grfl1bif.KPI_Visualizer.commands.SetPreset;
import de._82grfl1bif.KPI_Visualizer.commands.generateLayout;
import org.bukkit.plugin.java.JavaPlugin;
public final class main extends JavaPlugin {
@Override
public void onEnable() {
// Plugin startup logic
getCommand("setPreset").setExecutor(new SetPreset());
getCommand("generateLayout").setExecutor(new generateLayout());
}
@Override
public void onDisable() {
// Plugin shutdown logic
}
}
package de._82grfl1bif.KPI_Visualizer.structures;
import org.bukkit.Material;
import javax.persistence.Column;
public class Building extends Structure{
@Column(name = "height")
private final int height;
public Building(int width, int height, Material material){ //Buildings are Square -> no depth
this.width = width;
this.height = height;
this.material = material;
if(this.width < 3){
throw new IllegalArgumentException("keine Gebäude kleiner 3 wegen 2 gehweg");
}
}
public int getHeight() {
return this.height;
}
}
package de._82grfl1bif.KPI_Visualizer.structures;
import de._82grfl1bif.KPI_Visualizer.helpers.Layout;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.util.Vector;
import javax.management.AttributeNotFoundException;
import java.awt.Point;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
public class Foundation extends Structure{
private ArrayList<Structure> children = new ArrayList<>();
private Layout layout;
public Foundation(int depth, Material material){ //Foundations are uniform Height
this.width = 0;
this.depth = depth;
this.material = material;
}
public ArrayList<Structure> getChildren() {
return children;
}
public void addChildren(ArrayList<Structure> children) {
for (Structure s:children) {
s.setDepth(this.depth);
}
this.children.addAll(children);
}
public void removeChildren(){
this.children = new ArrayList<>();
}
public void optimizeLayout(){
//TODO: find cool Algorithms to do this scientifically and optimal.
int cWith = 0;
for (Structure s : children) {
s.setLocation(location.clone().add(new Vector(1,depth,((cWith)+1))));
cWith += (s.getWidth() + 2);
}
this.width = cWith;
}
private static class DepthComparator implements Comparator<Foundation>{
@Override
public int compare(Foundation o1, Foundation o2) {
return Integer.compare(o1.getDepth(), o2.getDepth());
}
}
private static class WidthComparator implements Comparator<Structure>{
@Override
public int compare(Structure o1, Structure o2) {
return Integer.compare(o1.getWidth(), o2.getWidth());
}
}
private boolean baseFoundation = true;
public void organizeFoundation(){
if(this.depth == 0 && baseFoundation){ //rootElement prepwork and recursion call
ArrayList<Foundation> allFoundations = collectAllFoundations();
baseFoundation = false;
allFoundations.sort(new DepthComparator());
Collections.reverse(allFoundations); //higher Depths first
for (Foundation f:allFoundations) {
//if(!this.equals(f))
f.organizeFoundation();
}
}else{ //normal Call and recursion
this.children.sort(new WidthComparator());
Collections.reverse(this.children); //Widest Building or Foundation first
this.layout = new Layout(this.children);
this.layout.createLayout();
this.width = layout.getSize();
}
}
private ArrayList<Foundation> collectAllFoundations(){ //called on the base Foundation
ArrayList<Foundation> fCollection = new ArrayList<>();
fCollection.add(this);
int currentDepth = this.depth;
int lastDepthAdded = -1;
while (lastDepthAdded != 0){ //while there are new nextDepths in this Depth.
for (int i = 0; i < fCollection.size();i++) {
if (!(fCollection.get(i).getDepth() < currentDepth)){ //if f is not part of a historical depth
fCollection.addAll(fCollection.get(i).getNextDepth());
lastDepthAdded = fCollection.get(i).getNextDepth().size();
}
}
currentDepth += 1;
}
return fCollection;
}
private ArrayList<Foundation> getNextDepth(){
ArrayList<Foundation> result = new ArrayList<>();
for (Structure s:this.children) {
if (s.getClass() == Foundation.class){
result.add((Foundation) s);
}else {
s.setDepth(this.depth);
}
}
for (Foundation f:result) {
f.setDepth((this.depth)+1);
}
return result;
}
public void correctAllLocations(Location location){
for (Structure s:this.children) {
try {
Point temp = this.layout.getCoordinateOf(s);
s.setLocation(location.clone().add(temp.x,0,temp.y));
if (s.getClass() == Foundation.class){
Foundation f = (Foundation)s;
f.correctAllLocations(f.getLocation());
}
} catch (AttributeNotFoundException e) {
e.printStackTrace();
}
}
}
}
package de._82grfl1bif.KPI_Visualizer.structures;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.util.Vector;
import javax.persistence.Column;
import javax.persistence.Entity;
@Entity
public class Structure{
@Column(name ="width")
protected int width;
@Column(name ="material")
protected Material material;
protected Location location;
protected int depth;
public Material getMaterial() {
return material;
}
public Location getLocation() {
return location;
}
public void setLocation(Location location) {
this.location = location;
}
public void addVector(Vector vector){
this.location.add(vector);
}
public int getWidth() {
return width;
}
public void setDepth(int depth) {
this.depth = depth;
}
public int getDepth() {
return depth;
}
}
name: main
version: '${project.version}'
main: de._82grfl1bif.KPI_Visualizer.main
api-version: 1.17
authors: [ FlorianGrabowski ]
description: Testing automated construcion of Buildings.
commands:
setPreset:
description: setzt einen ein Json Preset.
generateLayout:
description: generates Json
\ No newline at end of file
name: main
version: '1.0-SNAPSHOT'
main: de._82grfl1bif.KPI_Visualizer.main
api-version: 1.17
authors: [ FlorianGrabowski ]
description: Testing automated construcion of Buildings.
commands:
setPreset:
description: setzt einen ein Json Preset.
generateLayout:
description: generates Json
\ No newline at end of file
#Generated by Maven
#Thu Oct 07 13:56:29 CEST 2021
groupId=de.82grfl1bif
artifactId=BlockPlacer
version=1.0-SNAPSHOT
de/_82grfl1bif/blockplacer/commands/SetPreset.class
de/_82grfl1bif/blockplacer/structures/Foundation.class
de/_82grfl1bif/blockplacer/commands/generateLayout.class
de/_82grfl1bif/blockplacer/structures/Structure.class
de/_82grfl1bif/blockplacer/helpers/DataHolder.class
de/_82grfl1bif/blockplacer/BlockPlacer.class
de/_82grfl1bif/blockplacer/structures/Building.class
de/_82grfl1bif/blockplacer/commands/TestTread.class
/Users/flgr/IdeaProjects/BlockPlacerTest/src/main/java/de/_82grfl1bif/blockplacer/structures/Foundation.java
/Users/flgr/IdeaProjects/BlockPlacerTest/src/main/java/de/_82grfl1bif/blockplacer/structures/Structure.java
/Users/flgr/IdeaProjects/BlockPlacerTest/src/main/java/de/_82grfl1bif/blockplacer/commands/TestTread.java
/Users/flgr/IdeaProjects/BlockPlacerTest/src/main/java/de/_82grfl1bif/blockplacer/commands/generateLayout.java
/Users/flgr/IdeaProjects/BlockPlacerTest/src/main/java/de/_82grfl1bif/blockplacer/helpers/DataHolder.java
/Users/flgr/IdeaProjects/BlockPlacerTest/src/main/java/de/_82grfl1bif/blockplacer/structures/Building.java
/Users/flgr/IdeaProjects/BlockPlacerTest/src/main/java/de/_82grfl1bif/blockplacer/BlockPlacer.java
/Users/flgr/IdeaProjects/BlockPlacerTest/src/main/java/de/_82grfl1bif/blockplacer/commands/SetPreset.java
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment