Skip to content

Commit

Permalink
fix: Fix DeathCoordinatesFeature sending both the Wynn and the custom…
Browse files Browse the repository at this point in the history
… message [skip ci] (#2478)

      * fix: Fix DeathCoordinatesFeature

* fix: Don't send 2 death messages
  • Loading branch information
ShadowCat117 committed May 11, 2024
1 parent 4a46ba9 commit 87fd4f5
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright © Wynntils 2023.
* Copyright © Wynntils 2023-2024.
* This file is released under LGPLv3. See LICENSE for full license details.
*/
package com.wynntils.features.chat;
Expand All @@ -13,17 +13,21 @@
import com.wynntils.utils.mc.StyledTextUtils;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;

@ConfigCategory(Category.CHAT)
public class DeathCoordinatesFeature extends Feature {
@SubscribeEvent
// Lowest as this will always cancel the event
@SubscribeEvent(priority = EventPriority.LOWEST)
public void onCharacterDeath(CharacterDeathEvent e) {
StyledText deathMessage =
StyledText.fromComponent(Component.translatable("feature.wynntils.deathCoordinates.diedAt")
.withStyle(ChatFormatting.DARK_RED));
deathMessage = deathMessage.appendPart(StyledTextUtils.createLocationPart(e.getLocation()));

McUtils.player().sendSystemMessage(deathMessage.getComponent());

e.setCanceled(true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public final class CharacterModel extends Model {

// we need a .* in front because the message may have a custom timestamp prefix (or some other mod could do
// something weird)
private static final Pattern WYNN_DEATH_MESSAGE = Pattern.compile(".* §4§lYou have died\\.\\.\\.");
private static final Pattern WYNN_DEATH_MESSAGE = Pattern.compile(".*§4§lYou have died\\.\\.\\.");
private Position lastPositionBeforeTeleport;
private Location lastDeathLocation;

Expand Down Expand Up @@ -167,7 +167,12 @@ public void onWorldStateChanged(WorldStateEvent e) {
public void onChatReceived(ChatMessageReceivedEvent e) {
if (!e.getStyledText().matches(WYNN_DEATH_MESSAGE)) return;
lastDeathLocation = Location.containing(lastPositionBeforeTeleport);
WynntilsMod.postEvent(new CharacterDeathEvent(lastDeathLocation));
CharacterDeathEvent deathEvent = new CharacterDeathEvent(lastDeathLocation);
WynntilsMod.postEvent(deathEvent);

if (deathEvent.isCanceled()) {
e.setCanceled(true);
}
}

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
/*
* Copyright © Wynntils 2023.
* Copyright © Wynntils 2023-2024.
* This file is released under LGPLv3. See LICENSE for full license details.
*/
package com.wynntils.models.character.event;

import com.wynntils.utils.mc.type.Location;
import net.minecraftforge.eventbus.api.Cancelable;
import net.minecraftforge.eventbus.api.Event;

@Cancelable
public class CharacterDeathEvent extends Event {
private final Location location;

Expand Down

0 comments on commit 87fd4f5

Please sign in to comment.