src/main/java/noahnok/dbdl/files/game/ExitGate.java
package noahnok.dbdl.files.game;
import lombok.Getter;
import lombok.Setter;
import noahnok.dbdl.files.DeadByDaylight;
import noahnok.dbdl.files.game.levers.DLever;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.scheduler.BukkitRunnable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class ExitGate {
private final DeadByDaylight main;
@Getter
private final String facing;
@Getter
private final Location center;
private List<Location> locs = new ArrayList<>();
@Getter
@Setter
private DLever lever1;
@Getter
@Setter
private DLever lever2;
public ExitGate(String facing, Location center, DeadByDaylight main) {
this.facing = facing;
this.center = center;
this.main = main;
}
public void openGate() {
int timeDelay = 0;
for (final List<Location> locs : getRows()) {
new BukkitRunnable() {
public void run() {
for (Location loc : locs) {
loc.getBlock().getDrops().clear();
loc.getBlock().breakNaturally();
loc.getWorld().playSound(loc, Sound.BLOCK_ANVIL_BREAK, 1.0F, 1.0F);
}
}
}.runTaskLater(main, (20 * timeDelay));
timeDelay++;
}
new BukkitRunnable() {
public void run() {
Location loc = getCenter();
loc.getWorld().playSound(loc, Sound.ENTITY_ENDERDRAGON_DEATH, 10F, 1.5F);
}
}.runTaskLater(main, 90);
}
private List<List<Location>> getRows() {
int lowestY = 400;
for (Location loc : this.locs) {
if (loc.getY() <= lowestY) {
lowestY = loc.getBlockY();
}
}
List<List<Location>> rows = new ArrayList<>();
for (int i = 0; i < 3; i++) {
List<Location> row = new ArrayList<>();
for (Location loc : this.locs) {
if (loc.getY() == (lowestY + i)) {
row.add(loc);
}
}
rows.add(row);
}
return rows;
}
public List<Location> getLocs() {
return Collections.unmodifiableList(locs);
}
public void setLocs(List<Location> locs) {
this.locs = Collections.unmodifiableList(locs);
}
}