Stage 12: Data storage system
This commit is contained in:
parent
82ed455cd2
commit
4fd7955d56
62 changed files with 5613 additions and 0 deletions
72
src/main/java/dev/loki/window/Window.java
Normal file
72
src/main/java/dev/loki/window/Window.java
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
package dev.loki.window;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
|
||||
public class Window {
|
||||
private final Location bottomLocation;
|
||||
private final Location topLocation;
|
||||
private boolean blocked;
|
||||
|
||||
public Window(Location bottomLocation) {
|
||||
this.bottomLocation = bottomLocation;
|
||||
this.topLocation = bottomLocation.clone().add(0, 1, 0);
|
||||
this.blocked = false;
|
||||
}
|
||||
|
||||
public Location getBottomLocation() {
|
||||
return bottomLocation;
|
||||
}
|
||||
|
||||
public Location getTopLocation() {
|
||||
return topLocation;
|
||||
}
|
||||
|
||||
public Location getVaultTarget(boolean killerVault) {
|
||||
if (killerVault) {
|
||||
return bottomLocation.clone().add(0, -0.5, 0);
|
||||
}
|
||||
return topLocation.clone().add(0, 0.5, 0);
|
||||
}
|
||||
|
||||
public boolean isBlocked() {
|
||||
return blocked;
|
||||
}
|
||||
|
||||
public void setBlocked(boolean blocked) {
|
||||
this.blocked = blocked;
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
Block bottom = bottomLocation.getBlock();
|
||||
Block top = topLocation.getBlock();
|
||||
return bottom.getType().isSolid() || bottom.getType() == Material.AIR;
|
||||
}
|
||||
|
||||
public boolean isVaultable(PlayerContext ctx) {
|
||||
if (blocked && !ctx.isKiller()) return false;
|
||||
if (!isValid()) return false;
|
||||
|
||||
Location playerLoc = ctx.getLocation();
|
||||
return getDistance(playerLoc) <= 2.5;
|
||||
}
|
||||
|
||||
public double getDistance(Location location) {
|
||||
return bottomLocation.distance(location);
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.blocked = false;
|
||||
}
|
||||
|
||||
public record PlayerContext(boolean isKiller, Location location) {
|
||||
public boolean isKiller() {
|
||||
return isKiller;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue