aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt65
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DiagCommand.kt24
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/NEUStatsCommand.kt27
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/PackDevCommand.kt26
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/SimpleDevCommands.kt24
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/FeaturesCommand.kt4
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/HelpCommand.kt13
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/LinksCommand.kt3
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/SettingsCommand.kt15
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/StorageViewerWhyCommand.kt3
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/FairySoulsCommand.kt13
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/BrigadierRoot.kt21
-rw-r--r--src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/dsl.kt11
13 files changed, 132 insertions, 117 deletions
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt
index 4b7b42a4..351c0fa9 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DevTestCommand.kt
@@ -41,7 +41,6 @@ import net.minecraft.command.ICommandSender
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.launchwrapper.Launch
import net.minecraft.util.ChatComponentText
-import net.minecraft.util.EnumChatFormatting
import net.minecraft.util.EnumChatFormatting.*
import net.minecraft.util.EnumParticleTypes
import net.minecraftforge.common.MinecraftForge
@@ -108,33 +107,33 @@ class DevTestCommand {
val currentProfile = SBInfo.getInstance().currentProfile
val gamemode = SBInfo.getInstance().getGamemodeForProfile(currentProfile)
reply("${GOLD}You are on Profile $currentProfile with the mode $gamemode")
- }
+ }.withHelp("Display information about your current profile")
thenLiteralExecute("buildflags") {
reply("BuildFlags: \n" +
BuildFlags.getAllFlags().entries
.joinToString(("\n")) { (key, value) -> " + $key - $value" })
- }
+ }.withHelp("List the flags with which NEU was built")
thenLiteral("exteditor") {
- thenExecute {
- reply("Your external editor is: §Z${NotEnoughUpdates.INSTANCE.config.hidden.externalEditor}")
- }
thenArgument("editor", StringArgumentType.string()) { newEditor ->
thenExecute {
NotEnoughUpdates.INSTANCE.config.hidden.externalEditor = this[newEditor]
reply("You changed your external editor to: §Z${this[newEditor]}")
}
- }
- }
- thenLiteral("pricetest") {
+ }.withHelp("Change the editor used to edit repo files")
thenExecute {
- NotEnoughUpdates.INSTANCE.manager.auctionManager.updateBazaar()
+ reply("Your external editor is: §Z${NotEnoughUpdates.INSTANCE.config.hidden.externalEditor}")
}
+ }.withHelp("See your current external editor for repo files")
+ thenLiteral("pricetest") {
thenArgument("item", StringArgumentType.string()) { item ->
thenExecute {
NotEnoughUpdates.INSTANCE.openGui = GuiPriceGraph(this[item])
}
+ }.withHelp("Display the price graph for an item by id")
+ thenExecute {
+ NotEnoughUpdates.INSTANCE.manager.auctionManager.updateBazaar()
}
- }
+ }.withHelp("Update the price data from the bazaar")
thenLiteralExecute("zone") {
val target = Minecraft.getMinecraft().objectMouseOver.blockPos
?: Minecraft.getMinecraft().thePlayer.position
@@ -154,10 +153,10 @@ class DevTestCommand {
.getLocation()
)
)
- }
+ }.withHelp("Display information about the special block zone at your cursor (Custom Texture Regions)")
thenLiteralExecute("positiontest") {
NotEnoughUpdates.INSTANCE.openGui = GuiPositionEditor()
- }
+ }.withHelp("Open the gui position editor")
thenLiteral("pt") {
thenArgument("particle", EnumArgumentType.enum<EnumParticleTypes>()) { particle ->
thenExecute {
@@ -169,50 +168,46 @@ class DevTestCommand {
thenLiteralExecute("dev") {
NotEnoughUpdates.INSTANCE.config.hidden.dev = !NotEnoughUpdates.INSTANCE.config.hidden.dev
reply("§e[NEU] Dev mode " + if (NotEnoughUpdates.INSTANCE.config.hidden.dev) "§aenabled" else "§cdisabled")
- }
+ }.withHelp("Toggle developer mode")
thenLiteralExecute("saveconfig") {
NotEnoughUpdates.INSTANCE.saveConfig()
reply("Config saved")
- }
+ }.withHelp("Force sync the config to disk")
thenLiteralExecute("searchmode") {
NotEnoughUpdates.INSTANCE.config.hidden.firstTimeSearchFocus = true
reply(AQUA.toString() + "I would never search")
- }
+ }.withHelp("Reset your search data to redisplay the search tutorial")
thenLiteralExecute("bluehair") {
PronounDB.test()
- }
+ }.withHelp("Test the pronoundb integration")
thenLiteral("opengui") {
- thenArgument("class", StringArgumentType.string()) { className ->
- thenExecute {
- try {
- NotEnoughUpdates.INSTANCE.openGui =
- Class.forName(this[className]).newInstance() as GuiScreen
- reply("Opening gui: " + NotEnoughUpdates.INSTANCE.openGui)
- } catch (e: Exception) {
- e.printStackTrace()
- reply("Failed to open this GUI.")
- }
+ thenArgumentExecute("class", StringArgumentType.string()) { className ->
+ try {
+ NotEnoughUpdates.INSTANCE.openGui =
+ Class.forName(this[className]).newInstance() as GuiScreen
+ reply("Opening gui: " + NotEnoughUpdates.INSTANCE.openGui)
+ } catch (e: Exception) {
+ e.printStackTrace()
+ reply("Failed to open this GUI.")
}
- }
+ }.withHelp("Open a gui by class name")
}
thenLiteralExecute("center") {
val x = floor(Minecraft.getMinecraft().thePlayer.posX) + 0.5f
val z = floor(Minecraft.getMinecraft().thePlayer.posZ) + 0.5f
Minecraft.getMinecraft().thePlayer.setPosition(x, Minecraft.getMinecraft().thePlayer.posY, z)
reply("Literal hacks")
- }
+ }.withHelp("Center yourself on the block you are currently standing (like using AOTE)")
thenLiteral("minion") {
- thenArgument("args", RestArgumentType) { arg ->
- thenExecute {
- MinionHelperManager.getInstance().handleCommand(arrayOf("minion") + this[arg].split(" "))
- }
- }
+ thenArgumentExecute("args", RestArgumentType) { arg ->
+ MinionHelperManager.getInstance().handleCommand(arrayOf("minion") + this[arg].split(" "))
+ }.withHelp("Minion related commands. Not yet integrated in brigadier")
}
thenLiteralExecute("copytablist") {
val tabList = TabListUtils.getTabList().joinToString("\n", postfix = "\n")
MiscUtils.copyToClipboard(tabList)
reply("Copied tablist to clipboard!")
- }
+ }.withHelp("Copy the tab list")
}
hook.beforeCommand = Predicate {
if (!canPlayerExecute(it.context.source)) {
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DiagCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DiagCommand.kt
index 67765b9d..8985caaa 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DiagCommand.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/DiagCommand.kt
@@ -37,28 +37,25 @@ class DiagCommand {
fun onCommands(event: RegisterBrigadierCommandEvent) {
event.command("neudiag") {
thenLiteral("metal") {
- thenExecute {
- CrystalMetalDetectorSolver.logDiagnosticData(true)
- reply("Enabled metal detector diagnostic logging.")
- }
thenLiteral("center") {
thenArgumentExecute("usecenter", bool()) { useCenter ->
CrystalMetalDetectorSolver.setDebugDoNotUseCenter(this[useCenter])
reply("Center coordinates-based solutions ${if (this[useCenter]) "enabled" else "disabled"}")
}
+ }.withHelp("Toggle coordinate based solutions")
+ thenExecute {
+ CrystalMetalDetectorSolver.logDiagnosticData(true)
+ reply("Enabled metal detector diagnostic logging.")
}
- }
+ }.withHelp("Enable metal detector diagnostics")
thenLiteralExecute("wishing") {
CrystalWishingCompassSolver.getInstance().logDiagnosticData(true)
reply("Enabled wishing compass diagnostic logging")
- }
+ }.withHelp("Enable wishing compass diagnostic logging")
thenLiteral("debug") {
- thenExecute {
- reply("Effective debug flags: \n${NEUDebugFlag.getEnabledFlags()}")
- }
thenLiteralExecute("list") {
reply("Here are all flags:\n${NEUDebugFlag.getFlagList()}")
- }
+ }.withHelp("List all debug diagnostic logging flags")
thenLiteral("setflag") {
thenArgument("flag", enum<NEUDebugFlag>()) { flag ->
thenArgumentExecute("enable", bool()) { enable ->
@@ -69,10 +66,13 @@ class DiagCommand {
debugFlags.remove(this[flag])
}
reply("${if(this[enable]) "Enabled" else "Disabled"} the flag ${this[flag]}.")
- }
+ }.withHelp("Enable or disable a diagnostic logging stream")
}
}
- }
+ thenExecute {
+ reply("Effective debug flags: \n${NEUDebugFlag.getEnabledFlags()}")
+ }
+ }.withHelp("Log diagnostic data.")
}
}
}
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/NEUStatsCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/NEUStatsCommand.kt
index 97d1edb3..7035aaa3 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/NEUStatsCommand.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/NEUStatsCommand.kt
@@ -31,6 +31,7 @@ import io.github.moulberry.notenoughupdates.util.SBInfo
import io.github.moulberry.notenoughupdates.util.brigadier.reply
import io.github.moulberry.notenoughupdates.util.brigadier.thenExecute
import io.github.moulberry.notenoughupdates.util.brigadier.thenLiteralExecute
+import io.github.moulberry.notenoughupdates.util.brigadier.withHelp
import net.minecraft.client.Minecraft
import net.minecraft.client.renderer.OpenGlHelper
import net.minecraft.command.ICommandSender
@@ -54,23 +55,13 @@ class NEUStatsCommand {
@SubscribeEvent
fun onCommands(event: RegisterBrigadierCommandEvent) {
event.command("stats", "neustats") {
- thenExecute {
- clipboardAndSendMessage(
- DiscordMarkdownBuilder()
- .also(::appendStats)
- .also {
- if (Loader.instance().activeModList.size <= 15) appendModList(it)
- }
- .toString()
- )
- }
thenLiteralExecute("modlist") {
clipboardAndSendMessage(
DiscordMarkdownBuilder()
.also(::appendModList)
.toString()
)
- }
+ }.withHelp("Copy the mod list to your clipboard")
thenLiteralExecute("full") {
clipboardAndSendMessage(
DiscordMarkdownBuilder()
@@ -78,14 +69,24 @@ class NEUStatsCommand {
.also(::appendModList)
.toString()
)
- }
+ }.withHelp("Copy the full list of all NEU stats and your mod list to your clipboard")
thenLiteralExecute("dump") {
reply("${GREEN}This will upload a dump of the java classes your game has loaded how big they are and how many there are. This can take a few seconds as it is uploading to HasteBin.")
uploadDataUsageDump().thenAccept {
clipboardAndSendMessage(it)
}
+ }.withHelp("Dump all loaded classes and their memory usage and copy that to your clipboard.")
+ thenExecute {
+ clipboardAndSendMessage(
+ DiscordMarkdownBuilder()
+ .also(::appendStats)
+ .also {
+ if (Loader.instance().activeModList.size <= 15) appendModList(it)
+ }
+ .toString()
+ )
}
- }
+ }.withHelp("Copy a list of NEU relevant stats to your clipboard for debugging purposes")
}
interface DiagnosticCommandMXBean {
fun gcClassHistogram(array: Array<String>): String
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/PackDevCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/PackDevCommand.kt
index 6c1fa371..fceacfab 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/PackDevCommand.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/PackDevCommand.kt
@@ -36,6 +36,7 @@ import net.minecraft.entity.item.EntityArmorStand
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.item.ItemStack
import net.minecraft.util.EnumChatFormatting
+import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@NEUAutoSubscribe
class PackDevCommand {
@@ -61,14 +62,14 @@ class PackDevCommand {
thenLiteral(singleCommand) {
thenArgumentExecute("distance", doubleArg(0.0)) { dist ->
val dist = this[dist]
- val entity = getEntities(dist).firstOrNull()
+ val entity = getEntities(dist).minByOrNull { it.getDistanceSqToEntity(Minecraft.getMinecraft().thePlayer) }
if (entity == null) {
reply("No $name found within $dist blocks")
return@thenArgumentExecute
}
MiscUtils.copyToClipboard(StringBuilder().appendEntityData(entity).toString().trim())
reply("Copied data to clipboard")
- }
+ }.withHelp("Find the nearest $name and copy data about them to your clipboard")
}
thenLiteral(multipleCommand) {
thenArgumentExecute("distance", doubleArg(0.0)) { dist ->
@@ -84,7 +85,7 @@ class PackDevCommand {
reply("Copied data to clipboard")
}
- }
+ }.withHelp("Find all $name within range and copy data about them to your clipboard")
}
}
@@ -136,16 +137,9 @@ class PackDevCommand {
}
+ @SubscribeEvent
fun onCommands(event: RegisterBrigadierCommandEvent) {
event.command("neupackdev") {
- thenExecute {
- NotEnoughUpdates.INSTANCE.packDevEnabled = !NotEnoughUpdates.INSTANCE.packDevEnabled
- if (NotEnoughUpdates.INSTANCE.packDevEnabled) {
- reply("${EnumChatFormatting.GREEN}Enabled pack developer mode.")
- } else {
- reply("${EnumChatFormatting.RED}Disabled pack developer mode.")
- }
- }
npcListCommand("Player", "getplayer", "getplayers", AbstractClientPlayer::class.java) {
Minecraft.getMinecraft().theWorld.playerEntities
}
@@ -158,6 +152,14 @@ class PackDevCommand {
npcListCommand("armor stand", "getarmorstand", "getarmorstands", EntityArmorStand::class.java) {
Minecraft.getMinecraft().theWorld.loadedEntityList
}
- }
+ thenExecute {
+ NotEnoughUpdates.INSTANCE.packDevEnabled = !NotEnoughUpdates.INSTANCE.packDevEnabled
+ if (NotEnoughUpdates.INSTANCE.packDevEnabled) {
+ reply("${EnumChatFormatting.GREEN}Enabled pack developer mode.")
+ } else {
+ reply("${EnumChatFormatting.RED}Disabled pack developer mode.")
+ }
+ }
+ }.withHelp("Toggle pack developer mode")
}
}
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/SimpleDevCommands.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/SimpleDevCommands.kt
index 2990b24d..c8c9c1e0 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/SimpleDevCommands.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/dev/SimpleDevCommands.kt
@@ -44,16 +44,16 @@ class SimpleDevCommands {
NotEnoughUpdates.INSTANCE.manager.reloadRepository()
reply("§e[NEU] Reloaded repository.")
}
- }
+ }.withHelp("Reload the NEU data repository from disk (not from network)")
event.command("neudungeonwintest") {
- thenExecute {
- DungeonWin.displayWin()
- }
thenArgumentExecute("file", string()) { file ->
DungeonWin.TEAM_SCORE = ResourceLocation("notenoughupdates:dungeon_win/${this[file].lowercase()}.png")
reply("Changed the dungeon win display")
+ }.withHelp("Change the dungeon win test to load from a file")
+ thenExecute {
+ DungeonWin.displayWin()
}
- }
+ }.withHelp("Display the dungeon win pop up")
event.command("neuenablestorage") {
thenLiteralExecute("disable") {
NotEnoughUpdates.INSTANCE.config.storageGUI.enableStorageGUI3 = true
@@ -64,7 +64,7 @@ class SimpleDevCommands {
"/neuenablestorage"
)
}
- }
+ }.withHelp("Disable the neu storage overlay")
thenExecute {
NotEnoughUpdates.INSTANCE.config.storageGUI.enableStorageGUI3 = true
NotEnoughUpdates.INSTANCE.saveConfig()
@@ -75,27 +75,27 @@ class SimpleDevCommands {
)
}
}
- }
+ }.withHelp("Enable the neu storage overlay")
event.command("neuzeesphere") {
thenLiteralExecute("on") {
NullzeeSphere.enabled = true
reply("Enabled nullzee sphere")
- }
+ }.withHelp("Enable nullzee sphere")
thenLiteralExecute("off") {
NullzeeSphere.enabled = false
reply("Disabled nullzee sphere")
- }
+ }.withHelp("Disable nullzee sphere")
thenLiteralExecute("setcenter") {
val p = source as EntityPlayerSP
NullzeeSphere.centerPos = BlockPos(p.posX, p.posY, p.posZ)
NullzeeSphere.overlayVBO = null
reply("Set center to ${NullzeeSphere.centerPos}")
- }
+ }.withHelp("Set the center of the nullzee sphere")
thenArgumentExecute("radius", floatArg(0F)) { size ->
NullzeeSphere.size = this[size]
NullzeeSphere.overlayVBO = null
reply("Set size to ${this[size]}")
- }
+ }.withHelp("Set the radius of the nullzee sphere")
}
event.command("neuresetrepo") {
thenExecute {
@@ -105,6 +105,6 @@ class SimpleDevCommands {
it.forEach(::reply)
}
}
- }
+ }.withHelp("Reload the NEU data repository from network")
}
}
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/FeaturesCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/FeaturesCommand.kt
index 49b08d48..6cc4e255 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/FeaturesCommand.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/FeaturesCommand.kt
@@ -25,6 +25,7 @@ import io.github.moulberry.notenoughupdates.util.Constants
import io.github.moulberry.notenoughupdates.util.Utils
import io.github.moulberry.notenoughupdates.util.brigadier.reply
import io.github.moulberry.notenoughupdates.util.brigadier.thenExecute
+import io.github.moulberry.notenoughupdates.util.brigadier.withHelp
import net.minecraft.event.ClickEvent
import net.minecraft.util.ChatComponentText
import net.minecraft.util.EnumChatFormatting
@@ -58,8 +59,7 @@ class FeaturesCommand {
reply(clickTextFeatures)
}
reply("")
-
}
- }
+ }.withHelp("List all of NEUs features")
}
}
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/HelpCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/HelpCommand.kt
index 0b7ad503..1b4f817e 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/HelpCommand.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/HelpCommand.kt
@@ -23,10 +23,7 @@ import com.mojang.brigadier.arguments.StringArgumentType.string
import io.github.moulberry.notenoughupdates.NotEnoughUpdates
import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe
import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent
-import io.github.moulberry.notenoughupdates.util.brigadier.get
-import io.github.moulberry.notenoughupdates.util.brigadier.reply
-import io.github.moulberry.notenoughupdates.util.brigadier.thenArgumentExecute
-import io.github.moulberry.notenoughupdates.util.brigadier.thenExecute
+import io.github.moulberry.notenoughupdates.util.brigadier.*
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@NEUAutoSubscribe
@@ -83,14 +80,16 @@ class HelpCommand {
reply("Could not find NEU command with name ${this[commandName]}")
return@thenArgumentExecute
}
- reply(event.dispatcher.getAllUsage(commandNode, source, true).joinToString("\n"))
- }
+ reply(event.brigadierRoot.getAllUsages("/${this[commandName]}", commandNode).joinToString("\n"){
+ "${it.path} - ${it.help}"
+ })
+ }.withHelp("Display help for a specific NEU command")
thenExecute {
neuHelpMessages.forEach(::reply)
if (NotEnoughUpdates.INSTANCE.config.hidden.dev)
neuDevHelpMessages.forEach(::reply)
helpInfo.forEach(::reply)
}
- }
+ }.withHelp("Display a list of all NEU commands")
}
}
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/LinksCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/LinksCommand.kt
index c6947644..7f5bf913 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/LinksCommand.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/LinksCommand.kt
@@ -25,6 +25,7 @@ import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent
import io.github.moulberry.notenoughupdates.util.Utils
import io.github.moulberry.notenoughupdates.util.brigadier.reply
import io.github.moulberry.notenoughupdates.util.brigadier.thenExecute
+import io.github.moulberry.notenoughupdates.util.brigadier.withHelp
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@NEUAutoSubscribe
@@ -48,6 +49,6 @@ class LinksCommand {
Utils.showOutdatedRepoNotification()
}
}
- }
+ }.withHelp("Display links for Moulberry and NEU")
}
}
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/SettingsCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/SettingsCommand.kt
index 719d6957..07d4d203 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/SettingsCommand.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/SettingsCommand.kt
@@ -24,10 +24,7 @@ import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe
import io.github.moulberry.notenoughupdates.core.GuiScreenElementWrapper
import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent
import io.github.moulberry.notenoughupdates.options.NEUConfigEditor
-import io.github.moulberry.notenoughupdates.util.brigadier.RestArgumentType
-import io.github.moulberry.notenoughupdates.util.brigadier.get
-import io.github.moulberry.notenoughupdates.util.brigadier.thenArgumentExecute
-import io.github.moulberry.notenoughupdates.util.brigadier.thenExecute
+import io.github.moulberry.notenoughupdates.util.brigadier.*
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@NEUAutoSubscribe
@@ -35,10 +32,6 @@ class SettingsCommand {
@SubscribeEvent
fun onCommands(event: RegisterBrigadierCommandEvent) {
event.command("neu", "neusettings") {
- thenExecute {
- NotEnoughUpdates.INSTANCE.openGui =
- GuiScreenElementWrapper(NEUConfigEditor(NotEnoughUpdates.INSTANCE.config))
- }
thenArgumentExecute("search", RestArgumentType) { search ->
NotEnoughUpdates.INSTANCE.openGui = GuiScreenElementWrapper(
NEUConfigEditor(
@@ -46,7 +39,11 @@ class SettingsCommand {
this[search]
)
)
+ }.withHelp("Search the NEU settings")
+ thenExecute {
+ NotEnoughUpdates.INSTANCE.openGui =
+ GuiScreenElementWrapper(NEUConfigEditor(NotEnoughUpdates.INSTANCE.config))
}
- }
+ }.withHelp("Open the NEU settings")
}
}
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/StorageViewerWhyCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/StorageViewerWhyCommand.kt
index 66957e94..782eaf3d 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/StorageViewerWhyCommand.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/help/StorageViewerWhyCommand.kt
@@ -22,6 +22,7 @@ import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe
import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent
import io.github.moulberry.notenoughupdates.util.NotificationHandler
import io.github.moulberry.notenoughupdates.util.brigadier.thenExecute
+import io.github.moulberry.notenoughupdates.util.brigadier.withHelp
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@NEUAutoSubscribe
@@ -42,6 +43,6 @@ class StorageViewerWhyCommand {
), true
)
}
- }
+ }.withHelp("Display information about why you have to click twice in the NEU storage overlay")
}
}
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/FairySoulsCommand.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/FairySoulsCommand.kt
index 9edb36f1..1d766646 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/FairySoulsCommand.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/commands/misc/FairySoulsCommand.kt
@@ -22,10 +22,7 @@ package io.github.moulberry.notenoughupdates.commands.misc
import io.github.moulberry.notenoughupdates.autosubscribe.NEUAutoSubscribe
import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent
import io.github.moulberry.notenoughupdates.miscfeatures.FairySouls
-import io.github.moulberry.notenoughupdates.util.brigadier.literal
-import io.github.moulberry.notenoughupdates.util.brigadier.reply
-import io.github.moulberry.notenoughupdates.util.brigadier.thenLiteral
-import io.github.moulberry.notenoughupdates.util.brigadier.thenLiteralExecute
+import io.github.moulberry.notenoughupdates.util.brigadier.*
import net.minecraft.util.EnumChatFormatting.DARK_PURPLE
import net.minecraft.util.EnumChatFormatting.RED
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
@@ -43,22 +40,22 @@ class FairySoulsCommand {
}
reply("${DARK_PURPLE}Enabled fairy soul waypoints")
FairySouls.getInstance().setShowFairySouls(true)
- }
+ }.withHelp("Show fairy soul waypoints")
thenLiteral("on") { redirect(enable) }
val disable = thenLiteralExecute("disable") {
FairySouls.getInstance().setShowFairySouls(false)
reply("${DARK_PURPLE}Disabled fairy soul waypoints")
- }
+ }.withHelp("Hide fairy soul waypoints")
thenLiteral("off") { redirect(disable) }
val clear = thenLiteralExecute("clear") {
FairySouls.getInstance().markAllAsFound()
// Reply handled by mark all as found
- }
+ }.withHelp("Mark all fairy souls in your current world as found")
thenLiteral("markfound") { redirect(clear) }
val unclear = thenLiteralExecute("unclear") {
FairySouls.getInstance().markAllAsMissing()
// Reply handled by mark all as missing
- }
+ }.withHelp("Mark all fairy souls in your current world as not found")
thenLiteral("marknotfound") { redirect(unclear) }
}
}
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/BrigadierRoot.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/BrigadierRoot.kt
index f11738fc..8035c77e 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/BrigadierRoot.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/BrigadierRoot.kt
@@ -28,6 +28,7 @@ import io.github.moulberry.notenoughupdates.events.RegisterBrigadierCommandEvent
import io.github.moulberry.notenoughupdates.util.LRUCache
import net.minecraft.command.ICommandSender
import net.minecraftforge.client.ClientCommandHandler
+import java.lang.RuntimeException
import java.util.*
@NEUAutoSubscribe
@@ -45,6 +46,9 @@ object BrigadierRoot {
}
fun setHelpForNode(node: CommandNode<DefaultSource>, helpText: String) {
+ if (node.command == null) {
+ RuntimeException("Warning: Setting help on node that cannot be executed. Will be ignored").printStackTrace()
+ }
help[node] = helpText
}
@@ -52,15 +56,22 @@ object BrigadierRoot {
fun getAllUsages(
path: String,
node: CommandNode<ICommandSender>,
- visited: MutableSet<CommandNode<ICommandSender>>
+ visited: MutableSet<CommandNode<ICommandSender>> = mutableSetOf()
): Sequence<NEUBrigadierHook.Usage> = sequence {
if (node in visited) return@sequence
visited.add(node)
- yield(NEUBrigadierHook.Usage(path, getHelpForNode(node)))
+ val redirect = node.redirect
+ if (redirect != null) {
+ yieldAll(getAllUsages(path, node, visited))
+ visited.remove(node)
+ return@sequence
+ }
+ if (node.command != null)
+ yield(NEUBrigadierHook.Usage(path, getHelpForNode(node)))
node.children.forEach {
- val nodeName = when(node) {
- is ArgumentCommandNode<*, *> -> "<${node.name}>"
- else -> node.name
+ val nodeName = when (it) {
+ is ArgumentCommandNode<*, *> -> "<${it.name}>"
+ else -> it.name
}
yieldAll(getAllUsages("$path $nodeName", it, visited))
}
diff --git a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/dsl.kt b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/dsl.kt
index 96efd1aa..f6a326dc 100644
--- a/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/dsl.kt
+++ b/src/main/kotlin/io/github/moulberry/notenoughupdates/util/brigadier/dsl.kt
@@ -31,6 +31,7 @@ import io.github.moulberry.notenoughupdates.util.iterate
import net.minecraft.command.ICommandSender
import net.minecraft.util.ChatComponentText
import net.minecraft.util.IChatComponent
+import java.lang.RuntimeException
import java.lang.reflect.ParameterizedType
import java.lang.reflect.Type
import java.lang.reflect.TypeVariable
@@ -151,4 +152,14 @@ fun <T : ArgumentBuilder<DefaultSource, T>> T.thenExecute(block: CommandContext<
1
}
+fun NEUBrigadierHook.withHelp(helpText: String): NEUBrigadierHook {
+ commandNode.withHelp(helpText)
+ return this
+}
+
+fun <T : CommandNode<DefaultSource>> T.withHelp(helpText: String): T {
+ BrigadierRoot.setHelpForNode(this, helpText)
+ return this
+}
+