-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c4088a4
commit 3c66799
Showing
4 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/me/dustin/chatbot/process/impl/NumberCountProcess.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |