Fixed time unit for duration
This commit is contained in:
parent
2c2711e0e7
commit
24fcca1e3e
|
|
@ -72,6 +72,8 @@ public abstract class BoosterStorage {
|
||||||
Booster booster = loadBooster(parser);
|
Booster booster = loadBooster(parser);
|
||||||
if (Config.DEBUG)
|
if (Config.DEBUG)
|
||||||
ALogger.info("Loading booster [" + booster.getType() + "] activated by [" + booster.getActivator()+ "].");
|
ALogger.info("Loading booster [" + booster.getType() + "] activated by [" + booster.getActivator()+ "].");
|
||||||
|
if (new Date(booster.getEndTime()).after(new Date()))
|
||||||
|
continue;
|
||||||
boosters.put(booster.getUUID(), booster);
|
boosters.put(booster.getUUID(), booster);
|
||||||
if (parser.nextToken() != null && !parser.currentToken().isStructEnd()) {
|
if (parser.nextToken() != null && !parser.currentToken().isStructEnd()) {
|
||||||
ALogger.warn("Last loaded booster had more data than expected, skipping it...");
|
ALogger.warn("Last loaded booster had more data than expected, skipping it...");
|
||||||
|
|
@ -84,7 +86,7 @@ public abstract class BoosterStorage {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
saveBoosters(boosters.values());
|
||||||
return boosters;
|
return boosters;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -93,8 +95,9 @@ public abstract class BoosterStorage {
|
||||||
public void saveBoosters(Collection<Booster> boosters) {
|
public void saveBoosters(Collection<Booster> boosters) {
|
||||||
try {
|
try {
|
||||||
JsonGenerator generator = new JsonFactory().createGenerator(CONFIG_FILE, JsonEncoding.UTF8);
|
JsonGenerator generator = new JsonFactory().createGenerator(CONFIG_FILE, JsonEncoding.UTF8);
|
||||||
|
Date date = new Date();
|
||||||
for (Booster booster : boosters) {
|
for (Booster booster : boosters) {
|
||||||
if (booster.finished())
|
if (booster.finished() || new Date(booster.getEndTime()).after(date))
|
||||||
continue;
|
continue;
|
||||||
saveBooster(booster, generator);
|
saveBooster(booster, generator);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
public class BoosterCommand implements CommandExecutor {
|
public class BoosterCommand implements CommandExecutor {
|
||||||
|
|
||||||
|
|
@ -36,7 +37,7 @@ public class BoosterCommand implements CommandExecutor {
|
||||||
Placeholder.unparsed("type", booster.getType().getBoosterName()),
|
Placeholder.unparsed("type", booster.getType().getBoosterName()),
|
||||||
Placeholder.unparsed("activator", booster.getActivator()),
|
Placeholder.unparsed("activator", booster.getActivator()),
|
||||||
Placeholder.unparsed("start_time", DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT).format(booster.getStartingTime())),
|
Placeholder.unparsed("start_time", DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT).format(booster.getStartingTime())),
|
||||||
Placeholder.unparsed("duration", String.valueOf(booster.getDuration())),
|
Placeholder.unparsed("duration", TimeUnit.MILLISECONDS.toHours(booster.getDuration()) + " hours"),
|
||||||
Placeholder.unparsed("multiplier", String.valueOf(booster.getMultiplier())),
|
Placeholder.unparsed("multiplier", String.valueOf(booster.getMultiplier())),
|
||||||
Placeholder.unparsed("end_time", booster.isActive() ? DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT).format(expiryTime) : "unknown")
|
Placeholder.unparsed("end_time", booster.isActive() ? DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT).format(expiryTime) : "unknown")
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,6 @@ import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
|
||||||
import com.mojang.brigadier.suggestion.Suggestions;
|
import com.mojang.brigadier.suggestion.Suggestions;
|
||||||
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
import com.mojang.brigadier.suggestion.SuggestionsBuilder;
|
||||||
import com.mojang.brigadier.tree.LiteralCommandNode;
|
|
||||||
import com.velocitypowered.api.command.BrigadierCommand;
|
import com.velocitypowered.api.command.BrigadierCommand;
|
||||||
import com.velocitypowered.api.command.CommandMeta;
|
import com.velocitypowered.api.command.CommandMeta;
|
||||||
import com.velocitypowered.api.command.CommandSource;
|
import com.velocitypowered.api.command.CommandSource;
|
||||||
|
|
@ -25,7 +24,6 @@ import com.velocitypowered.api.proxy.Player;
|
||||||
import com.velocitypowered.api.proxy.ProxyServer;
|
import com.velocitypowered.api.proxy.ProxyServer;
|
||||||
import com.velocitypowered.api.util.GameProfile;
|
import com.velocitypowered.api.util.GameProfile;
|
||||||
import net.kyori.adventure.text.Component;
|
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.MiniMessage;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
|
||||||
|
|
@ -71,24 +69,24 @@ public class BoosterCommand {
|
||||||
Placeholder.unparsed("type", booster.getType().getBoosterName()),
|
Placeholder.unparsed("type", booster.getType().getBoosterName()),
|
||||||
Placeholder.unparsed("activator", booster.getActivator()),
|
Placeholder.unparsed("activator", booster.getActivator()),
|
||||||
Placeholder.unparsed("start_time", DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT).format(booster.getStartingTime())),
|
Placeholder.unparsed("start_time", DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT).format(booster.getStartingTime())),
|
||||||
Placeholder.unparsed("duration", String.valueOf(booster.getDuration())),
|
Placeholder.unparsed("duration", TimeUnit.MILLISECONDS.toHours(booster.getDuration()) + " hours"),
|
||||||
Placeholder.unparsed("multiplier", String.valueOf(booster.getMultiplier())));
|
Placeholder.unparsed("multiplier", String.valueOf(booster.getMultiplier())));
|
||||||
for (TagResolver tagResolver1 : templates)
|
for (TagResolver tagResolver1 : templates)
|
||||||
tagResolver.resolver(tagResolver1); // cheaty and lazy way I know
|
tagResolver.resolver(tagResolver1); // cheaty and lazy way I know
|
||||||
|
|
||||||
if (booster.isActive())
|
if (booster.isActive())
|
||||||
tagResolver.resolver(Placeholder.unparsed("end_time", DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT).format(expiryTime)));
|
templates.add(Template.of("end_time", DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT).format(expiryTime)));
|
||||||
else
|
else
|
||||||
tagResolver.resolver(Placeholder.unparsed("end_time", "unknown"));
|
templates.add(Template.of("end_time", "unknown"));
|
||||||
if (booster.isActive())
|
if (booster.isActive())
|
||||||
activeBoosterComponents.add(miniMessage.deserialize(activeBooster, tagResolver.build()));
|
activeBoosterComponents.add(miniMessage.parse(activeBooster, templates));
|
||||||
else if (!booster.finished())
|
else if (!booster.finished())
|
||||||
queuedBoosterComponents.add(miniMessage.deserialize(queuedBooster, tagResolver.build()));
|
queuedBoosterComponents.add(miniMessage.parse(queuedBooster, templates));
|
||||||
}
|
}
|
||||||
Component separator = miniMessage.deserialize("\n");
|
Component separator = miniMessage.parse("\n");
|
||||||
context.getSource().sendMessage(miniMessage.deserialize(message,TagResolver.resolver(
|
context.getSource().sendMessage(miniMessage.parse(message, List.of(
|
||||||
Placeholder.component("active_boosters", Component.join(JoinConfiguration.separator(separator), activeBoosterComponents)),
|
Template.of("active_boosters", Component.join(separator, activeBoosterComponents)),
|
||||||
Placeholder.component("queued_boosters", Component.join(JoinConfiguration.separator(separator), queuedBoosterComponents))
|
Template.of("queued_boosters", Component.join(separator, queuedBoosterComponents))
|
||||||
)));
|
)));
|
||||||
return 1;
|
return 1;
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user