Skip to content

Commit

Permalink
Added NumberCountProcess
Browse files Browse the repository at this point in the history
  • Loading branch information
DustinRepo committed Mar 21, 2022
1 parent c4088a4 commit 3c66799
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 0 deletions.
3 changes: 3 additions & 0 deletions config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ announcementDelay=300
#Quotes - Stores all player messages to be quoted later
quotes=true

#NumberCount - Checks if all numbers in a message add to 420 or 69
numberCount=true

#2b2t message check - Counts the amount of messages before someone mentions 2b2t in chat
2b2tCheck=true

Expand Down
6 changes: 6 additions & 0 deletions src/me/dustin/chatbot/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class Config {
private boolean twoB2tCheck;
private boolean twoB2tCount;
private boolean quotes;
private boolean numberCount;

private int protocolVersion;
private int reconnectDelay;
Expand Down Expand Up @@ -82,6 +83,7 @@ public void loadConfig() throws IOException {
twoB2tCheck = parser.readBoolean("2b2tCheck");
twoB2tCount = parser.readBoolean("2b2tCount");
quotes = parser.readBoolean("quotes");
numberCount = parser.readBoolean("numberCount");

reconnectDelay = parser.readInt("reconnectDelay");
messageDelay = parser.readInt("messageDelay");
Expand Down Expand Up @@ -194,6 +196,10 @@ public boolean isQuotes() {
return quotes;
}

public boolean isNumberCount() {
return numberCount;
}

public boolean isPasswordCreateUseTwice() {
return passwordCreateUseTwice;
}
Expand Down
2 changes: 2 additions & 0 deletions src/me/dustin/chatbot/network/ClientConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ public void loadProcesses() {
getProcessManager().addProcess(new Chat2b2tCountProcess(this));
if (ChatBot.getConfig().isQuotes())
getProcessManager().addProcess(new QuoteProcess(this));
if (ChatBot.getConfig().isNumberCount())
getProcessManager().addProcess(new NumberCountProcess(this));
}

public void connect() {
Expand Down
56 changes: 56 additions & 0 deletions src/me/dustin/chatbot/process/impl/NumberCountProcess.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package me.dustin.chatbot.process.impl;

import me.dustin.chatbot.event.EventReceiveChatMessage;
import me.dustin.chatbot.helper.GeneralHelper;
import me.dustin.chatbot.helper.MCAPIHelper;
import me.dustin.chatbot.network.ClientConnection;
import me.dustin.chatbot.process.ChatBotProcess;
import me.dustin.events.core.EventListener;
import me.dustin.events.core.annotate.EventPointer;

import java.util.StringJoiner;

public class NumberCountProcess extends ChatBotProcess {

public NumberCountProcess(ClientConnection clientConnection) {
super(clientConnection);
}

@Override
public void init() {
getClientConnection().getEventManager().register(this);
}

@EventPointer
private final EventListener<EventReceiveChatMessage> eventReceiveChatMessageEventListener = new EventListener<>(event -> {
if (event.getChatMessagePacket().getSender() == null || GeneralHelper.matchUUIDs(event.getChatMessagePacket().getSender().toString(), getClientConnection().getSession().getUuid()))
return;
String senderName = MCAPIHelper.getNameFromUUID(event.getChatMessagePacket().getSender());
String[] split = event.getChatMessagePacket().getMessage().getBody().split(" ");
int num = 0;
StringJoiner sj = new StringJoiner(" + ");
for (String s : split) {
try {
int n = Integer.parseInt(s);
sj.add(s);
num += n;
} catch (NumberFormatException e) {
}
}
if (num == 420) {
sendChat("All of the numers in " + senderName + "'s message add to 420! " + sj.toString() + " = 420");
} else if (num == 69) {
sendChat("All of the numers in " + senderName + "'s message add to 69! " + sj.toString() + " = 69");
}
});

@Override
public void tick() {

}

@Override
public void stop() {
getClientConnection().getEventManager().unregister(this);
}
}

0 comments on commit 3c66799

Please sign in to comment.