copied the booster show command to the server as well

This commit is contained in:
Teriuihi 2022-09-02 23:09:41 +02:00
parent 47e10bd61e
commit 2ef55fcfc0
3 changed files with 58 additions and 2 deletions

View File

@ -8,7 +8,7 @@ dependencies {
// API
implementation(project(":boosters-api"))
// Galaxy
compileOnly("com.alttd:Galaxy-API:1.18.1-R0.1-SNAPSHOT")
compileOnly("com.alttd:Galaxy-API:1.19.2-R0.1-SNAPSHOT")
// MyPet
compileOnly("de.keyle:mypet:3.12-SNAPSHOT")
// mcMMO

View File

@ -4,13 +4,13 @@ import com.alttd.boosterapi.BoosterAPI;
import com.alttd.boosterapi.BoosterImplementation;
import com.alttd.boosterapi.config.Config;
import com.alttd.boosterapi.util.ALogger;
import com.alttd.boosters.commands.BoosterCommand;
import com.alttd.boosters.listeners.MCmmoListener;
import com.alttd.boosters.listeners.MyPetListener;
import com.alttd.boosters.listeners.PhantomSpawnListener;
import com.alttd.boosters.listeners.PluginMessage;
import com.alttd.boosters.managers.BoosterManager;
import com.alttd.boosters.storage.ServerBoosterStorage;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandExecutor;
import org.bukkit.event.Listener;
import org.bukkit.plugin.java.JavaPlugin;
@ -40,6 +40,7 @@ public final class BoostersPlugin extends JavaPlugin {
getServer().getMessenger().registerOutgoingPluginChannel(this, Config.pluginMessageChannel);
getServer().getMessenger().registerIncomingPluginChannel(this, Config.pluginMessageChannel, new PluginMessage());
registerCommand("boosters", new BoosterCommand());
ServerBoosterStorage.getServerBoosterStorage(); //this loads the boosters in
}

View File

@ -0,0 +1,55 @@
package com.alttd.boosters.commands;
import com.alttd.boosterapi.Booster;
import com.alttd.boosters.storage.ServerBoosterStorage;
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 org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import java.text.DateFormat;
import java.util.*;
public class BoosterCommand implements CommandExecutor {
private static final MiniMessage miniMessage = MiniMessage.miniMessage();
@Override
public boolean onCommand(@NotNull CommandSender commandSender, @NotNull Command command, @NotNull String s, @NotNull String[] strings) {
if (!commandSender.hasPermission("command.proxy.booster")) {
commandSender.sendMiniMessage("<red>You don't have permission for this command", null);
return true;
}
String message = "Active boosters:\n<active_boosters>\n\nQueued boosters:\n<queued_boosters>";
String activeBooster = "<type> activated by <activator> until <end_time> [UTC], boosts <multiplier> times";
String queuedBooster = "<type> queued by <activator> starts at <start_time> [UTC] and will be active for <duration>, boosts <multiplier> times";
List<Component> activeBoosterComponents = new ArrayList<>();
List<Component> queuedBoosterComponents = new ArrayList<>();
for (Booster booster : ServerBoosterStorage.getServerBoosterStorage().getBoosters().values()) {
long expiryTime = new Date().getTime() + booster.getDuration();
TagResolver templates = TagResolver.resolver(
Placeholder.unparsed("type", booster.getType().getBoosterName()),
Placeholder.unparsed("activator", booster.getActivator()),
Placeholder.unparsed("start_time", DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT).format(booster.getStartingTime())),
Placeholder.unparsed("duration", String.valueOf(booster.getDuration())),
Placeholder.unparsed("multiplier", String.valueOf(booster.getMultiplier())),
Placeholder.unparsed("end_time", booster.isActive() ? DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.SHORT).format(expiryTime) : "unknown")
);
if (booster.isActive())
activeBoosterComponents.add(miniMessage.deserialize(activeBooster, templates));
else if (!booster.finished())
queuedBoosterComponents.add(miniMessage.deserialize(queuedBooster, templates));
}
commandSender.sendMiniMessage(message, TagResolver.resolver(
Placeholder.component("active_boosters", Component.join(JoinConfiguration.newlines(), activeBoosterComponents)),
Placeholder.component("queued_boosters", Component.join(JoinConfiguration.newlines(), queuedBoosterComponents))
));
return true;
}
}