rewrite chattimestamp core method and fix it not working with antispam, closing #477

This commit is contained in:
Bella 2020-04-18 16:12:41 -04:00
parent c56fe756f8
commit 8052eacd10
No known key found for this signature in database
GPG Key ID: DBD4A6030080C8B3
2 changed files with 18 additions and 18 deletions

View File

@ -19,6 +19,7 @@ import static me.zeroeightsix.kami.KamiMod.MODULE_MANAGER;
import static me.zeroeightsix.kami.util.MessageDetectionHelper.isDirect;
import static me.zeroeightsix.kami.util.MessageDetectionHelper.isDirectOther;
import static me.zeroeightsix.kami.util.MessageSendHelper.sendChatMessage;
import static me.zeroeightsix.kami.util.MessageSendHelper.sendRawChatMessage;
/**
* @author hub
@ -26,7 +27,7 @@ import static me.zeroeightsix.kami.util.MessageSendHelper.sendChatMessage;
* Created 19 November 2019 by hub
* Updated 12 January 2020 by hub
* Updated 19 February 2020 by aUniqueUser
* Updated by dominikaaaa on 13/03/20
* Updated by dominikaaaa on 18/04/20
*/
@Module.Info(
name = "AntiSpam",
@ -89,7 +90,15 @@ public class AntiSpam extends Module {
.collect(Collectors.toList())
.forEach(entry -> messageHistory.remove(entry.getKey()));
if (isSpam(sPacketChat.getChatComponent().getUnformattedText())) event.cancel();
String message = sPacketChat.getChatComponent().getUnformattedText();
if (!isSpam(message)) {
if (MODULE_MANAGER.isModuleEnabled(ChatTimestamp.class)) {
message = MODULE_MANAGER.getModuleT(ChatTimestamp.class).getFormattedTime(message);
}
sendRawChatMessage(message);
}
event.cancel();
});
@Override
@ -99,10 +108,6 @@ public class AntiSpam extends Module {
public void onDisable() { messageHistory = null; }
private boolean isSpam(String message) {
ChatTimestamp chatTimestamp = MODULE_MANAGER.getModuleT(ChatTimestamp.class);
if (chatTimestamp.isEnabled()) {
message = message.substring(chatTimestamp.returnFormatted().length() + 1);
}
/* Quick bandaid fix for mc.player being null when the module is being registered, so don't register it with the map */
final String[] OWN_MESSAGE = {
"^<" + mc.player.getName() + "> ",

View File

@ -11,12 +11,13 @@ import me.zeroeightsix.kami.util.TimeUtil;
import net.minecraft.network.play.server.SPacketChat;
import net.minecraft.util.text.TextFormatting;
import static me.zeroeightsix.kami.KamiMod.MODULE_MANAGER;
import static me.zeroeightsix.kami.util.ColourTextFormatting.toTextMap;
import static me.zeroeightsix.kami.util.MessageSendHelper.sendRawChatMessage;
/**
* @author dominikaaaa
* Updated by dominikaaaa on 25/03/20
* Updated by dominikaaaa on 18/04/20
*/
@Module.Info(
name = "ChatTimestamp",
@ -33,23 +34,17 @@ public class ChatTimestamp extends Module {
@EventHandler
public Listener<PacketEvent.Receive> listener = new Listener<>(event -> {
if (mc.player == null || isDisabled()) return;
if (mc.player == null || MODULE_MANAGER.isModuleEnabled(AntiSpam.class)) return;
if (!(event.getPacket() instanceof SPacketChat)) return;
SPacketChat sPacketChat = (SPacketChat) event.getPacket();
if (addTime(sPacketChat.getChatComponent().getFormattedText())) {
event.cancel();
}
sendRawChatMessage(getFormattedTime(sPacketChat.getChatComponent().getFormattedText()));
event.cancel();
});
private boolean addTime(String message) {
sendRawChatMessage("<" + TimeUtil.getFinalTime(setToText(secondColour.getValue()), setToText(firstColour.getValue()), timeUnitSetting.getValue(), timeTypeSetting.getValue(), doLocale.getValue()) + TextFormatting.RESET + "> " + message);
return true;
}
public String returnFormatted() {
return "<" + TimeUtil.getFinalTime(timeUnitSetting.getValue(), timeTypeSetting.getValue(), doLocale.getValue()) + "> ";
public String getFormattedTime(String message) {
return "<" + TimeUtil.getFinalTime(setToText(secondColour.getValue()), setToText(firstColour.getValue()), timeUnitSetting.getValue(), timeTypeSetting.getValue(), doLocale.getValue()) + TextFormatting.RESET + "> " + message;
}
private TextFormatting setToText(ColourTextFormatting.ColourCode colourCode) {