Skip to content

Commit

Permalink
Additional platform information for fabric
Browse files Browse the repository at this point in the history
  • Loading branch information
NickImpact committed Apr 23, 2023
1 parent 2e90ca6 commit 8e09693
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import net.impactdev.impactor.api.platform.plugins.PluginMetadata;
import net.impactdev.impactor.api.utility.printing.PrettyPrinter;
import net.impactdev.impactor.core.platform.ImpactorPlatformInfo;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -79,15 +80,16 @@ protected void printComponents(PrettyPrinter printer) {
printer.tr(component.name(), component.version());
}
printer.hr('-');

printer.newline().add("Mods: ");
printer.table("Mod", "Version");
printer.table("Mod", 40, "Version", "Parent");
List<ModContainer> mods = FabricLoader.getInstance().getAllMods()
.stream()
.filter(info -> !this.exclusions.contains(info.getMetadata().getId()))
.filter(info -> info.getContainingMod().isEmpty())
.collect(Collectors.toList());
for(ModContainer info : mods) {
printer.tr(info.getMetadata().getName(), info.getMetadata().getVersion().getFriendlyString());
this.printModContainer(info, printer);
}
}

Expand All @@ -105,4 +107,13 @@ private PluginMetadata translate(ModMetadata metadata) {
.description(metadata.getDescription())
.build();
}

private void printModContainer(ModContainer target, PrettyPrinter printer) {
@Nullable ModContainer parent = target.getContainingMod().orElse(null);
printer.tr(target.getMetadata().getName(), target.getMetadata().getVersion().getFriendlyString(), parent != null ? parent.getMetadata().getName() : "");

for (ModContainer child : target.getContainedMods()) {
this.printModContainer(child, printer);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,26 @@

package net.impactdev.impactor.fabric.platform.sources;

import net.impactdev.impactor.api.Impactor;
import net.impactdev.impactor.api.platform.sources.SourceType;
import net.impactdev.impactor.core.platform.sources.ImpactorPlatformSource;
import net.impactdev.impactor.fabric.platform.FabricPlatform;
import net.impactdev.impactor.minecraft.text.AdventureTranslator;
import net.kyori.adventure.audience.MessageType;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.NotNull;

import java.util.UUID;

public final class FabricPlatformSource extends ImpactorPlatformSource {
public FabricPlatformSource(UUID uuid, SourceType type) {
super(uuid, type);
}

@Override
public void sendMessage(@NotNull Identity source, @NotNull Component message, @NotNull MessageType type) {
FabricPlatform platform = (FabricPlatform) Impactor.instance().platform();
platform.server().sendSystemMessage(AdventureTranslator.toNative(message));
}
}

0 comments on commit 8e09693

Please sign in to comment.