Skip to content
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
8dfe353
WIP: Post death command execution
Jakubk15 Feb 20, 2026
e333117
Post death command execution
Jakubk15 Feb 20, 2026
16f45ca
Apply suggestions from code review
Jakubk15 Feb 20, 2026
13d9c09
fix build
Jakubk15 Feb 20, 2026
911ef7b
adjust to gemini's suggestion
Jakubk15 Feb 20, 2026
ce87394
Remove CauseOfTag.LOGOUT from the check
Jakubk15 Feb 20, 2026
356481e
Update eternalcombat-plugin/src/main/java/com/eternalcode/combat/figh…
Jakubk15 Mar 15, 2026
2a99c85
Update eternalcombat-plugin/src/main/java/com/eternalcode/combat/figh…
Jakubk15 Mar 15, 2026
320dd90
Adjust to Mike's suggestions. Simplify logic
Jakubk15 Mar 15, 2026
903fdaa
Merge remote-tracking branch 'origin/feature/post-death-commands' int…
Jakubk15 Mar 15, 2026
cb015b5
Merge branch 'master' into feature/post-death-commands
Jakubk15 Mar 15, 2026
15b2267
fix build
Jakubk15 Mar 22, 2026
115f8bb
Change EternalCore version to latest stable
Jakubk15 Mar 22, 2026
a606358
Adjust to DMK's suggestion
Jakubk15 Mar 22, 2026
dc0724b
Move to DeathSettings
Jakubk15 Mar 22, 2026
81afc4c
Merge branch 'master' into feature/post-death-commands
Jakubk15 May 10, 2026
bc83f4d
Merge branch 'master' into feature/post-death-commands
Jakubk15 Jul 9, 2026
34b1252
Fix build
Jakubk15 Jul 9, 2026
6b09a6f
Add additional comments per Mike's suggestion
Jakubk15 Jul 9, 2026
7bc712d
Update eternalcombat-plugin/src/main/java/com/eternalcode/combat/figh…
Jakubk15 Jul 25, 2026
ca25b99
Update eternalcombat-plugin/src/main/java/com/eternalcode/combat/figh…
Jakubk15 Jul 25, 2026
b9d6a5b
Update placeholders in settings
Jakubk15 Jul 25, 2026
ca05679
Add scheduler support for post-death command execution, improve logic…
Jakubk15 Jul 25, 2026
fd94fe1
Simplify whole code.
vLuckyyy Jul 26, 2026
f6f3e3b
Simplify config declaration.
vLuckyyy Jul 26, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions buildSrc/src/main/kotlin/Versions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ object Versions {
const val PACKETEVENTS = "2.11.1"
const val WORLDGUARD = "7.0.15-beta-01"
const val LUCKPERMS = "5.5.17"
const val ETERNALCORE = "2.0.0"

}

Expand Down
2 changes: 1 addition & 1 deletion eternalcombat-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import net.minecrell.pluginyml.paper.PaperPluginDescription
import net.minecrell.pluginyml.bukkit.BukkitPluginDescription
Comment thread
Jakubk15 marked this conversation as resolved.
import net.minecrell.pluginyml.paper.PaperPluginDescription

plugins {
`eternalcombat-java`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,27 @@
import com.eternalcode.combat.fight.blocker.ElytraBlocker;
import com.eternalcode.combat.fight.blocker.ElytraEquipBlocker;
import com.eternalcode.combat.fight.blocker.FlyingBlocker;
import com.eternalcode.combat.fight.blocker.InventoryContainersBlocker;
import com.eternalcode.combat.fight.blocker.PlaceBlockBlocker;
import com.eternalcode.combat.fight.controller.FightBypassAdminController;
import com.eternalcode.combat.fight.controller.FightBypassCreativeController;
import com.eternalcode.combat.fight.controller.FightBypassPermissionController;
import com.eternalcode.combat.fight.blocker.InventoryContainersBlocker;
import com.eternalcode.combat.fight.controller.FightMessageController;
import com.eternalcode.combat.fight.controller.FightTagController;
import com.eternalcode.combat.fight.controller.FightUnTagController;
import com.eternalcode.combat.fight.death.DeathCommandController;
import com.eternalcode.combat.fight.death.DeathCommandExecutor;
import com.eternalcode.combat.fight.death.DeathCommandService;
import com.eternalcode.combat.fight.death.DeathFlareController;
import com.eternalcode.combat.fight.death.DeathLightningController;
import com.eternalcode.combat.fight.death.KillerResolver;
import com.eternalcode.combat.fight.drop.DropController;
import com.eternalcode.combat.fight.drop.DropKeepInventoryService;
import com.eternalcode.combat.fight.drop.DropKeepInventoryServiceImpl;
import com.eternalcode.combat.fight.drop.DropService;
import com.eternalcode.combat.fight.drop.DropServiceImpl;
import com.eternalcode.combat.fight.drop.impl.PercentDropModifier;
import com.eternalcode.combat.fight.drop.impl.PlayersHealthDropModifier;
import com.eternalcode.combat.fight.blocker.PlaceBlockBlocker;
import com.eternalcode.combat.fight.effect.FightEffectController;
import com.eternalcode.combat.fight.effect.FightEffectService;
import com.eternalcode.combat.fight.effect.FightEffectServiceImpl;
Expand Down Expand Up @@ -70,7 +74,6 @@
import dev.rollczi.litecommands.bukkit.LiteBukkitFactory;
import dev.rollczi.litecommands.bukkit.LiteBukkitMessages;
import dev.rollczi.litecommands.folia.FoliaExtension;
import java.time.Duration;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bstats.bukkit.Metrics;
import org.bukkit.Server;
Expand All @@ -80,6 +83,7 @@
import org.bukkit.plugin.java.JavaPlugin;

import java.io.File;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
import java.util.stream.Stream;

Expand Down Expand Up @@ -128,7 +132,7 @@
this.dropService = new DropServiceImpl();
this.dropKeepInventoryService = new DropKeepInventoryServiceImpl();

UpdaterService updaterService = new UpdaterService(this.getDescription());

Check warning on line 135 in eternalcombat-plugin/src/main/java/com/eternalcode/combat/CombatPlugin.java

View workflow job for this annotation

GitHub Actions / build

[deprecation] getDescription() in JavaPlugin has been deprecated

MiniMessage miniMessage = MiniMessage.builder()
.postProcessor(new AdventureLegacyColorPostProcessor())
Expand Down Expand Up @@ -182,12 +186,17 @@
new PlayersHealthDropModifier(pluginConfig.drop, logoutService)
).forEach(this.dropService::registerModifier);

KillerResolver killerResolver = new KillerResolver(this.fightManager, server, pluginConfig);
DeathCommandExecutor deathCommandExecutor = new DeathCommandExecutor(server);
DeathCommandService deathCommandService = new DeathCommandService(pluginConfig, this.fightManager, killerResolver, deathCommandExecutor, scheduler);

eventManager.subscribe(
new FightTagController(this.fightManager, pluginConfig),
new FightUnTagController(this.fightManager, pluginConfig, logoutService),
new FightBypassAdminController(server, pluginConfig),
new FightBypassPermissionController(server, pluginConfig),
new FightBypassCreativeController(server, pluginConfig),
new DeathCommandController(deathCommandService, server),
new PlaceBlockBlocker(this.fightManager, noticeService, pluginConfig),
new PearlController(pluginConfig, this.pearlService, noticeService, fightManager),
new TridentController(pluginConfig, noticeService, this.fightManager, this.tridentService, server),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ public class PluginConfig extends OkaeriConfig {

@Comment({
" ",
"# This section contains effects displayed on death of the player"
"# This section contains effects displayed on death of the player",
"# You can also execute which commands will be executed post-death and on logout of the player."
})
public DeathSettings death = new DeathSettings();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.eternalcode.combat.fight.death;
Comment thread
Jakubk15 marked this conversation as resolved.

import com.eternalcode.combat.fight.event.FightUntagEvent;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerRespawnEvent;

public class DeathCommandController implements Listener {
Comment thread
Jakubk15 marked this conversation as resolved.
Outdated

private final DeathCommandService deathCommandService;
private final Server server;

public DeathCommandController(DeathCommandService deathCommandService, Server server) {
this.deathCommandService = deathCommandService;
this.server = server;
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
void onPlayerUntag(FightUntagEvent event) {
Player player = this.server.getPlayer(event.getPlayer());

if (player == null) {
return;
}

this.deathCommandService.handleUntag(player, event.getCause());
}

@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
void onPlayerDeath(PlayerDeathEvent event) {
this.deathCommandService.handleDeath(event.getEntity());
}

@EventHandler(priority = EventPriority.MONITOR)
void onPlayerRespawn(PlayerRespawnEvent event) {
this.deathCommandService.handleRespawn(event.getPlayer());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.eternalcode.combat.fight.death;

import org.bukkit.Server;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.Collection;

public class DeathCommandExecutor {

private final Server server;

public DeathCommandExecutor(Server server) {
this.server = server;
}

public void dispatch(DeathSettings.PostDeathCommandSettings.PostDeathCommands settings, Player player, String killerName) {
String playerName = player.getName();

this.dispatch(settings.console, this.server.getConsoleSender(), playerName, killerName);
this.dispatch(settings.player, player, playerName, killerName);
}

public void dispatch(Collection<String> commands, CommandSender sender, String playerName, String killerName) {
for (String command : commands) {
String resolved = this.replacePlaceholders(command, playerName, killerName);
this.server.dispatchCommand(sender, resolved);
}
}

private String replacePlaceholders(String command, String playerName, String killerName) {
return command
.replace("{PLAYER}", playerName)
.replace("{KILLER}", killerName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package com.eternalcode.combat.fight.death;

import com.eternalcode.combat.config.implementation.PluginConfig;
import com.eternalcode.combat.fight.FightManager;
import com.eternalcode.combat.fight.event.CauseOfUnTag;
import com.eternalcode.commons.scheduler.Scheduler;
import org.bukkit.entity.Player;

import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;

public class DeathCommandService {

private final PluginConfig config;
private final FightManager fightManager;
private final KillerResolver killerResolver;
private final DeathCommandExecutor executor;
private final Scheduler scheduler;

private final Map<UUID, String> killerNames = new ConcurrentHashMap<>();
private final Set<UUID> handledByUntag = Collections.newSetFromMap(new ConcurrentHashMap<>());

public DeathCommandService(PluginConfig config, FightManager fightManager, KillerResolver killerResolver, DeathCommandExecutor executor, Scheduler scheduler) {
this.config = config;
this.fightManager = fightManager;
this.killerResolver = killerResolver;
this.executor = executor;
this.scheduler = scheduler;
}

/**
* scheduleUntagCommands runs in next tick,
* because we wait for the untag to fully complete,
* see {@link com.eternalcode.combat.fight.FightManagerImpl#untag(UUID, CauseOfUnTag)}
*/

public void handleUntag(Player player, CauseOfUnTag cause) {
if (cause != CauseOfUnTag.DEATH && cause != CauseOfUnTag.DEATH_BY_PLAYER) {
this.scheduleUntagCommands(player);
return;
}

UUID playerUniqueId = player.getUniqueId();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is the UUID called playerUniqueId in some places and playerUUID in others?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These names were picked during coding, no particular reason

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, just pointing it out. My bad asking it as a question

String killerName = this.killerResolver.resolveKillerName(playerUniqueId, player);

this.handledByUntag.add(playerUniqueId);
this.killerNames.put(playerUniqueId, killerName);
}

public void handleDeath(Player player) {
UUID playerUUID = player.getUniqueId();
String killerName = this.killerNames.computeIfAbsent(
playerUUID,
ignored -> this.killerResolver.resolveKillerName(playerUUID, player)
);

this.executor.dispatch(this.config.death.postDeathCommands.onAnyDeath, player, killerName);

if (this.handledByUntag.remove(playerUUID)) {
return;
}

if (this.fightManager.isInCombat(playerUUID)) {
this.handleDeathInCombat(player, killerName);
}
}

public void handleRespawn(Player player) {
UUID playerUUID = player.getUniqueId();

this.handledByUntag.remove(playerUUID);

String killerName = this.killerNames.remove(playerUUID);
if (killerName == null) {
killerName = this.config.death.postDeathCommands.unknownKillerPlaceholder;
}

this.executor.dispatch(this.config.death.postDeathCommands.afterRespawn, player, killerName);
}

private void handleDeathInCombat(Player player, String killerName) {
this.executor.dispatch(this.config.death.postDeathCommands.onDeathInCombat, player, killerName);

Player killer = this.killerResolver.resolveKiller(player.getUniqueId(), player);
if (killer != null) {
this.executor.dispatch(this.config.death.postDeathCommands.killerPostDeathCommands, killer, player.getName(), killerName);
}
}

private void scheduleUntagCommands(Player player) {
this.scheduler.run(
() -> this.executor.dispatch(
this.config.death.postDeathCommands.onUntag,
player,
this.config.death.postDeathCommands.unknownKillerPlaceholder
)
);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import eu.okaeri.configs.annotation.Comment;
import org.bukkit.FireworkEffect;

import java.util.List;

public class DeathSettings extends OkaeriConfig {

@Comment({
Expand Down Expand Up @@ -74,4 +76,41 @@ public static class FlareSettings extends OkaeriConfig {
public int secondaryParticleCount = 3;

}

@Comment({
"Commands that will be executed after a player's death/respawn/untag.",
"You can use {PLAYER} to represent the name of the player who died and {KILLER} for the killer's name (if applicable).",
"Do not include the leading slash (/) in the commands.",
})
public PostDeathCommandSettings postDeathCommands = new PostDeathCommandSettings();

public static class PostDeathCommandSettings extends OkaeriConfig {

Comment thread
Jakubk15 marked this conversation as resolved.
@Comment("Commands executed when a player dies in combat")
public PostDeathCommands onDeathInCombat = new PostDeathCommands();

@Comment("Commands executed on any player death")
public PostDeathCommands onAnyDeath = new PostDeathCommands();

@Comment("Commands executed after a player respawns")
public PostDeathCommands afterRespawn = new PostDeathCommands();

@Comment("Commands executed when a player is untagged from combat")
public PostDeathCommands onUntag = new PostDeathCommands();

public static class PostDeathCommands extends OkaeriConfig {
public List<String> console = List.of();
public List<String> player = List.of();
}

@Comment({
"# List of commands that will be executed from the killer's perspective after killing a player.",
"# Use {PLAYER} to represent the name of the player who was killed and {KILLER} for the killer's name (if applicable).",
"# Example: 'give {KILLER} diamond 1' will give the killer a diamond after killing a player."
})
public List<String> killerPostDeathCommands = List.of();

@Comment("# The returned string when the killer is unknown")
public String unknownKillerPlaceholder = "Unknown";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.eternalcode.combat.fight.death;

import com.eternalcode.combat.config.implementation.PluginConfig;
import com.eternalcode.combat.fight.FightManager;
import com.eternalcode.combat.fight.FightTag;
import org.bukkit.Server;
import org.bukkit.entity.Player;

import java.util.UUID;

public class KillerResolver {

private final FightManager fightManager;
private final Server server;
private final PluginConfig config;

public KillerResolver(FightManager fightManager, Server server, PluginConfig config) {
this.fightManager = fightManager;
this.server = server;
this.config = config;
}

public Player resolveKiller(UUID deadPlayerUUID, Player deadPlayer) {
Player killer = deadPlayer.getKiller();

if (killer != null) {
return killer;
}

FightTag tag = this.fightManager.getTag(deadPlayerUUID);

if (tag != null && tag.getTagger() != null) {
return this.server.getPlayer(tag.getTagger());
}

return null;
}

public String resolveKillerName(UUID deadPlayerUUID, Player deadPlayer) {
Player killer = this.resolveKiller(deadPlayerUUID, deadPlayer);
return killer != null ? killer.getName() : this.config.death.postDeathCommands.unknownKillerPlaceholder;
}
}

Loading