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;
|
2022-08-01 18:47:32 +00:00
|
|
|
import com.alttd.vboosters.storage.VelocityBoosterStorage;
|
2021-11-04 16:57:55 +00:00
|
|
|
|
2022-08-01 18:47:32 +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;
|
2022-07-25 16:50:02 +00:00
|
|
|
private Double multiplier;
|
2021-11-04 16:57:55 +00:00
|
|
|
private Boolean active;
|
|
|
|
|
private Boolean finished;
|
|
|
|
|
|
2022-07-25 16:50:02 +00:00
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2022-07-25 16:50:02 +00:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-01 18:47:32 +00:00
|
|
|
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
|
2022-07-25 16:50:02 +00:00
|
|
|
public double getMultiplier() {
|
2021-11-04 16:57:55 +00:00
|
|
|
return multiplier;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2022-07-25 16:50:02 +00:00
|
|
|
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
|
2022-08-01 18:47:32 +00:00
|
|
|
public void stopBooster() { //TODO stop it on the servers as well
|
2021-12-25 17:05:07 +00:00
|
|
|
setDuration(getTimeRemaining());
|
|
|
|
|
setActive(false);
|
|
|
|
|
saveBooster();
|
2021-11-04 16:57:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void saveBooster() {
|
2022-08-01 18:47:32 +00:00
|
|
|
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
|
|
|
|
2022-08-01 18:47:32 +00:00
|
|
|
public void finish() { //TODO finish it on the servers as well
|
2021-12-25 17:05:07 +00:00
|
|
|
finished = true;
|
|
|
|
|
stopBooster();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean finished() {
|
|
|
|
|
return finished;
|
2021-11-04 16:57:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|