38 lines
1.3 KiB
Java
38 lines
1.3 KiB
Java
package org.branulf.scrafitipty;
|
|
|
|
import net.minecraft.client.MinecraftClient;
|
|
import net.minecraft.client.gui.screen.ChatScreen;
|
|
import net.minecraft.text.Text;
|
|
|
|
public class BuiltInFunctions {
|
|
public static void execute(String function, String args) {
|
|
switch (function.toLowerCase()) {
|
|
case "chat" -> sendChat(args.replace("\"", ""));
|
|
case "command" -> sendCommand(args.replace("\"", ""));
|
|
case "sleep" -> sleep(Integer.parseInt(args));
|
|
case "opengui" -> MinecraftClient.getInstance().setScreen(new ChatScreen(""));
|
|
case "crash" -> throw new RuntimeException("Script forced crash");
|
|
}
|
|
}
|
|
|
|
private static void sendChat(String message) {
|
|
MinecraftClient client = MinecraftClient.getInstance();
|
|
if (client.player != null) {
|
|
client.player.networkHandler.sendChatMessage(message);
|
|
}
|
|
}
|
|
|
|
private static void sendCommand(String command) {
|
|
MinecraftClient client = MinecraftClient.getInstance();
|
|
if (client.player != null) {
|
|
client.player.networkHandler.sendChatCommand(command);
|
|
}
|
|
}
|
|
|
|
private static void sleep(int milliseconds) {
|
|
try {
|
|
Thread.sleep(milliseconds);
|
|
} catch (InterruptedException ignored) {}
|
|
}
|
|
}
|