Skip to content

Commit

Permalink
💟 Initial
Browse files Browse the repository at this point in the history
  • Loading branch information
Tryflle committed Jan 7, 2024
1 parent 2fa53a4 commit b73988c
Show file tree
Hide file tree
Showing 17 changed files with 367 additions and 29 deletions.
83 changes: 83 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
##############################
## Java
##############################
.mtj.tmp/
*.class
*.jar
*.war
*.ear
*.nar
hs_err_pid*
replay_pid*

##############################
## Maven
##############################
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
pom.xml.bak
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar

##############################
## Gradle
##############################
bin/
build/
.gradle
.gradletasknamecache
gradle-app.setting
!gradle-wrapper.jar

##############################
## IntelliJ
##############################
out/
.idea/
.idea_modules/
*.iml
*.ipr
*.iws

##############################
## Eclipse
##############################
.settings/
tmp/
.metadata
.classpath
.project
*.tmp
*.bak
*.swp
*~.nib
local.properties
.loadpath
.factorypath

##############################
## NetBeans
##############################
nbproject/private/
nbbuild/
dist/
nbdist/
nbactions.xml
nb-configuration.xml

##############################
## Visual Studio Code
##############################
.vscode/
.code-workspace

##############################
## OS X
##############################
.DS_Store
5 changes: 3 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
plugins {
kotlin("jvm") version "1.8.21"
kotlin("plugin.serialization") version "1.9.21"
id("com.github.weave-mc.weave-gradle") version "649dba7468"
}

group = "com.example"
group = "me.tryfle"
version = "1.0"

minecraft.version("1.8.9")
Expand All @@ -15,8 +16,8 @@ repositories {

dependencies {
compileOnly("com.github.weave-mc:weave-loader:v0.2.4")

compileOnly("org.spongepowered:mixin:0.8.5")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.1")
}

tasks.compileJava {
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
rootProject.name = "ExampleMod"
rootProject.name = "KtLon"

pluginManagement {
repositories {
Expand Down
29 changes: 29 additions & 0 deletions src/main/kotlin/me/tryfle/ktlon/Init.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package me.tryfle.ktlon

import me.tryfle.ktlon.command.*
import me.tryfle.ktlon.config.Data
import me.tryfle.ktlon.listener.ClickListener
import me.tryfle.ktlon.listener.WorldLoadListener
import net.weavemc.loader.api.ModInitializer
import net.weavemc.loader.api.command.CommandBus
import net.weavemc.loader.api.event.EventBus
import net.weavemc.loader.api.event.StartGameEvent

class Init: ModInitializer {
override fun preInit() {
println("[KtLon] Loading..")
Data.loadData()
EventBus.subscribe(StartGameEvent.Post::class.java) {
init()
}
}
private fun init() {
CommandBus.register(Help())
CommandBus.register(CPS())
CommandBus.register(Button())
CommandBus.register(Toggle())
CommandBus.register(Chance())
EventBus.subscribe(WorldLoadListener())
if (Data.instance.enabled) EventBus.subscribe(ClickListener())
}
}
13 changes: 13 additions & 0 deletions src/main/kotlin/me/tryfle/ktlon/command/Button.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package me.tryfle.ktlon.command

import me.tryfle.ktlon.config.Data
import me.tryfle.ktlon.util.Util
import net.weavemc.loader.api.command.Command

class Button: Command("ktlbutton") {
override fun handle(args: Array<out String>) {
Data.instance.isLmb = !Data.instance.isLmb
Util.msg("Button has been set to " + if (Data.instance.isLmb) "LMB" else "RMB" + ".")
Data.saveData(Data.instance)
}
}
13 changes: 13 additions & 0 deletions src/main/kotlin/me/tryfle/ktlon/command/CPS.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package me.tryfle.ktlon.command

import me.tryfle.ktlon.config.Data
import me.tryfle.ktlon.util.Util
import net.weavemc.loader.api.command.Command

class CPS: Command("ktlcps") {
override fun handle(args: Array<out String>) {
Data.instance.fiveCps = !Data.instance.fiveCps
Util.msg("5 CPS check is now " + if (Data.instance.fiveCps) "enabled" else "disabled" + ".")
Data.saveData(Data.instance)
}
}
18 changes: 18 additions & 0 deletions src/main/kotlin/me/tryfle/ktlon/command/Chance.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package me.tryfle.ktlon.command

import me.tryfle.ktlon.config.Data
import me.tryfle.ktlon.util.Util
import net.weavemc.loader.api.command.Command

class Chance: Command("ktlchance") {
override fun handle(args: Array<out String>) {
if (args[0].toInt() in 1..100) {
Data.instance.chance = args[0].toInt()
Util.msg("Chance has been set to " + args[0] + "%.")
Data.saveData(Data.instance)
}
else {
Util.msg("Please specify a chance from 1-100 in integer form.")
}
}
}
18 changes: 18 additions & 0 deletions src/main/kotlin/me/tryfle/ktlon/command/Help.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package me.tryfle.ktlon.command

import net.weavemc.loader.api.command.Command
import me.tryfle.ktlon.util.Util

class Help: Command("ktlon") {
override fun handle(args: Array<out String>) {
Util.msg("Ktlon - A double clicker for Weave written in Kotlin.")
Util.msg("---------------------------------------------------")
Util.msg("Commands:")
Util.msg("/ktlon - Shows this message.")
Util.msg("/ktlcps - Toggles 5 CPS check.")
Util.msg("/ktltoggle - Toggles the mod.")
Util.msg("/ktlbutton - Toggles between LMB and RMB modes.")
Util.msg("/ktlchance (int) - Sets the chance of a double click.")
Util.msg("---------------------------------------------------")
}
}
20 changes: 20 additions & 0 deletions src/main/kotlin/me/tryfle/ktlon/command/Toggle.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package me.tryfle.ktlon.command

import me.tryfle.ktlon.config.Data
import me.tryfle.ktlon.listener.ClickListener
import me.tryfle.ktlon.util.Util
import net.weavemc.loader.api.command.Command

class Toggle: Command("ktltoggle") {
override fun handle(args: Array<out String>) {
if (Data.instance.enabled) {
Data.instance.enabled = false
ClickListener.disable()
} else {
Data.instance.enabled = true
ClickListener.enable()
}
Util.msg("Ktlon has been " + if (Data.instance.enabled) "enabled" else "disabled" + ".")
Data.saveData(Data.instance)
}
}
30 changes: 30 additions & 0 deletions src/main/kotlin/me/tryfle/ktlon/config/Data.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package me.tryfle.ktlon.config

import kotlinx.serialization.Serializable
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import java.io.File

@Serializable
data class Data(
var firstJoin: Boolean = true,
var enabled: Boolean = false,
var fiveCps: Boolean = false,
var isLmb: Boolean = true,
var chance: Int = 50
) {
companion object {
private val filePath: String = "${System.getProperty("user.home")}/.weave/ktlonconfig.json"
private val file = File(filePath)
val instance = loadData()

fun saveData(data: Data) {
file.parentFile.mkdirs()
file.writeText(Json.encodeToString(data))
}

fun loadData(): Data = if (file.exists())
Json.decodeFromString<Data>(file.readText())
else Data()
}
}
78 changes: 78 additions & 0 deletions src/main/kotlin/me/tryfle/ktlon/listener/ClickListener.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package me.tryfle.ktlon.listener

import me.tryfle.ktlon.config.Data
import me.tryfle.ktlon.util.TimerUtil
import me.tryfle.ktlon.util.Util
import net.minecraft.client.Minecraft
import net.weavemc.loader.api.event.EventBus
import net.weavemc.loader.api.event.MouseEvent
import net.weavemc.loader.api.event.SubscribeEvent
import net.weavemc.loader.api.event.TickEvent

import java.awt.*

class ClickListener {

private var cps: Int = 0
private var t: TimerUtil = TimerUtil()
private var r = Robot()
private var shouldClick: Boolean = false

private fun getEventButton(): Int {
return if (Data.loadData().isLmb) 1 else 2
}

private fun robotGetButton(): Int {
return if (Data.loadData().isLmb) 16 else 4
}

private fun rClick() {
val sleepTime: Long = Util.randInt(30, 60).toLong()
Thread {
shouldClick = if (shouldClick) {
r.mouseRelease(robotGetButton())
r.mousePress(robotGetButton())
Thread.sleep(sleepTime)
r.mouseRelease(robotGetButton())
false
} else true
}
println("[K-Debug] Sleeping for $sleepTime")
}

@SubscribeEvent
fun onClick(e: MouseEvent) {
if (Minecraft.getMinecraft().thePlayer != null && e.button == getEventButton()) {
cps++
if (shouldClick) {
val ch: Double = Math.random() * 100;
if (ch.toInt() >= Data.instance.chance) {
println("[K-Debug] Chance missed, value $ch")
return
}
}
if (Data.instance.fiveCps && cps < 5) return
rClick()
}
}

@SubscribeEvent
fun onTick(e: TickEvent) {
if (t.hasPassed(1000)) {
cps = 0
t.reset()
}
}

companion object {
fun disable() {
EventBus.unsubscribe(this)
println("[K-Debug] Disabled ClickListener")
}

fun enable() {
EventBus.subscribe(this)
println("[K-Debug] Enabled ClickListener")
}
}
}
29 changes: 29 additions & 0 deletions src/main/kotlin/me/tryfle/ktlon/listener/WorldLoadListener.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package me.tryfle.ktlon.listener

import me.tryfle.ktlon.config.Data
import me.tryfle.ktlon.util.Util
import net.weavemc.loader.api.event.EventBus
import net.weavemc.loader.api.event.SubscribeEvent
import net.weavemc.loader.api.event.WorldEvent

class WorldLoadListener {
@SubscribeEvent
fun onWorldLoad(e: WorldEvent.Load) {
if (Data.instance.firstJoin) {
Data.instance.firstJoin = false
Data.saveData(Data.instance)
Util.msg("This is your first time using KtLon! Here's a list of commands.")
Util.msg("---------------------------------------------------")
Util.msg("Commands:")
Util.msg("/ktlon - Shows this message.")
Util.msg("/ktlcps - Toggles 5 CPS check.")
Util.msg("/ktltoggle - Toggles the mod.")
Util.msg("/ktlbutton - Toggles between LMB and RMB modes. (Default: LMB)")
Util.msg("/ktlchance (int) - Sets the chance of a double click. (Default: 50)")
Util.msg("---------------------------------------------------")
Util.msg("Remember, you can run the command /ktlon at any time to see a list of commands.")
Util.msg("By default, the mod is disabled. You can enable it by running /ktltoggle.")
}
EventBus.unsubscribe(this)
}
}
15 changes: 15 additions & 0 deletions src/main/kotlin/me/tryfle/ktlon/util/TimerUtil.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package me.tryfle.ktlon.util

class TimerUtil {
private var lastMS: Long = 0

fun hasPassed(ms: Long): Boolean {
return getCurrentMS() - lastMS >= ms
}
fun getCurrentMS(): Long {
return System.nanoTime() / 1000000
}
fun reset() {
lastMS = getCurrentMS()
}
}
Loading

0 comments on commit b73988c

Please sign in to comment.