add custom options to autoreply

This commit is contained in:
Bella 2020-03-03 12:05:22 -05:00
parent 4ec845e14d
commit b5d54669f8
3 changed files with 114 additions and 24 deletions

View File

@ -0,0 +1,50 @@
package me.zeroeightsix.kami.command.commands;
import me.zeroeightsix.kami.command.Command;
import me.zeroeightsix.kami.command.syntax.ChunkBuilder;
import me.zeroeightsix.kami.module.ModuleManager;
import me.zeroeightsix.kami.module.modules.chat.AutoReply;
/**
* @author S-B99
* Created by S-B99 on 17/02/20
*/
public class AutoReplyCommand extends Command {
public AutoReplyCommand() {
super("autoreply", new ChunkBuilder().append("message").append("=listener").append("-replyCommand").build(), "reply");
setDescription("Allows you to customize AutoReply's message setting");
}
@Override
public void call(String[] args) {
AutoReply autoReply = (AutoReply) ModuleManager.getModuleByName("AutoReply");
if (autoReply == null) {
Command.sendErrorMessage("&cThe AutoReply module is not available for some reason. Make sure the name you're calling is correct and that you have the module installed!!");
return;
}
if (!autoReply.isEnabled()) {
Command.sendWarningMessage("&6Warning: The AutoReply module is not enabled!");
Command.sendWarningMessage("The command will still work, but will not visibly do anything.");
}
if (!autoReply.customMessage.getValue()) {
Command.sendWarningMessage("&6Warning: You don't have custom mode enabled in AutoReply!");
Command.sendWarningMessage("The command will still work, but will not visibly do anything.");
}
for (String s : args) {
if (s == null)
continue;
if (s.startsWith("=")) {
String sT = s.replace("=" ,"");
autoReply.listener.setValue(sT);
Command.sendChatMessage("Set the AutoReply listener to <" + sT + ">");
} else if (s.startsWith("-")) {
String sT = s.replace("-" ,"");
autoReply.replyCommand.setValue(sT);
Command.sendChatMessage("Set the AutoReply reply command to <" + sT + ">");
} else {
autoReply.message.setValue(s);
Command.sendChatMessage("Set the AutoReply message to <" + s + ">");
}
}
}
}

View File

@ -0,0 +1,64 @@
package me.zeroeightsix.kami.module.modules.chat;
import me.zeroeightsix.kami.command.Command;
import me.zeroeightsix.kami.setting.Setting;
import me.zeroeightsix.kami.setting.Settings;
import me.zeroeightsix.kami.util.Wrapper;
import net.minecraft.network.play.server.SPacketChat;
import me.zero.alpine.listener.EventHandler;
import me.zeroeightsix.kami.event.events.PacketEvent;
import me.zero.alpine.listener.Listener;
import me.zeroeightsix.kami.module.Module;
/**
* @author Diamarald
* Updated by S-B99 on 03/03/20
*/
@Module.Info(name = "AutoReply", description = "Automatically replies to messages", category = Module.Category.CHAT)
public class AutoReply extends Module {
public Setting<Boolean> customMessage = register(Settings.b("Custom Message", false));
public Setting<String> message = register(Settings.stringBuilder("Custom Text").withValue("Use &7" + Command.getCommandPrefix() + "&rautoreply to modify this").withConsumer((old, value) -> {}).withVisibility(v -> customMessage.getValue()).build());
public Setting<Boolean> customListener = register(Settings.b("Custom Listener", false));
public Setting<String> listener = register(Settings.stringBuilder("Custom Listener Name").withValue("unchanged").withConsumer((old, value) -> {}).withVisibility(v -> customListener.getValue()).build());
public Setting<Boolean> customReplyCommand = register(Settings.b("Custom Listener", false));
public Setting<String> replyCommand = register(Settings.stringBuilder("Custom Reply Command").withValue("unchanged").withConsumer((old, value) -> {}).withVisibility(v -> customReplyCommand.getValue()).build());
private String listenerDefault = "whispers:";
private String replyCommandDefault = "r";
@EventHandler
public Listener<PacketEvent.Receive> receiveListener;
public AutoReply() {
receiveListener = new Listener<>(event -> {
if (event.getPacket() instanceof SPacketChat && ((SPacketChat) event.getPacket()).getChatComponent().getUnformattedText().contains(listenerDefault) && !((SPacketChat) event.getPacket()).getChatComponent().getUnformattedText().contains(mc.player.getName())) {
if (customMessage.getValue()) {
Wrapper.getPlayer().sendChatMessage("/" + replyCommandDefault + " " + message.getValue());
} else {
Wrapper.getPlayer().sendChatMessage("/" + replyCommandDefault + " I am currently afk, thanks to KAMI Blue's AutoReply module!");
}
}
});
}
private static long startTime = 0;
@Override
public void onUpdate() {
if (customListener.getValue()) listenerDefault = listener.getValue();
else listenerDefault = "whispers:";
if (customReplyCommand.getValue()) replyCommandDefault = replyCommand.getName();
else replyCommandDefault = "r";
if (startTime == 0) startTime = System.currentTimeMillis();
if (startTime + 5000 <= System.currentTimeMillis()) { // 5 seconds in milliseconds
if (customListener.getValue() && listener.getValue().equalsIgnoreCase("unchanged") && mc.player != null) {
Command.sendWarningMessage(this.getChatName() + " Warning: In order to use the custom listener, please run the &7" + Command.getCommandPrefix() + "&rautoreply =LISTENERNAME command to change it");
}
if (customReplyCommand.getValue() && replyCommand.getValue().equalsIgnoreCase("unchanged") && mc.player != null) {
Command.sendWarningMessage(this.getChatName() + " Warning: In order to use the custom reply command, please run the &7" + Command.getCommandPrefix() + "&rautoreply -REPLYCOMMAND command to change it");
}
startTime = System.currentTimeMillis();
}
}
}

View File

@ -1,24 +0,0 @@
package me.zeroeightsix.kami.module.modules.misc;
import java.util.function.Predicate;
import me.zeroeightsix.kami.util.Wrapper;
import net.minecraft.network.play.server.SPacketChat;
import me.zero.alpine.listener.EventHandler;
import me.zeroeightsix.kami.event.events.PacketEvent;
import me.zero.alpine.listener.Listener;
import me.zeroeightsix.kami.module.Module;
@Module.Info(name = "AutoReply", description = "automatically replies to private messages", category = Module.Category.MISC)
public class AutoReply extends Module
{
@EventHandler
public Listener<PacketEvent.Receive> receiveListener;
public AutoReply() {
this.receiveListener = new Listener<PacketEvent.Receive>(event -> {
if (event.getPacket() instanceof SPacketChat && ((SPacketChat)event.getPacket()).getChatComponent().getUnformattedText().contains("whispers:")) {
Wrapper.getPlayer().sendChatMessage("/r Kami Blue On Top");
}
}, (Predicate<PacketEvent.Receive>[])new Predicate[0]);
}
}