fix chat (/say and /me) i guess

This commit is contained in:
Chayapak 2023-04-24 14:16:14 +07:00
parent 6e91fe82d4
commit a49b078a6f
5 changed files with 71 additions and 46 deletions

View file

@ -4,13 +4,12 @@
<option name="autoReloadType" value="SELECTIVE" /> <option name="autoReloadType" value="SELECTIVE" />
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="50f184fa-7bed-4956-baf5-7586ff26ea08" name="Changes" comment="actually revert greplog update because it breaks stuff"> <list default="true" id="50f184fa-7bed-4956-baf5-7586ff26ea08" name="Changes" comment="fix chat (/say and /me) i guess">
<change afterPath="$PROJECT_DIR$/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/FilterCommand.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/land/chipmunk/chayapak/chomens_bot/data/FilteredPlayer.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/FilterPlugin.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/land/chipmunk/chayapak/chomens_bot/command/ConsoleCommandContext.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/land/chipmunk/chayapak/chomens_bot/command/ConsoleCommandContext.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/CommandHandlerPlugin.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/main/java/land/chipmunk/chayapak/chomens_bot/command/PlayerCommandContext.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/land/chipmunk/chayapak/chomens_bot/command/PlayerCommandContext.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/TestCommand.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/land/chipmunk/chayapak/chomens_bot/commands/TestCommand.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ChatPlugin.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/ChatPlugin.java" afterDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
@ -102,13 +101,6 @@
<option name="presentableId" value="Default" /> <option name="presentableId" value="Default" />
<updated>1680245437032</updated> <updated>1680245437032</updated>
</task> </task>
<task id="LOCAL-00060" summary="improve serverinfo">
<created>1681536905476</created>
<option name="number" value="00060" />
<option name="presentableId" value="LOCAL-00060" />
<option name="project" value="LOCAL" />
<updated>1681536905476</updated>
</task>
<task id="LOCAL-00061" summary="make self care use core if it can"> <task id="LOCAL-00061" summary="make self care use core if it can">
<created>1681547507213</created> <created>1681547507213</created>
<option name="number" value="00061" /> <option name="number" value="00061" />
@ -445,7 +437,14 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1682250189954</updated> <updated>1682250189954</updated>
</task> </task>
<option name="localTasksCounter" value="109" /> <task id="LOCAL-00109" summary="add filter (ignore messy code plz)">
<created>1682317167720</created>
<option name="number" value="00109" />
<option name="presentableId" value="LOCAL-00109" />
<option name="project" value="LOCAL" />
<updated>1682317167721</updated>
</task>
<option name="localTasksCounter" value="110" />
<servers /> <servers />
</component> </component>
<component name="Vcs.Log.Tabs.Properties"> <component name="Vcs.Log.Tabs.Properties">
@ -460,8 +459,6 @@
</option> </option>
</component> </component>
<component name="VcsManagerConfiguration"> <component name="VcsManagerConfiguration">
<MESSAGE value="add a working (or not?) stereo to music" />
<MESSAGE value="improve and fix cmd handler (first commit on arch)&#10;yup this is my first commit on arch linux,.,.,..,.,.,&#10;yes i use arch btw :sunglasses:" />
<MESSAGE value="1.19.4 + add stuff (kinda broken ..,,.)" /> <MESSAGE value="1.19.4 + add stuff (kinda broken ..,,.)" />
<MESSAGE value="add/improve/fix stuff&#10;ig mabe mabe mabe&#10;useCore!1!1!" /> <MESSAGE value="add/improve/fix stuff&#10;ig mabe mabe mabe&#10;useCore!1!1!" />
<MESSAGE value="ig fix music filename mabe mabe" /> <MESSAGE value="ig fix music filename mabe mabe" />
@ -485,7 +482,9 @@
<MESSAGE value="put the setter back" /> <MESSAGE value="put the setter back" />
<MESSAGE value="use serverName instead of host:port for console i guess" /> <MESSAGE value="use serverName instead of host:port for console i guess" />
<MESSAGE value="actually revert greplog update because it breaks stuff" /> <MESSAGE value="actually revert greplog update because it breaks stuff" />
<option name="LAST_COMMIT_MESSAGE" value="actually revert greplog update because it breaks stuff" /> <MESSAGE value="add filter (ignore messy code plz)" />
<MESSAGE value="fix chat (/say and /me) i guess" />
<option name="LAST_COMMIT_MESSAGE" value="fix chat (/say and /me) i guess" />
</component> </component>
<component name="XSLT-Support.FileAssociations.UIState"> <component name="XSLT-Support.FileAssociations.UIState">
<expand /> <expand />

View file

@ -9,7 +9,7 @@ public class ConsoleCommandContext extends CommandContext {
private final Bot bot; private final Bot bot;
public ConsoleCommandContext (Bot bot, String prefix) { public ConsoleCommandContext (Bot bot, String prefix) {
super(bot, prefix, bot.players().getEntry(bot.username()) /* real */, null, null); super(bot, prefix, bot.players().getBotEntry() /* real */, null, null);
this.bot = bot; this.bot = bot;
} }
@ -21,6 +21,6 @@ public class ConsoleCommandContext extends CommandContext {
@Override @Override
public Component displayName () { public Component displayName () {
return Component.text(bot.username()).color(NamedTextColor.YELLOW); return sender().displayName().color(NamedTextColor.YELLOW);
} }
} }

View file

@ -26,6 +26,6 @@ public class PlayerCommandContext extends CommandContext {
@Override @Override
public Component displayName () { public Component displayName () {
return Component.text(playerName); return sender().displayName();
} }
} }

View file

@ -36,7 +36,7 @@ public class TestCommand implements Command {
public Component execute(CommandContext context, String[] args, String[] fullArgs) { public Component execute(CommandContext context, String[] args, String[] fullArgs) {
final Component component = Component.translatable( final Component component = Component.translatable(
"Hello, World! Username: %s, Sender UUID: %s, Prefix: %s, Args: %s", "Hello, World! Username: %s, Sender UUID: %s, Prefix: %s, Args: %s",
context.displayName(), context.sender().profile().getName(),
Component.text(context.sender().profile().getIdAsString()), Component.text(context.sender().profile().getIdAsString()),
Component.text(context.prefix()), Component.text(context.prefix()),
Component.text(String.join(", ", args)) Component.text(String.join(", ", args))

View file

@ -96,43 +96,69 @@ public class ChatPlugin extends SessionAdapter {
if (entry == null) return; if (entry == null) return;
final PlayerMessage playerMessage = new PlayerMessage(entry, packet.getName(), Component.text(packet.getContent())); final PlayerMessage playerMessage = new PlayerMessage(
entry,
packet.getName(),
Component.text(packet.getContent())
);
for (ChatListener listener : listeners) { for (ChatListener listener : listeners) {
listener.playerMessageReceived(playerMessage); listener.playerMessageReceived(playerMessage);
final Component component = Component.translatable( if (packet.getChatType() == 4) { // type 4 is /say
"chat.type.text", final Component component = Component.translatable(
entry.displayName(), "chat.type.announcement",
Component.text(packet.getContent()) playerMessage.displayName(),
); playerMessage.contents()
listener.systemMessageReceived( );
ComponentUtilities.stringify(component),
component listener.systemMessageReceived(
); ComponentUtilities.stringify(component),
component
);
} else {
final Component unsignedContent = packet.getUnsignedContent();
if (unsignedContent == null) return;
listener.systemMessageReceived(
ComponentUtilities.stringify(unsignedContent),
unsignedContent
);
}
} }
} }
public void packetReceived (ClientboundDisguisedChatPacket packet) { public void packetReceived (ClientboundDisguisedChatPacket packet) {
// totallynotskidded from chipmunkbot // totallynotskidded from chipmunkbot and modified a bit i guess
PlayerMessage parsedFromMessage = null; // PlayerMessage parsedFromMessage = null;
final Component component = packet.getMessage();
for (ChatParser parser : chatParsers) { // i think im missing other types
parsedFromMessage = parser.parse(component); if (packet.getChatType() == 1) { // type 1 is /me
if (parsedFromMessage != null) break; final Component name = packet.getName();
} final Component content = packet.getMessage();
if (parsedFromMessage == null) return; for (ChatParser parser : chatParsers) {
final Component component = Component.translatable(
"chat.type.emote",
name,
content
);
final PlayerMessage playerMessage = new PlayerMessage(parsedFromMessage.sender(), packet.getName(), parsedFromMessage.contents()); final PlayerMessage parsed = parser.parse(component);
for (ChatListener listener : listeners) { if (parsed == null) continue;
listener.playerMessageReceived(playerMessage);
listener.systemMessageReceived( final PlayerMessage playerMessage = new PlayerMessage(parsed.sender(), packet.getName(), parsed.contents());
ComponentUtilities.stringify(component),
component for (ChatListener listener : listeners) {
); listener.playerMessageReceived(playerMessage);
listener.systemMessageReceived(
ComponentUtilities.stringify(component),
component
);
}
}
} }
} }