aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorCalMWolfs <94038482+CalMWolfs@users.noreply.github.com>2023-10-21 23:11:38 +1100
committerGitHub <noreply@github.com>2023-10-21 14:11:38 +0200
commit75a4a1d4f430d74bd65d7b9beddf767586fbdf17 (patch)
treebf7392a855187f5a27089f6c23c50d9fc8087615 /src/main/java
parentbae35a31e931db572c36a45876fb168ddc4f1f5f (diff)
downloadskyhanni-75a4a1d4f430d74bd65d7b9beddf767586fbdf17.tar.gz
skyhanni-75a4a1d4f430d74bd65d7b9beddf767586fbdf17.tar.bz2
skyhanni-75a4a1d4f430d74bd65d7b9beddf767586fbdf17.zip
Backend: Change SimpleCommand to Kotlin (#564)
Backend: Change SimpleCommand to Kotlin #564
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt35
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/commands/SimpleCommand.java66
-rw-r--r--src/main/java/at/hannibal2/skyhanni/config/commands/SimpleCommand.kt55
3 files changed, 73 insertions, 83 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
index 6c00abb66..439e6cd0f 100644
--- a/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
+++ b/src/main/java/at/hannibal2/skyhanni/config/commands/Commands.kt
@@ -2,7 +2,6 @@ package at.hannibal2.skyhanni.config.commands
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.config.ConfigGuiManager
-import at.hannibal2.skyhanni.config.commands.SimpleCommand.ProcessCommandRunnable
import at.hannibal2.skyhanni.data.ChatManager
import at.hannibal2.skyhanni.data.GuiEditManager
import at.hannibal2.skyhanni.data.PartyAPI
@@ -49,6 +48,7 @@ import net.minecraft.client.Minecraft
import net.minecraft.command.ICommandSender
import net.minecraft.event.ClickEvent
import net.minecraft.event.HoverEvent
+import net.minecraft.util.BlockPos
import net.minecraft.util.ChatComponentText
import net.minecraftforge.client.ClientCommandHandler
@@ -292,7 +292,6 @@ object Commands {
// "shsendtranslation",
// "Respond with a translation of the message that the user clicks"
// ) { Translator.toEnglish(it) }
- registerCommand("shwords", "Opens the config list for modifying visual words") { openVisualWords() }
}
private fun commandHelp(args: Array<String>) {
@@ -357,11 +356,10 @@ object Commands {
config.outdatedItems.clear()
}
- private fun registerCommand(
- name: String,
- description: String,
- function: (Array<String>) -> Unit
- ) = registerCommand0(name, description, function)
+ private fun registerCommand(name: String, description: String, function: (Array<String>) -> Unit) {
+ ClientCommandHandler.instance.registerCommand(SimpleCommand(name, createCommand(function)))
+ commands.add(CommandInfo(name, description, currentCategory))
+ }
private fun registerCommand0(
name: String,
@@ -369,19 +367,22 @@ object Commands {
function: (Array<String>) -> Unit,
autoComplete: ((Array<String>) -> List<String>) = { listOf() }
) {
- ClientCommandHandler.instance.registerCommand(
- SimpleCommand(
- name,
- createCommand(function)
- ) { _, b, _ -> autoComplete(b) }
+ val command = SimpleCommand(
+ name,
+ createCommand(function),
+ object : SimpleCommand.TabCompleteRunnable {
+ override fun tabComplete(sender: ICommandSender?, args: Array<String>?, pos: BlockPos?): List<String> {
+ return autoComplete(args ?: emptyArray())
+ }
+ }
)
+ ClientCommandHandler.instance.registerCommand(command)
commands.add(CommandInfo(name, description, currentCategory))
}
- private fun createCommand(function: (Array<String>) -> Unit) =
- object : ProcessCommandRunnable() {
- override fun processCommand(sender: ICommandSender?, args: Array<out String>) {
- function(args.asList().toTypedArray())
- }
+ private fun createCommand(function: (Array<String>) -> Unit) = object : SimpleCommand.ProcessCommandRunnable() {
+ override fun processCommand(sender: ICommandSender?, args: Array<String>?) {
+ if (args != null) function(args.asList().toTypedArray())
}
+ }
}
diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/SimpleCommand.java b/src/main/java/at/hannibal2/skyhanni/config/commands/SimpleCommand.java
deleted file mode 100644
index 0bb0bd664..000000000
--- a/src/main/java/at/hannibal2/skyhanni/config/commands/SimpleCommand.java
+++ /dev/null
@@ -1,66 +0,0 @@
-package at.hannibal2.skyhanni.config.commands;
-
-import at.hannibal2.skyhanni.test.command.ErrorManager;
-import net.minecraft.command.CommandBase;
-import net.minecraft.command.ICommandSender;
-import net.minecraft.util.BlockPos;
-
-import java.util.List;
-
-/**
- * @author Moulberry
- **/
-public class SimpleCommand extends CommandBase {
-
- private final String commandName;
- private final ProcessCommandRunnable runnable;
- private TabCompleteRunnable tabRunnable;
-
- public SimpleCommand(String commandName, ProcessCommandRunnable runnable) {
- this.commandName = commandName;
- this.runnable = runnable;
- }
-
- public SimpleCommand(String commandName, ProcessCommandRunnable runnable, TabCompleteRunnable tabRunnable) {
- this.commandName = commandName;
- this.runnable = runnable;
- this.tabRunnable = tabRunnable;
- }
-
- public abstract static class ProcessCommandRunnable {
-
- public abstract void processCommand(ICommandSender sender, String[] args);
- }
-
- public interface TabCompleteRunnable {
-
- List<String> tabComplete(ICommandSender sender, String[] args, BlockPos pos);
- }
-
- public boolean canCommandSenderUseCommand(ICommandSender sender) {
- return true;
- }
-
- public String getCommandName() {
- return commandName;
- }
-
- public String getCommandUsage(ICommandSender sender) {
- return "/" + commandName;
- }
-
- @Override
- public void processCommand(ICommandSender sender, String[] args) {
- try {
- runnable.processCommand(sender, args);
- } catch (Throwable e) {
- ErrorManager.INSTANCE.logError(e, "Error while running command /" + commandName);
- }
- }
-
- @Override
- public List<String> addTabCompletionOptions(ICommandSender sender, String[] args, BlockPos pos) {
- if (tabRunnable != null) return tabRunnable.tabComplete(sender, args, pos);
- return null;
- }
-}
diff --git a/src/main/java/at/hannibal2/skyhanni/config/commands/SimpleCommand.kt b/src/main/java/at/hannibal2/skyhanni/config/commands/SimpleCommand.kt
new file mode 100644
index 000000000..59c6044c3
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/config/commands/SimpleCommand.kt
@@ -0,0 +1,55 @@
+package at.hannibal2.skyhanni.config.commands
+
+import at.hannibal2.skyhanni.test.command.ErrorManager
+import net.minecraft.command.CommandBase
+import net.minecraft.command.ICommandSender
+import net.minecraft.util.BlockPos
+
+class SimpleCommand : CommandBase {
+ private val commandName: String
+ private val runnable: ProcessCommandRunnable
+ private var tabRunnable: TabCompleteRunnable? = null
+
+ constructor(commandName: String, runnable: ProcessCommandRunnable) {
+ this.commandName = commandName
+ this.runnable = runnable
+ }
+
+ constructor(commandName: String, runnable: ProcessCommandRunnable, tabRunnable: TabCompleteRunnable?) {
+ this.commandName = commandName
+ this.runnable = runnable
+ this.tabRunnable = tabRunnable
+ }
+
+ abstract class ProcessCommandRunnable {
+ abstract fun processCommand(sender: ICommandSender?, args: Array<String>?)
+ }
+
+ interface TabCompleteRunnable {
+ fun tabComplete(sender: ICommandSender?, args: Array<String>?, pos: BlockPos?): List<String>
+ }
+
+ override fun canCommandSenderUseCommand(sender: ICommandSender): Boolean {
+ return true
+ }
+
+ override fun getCommandName(): String {
+ return commandName
+ }
+
+ override fun getCommandUsage(sender: ICommandSender): String {
+ return "/$commandName"
+ }
+
+ override fun processCommand(sender: ICommandSender, args: Array<String>) {
+ try {
+ runnable.processCommand(sender, args)
+ } catch (e: Throwable) {
+ ErrorManager.logError(e, "Error while running command /$commandName")
+ }
+ }
+
+ override fun addTabCompletionOptions(sender: ICommandSender, args: Array<String>, pos: BlockPos): List<String>? {
+ return if (tabRunnable != null) tabRunnable!!.tabComplete(sender, args, pos) else null
+ }
+} \ No newline at end of file