-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add /balm export config command for exporting config docs
- Loading branch information
1 parent
62d5b76
commit d904393
Showing
6 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
common/src/main/java/net/blay09/mods/balm/common/command/BalmCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package net.blay09.mods.balm.common.command; | ||
|
||
import com.mojang.brigadier.CommandDispatcher; | ||
import com.mojang.brigadier.arguments.StringArgumentType; | ||
import net.blay09.mods.balm.api.config.ConfigJsonExport; | ||
import net.minecraft.commands.CommandSourceStack; | ||
import net.minecraft.commands.Commands; | ||
import net.minecraft.network.chat.Component; | ||
|
||
import java.io.File; | ||
|
||
public class BalmCommand { | ||
|
||
public static void register(CommandDispatcher<CommandSourceStack> dispatcher) { | ||
dispatcher.register(Commands.literal("balm") | ||
.then(Commands.literal("export") | ||
.then(Commands.literal("config").then(Commands.argument("class", StringArgumentType.string()).executes(context -> { | ||
final var className = context.getArgument("class", String.class); | ||
try { | ||
final var configDataClass = Class.forName(className); | ||
ConfigJsonExport.exportToFile(configDataClass, new File("exports/config/" + configDataClass.getSimpleName() + ".json")); | ||
} catch (ClassNotFoundException e) { | ||
e.printStackTrace(); | ||
throw new RuntimeException("Invalid config data class: " + className, e); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
throw new RuntimeException("Error exporting config data class: " + className, e); | ||
} | ||
|
||
return 0; | ||
}) | ||
)).then(Commands.literal("icons")).then(Commands.argument("mod", StringArgumentType.string())).executes(context -> { | ||
context.getSource().sendFailure(Component.literal("Not yet implemented")); | ||
return 0; | ||
}))); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters