generated from Tryflle/kotlin-base
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
367 additions
and
29 deletions.
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
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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
rootProject.name = "ExampleMod" | ||
rootProject.name = "KtLon" | ||
|
||
pluginManagement { | ||
repositories { | ||
|
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,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()) | ||
} | ||
} |
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,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) | ||
} | ||
} |
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,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) | ||
} | ||
} |
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,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.") | ||
} | ||
} | ||
} |
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,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("---------------------------------------------------") | ||
} | ||
} |
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,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) | ||
} | ||
} |
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,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() | ||
} | ||
} |
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,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
29
src/main/kotlin/me/tryfle/ktlon/listener/WorldLoadListener.kt
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,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) | ||
} | ||
} |
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,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() | ||
} | ||
} |
Oops, something went wrong.