mirror of
https://github.com/kami-blue/client
synced 2025-04-04 23:40:51 +00:00
Kotlinized Spammer and added delay for when chat is open
This commit is contained in:
commit
20c5f2b515
@ -1,96 +0,0 @@
|
|||||||
package me.zeroeightsix.kami.module.modules.chat;
|
|
||||||
|
|
||||||
import me.zeroeightsix.kami.module.Module;
|
|
||||||
import me.zeroeightsix.kami.setting.Setting;
|
|
||||||
import me.zeroeightsix.kami.setting.Settings;
|
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.InputStreamReader;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Random;
|
|
||||||
|
|
||||||
import static me.zeroeightsix.kami.util.MessageSendHelper.*;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @author dominikaaaa
|
|
||||||
* Created by dominikaaaa on 10/04/20
|
|
||||||
*/
|
|
||||||
@Module.Info(
|
|
||||||
name = "Spammer",
|
|
||||||
description = "Spams text from a file on a set delay into the chat",
|
|
||||||
category = Module.Category.CHAT
|
|
||||||
)
|
|
||||||
public class Spammer extends Module {
|
|
||||||
private Setting<Mode> modeSetting = register(Settings.e("Order", Mode.RANDOM_ORDER));
|
|
||||||
private Setting<Integer> timeoutTime = register(Settings.integerBuilder().withName("Timeout(s)").withMinimum(1).withMaximum(240).withValue(10).build());
|
|
||||||
|
|
||||||
private List<String> tempLines = new ArrayList<>();
|
|
||||||
private String[] spammer;
|
|
||||||
private static int currentLine = 0;
|
|
||||||
private enum Mode { IN_ORDER, RANDOM_ORDER }
|
|
||||||
|
|
||||||
public void onEnable() {
|
|
||||||
BufferedReader bufferedReader;
|
|
||||||
try {
|
|
||||||
sendChatMessage(getChatName() + " Trying to find '&7spammer.txt&f'");
|
|
||||||
bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream("spammer.txt"), "UTF-8"));
|
|
||||||
String line;
|
|
||||||
tempLines.clear();
|
|
||||||
while ((line = bufferedReader.readLine()) != null) {
|
|
||||||
tempLines.add(line);
|
|
||||||
}
|
|
||||||
bufferedReader.close();
|
|
||||||
spammer = tempLines.toArray(new String[]{});
|
|
||||||
} catch (FileNotFoundException exception) {
|
|
||||||
sendErrorMessage(getChatName() + " Couldn't find a file called '&7spammer.txt&f' inside your '&7.minecraft&f' folder, disabling");
|
|
||||||
disable();
|
|
||||||
return;
|
|
||||||
} catch (IOException exception) {
|
|
||||||
sendErrorMessage(exception.toString());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
sendChatMessage(getChatName() + " Found '&7spammer.txt&f'!");
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onUpdate() {
|
|
||||||
sendMsg();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static long startTime = 0;
|
|
||||||
private void sendMsg() {
|
|
||||||
String message = "";
|
|
||||||
if (startTime == 0) startTime = System.currentTimeMillis();
|
|
||||||
|
|
||||||
if (startTime + (timeoutTime.getValue() * 1000) <= System.currentTimeMillis()) { // 1 timeout = 1 second = 1000 ms
|
|
||||||
startTime = System.currentTimeMillis();
|
|
||||||
switch (modeSetting.getValue()) {
|
|
||||||
case IN_ORDER:
|
|
||||||
message = getOrdered(spammer);
|
|
||||||
break;
|
|
||||||
case RANDOM_ORDER:
|
|
||||||
message = getRandom(spammer);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
sendServerMessage(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getOrdered(String[] array) {
|
|
||||||
currentLine++;
|
|
||||||
if (currentLine > array.length - 1) currentLine = 0;
|
|
||||||
return array[currentLine];
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getRandom(String[] array) {
|
|
||||||
int rand = new Random().nextInt(array.length);
|
|
||||||
while (array[rand].isEmpty() || array[rand].equals(" ")) {
|
|
||||||
rand = new Random().nextInt(array.length); // big meme to try to avoid sending empty messages
|
|
||||||
}
|
|
||||||
return array[rand];
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,93 @@
|
|||||||
|
package me.zeroeightsix.kami.module.modules.chat
|
||||||
|
|
||||||
|
import me.zeroeightsix.kami.module.Module
|
||||||
|
import me.zeroeightsix.kami.setting.Settings
|
||||||
|
import me.zeroeightsix.kami.util.MessageSendHelper.*
|
||||||
|
import net.minecraft.client.gui.GuiChat
|
||||||
|
import java.io.*
|
||||||
|
import kotlin.random.Random
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author dominikaaaa
|
||||||
|
* Created by dominikaaaa on 10/04/20
|
||||||
|
* Updated by Xiaro on 27/6/20
|
||||||
|
*/
|
||||||
|
@Module.Info(
|
||||||
|
name = "Spammer",
|
||||||
|
description = "Spams text from a file on a set delay into the chat",
|
||||||
|
category = Module.Category.CHAT
|
||||||
|
)
|
||||||
|
class Spammer : Module() {
|
||||||
|
private val modeSetting = register(Settings.e<Mode>("Order", Mode.RANDOM_ORDER))
|
||||||
|
private val timeoutTime = register(Settings.integerBuilder("Timeout (s)").withRange(1, 240).withValue(10).build())
|
||||||
|
|
||||||
|
private var spammer = ArrayList<String>()
|
||||||
|
private var currentLine = 0
|
||||||
|
private var startTime = 0L
|
||||||
|
private var isChatOpen = false
|
||||||
|
|
||||||
|
private enum class Mode { IN_ORDER, RANDOM_ORDER }
|
||||||
|
|
||||||
|
override fun onEnable() {
|
||||||
|
val bufferedReader: BufferedReader
|
||||||
|
try {
|
||||||
|
sendChatMessage("$chatName Trying to find '&7spammer.txt&f'")
|
||||||
|
bufferedReader = BufferedReader(InputStreamReader(FileInputStream("spammer.txt"), "UTF-8"))
|
||||||
|
spammer.clear()
|
||||||
|
var str = bufferedReader.readLine()
|
||||||
|
while (str != null) {
|
||||||
|
spammer.add(str)
|
||||||
|
str = bufferedReader.readLine()
|
||||||
|
}
|
||||||
|
bufferedReader.close()
|
||||||
|
} catch (exception: FileNotFoundException) {
|
||||||
|
sendErrorMessage("$chatName Couldn't find a file called '&7spammer.txt&f' inside your '&7.minecraft&f' folder, disabling")
|
||||||
|
disable()
|
||||||
|
return
|
||||||
|
} catch (exception: IOException) {
|
||||||
|
sendErrorMessage(exception.toString())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
sendChatMessage("$chatName Found '&7spammer.txt&f'!")
|
||||||
|
startTime = System.currentTimeMillis()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onUpdate() {
|
||||||
|
sendMsg()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun sendMsg() {
|
||||||
|
if (startTime + (timeoutTime.value * 1000) <= System.currentTimeMillis()) { // 1 timeout = 1 second = 1000 ms
|
||||||
|
when {
|
||||||
|
mc.currentScreen is GuiChat -> { /* Delays the spammer msg if the chat gui is open */
|
||||||
|
startTime = System.currentTimeMillis() - (timeoutTime.value * 1000)
|
||||||
|
isChatOpen = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
isChatOpen -> { /* Adds extra delay after the chat gui is closed */
|
||||||
|
startTime += 3000
|
||||||
|
isChatOpen = false
|
||||||
|
}
|
||||||
|
else -> {
|
||||||
|
startTime = System.currentTimeMillis()
|
||||||
|
if (modeSetting.value == Mode.IN_ORDER) {
|
||||||
|
sendServerMessage(getOrdered(spammer))
|
||||||
|
} else {
|
||||||
|
sendServerMessage(getRandom(spammer, currentLine))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getOrdered(array: ArrayList<String>): String {
|
||||||
|
if (currentLine >= array.size) currentLine = 0
|
||||||
|
currentLine++
|
||||||
|
return array[currentLine - 1]
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getRandom(array: ArrayList<String>, LastLine: Int): String {
|
||||||
|
while (currentLine == LastLine) currentLine = Random.nextInt(array.size) /* Avoids sending the same message */
|
||||||
|
return array[currentLine]
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user