Reworked everything to be much easier to read and just over all better (didnt rewrite the ranks part tho)

This commit is contained in:
auto committed 2023-06-27 04:37:56 +02:00
1 parent fb41198073
commit 84e306f45f
39 files changed
+1500 -1708

No files matched your search

@@ -1,23 +1,54 @@
package com.alttd.vboosters.task;
import com.alttd.boosterapi.data.Booster;
import com.alttd.boosterapi.config.Config;
import com.alttd.boosterapi.data.BoosterCache;
import com.alttd.boosterapi.util.Logger;
import com.alttd.vboosters.VelocityBoosters;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import java.time.Duration;
import java.time.Instant;
import java.util.List;
import java.util.concurrent.TimeUnit;
public class BoosterTask {
private VelocityBoosters plugin;
private final Logger logger;
private final BoosterCache boosterCache;
public BoosterTask() {
public BoosterTask(Logger logger, BoosterCache boosterCache) {
super();
this.logger = logger;
this.boosterCache = boosterCache;
plugin = VelocityBoosters.getPlugin();
}
public void init() {
plugin.getProxy().getScheduler().buildTask(plugin, () -> {
private void run() {
boolean update = false;
List<Booster> values = boosterCache.getAllActiveBoosters();
for (Booster booster : values) {
logger.debug("Handling booster: " + booster);
Instant currentTime = Instant.now();
Duration elapsedTime = Duration.between(booster.getStartingTime(), currentTime);
if (elapsedTime.compareTo(booster.getDuration()) >= 0) {
logger.debug("No time remaining, finishing booster: " + booster);
boosterCache.finishBooster(booster);
update = true;
}
}
if (!update)
return;
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("reload");
plugin.getProxy().getAllServers()
.forEach(registeredServer -> registeredServer.sendPluginMessage(VelocityBoosters.getPlugin().getChannelIdentifier(), out.toByteArray()));
}
}).repeat(Config.taskCheckFrequency, TimeUnit.SECONDS).schedule();
public void init() {
plugin.getProxy().getScheduler().buildTask(plugin, this::run).repeat(Config.SETTINGS.UPDATE_FREQUENCY_MINUTES, TimeUnit.MINUTES).schedule();
}
}