Boosters/velocity/src/main/java/com/alttd/vboosters/data/VelocityBooster.java

151 lines
3.7 KiB
Java
Raw Normal View History

2021-11-04 16:57:55 +00:00
package com.alttd.vboosters.data;
2021-12-25 17:05:07 +00:00
import com.alttd.boosterapi.Booster;
import com.alttd.boosterapi.BoosterType;
import com.alttd.vboosters.storage.VelocityBoosterStorage;
2021-11-04 16:57:55 +00:00
import java.util.Collection;
import java.util.List;
2021-11-04 16:57:55 +00:00
import java.util.UUID;
2021-12-25 17:05:07 +00:00
public class VelocityBooster implements Booster {
2021-11-04 16:57:55 +00:00
private UUID uuid;
private String activator;
private Long startingTime;
private long duration;
private BoosterType boosterType;
private Double multiplier;
2021-11-04 16:57:55 +00:00
private Boolean active;
private Boolean finished;
public VelocityBooster(UUID uuid, BoosterType boosterType, String reason, long duration, double multiplier) {
2021-11-04 16:57:55 +00:00
this.uuid = uuid;
this.boosterType = boosterType;
this.activator = reason;
this.duration = duration;
this.multiplier = multiplier;
this.active = false;
this.finished = false;
saveBooster();
}
public VelocityBooster(BoosterType type, String playerName, long duration, double multiplier) {
2021-11-04 16:57:55 +00:00
this(UUID.randomUUID(), type, playerName, duration, multiplier);
}
public VelocityBooster(UUID uuid, String activator, BoosterType boosterType, long startingTime,
long duration, double multiplier, boolean active, boolean finished) {
this.uuid = uuid;
this.activator = activator;
this.boosterType = boosterType;
this.startingTime = startingTime;
this.duration = duration;
this.multiplier = multiplier;
this.active = active;
this.finished = finished;
}
2021-11-04 16:57:55 +00:00
@Override
public boolean isActive() {
return active;
}
@Override
public void setActive(Boolean active) {
this.active = active;
}
@Override
public BoosterType getType() {
return boosterType;
}
@Override
public void setType(BoosterType boosterType) {
this.boosterType = boosterType;
}
@Override
public double getMultiplier() {
2021-11-04 16:57:55 +00:00
return multiplier;
}
@Override
public void setMultiplier(double multiplier) {
2021-11-04 16:57:55 +00:00
this.multiplier = multiplier;
}
@Override
public Long getStartingTime() {
return startingTime;
}
@Override
public void setStartingTime(long startingTime) {
this.startingTime = startingTime;
}
@Override
public Long getDuration() {
return duration;
}
@Override
public void setDuration(long duration) {
this.duration = duration;
}
@Override
public String getActivator() {
return activator;
}
@Override
public void setActivator(String activationReason) {
this.activator = activationReason;
}
@Override
public long getTimeRemaining() {
if(active) {
return startingTime + duration - System.currentTimeMillis();
}
return duration;
}
@Override
public UUID getUUID() {
return uuid;
}
@Override
public void stopBooster() { //TODO stop it on the servers as well
2021-12-25 17:05:07 +00:00
setDuration(getTimeRemaining());
setActive(false);
saveBooster();
if (!finished) {
//TODO send plugin message that its stopped
}
2021-11-04 16:57:55 +00:00
}
@Override
public void saveBooster() {
VelocityBoosterStorage vbs = VelocityBoosterStorage.getVelocityBoosterStorage();
vbs.getBoosters().put(uuid, this);
vbs.saveBoosters(vbs.getBoosters().values());
2021-12-25 17:05:07 +00:00
}
2021-11-04 16:57:55 +00:00
public void finish() { //TODO finish it on the servers as well
2021-12-25 17:05:07 +00:00
finished = true;
stopBooster();
//TODO send plugin message that this is finished
2021-12-25 17:05:07 +00:00
}
@Override
public boolean finished() {
return finished;
2021-11-04 16:57:55 +00:00
}
}