add chomens chat parser + merge to 1 line

This commit is contained in:
ChomeNS 2023-03-20 14:10:34 +07:00
parent 394f22bbfb
commit b340175aab
3 changed files with 43 additions and 2 deletions

View file

@ -41,8 +41,7 @@ public class Main {
config = yaml.load(reader);
final Object reconnectDelayObject = config.get("reconnectDelay");
final int reconnectDelay = (int) reconnectDelayObject;
final int reconnectDelay = (int) ((Object) config.get("reconnectDelay"));
List<Map<String, Object>> botsOptions = config.get("bots");

View file

@ -0,0 +1,40 @@
package me.chayapak1.chomensbot_mabe.chatParsers;
import me.chayapak1.chomensbot_mabe.chatParsers.data.ChatParser;
import me.chayapak1.chomensbot_mabe.chatParsers.data.PlayerMessage;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.TranslatableComponent;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
// Might be a confusing name, but I mean the [Chat] chayapak custom chat thing or any other
// custom chat that uses the `[%s] %s %s` translation
public class ChomeNSCustomChatParser implements ChatParser {
public ChomeNSCustomChatParser () {
}
@Override
public PlayerMessage parse (Component message) {
if (message instanceof TranslatableComponent) return parse((TranslatableComponent) message);
return null;
}
// very similar to MinecraftChatParser
public PlayerMessage parse (TranslatableComponent message) {
final List<Component> args = message.args();
if (args.size() < 3 || !message.key().equals("[%s] %s %s")) return null;
final Map<String, Component> parameters = new HashMap<>();
final Component username = args.get(1);
final Component contents = args.get(2);
parameters.put("sender", username);
parameters.put("contents", contents);
return new PlayerMessage(parameters);
}
}

View file

@ -7,6 +7,7 @@ import com.github.steveice10.packetlib.Session;
import com.github.steveice10.packetlib.event.session.SessionAdapter;
import com.github.steveice10.packetlib.packet.Packet;
import me.chayapak1.chomensbot_mabe.Bot;
import me.chayapak1.chomensbot_mabe.chatParsers.ChomeNSCustomChatParser;
import me.chayapak1.chomensbot_mabe.chatParsers.KaboomChatParser;
import me.chayapak1.chomensbot_mabe.chatParsers.MinecraftChatParser;
import me.chayapak1.chomensbot_mabe.chatParsers.data.ChatParser;
@ -36,6 +37,7 @@ public class ChatPlugin extends SessionAdapter {
chatParsers = new ArrayList<>();
chatParsers.add(new MinecraftChatParser());
chatParsers.add(new KaboomChatParser());
chatParsers.add(new ChomeNSCustomChatParser());
}
@Override