Feat: Add @All reminder.

This commit is contained in:
APairOfMoons 2026-07-06 15:00:49 +08:00
parent 9fb66dc69a
commit 5961e16cf9
2 changed files with 99 additions and 0 deletions

View File

@ -0,0 +1,66 @@
package cn.revaria.chatplus.format.formats.insertformats;
import cn.revaria.chatplus.ChatPlus;
import cn.revaria.chatplus.format.ChatFormatType;
import cn.revaria.chatplus.format.formats.ChatInsertFormat;
import net.minecraft.ChatFormatting;
import net.minecraft.core.Holder;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.network.chat.TextColor;
import net.minecraft.network.protocol.game.ClientboundSoundPacket;
import net.minecraft.resources.Identifier;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource;
public class ChatInsertRemindAllFormat implements ChatInsertFormat {
private final String reminderText;
private boolean soundPlayed = false;
private final int startingIndex;
private final ChatFormatType formatType = ChatFormatType.INSERT;
public ChatInsertRemindAllFormat(int startingIndex, String reminderText) {
this.startingIndex = startingIndex;
this.reminderText = reminderText;
}
@Override
public MutableComponent getInsertComponent() {
if (!soundPlayed) {
soundPlayed = true;
for (ServerPlayer player : ChatPlus.getServer().getPlayerList().getPlayers()) {
player.connection.send(new ClientboundSoundPacket(
Holder.direct(SoundEvent.createVariableRangeEvent(Identifier.fromNamespaceAndPath("minecraft", "entity.experience_orb.pickup"))),
SoundSource.MASTER,
player.position().x,
player.position().y,
player.position().z,
3,
1,
player.level().getRandom().nextLong()
));
}
}
return Component.literal("@").append(reminderText)
.withColor(TextColor.GREEN)
.withStyle(ChatFormatting.BOLD);
}
@Override
public int startingIndex() {
return startingIndex;
}
@Override
public ChatFormatType formatType() {
return formatType;
}
@Override
public ChatInsertFormat copy() {
return new ChatInsertRemindAllFormat(startingIndex, reminderText);
}
}

View File

@ -7,6 +7,7 @@ import net.minecraft.network.chat.contents.LiteralContents;
import cn.revaria.chatplus.ChatPlus; import cn.revaria.chatplus.ChatPlus;
import cn.revaria.chatplus.format.formats.ChatInsertFormat; import cn.revaria.chatplus.format.formats.ChatInsertFormat;
import cn.revaria.chatplus.format.formats.insertformats.ChatInsertReminderFormat; import cn.revaria.chatplus.format.formats.insertformats.ChatInsertReminderFormat;
import cn.revaria.chatplus.format.formats.insertformats.ChatInsertRemindAllFormat;
import cn.revaria.chatplus.format.ChatFormat; import cn.revaria.chatplus.format.ChatFormat;
import cn.revaria.chatplus.format.ChatFormatType; import cn.revaria.chatplus.format.ChatFormatType;
import cn.revaria.chatplus.format.formats.ChatColorFormat; import cn.revaria.chatplus.format.formats.ChatColorFormat;
@ -274,6 +275,38 @@ public class TextStyleFormatter {
} }
} }
if (character == '@') {
if (sourceRawText.startsWith("All", i + 1)
|| sourceRawText.startsWith("ALL", i + 1)
|| sourceRawText.startsWith("all", i + 1)) {
if (!formatsTableOutput.containsKey(currentIndex)) {
formatsTableOutput.put(currentIndex, new ArrayList<>());
}
formatsTableOutput.get(currentIndex).add(new ChatInsertRemindAllFormat(
currentIndex,
"All"
));
i += 3;
continue;
}
if (sourceRawText.startsWith("所有人", i + 1)) {
if (!formatsTableOutput.containsKey(currentIndex)) {
formatsTableOutput.put(currentIndex, new ArrayList<>());
}
formatsTableOutput.get(currentIndex).add(new ChatInsertRemindAllFormat(
currentIndex,
"所有人"
));
i += 3;
continue;
}
}
if ((character >= '0' && character <= '9') if ((character >= '0' && character <= '9')
|| (character >= 'a' && character <= 'z') || (character >= 'a' && character <= 'z')
|| (character >= 'A' && character <= 'Z') || (character >= 'A' && character <= 'Z')