Auto sort boosters based on how good they are, fix boosters not starting
This commit is contained in:
+20
-5
@@ -1,11 +1,13 @@
|
||||
package com.alttd.boosters.data;
|
||||
|
||||
import com.alttd.boosterapi.Booster;
|
||||
import com.alttd.boosterapi.BoosterType;
|
||||
import com.alttd.boosterapi.util.ALogger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class Booster implements com.alttd.boosterapi.Booster {
|
||||
public class ServerBooster implements Booster {
|
||||
|
||||
private UUID uuid;
|
||||
private String activator;
|
||||
@@ -16,7 +18,7 @@ public class Booster implements com.alttd.boosterapi.Booster {
|
||||
private Boolean active;
|
||||
private Boolean finished;
|
||||
|
||||
public Booster(UUID uuid, BoosterType boosterType, String reason, long duration, double multiplier) {
|
||||
public ServerBooster(UUID uuid, BoosterType boosterType, String reason, long duration, double multiplier) {
|
||||
this.uuid = uuid;
|
||||
this.boosterType = boosterType;
|
||||
this.activator = reason;
|
||||
@@ -26,11 +28,11 @@ public class Booster implements com.alttd.boosterapi.Booster {
|
||||
this.finished = false;
|
||||
}
|
||||
|
||||
public Booster(BoosterType type, String playerName, long duration, double multiplier) {
|
||||
public ServerBooster(BoosterType type, String playerName, long duration, double multiplier) {
|
||||
this(UUID.randomUUID(), type, playerName, duration, multiplier);
|
||||
}
|
||||
|
||||
public Booster(UUID uuid, String activator, BoosterType boosterType, long startingTime, long duration, double multiplier, boolean active, boolean finished) {
|
||||
public ServerBooster(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;
|
||||
@@ -81,6 +83,11 @@ public class Booster implements com.alttd.boosterapi.Booster {
|
||||
this.startingTime = startingTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getEndTime() {
|
||||
return startingTime = duration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Long getDuration() {
|
||||
return duration;
|
||||
@@ -137,5 +144,13 @@ public class Booster implements com.alttd.boosterapi.Booster {
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public int compareTo(@NotNull Object o) {
|
||||
Booster booster = (Booster) o;
|
||||
if (booster.getMultiplier() < getMultiplier())
|
||||
return -1;
|
||||
if (booster.getMultiplier() > getMultiplier())
|
||||
return 1;
|
||||
return booster.isActive() ? 1 : -1;
|
||||
}
|
||||
}
|
||||
@@ -18,12 +18,19 @@ public class PluginMessage implements PluginMessageListener {
|
||||
if(!channel.equals(Config.pluginMessageChannel)) return;
|
||||
ByteArrayDataInput in = ByteStreams.newDataInput(bytes);
|
||||
String subChannel = in.readUTF();
|
||||
// Listen to plugin messages from velocity to either activate or deactive a booster.
|
||||
switch (subChannel) {
|
||||
case "activate" -> {
|
||||
ServerBoosterStorage.getServerBoosterStorage().reload();
|
||||
//TODO maybe make this add one thing to the map without resetting it to avoid having to clear it
|
||||
// (still need to load it all to get that one booster though)
|
||||
UUID uuid = UUID.fromString(in.readUTF());
|
||||
Booster booster = ServerBoosterStorage.getServerBoosterStorage().getBoosters().get(uuid);
|
||||
if (booster == null) {
|
||||
ServerBoosterStorage.getServerBoosterStorage().reload();
|
||||
booster = ServerBoosterStorage.getServerBoosterStorage().getBoosters().get(uuid);
|
||||
}
|
||||
if (booster == null) {
|
||||
ALogger.warn("Unable to load and activate booster [" + uuid + "]");
|
||||
break;
|
||||
}
|
||||
booster.setActive(true);
|
||||
}
|
||||
case "finish" -> {
|
||||
UUID uuid = UUID.fromString(in.readUTF());
|
||||
@@ -43,6 +50,9 @@ public class PluginMessage implements PluginMessageListener {
|
||||
}
|
||||
booster.stopBooster();
|
||||
}
|
||||
case "reload" -> {
|
||||
ServerBoosterStorage.getServerBoosterStorage().reload();
|
||||
}
|
||||
default -> {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,15 +2,15 @@ package com.alttd.boosters.managers;
|
||||
|
||||
import com.alttd.boosterapi.Booster;
|
||||
import com.alttd.boosterapi.BoosterType;
|
||||
import com.alttd.boosterapi.config.BoosterStorage;
|
||||
import com.alttd.boosters.storage.ServerBoosterStorage;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class BoosterManager {
|
||||
|
||||
private static List<Booster> activeBoosters;
|
||||
|
||||
public boolean isBoosted(BoosterType type) {
|
||||
for (Booster b : activeBoosters) {
|
||||
for (Booster b : ServerBoosterStorage.getServerBoosterStorage().getBoosters().values()) {
|
||||
if (b.getType() == type && b.isActive()) {
|
||||
return true;
|
||||
}
|
||||
@@ -19,7 +19,7 @@ public class BoosterManager {
|
||||
}
|
||||
|
||||
public Booster getBooster(BoosterType type) {
|
||||
for (Booster b : activeBoosters) {
|
||||
for (Booster b : ServerBoosterStorage.getServerBoosterStorage().getBoosters().values()) {
|
||||
if (b.getType() == type && b.isActive()) {
|
||||
return b;
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.alttd.boosterapi.Booster;
|
||||
import com.alttd.boosterapi.BoosterType;
|
||||
import com.alttd.boosterapi.config.BoosterStorage;
|
||||
import com.alttd.boosterapi.util.ALogger;
|
||||
import com.alttd.boosters.data.ServerBooster;
|
||||
import com.fasterxml.jackson.core.JsonParser;
|
||||
import com.fasterxml.jackson.core.JsonToken;
|
||||
|
||||
@@ -77,7 +78,7 @@ public class ServerBoosterStorage extends BoosterStorage {
|
||||
return error("Didn't find finished at expected location");
|
||||
parser.nextValue();
|
||||
boolean finished = parser.getValueAsBoolean();
|
||||
return new com.alttd.boosters.data.Booster(uuid, activator, boosterType, startingTime, duration, multiplier, active, finished);
|
||||
return new ServerBooster(uuid, activator, boosterType, startingTime, duration, multiplier, active, finished);
|
||||
}
|
||||
|
||||
private static Booster error(String error) {
|
||||
|
||||
Reference in New Issue
Block a user