-
-
Notifications
You must be signed in to change notification settings - Fork 9
GH-348 Post death command execution #348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Jakubk15
wants to merge
15
commits into
master
Choose a base branch
from
feature/post-death-commands
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+288
−33
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
8dfe353
WIP: Post death command execution
Jakubk15 e333117
Post death command execution
Jakubk15 16f45ca
Apply suggestions from code review
Jakubk15 13d9c09
fix build
Jakubk15 911ef7b
adjust to gemini's suggestion
Jakubk15 ce87394
Remove CauseOfTag.LOGOUT from the check
Jakubk15 356481e
Update eternalcombat-plugin/src/main/java/com/eternalcode/combat/figh…
Jakubk15 2a99c85
Update eternalcombat-plugin/src/main/java/com/eternalcode/combat/figh…
Jakubk15 320dd90
Adjust to Mike's suggestions. Simplify logic
Jakubk15 903fdaa
Merge remote-tracking branch 'origin/feature/post-death-commands' int…
Jakubk15 cb015b5
Merge branch 'master' into feature/post-death-commands
Jakubk15 15b2267
fix build
Jakubk15 115f8bb
Change EternalCore version to latest stable
Jakubk15 a606358
Adjust to DMK's suggestion
Jakubk15 dc0724b
Move to DeathSettings
Jakubk15 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
...ombat-plugin/src/main/java/com/eternalcode/combat/fight/death/DeathCommandController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| package com.eternalcode.combat.fight.death; | ||
Jakubk15 marked this conversation as resolved.
Show resolved
Hide 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 { | ||
Jakubk15 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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()); | ||
| } | ||
| } | ||
36 changes: 36 additions & 0 deletions
36
...lcombat-plugin/src/main/java/com/eternalcode/combat/fight/death/DeathCommandExecutor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } |
84 changes: 84 additions & 0 deletions
84
...alcombat-plugin/src/main/java/com/eternalcode/combat/fight/death/DeathCommandService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| 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 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 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) { | ||
| this.config = config; | ||
| this.fightManager = fightManager; | ||
| this.killerResolver = killerResolver; | ||
| this.executor = executor; | ||
| } | ||
|
|
||
| public void handleUntag(Player player, CauseOfUnTag cause) { | ||
| UUID playerUUID = player.getUniqueId(); | ||
|
|
||
| if (cause == CauseOfUnTag.DEATH || cause == CauseOfUnTag.DEATH_BY_PLAYER) { | ||
| String killerName = this.killerResolver.resolveKillerName(playerUUID, player); | ||
| this.handleDeathInCombat(player, killerName); | ||
| this.handledByUntag.add(playerUUID); | ||
| this.killerNames.put(playerUUID, killerName); | ||
| return; | ||
| } | ||
|
|
||
| this.executor.dispatch(this.config.death.postDeathCommands.onUntag, player, this.config.death.postDeathCommands.unknownKillerPlaceholder); | ||
| } | ||
|
|
||
| public void handleDeath(Player player) { | ||
| UUID playerUUID = player.getUniqueId(); | ||
| String killerName = this.killerResolver.resolveKillerName(playerUUID, player); | ||
|
|
||
| this.killerNames.putIfAbsent(playerUUID, killerName); | ||
|
|
||
| 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); | ||
| } | ||
| } | ||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.