This commit is contained in:
parent
ff407b1c74
commit
b78675db11
@ -1,5 +1,9 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
**1.1.4**
|
||||||
|
* Add Refresh Button To GUI
|
||||||
|
* Add ``/modupdater`` Command
|
||||||
|
|
||||||
**1.1.3**
|
**1.1.3**
|
||||||
* Swap Buttons In GUI
|
* Swap Buttons In GUI
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ org.gradle.jvmargs = -Xmx1G
|
|||||||
fabric_loader_version = 0.8.8+build.202
|
fabric_loader_version = 0.8.8+build.202
|
||||||
|
|
||||||
# Mod Properties
|
# Mod Properties
|
||||||
mod_version = 1.1.3
|
mod_version = 1.1.4
|
||||||
maven_group = com.thebrokenrail
|
maven_group = com.thebrokenrail
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package com.thebrokenrail.modupdater;
|
package com.thebrokenrail.modupdater;
|
||||||
|
|
||||||
|
import com.thebrokenrail.modupdater.command.ModUpdaterCommand;
|
||||||
import com.thebrokenrail.modupdater.strategy.util.UpdateStrategyRunner;
|
import com.thebrokenrail.modupdater.strategy.util.UpdateStrategyRunner;
|
||||||
import com.thebrokenrail.modupdater.data.ModUpdate;
|
import com.thebrokenrail.modupdater.data.ModUpdate;
|
||||||
import net.fabricmc.api.ModInitializer;
|
import net.fabricmc.api.ModInitializer;
|
||||||
@ -25,10 +26,11 @@ public class ModUpdater implements ModInitializer {
|
|||||||
getLogger().info(info);
|
getLogger().info(info);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static volatile ModUpdate[] updates;
|
private static volatile ModUpdate[] updates = null;
|
||||||
|
|
||||||
public static void findUpdates() {
|
public static void findUpdates() {
|
||||||
updates = UpdateStrategyRunner.checkAllModsForUpdates();
|
updates = null;
|
||||||
|
new Thread(() -> updates = UpdateStrategyRunner.checkAllModsForUpdates()).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
@ -38,7 +40,7 @@ public class ModUpdater implements ModInitializer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onInitialize() {
|
public void onInitialize() {
|
||||||
Thread updateThread = new Thread(ModUpdater::findUpdates);
|
findUpdates();
|
||||||
updateThread.start();
|
ModUpdaterCommand.register();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,8 +20,11 @@ import java.util.Arrays;
|
|||||||
public class ModUpdateScreen extends Screen {
|
public class ModUpdateScreen extends Screen {
|
||||||
public ModUpdateListWidget list;
|
public ModUpdateListWidget list;
|
||||||
private ButtonWidget download;
|
private ButtonWidget download;
|
||||||
|
private ButtonWidget refresh;
|
||||||
private final Screen parent;
|
private final Screen parent;
|
||||||
|
|
||||||
|
private static final int BOTTOM_ROW = 60;
|
||||||
|
|
||||||
public ModUpdateScreen(Screen parent) {
|
public ModUpdateScreen(Screen parent) {
|
||||||
super(new TranslatableText("gui." + ModUpdater.NAMESPACE + ".title"));
|
super(new TranslatableText("gui." + ModUpdater.NAMESPACE + ".title"));
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
@ -31,25 +34,31 @@ public class ModUpdateScreen extends Screen {
|
|||||||
protected void init() {
|
protected void init() {
|
||||||
list = new ModUpdateListWidget(client, this);
|
list = new ModUpdateListWidget(client, this);
|
||||||
children.add(list);
|
children.add(list);
|
||||||
|
int buttonHeight = 20;
|
||||||
|
int padding = 2;
|
||||||
|
int actionRowY = height - BOTTOM_ROW / 2 - padding - buttonHeight;
|
||||||
|
int doneY = height - BOTTOM_ROW / 2 + padding;
|
||||||
int buttonWidth = 150;
|
int buttonWidth = 150;
|
||||||
int paddingX = 5;
|
int refreshX = width / 2 - buttonWidth - padding;
|
||||||
int downloadX = width / 2 - buttonWidth - paddingX;
|
int downloadX = width / 2 + padding;
|
||||||
int doneX = width / 2 + paddingX;
|
int doneX = width / 2 - buttonWidth / 2;
|
||||||
addButton(new ButtonWidget(doneX, height - 30, buttonWidth, 20, ScreenTexts.DONE, buttonWidget -> {
|
refresh = addButton(new ButtonWidget(refreshX, actionRowY, buttonWidth, buttonHeight, new TranslatableText("gui." + ModUpdater.NAMESPACE + ".refresh"), buttonWidget -> ModUpdater.findUpdates()));
|
||||||
assert client != null;
|
download = addButton(new ButtonWidget(downloadX, actionRowY, buttonWidth, buttonHeight, new TranslatableText("gui." + ModUpdater.NAMESPACE + ".download"), buttonWidget -> {
|
||||||
client.openScreen(parent);
|
|
||||||
}));
|
|
||||||
download = addButton(new ButtonWidget(downloadX, height - 30, buttonWidth, 20, new TranslatableText("gui." + ModUpdater.NAMESPACE + ".download"), buttonWidget -> {
|
|
||||||
if (list.getSelected() != null) {
|
if (list.getSelected() != null) {
|
||||||
Util.getOperatingSystem().open(list.getSelected().update.downloadURL);
|
Util.getOperatingSystem().open(list.getSelected().update.downloadURL);
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
download.active = false;
|
addButton(new ButtonWidget(doneX, doneY, buttonWidth, buttonHeight, ScreenTexts.DONE, buttonWidget -> {
|
||||||
|
assert client != null;
|
||||||
|
client.openScreen(parent);
|
||||||
|
}));
|
||||||
super.init();
|
super.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
|
||||||
|
refresh.active = ModUpdater.getUpdates() != null;
|
||||||
|
download.active = list.getSelected() != null;
|
||||||
list.render(matrices, mouseX, mouseY, delta);
|
list.render(matrices, mouseX, mouseY, delta);
|
||||||
drawCenteredText(matrices, textRenderer, title, width / 2, 16, 16777215);
|
drawCenteredText(matrices, textRenderer, title, width / 2, 16, 16777215);
|
||||||
super.render(matrices, mouseX, mouseY, delta);
|
super.render(matrices, mouseX, mouseY, delta);
|
||||||
@ -61,7 +70,7 @@ public class ModUpdateScreen extends Screen {
|
|||||||
private ModUpdate[] updates = null;
|
private ModUpdate[] updates = null;
|
||||||
|
|
||||||
private ModUpdateListWidget(MinecraftClient client, ModUpdateScreen screen) {
|
private ModUpdateListWidget(MinecraftClient client, ModUpdateScreen screen) {
|
||||||
super(client, screen.width, screen.height, 32, screen.height - 40, 18);
|
super(client, screen.width, screen.height, 32, screen.height - BOTTOM_ROW, 18);
|
||||||
this.screen = screen;
|
this.screen = screen;
|
||||||
|
|
||||||
reload();
|
reload();
|
||||||
@ -71,6 +80,7 @@ public class ModUpdateScreen extends Screen {
|
|||||||
ModUpdate[] newUpdates = ModUpdater.getUpdates();
|
ModUpdate[] newUpdates = ModUpdater.getUpdates();
|
||||||
if (!Arrays.equals(updates, newUpdates)) {
|
if (!Arrays.equals(updates, newUpdates)) {
|
||||||
clearEntries();
|
clearEntries();
|
||||||
|
setSelected(null);
|
||||||
if (newUpdates != null) {
|
if (newUpdates != null) {
|
||||||
for (ModUpdate update : newUpdates) {
|
for (ModUpdate update : newUpdates) {
|
||||||
addEntry(new ModUpdateEntry(update, screen, this));
|
addEntry(new ModUpdateEntry(update, screen, this));
|
||||||
@ -99,9 +109,6 @@ public class ModUpdateScreen extends Screen {
|
|||||||
super.setSelected(entry);
|
super.setSelected(entry);
|
||||||
if (entry != null) {
|
if (entry != null) {
|
||||||
NarratorManager.INSTANCE.narrate(new TranslatableText("narrator.select", entry.update.text).asString());
|
NarratorManager.INSTANCE.narrate(new TranslatableText("narrator.select", entry.update.text).asString());
|
||||||
screen.download.active = true;
|
|
||||||
} else {
|
|
||||||
screen.download.active = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,7 +127,7 @@ public class ModUpdateScreen extends Screen {
|
|||||||
reload();
|
reload();
|
||||||
super.render(matrices, mouseX, mouseY, delta);
|
super.render(matrices, mouseX, mouseY, delta);
|
||||||
if (updates == null) {
|
if (updates == null) {
|
||||||
drawCenteredText(matrices, screen.textRenderer, new TranslatableText("gui.modupdater.loading"), width / 2, height / 2 - screen.textRenderer.fontHeight, 16777215);
|
drawCenteredText(matrices, screen.textRenderer, new TranslatableText("gui.modupdater.loading"), width / 2, (bottom - top) / 2 - screen.textRenderer.fontHeight + top, 16777215);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,41 @@
|
|||||||
|
package com.thebrokenrail.modupdater.command;
|
||||||
|
|
||||||
|
import com.thebrokenrail.modupdater.ModUpdater;
|
||||||
|
import com.thebrokenrail.modupdater.data.ModUpdate;
|
||||||
|
import net.fabricmc.fabric.api.command.v1.CommandRegistrationCallback;
|
||||||
|
import net.minecraft.command.CommandException;
|
||||||
|
import net.minecraft.server.command.CommandManager;
|
||||||
|
import net.minecraft.text.ClickEvent;
|
||||||
|
import net.minecraft.text.HoverEvent;
|
||||||
|
import net.minecraft.text.LiteralText;
|
||||||
|
import net.minecraft.text.TranslatableText;
|
||||||
|
import net.minecraft.util.Formatting;
|
||||||
|
|
||||||
|
public class ModUpdaterCommand {
|
||||||
|
private static void checkLoaded() throws CommandException {
|
||||||
|
if (ModUpdater.getUpdates() == null) {
|
||||||
|
throw new CommandException(new TranslatableText("commands." + ModUpdater.NAMESPACE + ".not_loaded"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void register() {
|
||||||
|
CommandRegistrationCallback.EVENT.register((dispatcher, isDedicated) -> dispatcher.register(CommandManager.literal(ModUpdater.NAMESPACE)
|
||||||
|
.then(CommandManager.literal("list").executes(context -> {
|
||||||
|
checkLoaded();
|
||||||
|
context.getSource().sendFeedback(new TranslatableText("commands." + ModUpdater.NAMESPACE + ".list_title").formatted(Formatting.YELLOW), false);
|
||||||
|
ModUpdate[] updates = ModUpdater.getUpdates();
|
||||||
|
assert updates != null;
|
||||||
|
for (ModUpdate update : updates) {
|
||||||
|
context.getSource().sendFeedback(new LiteralText(update.text).styled(style -> style.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, update.downloadURL)).setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TranslatableText("commands." + ModUpdater.NAMESPACE + ".hover")))), false);
|
||||||
|
}
|
||||||
|
return updates.length;
|
||||||
|
}))
|
||||||
|
.then(CommandManager.literal("refresh").requires(source -> source.hasPermissionLevel(3)).executes(context -> {
|
||||||
|
checkLoaded();
|
||||||
|
ModUpdater.findUpdates();
|
||||||
|
context.getSource().sendFeedback(new TranslatableText("commands." + ModUpdater.NAMESPACE + ".refresh_start"), true);
|
||||||
|
return 1;
|
||||||
|
}))
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
@ -63,20 +63,24 @@ public class UpdateStrategyRunner {
|
|||||||
|
|
||||||
for (ModContainer mod : FabricLoader.getInstance().getAllMods()) {
|
for (ModContainer mod : FabricLoader.getInstance().getAllMods()) {
|
||||||
Thread thread = new Thread(() -> {
|
Thread thread = new Thread(() -> {
|
||||||
ModMetadata metadata = mod.getMetadata();
|
try {
|
||||||
|
ModMetadata metadata = mod.getMetadata();
|
||||||
|
|
||||||
ModUpdate update = checkModForUpdate(metadata);
|
ModUpdate update = checkModForUpdate(metadata);
|
||||||
|
|
||||||
if (update != null) {
|
if (update != null) {
|
||||||
ModUpdater.logInfo(update.text + " (" + update.downloadURL + ')');
|
ModUpdater.logInfo(update.text + " (" + update.downloadURL + ')');
|
||||||
synchronized (updates) {
|
synchronized (updates) {
|
||||||
updates.add(update);
|
updates.add(update);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
synchronized (remaining) {
|
||||||
|
remaining.decrementAndGet();
|
||||||
|
remaining.notifyAll();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
synchronized (remaining) {
|
|
||||||
remaining.decrementAndGet();
|
|
||||||
remaining.notifyAll();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
synchronized (remaining) {
|
synchronized (remaining) {
|
||||||
|
@ -1,5 +1,10 @@
|
|||||||
{
|
{
|
||||||
"gui.modupdater.title": "Available Mod Updates",
|
"gui.modupdater.title": "Available Mod Updates",
|
||||||
"gui.modupdater.download": "Download",
|
"gui.modupdater.download": "Download",
|
||||||
"gui.modupdater.loading": "Loading..."
|
"gui.modupdater.refresh": "Refresh",
|
||||||
|
"gui.modupdater.loading": "Loading...",
|
||||||
|
"commands.modupdater.not_loaded": "Unable To Perform Operation While Mod Updates Are Loading",
|
||||||
|
"commands.modupdater.refresh_start": "Refreshing Mod Updates",
|
||||||
|
"commands.modupdater.hover": "Click To Download",
|
||||||
|
"commands.modupdater.list_title": "Available Mod Updates:"
|
||||||
}
|
}
|
Reference in New Issue
Block a user