[Feature] Update Checker
This commit is contained in:
parent
2ef9e51ef1
commit
69d472d107
21 changed files with 633 additions and 22 deletions
|
@ -53,7 +53,10 @@ public class CommandRegistry {
|
|||
.then(Commands.literal("dimensions")
|
||||
.requires(source -> source.hasPermission(Commands.LEVEL_OWNERS))
|
||||
.executes(ctx -> PrintInfo.printDimensions(ctx))
|
||||
)
|
||||
).then(Commands.literal("updates")
|
||||
.requires(source -> source.hasPermission(Commands.LEVEL_OWNERS))
|
||||
.executes(ctx -> PrintInfo.printUpdates(ctx, true))
|
||||
)
|
||||
)
|
||||
.then(Commands.literal("debug_ore")
|
||||
.requires(source -> source.hasPermission(Commands.LEVEL_OWNERS))
|
||||
|
|
|
@ -1,14 +1,24 @@
|
|||
package org.betterx.bclib.commands;
|
||||
|
||||
import org.betterx.bclib.BCLib;
|
||||
import org.betterx.bclib.client.gui.screens.UpdatesScreen;
|
||||
import org.betterx.bclib.config.Configs;
|
||||
import org.betterx.bclib.networking.VersionChecker;
|
||||
|
||||
import com.mojang.brigadier.Command;
|
||||
import com.mojang.brigadier.context.CommandContext;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.network.chat.ClickEvent;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.world.level.Level;
|
||||
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
import net.fabricmc.loader.api.ModContainer;
|
||||
|
||||
public class PrintInfo {
|
||||
static int printDimensions(CommandContext<CommandSourceStack> ctx) {
|
||||
|
||||
|
@ -37,4 +47,70 @@ public class PrintInfo {
|
|||
ctx.getSource().sendSuccess(result, false);
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
|
||||
static int printUpdates(CommandContext<CommandSourceStack> ctx, boolean withUI) {
|
||||
boolean hasOne = false;
|
||||
MutableComponent header = Component.literal("Mod Updates:")
|
||||
.setStyle(Style.EMPTY.withBold(false)
|
||||
.withColor(ChatFormatting.WHITE));
|
||||
ctx.getSource().sendSuccess(header, false);
|
||||
|
||||
VersionChecker.forEachUpdate((mod, cur, updated) -> {
|
||||
ModContainer nfo = FabricLoader.getInstance().getModContainer(mod).orElse(null);
|
||||
MutableComponent result = Component.literal(" - ")
|
||||
.setStyle(Style.EMPTY.withBold(false)
|
||||
.withUnderlined(false)
|
||||
.withColor(ChatFormatting.WHITE));
|
||||
if (nfo != null)
|
||||
result.append(Component.literal(nfo.getMetadata().getName())
|
||||
.setStyle(Style.EMPTY.withBold(false).withColor(ChatFormatting.WHITE)));
|
||||
else
|
||||
result.append(Component.literal(mod)
|
||||
.setStyle(Style.EMPTY.withBold(false).withColor(ChatFormatting.WHITE)));
|
||||
result.append(Component.literal(": ")
|
||||
.setStyle(Style.EMPTY.withBold(false).withColor(ChatFormatting.WHITE)));
|
||||
result.append(Component.literal(cur).setStyle(Style.EMPTY.withBold(false).withColor(ChatFormatting.WHITE)));
|
||||
result.append(Component.literal(" -> ")
|
||||
.setStyle(Style.EMPTY.withBold(false).withColor(ChatFormatting.WHITE)));
|
||||
if (nfo != null && nfo.getMetadata().getContact().get("homepage").isPresent()) {
|
||||
var ce = new ClickEvent(
|
||||
ClickEvent.Action.OPEN_URL,
|
||||
nfo.getMetadata().getContact().get("homepage").get()
|
||||
);
|
||||
|
||||
result.append(Component.literal(updated)
|
||||
.setStyle(Style.EMPTY.withClickEvent(ce)
|
||||
.withBold(false)
|
||||
.withItalic(true)
|
||||
.withColor(ChatFormatting.GREEN)));
|
||||
result.append(Component.literal(" ")
|
||||
.setStyle(Style.EMPTY.withClickEvent(ce).withBold(true).withItalic(false)));
|
||||
|
||||
result = result.append(Component.literal("[CurseForge]")
|
||||
.setStyle(Style.EMPTY.withClickEvent(ce)
|
||||
.withBold(true)
|
||||
.withColor(ChatFormatting.GREEN)
|
||||
.withUnderlined(true)));
|
||||
|
||||
} else {
|
||||
result.append(Component.literal(updated)
|
||||
.setStyle(Style.EMPTY.withBold(false)
|
||||
.withItalic(true)
|
||||
.withColor(ChatFormatting.WHITE)));
|
||||
result.append(Component.literal(" ").setStyle(Style.EMPTY.withBold(true).withItalic(false)));
|
||||
|
||||
}
|
||||
ctx.getSource().sendSuccess(result, false);
|
||||
});
|
||||
MutableComponent footer = Component.literal("\n")
|
||||
.setStyle(Style.EMPTY.withBold(false)
|
||||
.withUnderlined(true)
|
||||
.withColor(ChatFormatting.WHITE));
|
||||
ctx.getSource().sendSuccess(footer, false);
|
||||
|
||||
if (withUI && BCLib.isClient() && Configs.CLIENT_CONFIG.showUpdateInfo() && !VersionChecker.isEmpty()) {
|
||||
Minecraft.getInstance().setScreen(new UpdatesScreen(Minecraft.getInstance().screen));
|
||||
}
|
||||
return Command.SINGLE_SUCCESS;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue