Stage 13: Perks and Totems
This commit is contained in:
parent
d1f854fc79
commit
37e67ce97d
23 changed files with 2070 additions and 25 deletions
116
src/main/java/dev/loki/gate/ExitGate.java
Normal file
116
src/main/java/dev/loki/gate/ExitGate.java
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
package dev.loki.gate;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Sound;
|
||||
import org.bukkit.World;
|
||||
|
||||
public class ExitGate {
|
||||
private final Location location;
|
||||
private GateState state;
|
||||
private double progress;
|
||||
private boolean powered;
|
||||
|
||||
public enum GateState {
|
||||
CLOSED,
|
||||
OPENING,
|
||||
OPEN
|
||||
}
|
||||
|
||||
public ExitGate(Location location) {
|
||||
this.location = location;
|
||||
this.state = GateState.CLOSED;
|
||||
this.progress = 0.0;
|
||||
this.powered = false;
|
||||
}
|
||||
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
public GateState getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public boolean isClosed() {
|
||||
return state == GateState.CLOSED;
|
||||
}
|
||||
|
||||
public boolean isOpening() {
|
||||
return state == GateState.OPENING;
|
||||
}
|
||||
|
||||
public boolean isOpen() {
|
||||
return state == GateState.OPEN;
|
||||
}
|
||||
|
||||
public double getProgress() {
|
||||
return progress;
|
||||
}
|
||||
|
||||
public int getProgressPercent() {
|
||||
return (int) (progress * 100);
|
||||
}
|
||||
|
||||
public boolean isPowered() {
|
||||
return powered;
|
||||
}
|
||||
|
||||
public void setPowered(boolean powered) {
|
||||
this.powered = powered;
|
||||
if (powered && state == GateState.CLOSED) {
|
||||
state = GateState.OPENING;
|
||||
}
|
||||
}
|
||||
|
||||
public void startOpening() {
|
||||
if (state == GateState.CLOSED && powered) {
|
||||
state = GateState.OPENING;
|
||||
playOpenSound();
|
||||
}
|
||||
}
|
||||
|
||||
public void updateProgress(double delta) {
|
||||
if (state != GateState.OPENING) return;
|
||||
|
||||
progress += delta;
|
||||
if (progress >= 1.0) {
|
||||
progress = 1.0;
|
||||
state = GateState.OPEN;
|
||||
playOpenedSound();
|
||||
}
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
this.state = GateState.CLOSED;
|
||||
this.progress = 0.0;
|
||||
this.powered = false;
|
||||
}
|
||||
|
||||
public boolean isInRange(Location playerLoc, double radius) {
|
||||
return location.distance(playerLoc) <= radius;
|
||||
}
|
||||
|
||||
public void playOpenSound() {
|
||||
World world = location.getWorld();
|
||||
if (world != null) {
|
||||
world.playSound(location, Sound.BLOCK_IRON_DOOR_OPEN, 1.0f, 0.8f);
|
||||
}
|
||||
}
|
||||
|
||||
public void playOpenedSound() {
|
||||
World world = location.getWorld();
|
||||
if (world != null) {
|
||||
world.playSound(location, Sound.BLOCK_IRON_DOOR_CLOSE, 1.0f, 1.2f);
|
||||
world.playSound(location, Sound.ENTITY_PLAYER_LEVELUP, 0.5f, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
public void spawnOpenParticles() {
|
||||
World world = location.getWorld();
|
||||
if (world == null) return;
|
||||
|
||||
world.spawnParticle(org.bukkit.Particle.PORTAL,
|
||||
location.clone().add(0.5, 1.5, 0.5),
|
||||
50, 0.5, 1.0, 0.5, 0.1);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue