Fixed boosters not updating on galaxy and not being stored properly
This commit is contained in:
@@ -10,6 +10,8 @@ import com.alttd.vboosters.VelocityBoosters;
|
||||
import com.alttd.vboosters.data.VelocityBooster;
|
||||
import com.alttd.vboosters.managers.BoosterManager;
|
||||
import com.alttd.vboosters.storage.VelocityBoosterStorage;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
import com.mojang.brigadier.arguments.DoubleArgumentType;
|
||||
import com.mojang.brigadier.arguments.IntegerArgumentType;
|
||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.alttd.vboosters.data;
|
||||
|
||||
import com.alttd.boosterapi.Booster;
|
||||
import com.alttd.boosterapi.BoosterType;
|
||||
import com.alttd.boosterapi.config.BoosterStorage;
|
||||
import com.alttd.vboosters.VelocityBoosters;
|
||||
import com.alttd.vboosters.storage.VelocityBoosterStorage;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
@@ -35,7 +36,6 @@ public class VelocityBooster implements Booster {
|
||||
this.active = false;
|
||||
this.finished = false;
|
||||
this.startingTime = new Date().getTime();
|
||||
saveBooster();
|
||||
}
|
||||
|
||||
public VelocityBooster(BoosterType type, String playerName, long duration, double multiplier) {
|
||||
@@ -62,6 +62,7 @@ public class VelocityBooster implements Booster {
|
||||
@Override
|
||||
public void setActive(Boolean active) {
|
||||
this.active = active;
|
||||
updateQueue();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -150,28 +151,17 @@ public class VelocityBooster implements Booster {
|
||||
public void saveBooster() {
|
||||
VelocityBoosterStorage vbs = VelocityBoosterStorage.getVelocityBoosterStorage();
|
||||
vbs.getBoosters().put(uuid, this);
|
||||
vbs.saveBoosters(vbs.getBoosters().values());
|
||||
updateQueue();
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF("reload");
|
||||
VelocityBoosters.getPlugin().getProxy().getAllServers()
|
||||
.forEach(registeredServer -> registeredServer.sendPluginMessage(VelocityBoosters.getPlugin().getChannelIdentifier(), out.toByteArray()));
|
||||
}
|
||||
|
||||
public void finish() { //TODO finish it on the servers as well
|
||||
finished = true;
|
||||
stopBooster();
|
||||
saveBooster(); //Deletes inactive boosters
|
||||
updateQueue(); //Deletes inactive boosters
|
||||
List<Booster> collect = VelocityBoosterStorage.getVelocityBoosterStorage().getBoosters(boosterType).stream().sorted().collect(Collectors.toList());
|
||||
if (collect.size() <= 1)
|
||||
return;
|
||||
Booster booster = collect.get(1);
|
||||
booster.setActive(true);
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF("activate");
|
||||
out.writeUTF(booster.getUUID().toString());
|
||||
VelocityBoosters.getPlugin().getProxy().getAllServers()
|
||||
.forEach(registeredServer -> registeredServer.sendPluginMessage(VelocityBoosters.getPlugin().getChannelIdentifier(), out.toByteArray()));
|
||||
//TODO send plugin message that this is finished
|
||||
}
|
||||
|
||||
@@ -180,7 +170,7 @@ public class VelocityBooster implements Booster {
|
||||
return finished;
|
||||
}
|
||||
|
||||
private void updateQueue() {
|
||||
public void updateQueue() {
|
||||
Collection<Booster> boosters = VelocityBoosterStorage.getVelocityBoosterStorage().getBoosters(getType());
|
||||
if (boosters.isEmpty())
|
||||
return;
|
||||
@@ -192,6 +182,12 @@ public class VelocityBooster implements Booster {
|
||||
}
|
||||
if (collect.size() > 1)
|
||||
fixTimes(collect);
|
||||
|
||||
VelocityBoosterStorage.getVelocityBoosterStorage().saveBoosters();
|
||||
ByteArrayDataOutput out = ByteStreams.newDataOutput();
|
||||
out.writeUTF("reload");
|
||||
VelocityBoosters.getPlugin().getProxy().getAllServers()
|
||||
.forEach(registeredServer -> registeredServer.sendPluginMessage(VelocityBoosters.getPlugin().getChannelIdentifier(), out.toByteArray()));
|
||||
}
|
||||
|
||||
private void fixTimes(List<Booster> sorted) {
|
||||
|
||||
@@ -3,13 +3,23 @@ package com.alttd.vboosters.managers;
|
||||
import com.alttd.boosterapi.Booster;
|
||||
import com.alttd.boosterapi.BoosterType;
|
||||
import com.alttd.boosterapi.config.Config;
|
||||
import com.alttd.boosterapi.util.ALogger;
|
||||
import com.alttd.vboosters.VelocityBoosters;
|
||||
import com.alttd.vboosters.data.VelocityBooster;
|
||||
import com.alttd.vboosters.storage.VelocityBoosterStorage;
|
||||
import com.mysql.cj.log.Log;
|
||||
import com.velocitypowered.api.scheduler.ScheduledTask;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.JoinConfiguration;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class BoosterManager {
|
||||
@@ -32,6 +42,8 @@ public class BoosterManager {
|
||||
for (Booster booster: getActiveBoosters()) {
|
||||
if (booster.getTimeRemaining() > 0) continue;
|
||||
booster.finish();
|
||||
|
||||
plugin.getProxy().sendMessage(MiniMessage.miniMessage().deserialize("<green>Booster <booster> ended!</green>", Placeholder.unparsed("booster", booster.getType().getBoosterName())));
|
||||
// send data to the backend servers to let them know the booster is no longer active
|
||||
}
|
||||
getActiveBoosters().removeIf(Booster::finished);
|
||||
@@ -67,16 +79,21 @@ public class BoosterManager {
|
||||
}
|
||||
|
||||
public void addBooster(Booster booster) {
|
||||
BoosterType type = booster.getType();
|
||||
if(isBoosted(type)) {
|
||||
Booster activeBooster = getBoosted(type);
|
||||
Booster queuedBooster = getHighestBooster(type);
|
||||
if (queuedBooster != null && queuedBooster.getMultiplier() > activeBooster.getMultiplier()) {
|
||||
swapBooster(activeBooster, queuedBooster);
|
||||
}
|
||||
} else {
|
||||
activateBooster(booster);
|
||||
}
|
||||
// BoosterType type = booster.getType();
|
||||
// if (isBoosted(type)) {
|
||||
// Booster activeBooster = getBoosted(type);
|
||||
// Booster queuedBooster = getHighestBooster(type);
|
||||
// if (queuedBooster != null && queuedBooster.getMultiplier() > activeBooster.getMultiplier()) {
|
||||
// swapBooster(activeBooster, queuedBooster);
|
||||
// }
|
||||
// } else {
|
||||
// activateBooster(booster);
|
||||
// }
|
||||
VelocityBoosterStorage.getVelocityBoosterStorage().add(booster);
|
||||
if (booster instanceof VelocityBooster velocityBooster)
|
||||
velocityBooster.updateQueue();
|
||||
else
|
||||
ALogger.error("Tried to add a not velocity booster from velocity");
|
||||
}
|
||||
|
||||
public void removeBooster(Booster booster) {
|
||||
@@ -96,7 +113,8 @@ public class BoosterManager {
|
||||
}
|
||||
|
||||
public void deactivateBooster(Booster booster) {
|
||||
queuedBoosters.add(booster);
|
||||
if (booster.isActive())
|
||||
queuedBoosters.add(booster);
|
||||
activeBoosters.remove(booster);
|
||||
booster.setActive(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user