Skip to content

Commit

Permalink
toggleable plugins (#253)
Browse files Browse the repository at this point in the history
* reloadable plugins

* pass 2

* pass 3

* pass 4

* pass 5

* format translations
  • Loading branch information
deirn authored Mar 10, 2024
1 parent 4de486b commit 6556096
Show file tree
Hide file tree
Showing 87 changed files with 1,920 additions and 378 deletions.
7 changes: 5 additions & 2 deletions platform/fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,13 @@ loom {
}

runs {
getByName("client") {
programArgs("--username", "A")
}

configureEach {
isIdeConfigGenerated = true
vmArgs += "-Dwaila.enableTestPlugin=true"
vmArgs += "-Dwaila.debugCommands=true"
runDir = "run/${namer.determineName(this)}"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package mcp.mobius.waila.fabric;

import java.util.function.Supplier;

import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
Expand All @@ -10,33 +12,24 @@

public class FabricClientCommand extends ClientCommand<FabricClientCommandSource> {

public FabricClientCommand() {
super(new ArgumentBuilderFactory<>() {
@Override
public LiteralArgumentBuilder<FabricClientCommandSource> literal(String name) {
return ClientCommandManager.literal(name);
}

@Override
public <T> RequiredArgumentBuilder<FabricClientCommandSource, T> required(String name, ArgumentType<T> type) {
return ClientCommandManager.argument(name, type);
}
});
@Override
protected LiteralArgumentBuilder<FabricClientCommandSource> literal(String name) {
return ClientCommandManager.literal(name);
}

@Override
protected <T> RequiredArgumentBuilder<FabricClientCommandSource, T> argument(String name, ArgumentType<T> type) {
return ClientCommandManager.argument(name, type);
}

@Override
protected void success(FabricClientCommandSource source, Supplier<Component> msg) {
source.sendFeedback(msg.get());
}

@Override
protected FeedbackSender feedback(FabricClientCommandSource source) {
return new FeedbackSender() {
@Override
public void success(Component message) {
source.sendFeedback(message);
}

@Override
public void fail(Component message) {
source.sendError(message);
}
};
protected void fail(FabricClientCommandSource source, Component msg) {
source.sendError(msg);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ protected void gatherPlugins() {
continue;
}

PluginInfo.register(mod.getMetadata().getId(), id, side, initializer, requiredDeps, true);
PluginInfo.register(mod.getMetadata().getId(), id, side, initializer, requiredDeps, true, true);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import mcp.mobius.waila.config.PluginConfig;
import mcp.mobius.waila.debug.DumpGenerator;
import mcp.mobius.waila.network.Packets;
import mcp.mobius.waila.plugin.PluginLoader;
import mcp.mobius.waila.util.ModInfo;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback;
Expand All @@ -24,7 +25,7 @@ public void onInitialize() {
Packets.initServer();

CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) ->
ServerCommand.register(dispatcher));
new ServerCommand().register(dispatcher));

ServerLifecycleEvents.SERVER_STARTING.register(server -> PluginConfig.reload());
ServerLifecycleEvents.SERVER_STOPPED.register(server -> onServerStopped());
Expand All @@ -40,7 +41,7 @@ public void onInitialize() {
.ifPresent(m -> DumpGenerator.VERSIONS.put(m.getName(), m.getVersion().getFriendlyString()));
}

new FabricPluginLoader().loadPlugins();
PluginLoader.INSTANCE.loadPlugins();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mcp.mobius.waila.fabric.FabricPluginLoader
5 changes: 5 additions & 0 deletions platform/fabric/src/main/resources/waila_plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,10 @@
"initializer": "mcp.mobius.waila.plugin.trenergy.WailaPluginTeamRebornEnergy",
"side" : "*",
"required" : ["team_reborn_energy"]
},

"waila:test" : {
"initializer" : "mcp.mobius.waila.plugin.test.WailaPluginTest",
"defaultEnabled": false
}
}
18 changes: 10 additions & 8 deletions platform/forge/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import net.minecraftforge.gradle.common.util.RunConfig
import java.text.SimpleDateFormat
import java.util.*

Expand All @@ -21,12 +20,13 @@ dependencies {

// https://www.curseforge.com/minecraft/mc-mods/travelers-backpack/files/4584396
// runtimeOnly(fg.deobf("curse.maven:travelers-backpack-321117:4584396"))

when (rootProp["recipeViewer"]) {
"rei" -> {
runtimeOnly(fg.deobf("me.shedaniel:RoughlyEnoughItems-forge:${rootProp["rei"]}"))
// runtimeOnly(fg.deobf("me.shedaniel:RoughlyEnoughItems-plugin-compatibilities-forge:${rootProp["rei"]}"))
}

"jei" -> rootProp["jei"].split("-").also { (mc, jei) ->
runtimeOnly(fg.deobf("mezz.jei:jei-${mc}-forge:${jei}"))
}
Expand All @@ -50,17 +50,19 @@ sourceSets {
minecraft {
mappings("official", rootProp["minecraft"])
runs {
val runConfig = Action<RunConfig> {
workingDirectory(file("run"))
create("server")
create("client") {
args("--username", "A")
}

configureEach {
workingDirectory(file("run/${namer.determineName(this)}"))
ideaModule("${rootProject.name}.${project.name}.main")
property("waila.enableTestPlugin", "true")
property("waila.debugCommands", "true")

source(sourceSets["main"])
source(sourceSets["plugin"])
rootProject.sourceSets.forEach { source(it) }
}
create("client", runConfig)
create("server", runConfig)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package mcp.mobius.waila.forge;

import java.util.function.Supplier;

import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
Expand All @@ -10,33 +12,24 @@

public class ForgeClientCommand extends ClientCommand<CommandSourceStack> {

public ForgeClientCommand() {
super(new ArgumentBuilderFactory<>() {
@Override
public LiteralArgumentBuilder<CommandSourceStack> literal(String name) {
return Commands.literal(name);
}

@Override
public <T> RequiredArgumentBuilder<CommandSourceStack, T> required(String name, ArgumentType<T> type) {
return Commands.argument(name, type);
}
});
@Override
protected LiteralArgumentBuilder<CommandSourceStack> literal(String name) {
return Commands.literal(name);
}

@Override
protected <T> RequiredArgumentBuilder<CommandSourceStack, T> argument(String name, ArgumentType<T> type) {
return Commands.argument(name, type);
}

@Override
protected void success(CommandSourceStack source, Supplier<Component> msg) {
source.sendSuccess(msg, false);
}

@Override
protected FeedbackSender feedback(CommandSourceStack source) {
return new FeedbackSender() {
@Override
public void success(Component message) {
source.sendSuccess(() -> message, false);
}

@Override
public void fail(Component message) {
source.sendFailure(message);
}
};
protected void fail(CommandSourceStack source, Component msg) {
source.sendFailure(msg);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ protected void gatherPlugins() {
}

if (satisfied) {
PluginInfo.register(modFile.getMods().get(0).getModId(), id, side, annotation.memberName(), Arrays.asList(required), true);
PluginInfo.register(modFile.getMods().get(0).getModId(), id, side, annotation.memberName(), Arrays.asList(required), true, true);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import mcp.mobius.waila.config.PluginConfig;
import mcp.mobius.waila.debug.DumpGenerator;
import mcp.mobius.waila.network.Packets;
import mcp.mobius.waila.plugin.PluginLoader;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.event.TagsUpdatedEvent;
import net.minecraftforge.event.server.ServerStartingEvent;
Expand Down Expand Up @@ -37,7 +38,7 @@ static void setup(FMLCommonSetupEvent event) {

@SubscribeEvent
static void loadComplete(FMLLoadCompleteEvent event) {
new ForgePluginLoader().loadPlugins();
PluginLoader.INSTANCE.loadPlugins();
}

@EventBusSubscriber(modid = WailaConstants.WAILA)
Expand All @@ -60,7 +61,7 @@ static void tagReload(TagsUpdatedEvent event) {

@SubscribeEvent
static void registerCommands(RegisterCommandsEvent event) {
ServerCommand.register(event.getDispatcher());
new ServerCommand().register(event.getDispatcher());
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mcp.mobius.waila.forge.ForgePluginLoader
5 changes: 5 additions & 0 deletions platform/forge/src/main/resources/waila_plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,10 @@
"initializer": "mcp.mobius.waila.plugin.forge.WailaPluginForge",
"side" : "*",
"required" : ["forge"]
},

"waila:test" : {
"initializer" : "mcp.mobius.waila.plugin.test.WailaPluginTest",
"defaultEnabled": false
}
}
16 changes: 7 additions & 9 deletions platform/neo/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import net.neoforged.gradle.dsl.common.runs.run.Run

plugins {
id("net.neoforged.gradle.userdev") version "7.0.+"
}
Expand All @@ -26,18 +24,18 @@ sourceSets {
}

runs {
val runConfig = Action<Run> {
workingDirectory(file("run"))
jvmArgument("-Dwaila.enableTestPlugin=true")
jvmArgument("-Dwaila.debugCommands=true")
create("server")
create("client") {
programArguments("--username", "A")
}

configureEach {
workingDirectory(file("run/${namer.determineName(this)}"))

modSource(sourceSets["main"])
modSource(sourceSets["plugin"])
modSource(sourceSets["dummy"])
}

create("client", runConfig)
create("server", runConfig)
}

tasks.processResources {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package mcp.mobius.waila.neo;

import java.util.function.Supplier;

import com.mojang.brigadier.arguments.ArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.builder.RequiredArgumentBuilder;
Expand All @@ -10,33 +12,24 @@

public class NeoClientCommand extends ClientCommand<CommandSourceStack> {

public NeoClientCommand() {
super(new ArgumentBuilderFactory<>() {
@Override
public LiteralArgumentBuilder<CommandSourceStack> literal(String name) {
return Commands.literal(name);
}

@Override
public <T> RequiredArgumentBuilder<CommandSourceStack, T> required(String name, ArgumentType<T> type) {
return Commands.argument(name, type);
}
});
@Override
protected LiteralArgumentBuilder<CommandSourceStack> literal(String name) {
return Commands.literal(name);
}

@Override
protected <T> RequiredArgumentBuilder<CommandSourceStack, T> argument(String name, ArgumentType<T> type) {
return Commands.argument(name, type);
}

@Override
protected void success(CommandSourceStack source, Supplier<Component> msg) {
source.sendSuccess(msg, false);
}

@Override
protected FeedbackSender feedback(CommandSourceStack source) {
return new FeedbackSender() {
@Override
public void success(Component message) {
source.sendSuccess(() -> message, false);
}

@Override
public void fail(Component message) {
source.sendFailure(message);
}
};
protected void fail(CommandSourceStack source, Component msg) {
source.sendFailure(msg);
}

}
5 changes: 3 additions & 2 deletions platform/neo/src/main/java/mcp/mobius/waila/neo/NeoWaila.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import mcp.mobius.waila.config.PluginConfig;
import mcp.mobius.waila.debug.DumpGenerator;
import mcp.mobius.waila.network.Packets;
import mcp.mobius.waila.plugin.PluginLoader;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.ModContainer;
import net.neoforged.fml.ModList;
Expand Down Expand Up @@ -37,7 +38,7 @@ static void setup(FMLCommonSetupEvent event) {

@SubscribeEvent
static void loadComplete(FMLLoadCompleteEvent event) {
new NeoPluginLoader().loadPlugins();
PluginLoader.INSTANCE.loadPlugins();
}

@EventBusSubscriber(modid = WailaConstants.WAILA)
Expand All @@ -60,7 +61,7 @@ static void tagReload(TagsUpdatedEvent event) {

@SubscribeEvent
static void registerCommands(RegisterCommandsEvent event) {
ServerCommand.register(event.getDispatcher());
new ServerCommand().register(event.getDispatcher());
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mcp.mobius.waila.neo.NeoPluginLoader
5 changes: 5 additions & 0 deletions platform/neo/src/main/resources/waila_plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,10 @@
"initializer": "mcp.mobius.waila.plugin.neo.WailaPluginNeo",
"side" : "*",
"required" : ["neoforge"]
},

"waila:test" : {
"initializer" : "mcp.mobius.waila.plugin.test.WailaPluginTest",
"defaultEnabled": false
}
}
Loading

0 comments on commit 6556096

Please sign in to comment.