Skip to content

Commit

Permalink
Fixed wrong event firing if another mod cancelled player's death
Browse files Browse the repository at this point in the history
  • Loading branch information
Druzai committed Jan 24, 2023
2 parents dcef4df + f754ffe commit cb0c1ff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
org.gradle.jvmargs=-Xmx3G
org.gradle.daemon=false

mod_version=3.0
mod_version=3.1
minecraft_version=1.19.3
forge_version=44.0.40
parchment_version=2022.12.18
17 changes: 10 additions & 7 deletions src/main/java/com/cazsius/deathquotes/event/ModEventListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import org.apache.logging.log4j.LogManager;
Expand All @@ -24,12 +25,16 @@ public static void registerCommands(RegisterCommandsEvent event) {
QuotesCommands.register(event.getDispatcher());
}

@SubscribeEvent
public static void livingDeath(LivingDeathEvent event) {
@SubscribeEvent(priority = EventPriority.LOWEST)
public static void onLivingDeath(LivingDeathEvent event) {
// Run only on dedicated or integrated server
if (event.getEntity().getServer() == null) {
return;
}
// Check if event was cancelled by other mod
if (event.isCanceled()){
return;
}
// For players only
if (!(event.getEntity() instanceof Player player)) {
return;
Expand All @@ -45,11 +50,9 @@ public static void livingDeath(LivingDeathEvent event) {
// Generating "tellraw" component for quote
quote = Funcs.handleQuote(quote, player);
Component tellrawComponent = Funcs.generateTellrawComponentForQuote(quote);
if (!event.isCanceled()) {
// Send quote only to players
for (ServerPlayer serverPlayer : player.getServer().getPlayerList().getPlayers()) {
serverPlayer.sendSystemMessage(tellrawComponent);
}
// Send quote only to players
for (ServerPlayer serverPlayer : player.getServer().getPlayerList().getPlayers()) {
serverPlayer.sendSystemMessage(tellrawComponent);
}
}
}

0 comments on commit cb0c1ff

Please sign in to comment.