From 9a4d3276a122ca4c17d393ed4e840b869e29a863 Mon Sep 17 00:00:00 2001 From: NoahTheNerd Date: Fri, 7 Jun 2024 22:21:05 +0200 Subject: [PATCH] Implement identity return command, visibility action and more. --- .../live/ixnoah/tapactions/TapActions.kt | 10 ++++--- .../tapactions/actions/GeneralActions.kt | 28 +++++++++++++++---- .../ixnoah/tapactions/actions/HudActions.kt | 2 +- .../tapactions/commands/CommandQueue.kt | 8 ++++-- ...reateCommand.kt => CreateActionCommand.kt} | 8 ++++-- .../ixnoah/tapactions/events/ClientTick.kt | 17 +++++++++++ .../ixnoah/tapactions/events/WorldLoad.kt | 5 ++-- 7 files changed, 62 insertions(+), 16 deletions(-) rename src/main/kotlin/live/ixnoah/tapactions/commands/{CreateCommand.kt => CreateActionCommand.kt} (83%) create mode 100644 src/main/kotlin/live/ixnoah/tapactions/events/ClientTick.kt diff --git a/src/main/kotlin/live/ixnoah/tapactions/TapActions.kt b/src/main/kotlin/live/ixnoah/tapactions/TapActions.kt index 0564f83..4a0f5e3 100644 --- a/src/main/kotlin/live/ixnoah/tapactions/TapActions.kt +++ b/src/main/kotlin/live/ixnoah/tapactions/TapActions.kt @@ -2,7 +2,8 @@ package live.ixnoah.tapactions import live.ixnoah.tapactions.actions.GeneralActions import live.ixnoah.tapactions.actions.HudActions -import live.ixnoah.tapactions.commands.CreateCommand +import live.ixnoah.tapactions.commands.CreateActionCommand +import live.ixnoah.tapactions.events.ClientTick import live.ixnoah.tapactions.events.WorldLoad import net.minecraft.client.Minecraft import net.minecraftforge.client.ClientCommandHandler @@ -26,13 +27,14 @@ class TapActions { throw java.lang.RuntimeException(e) } // Commands - ClientCommandHandler.instance.registerCommand(CreateCommand()) + ClientCommandHandler.instance.registerCommand(CreateActionCommand()) // Events MinecraftForge.EVENT_BUS.register(WorldLoad()) + MinecraftForge.EVENT_BUS.register(ClientTick()) // Deploy actions - GeneralActions().deploy() - HudActions().deploy() + GeneralActions.deploy() + HudActions.deploy() } } diff --git a/src/main/kotlin/live/ixnoah/tapactions/actions/GeneralActions.kt b/src/main/kotlin/live/ixnoah/tapactions/actions/GeneralActions.kt index 746fd3f..7eec181 100644 --- a/src/main/kotlin/live/ixnoah/tapactions/actions/GeneralActions.kt +++ b/src/main/kotlin/live/ixnoah/tapactions/actions/GeneralActions.kt @@ -1,21 +1,39 @@ package live.ixnoah.tapactions.actions +import CommandQueue import live.ixnoah.tapactions.ActionManager import live.ixnoah.tapactions.wrappers.Scoreboard -class GeneralActions { +object GeneralActions { private val nameRegex = Regex("^[0-9A-z '\"!@#\$%^*?]{0,20}\$") + var hasStatedIdentity = false - /** This can be used to show the identity of a house, like name, links & description! :D */ + /** This can be used to show the identity of a house, like name, links & description! */ private val actionIdentity = { params : MutableMap -> - val paramName = params["name"] ?: "Housing" + if (!hasStatedIdentity) { + hasStatedIdentity = true + val paramName = params["name"] ?: "Housing" - if (nameRegex.containsMatchIn(paramName)) { - Scoreboard.setTitle("§e§l" + paramName.uppercase()) + if (nameRegex.containsMatchIn(paramName)) { + Scoreboard.setTitle("§e§l" + paramName.uppercase()) + } + + if (params["run"] !== null) { + CommandQueue.pushCommand("house:${params["run"]}") + } + } + } + + private val actionVisibility = { params : MutableMap -> + val paramVis : Int? = params["max"]?.toIntOrNull() + + if (paramVis !== null) { + CommandQueue.pushCommand("visibility $paramVis") } } fun deploy() { ActionManager.registerAction("tap:identity", actionIdentity) + ActionManager.registerAction("tap:visibility", actionVisibility) } } \ No newline at end of file diff --git a/src/main/kotlin/live/ixnoah/tapactions/actions/HudActions.kt b/src/main/kotlin/live/ixnoah/tapactions/actions/HudActions.kt index c3a6660..9f61f69 100644 --- a/src/main/kotlin/live/ixnoah/tapactions/actions/HudActions.kt +++ b/src/main/kotlin/live/ixnoah/tapactions/actions/HudActions.kt @@ -3,7 +3,7 @@ package live.ixnoah.tapactions.actions import live.ixnoah.tapactions.ActionManager import net.minecraft.entity.boss.BossStatus -class HudActions { +object HudActions { private val actionBossbar = { params : MutableMap -> if (params["no-clear"] == null) { BossStatus.statusBarTime = Int.MAX_VALUE diff --git a/src/main/kotlin/live/ixnoah/tapactions/commands/CommandQueue.kt b/src/main/kotlin/live/ixnoah/tapactions/commands/CommandQueue.kt index d0c8d29..5d08e9d 100644 --- a/src/main/kotlin/live/ixnoah/tapactions/commands/CommandQueue.kt +++ b/src/main/kotlin/live/ixnoah/tapactions/commands/CommandQueue.kt @@ -11,9 +11,13 @@ object CommandQueue { if (queue.size == 0) return val command = queue.first() - queue.drop(1) + queue = queue.drop(1).toMutableList() - Minecraft.getMinecraft().thePlayer.sendChatMessage("/" + command) + Minecraft.getMinecraft().thePlayer.sendChatMessage("/$command") + } + + fun onTick(tick: Int) { + if (tick == 1) runNextCommand() } fun clearQueue() { diff --git a/src/main/kotlin/live/ixnoah/tapactions/commands/CreateCommand.kt b/src/main/kotlin/live/ixnoah/tapactions/commands/CreateActionCommand.kt similarity index 83% rename from src/main/kotlin/live/ixnoah/tapactions/commands/CreateCommand.kt rename to src/main/kotlin/live/ixnoah/tapactions/commands/CreateActionCommand.kt index ade077d..4c44d8e 100644 --- a/src/main/kotlin/live/ixnoah/tapactions/commands/CreateCommand.kt +++ b/src/main/kotlin/live/ixnoah/tapactions/commands/CreateActionCommand.kt @@ -6,11 +6,15 @@ import net.minecraft.command.CommandException import net.minecraft.command.ICommandSender import net.minecraft.util.ChatComponentText -class CreateCommand: CommandBase() { +class CreateActionCommand: CommandBase() { private val splitter = " | " override fun getCommandName(): String { - return "createaction" + return "tap:createaction" + } + + override fun getCommandAliases(): MutableList { + return mutableListOf("createaction", "ca") } override fun getCommandUsage(sender: ICommandSender?): String { diff --git a/src/main/kotlin/live/ixnoah/tapactions/events/ClientTick.kt b/src/main/kotlin/live/ixnoah/tapactions/events/ClientTick.kt new file mode 100644 index 0000000..614089e --- /dev/null +++ b/src/main/kotlin/live/ixnoah/tapactions/events/ClientTick.kt @@ -0,0 +1,17 @@ +package live.ixnoah.tapactions.events + +import CommandQueue +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent +import net.minecraftforge.fml.common.gameevent.TickEvent.ClientTickEvent + +class ClientTick { + private var tick = 0; + + @SubscribeEvent + fun onEvent(event: ClientTickEvent) { + if (tick > 20) tick = 0 + tick += 1 + + CommandQueue.onTick(tick) + } +} \ No newline at end of file diff --git a/src/main/kotlin/live/ixnoah/tapactions/events/WorldLoad.kt b/src/main/kotlin/live/ixnoah/tapactions/events/WorldLoad.kt index fbe728f..a57c0bc 100644 --- a/src/main/kotlin/live/ixnoah/tapactions/events/WorldLoad.kt +++ b/src/main/kotlin/live/ixnoah/tapactions/events/WorldLoad.kt @@ -1,7 +1,7 @@ package live.ixnoah.tapactions.events -import live.ixnoah.tapactions.commands.CommandQueue - +import CommandQueue +import live.ixnoah.tapactions.actions.GeneralActions import net.minecraft.client.Minecraft import net.minecraft.entity.boss.BossStatus import net.minecraftforge.event.entity.EntityJoinWorldEvent @@ -14,5 +14,6 @@ class WorldLoad { BossStatus.statusBarTime = 0 // clears the bossbar CommandQueue.clearQueue() + GeneralActions.hasStatedIdentity = false } }