GH-221 Add EventPriority to config for player quit event, add whitelist reasons for kick ex. "Server restart" and untagall command#221
Conversation
WalkthroughThis update adds new options to control how the plugin handles players who quit or get kicked during combat. It introduces a setting to pick the event priority for quit punishments and a list of kick reasons that prevent punishment if matched. The code now listens for player kicks and tracks those who shouldn’t be punished when they quit. Quit event handling is split into multiple priority-based handlers, all calling a shared method that respects these new settings. Also, a new admin message was added for when many players are removed from combat at once, and a new command lets admins untag all players from combat with a message sent to the command sender. Additionally, permission checks were added to skip combat tagging for certain players, and player death handling was expanded to support all event priorities with new options for dropping player heads on death. The event system was refactored to use a new centralized event manager, replacing the old event caller, and dynamic listeners were introduced for more flexible event handling. Finally, a new restriction prevents Elytra gliding during combat when enabled. Tip ⚡️ Faster reviews with caching
Enjoy the performance boost—your workflow just got faster. 📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (8)
💤 Files with no reviewable changes (1)
✅ Files skipped from review due to trivial changes (3)
🚧 Files skipped from review as they are similar to previous changes (1)
🧰 Additional context used🧬 Code Graph Analysis (1)eternalcombat-plugin/src/main/java/com/eternalcode/combat/CombatPlugin.java (1)
🔇 Additional comments (17)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/logout/LogoutController.java
Outdated
Show resolved
Hide resolved
eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/logout/LogoutController.java
Outdated
Show resolved
Hide resolved
igoyek
left a comment
There was a problem hiding this comment.
Minor comments, just our code-style.
Nice pull request, thank you :)
eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/logout/LogoutController.java
Outdated
Show resolved
Hide resolved
eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/logout/LogoutController.java
Outdated
Show resolved
Hide resolved
eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/logout/LogoutController.java
Outdated
Show resolved
Hide resolved
eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/logout/LogoutController.java
Outdated
Show resolved
Hide resolved
eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/logout/LogoutController.java
Outdated
Show resolved
Hide resolved
eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/logout/LogoutController.java
Outdated
Show resolved
Hide resolved
…t/logout/LogoutController.java Co-authored-by: Michał Wojtas <80779749+CitralFlo@users.noreply.github.com>
…t/logout/LogoutController.java Co-authored-by: Michał Wojtas <80779749+CitralFlo@users.noreply.github.com>
…t/logout/LogoutController.java Co-authored-by: Michał Wojtas <80779749+CitralFlo@users.noreply.github.com>
…t/logout/LogoutController.java Co-authored-by: Michał Wojtas <80779749+CitralFlo@users.noreply.github.com>
…t/logout/LogoutController.java Co-authored-by: Michał Wojtas <80779749+CitralFlo@users.noreply.github.com>
…t/logout/LogoutController.java Co-authored-by: Michał Wojtas <80779749+CitralFlo@users.noreply.github.com>
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/logout/LogoutController.java (1)
35-57: Good implementation of kick reason checksThis new handler properly checks if kicked players should be exempt from combat punishment based on the whitelist.
Two small suggestions:
- Consider making this method package-private instead of private so the event system can access it
- The string matching might be too broad since it uses
contains- this could match partial words- private void onKick(PlayerKickEvent event) { + void onKick(PlayerKickEvent event) {Consider using more precise matching for kick reasons:
- if (reason.toLowerCase().contains(whitelisted.toLowerCase())) { + if (reason.toLowerCase().equals(whitelisted.toLowerCase()) + || reason.toLowerCase().matches(".*\\b" + whitelisted.toLowerCase() + "\\b.*")) {
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
eternalcombat-plugin/src/main/java/com/eternalcode/combat/config/implementation/CombatSettings.java(2 hunks)eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/logout/LogoutController.java(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- eternalcombat-plugin/src/main/java/com/eternalcode/combat/config/implementation/CombatSettings.java
🔇 Additional comments (3)
eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/logout/LogoutController.java (3)
26-26: Nice addition of a thread-safe set for tracking exempt playersThe use of a
ConcurrentHashMap-backed set is a good choice for tracking players who shouldn't be punished when quitting.
59-99: Handlers for different event priorities look goodThe implementation correctly checks the configured priority before handling the event.
101-110: Smart way to skip punishment for whitelisted kick reasonsThe check for exempt players works well by removing them from the set after checking.
- Added untagall command to untag all tagged players at once. useful in cases when you want to do something related to events.
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
eternalcombat-plugin/src/main/java/com/eternalcode/combat/config/implementation/MessagesSettings.java (1)
131-136: Update the comment to match the feature.The current comment says it's for when an admin removes "a player" but this message is used when removing multiple players at once.
@Comment({ - "# Message displayed to an admin when they remove a player from combat.", - "# The {PLAYER} placeholder is replaced with the player's name." + "# Message displayed to an admin when they remove all players from combat.", + "# The {COUNT} placeholder is replaced with the number of players removed." })
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
eternalcombat-plugin/src/main/java/com/eternalcode/combat/config/implementation/CombatSettings.java(2 hunks)eternalcombat-plugin/src/main/java/com/eternalcode/combat/config/implementation/MessagesSettings.java(1 hunks)eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/FightTagCommand.java(2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- eternalcombat-plugin/src/main/java/com/eternalcode/combat/config/implementation/CombatSettings.java
🔇 Additional comments (1)
eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/FightTagCommand.java (1)
127-127: Good change to support more command senders.Changing from Player to CommandSender allows both players and console to use this command.
eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/FightTagCommand.java
Show resolved
Hide resolved
CitralFlo
left a comment
There was a problem hiding this comment.
Everything looks good to me
Nice work!
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/drop/DropController.java (2)
75-139: Consider breaking down the handleDeath method.The method is quite long with multiple responsibilities. Consider splitting it into smaller methods like
processHeadDrop()andprocessItemDrops()for better readability.private void handleDeath(PlayerDeathEvent event) { Player player = event.getEntity(); UUID uuid = player.getUniqueId(); DropType dropType = this.dropSettings.dropType; boolean inCombat = this.fightManager.isInCombat(uuid); + processHeadDrop(event, player, inCombat); + processItemDrops(event, player, dropType, inCombat); + } + + private void processHeadDrop(PlayerDeathEvent event, Player player, boolean inCombat) { if (this.dropSettings.headDropEnabled && this.dropSettings.headDropChance > 0.0) { boolean shouldDrop = (!this.dropSettings.headDropOnlyInCombat || inCombat) && ThreadLocalRandom.current().nextDouble(0, 100) <= this.dropSettings.headDropChance; if (shouldDrop) { ItemStack head = new ItemStack(Material.PLAYER_HEAD); SkullMeta meta = (SkullMeta) head.getItemMeta(); if (meta != null) { meta.setOwningPlayer(player); String killerName = player.getKiller() != null ? player.getKiller().getName() : "Unknown"; String displayName = this.dropSettings.headDropDisplayName .replace("{PLAYER}", player.getName()) .replace("{KILLER}", killerName); meta.setDisplayName(displayName); if (!this.dropSettings.headDropLore.isEmpty()) { List<String> lore = this.dropSettings.headDropLore.stream() .map(line -> line.replace("{PLAYER}", player.getName()).replace("{KILLER}", killerName)) .toList(); meta.setLore(lore); } head.setItemMeta(meta); } event.getDrops().add(head); } } + } + + private void processItemDrops(PlayerDeathEvent event, Player player, DropType dropType, boolean inCombat) { if (dropType == DropType.UNCHANGED || !inCombat) { return; } List<ItemStack> drops = event.getDrops(); Drop drop = Drop.builder() .player(player) .killer(player.getKiller()) .droppedItems(drops) .droppedExp(player.getTotalExperience()) .build(); DropResult result = this.dropService.modify(dropType, drop); if (result == null) { return; } drops.clear(); drops.addAll(result.droppedItems()); this.keepInventoryManager.addItems(player.getUniqueId(), result.removedItems()); if (this.dropSettings.affectExperience) { event.setDroppedExp(drop.getDroppedExp()); } }
93-103: Extract placeholder replacement to a helper method.The placeholder replacement logic is duplicated for display name and lore. Consider creating a helper method to reduce duplication.
+ private String replacePlaceholders(String text, Player player) { + String killerName = player.getKiller() != null ? player.getKiller().getName() : "Unknown"; + return text + .replace("{PLAYER}", player.getName()) + .replace("{KILLER}", killerName); + } String displayName = this.dropSettings.headDropDisplayName - .replace("{PLAYER}", player.getName()) - .replace("{KILLER}", killerName); + replacePlaceholders(this.dropSettings.headDropDisplayName, player); meta.setDisplayName(displayName); if (!this.dropSettings.headDropLore.isEmpty()) { List<String> lore = this.dropSettings.headDropLore.stream() - .map(line -> line.replace("{PLAYER}", player.getName()).replace("{KILLER}", killerName)) + .map(line -> replacePlaceholders(line, player)) .toList(); meta.setLore(lore); }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (3)
eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/controller/FightTagController.java(4 hunks)eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/drop/DropController.java(4 hunks)eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/drop/DropSettings.java(2 hunks)
🔇 Additional comments (11)
eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/controller/FightTagController.java (4)
59-64: Good addition of permission checksSimple permission checks to let certain players bypass combat tagging. Makes the plugin more flexible for server admins.
86-96: Nice implementation of conditional taggingThe code now checks permissions before tagging players, and extracts UUIDs into variables for better readability. This makes the system more flexible while keeping the code clean.
118-121: Added general bypass permissionGood addition of a general bypass check that complements the more specific permissions added earlier.
123-123: Consistent timer retrievalThis matches the same pattern used in the other event handler, maintaining consistency.
eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/drop/DropSettings.java (5)
12-18: Good use of comments for explaining EventPriority settings.Clear and detailed comments help users understand what each priority level means and when they'd want to use them.
36-40: Nice addition of head drop feature toggle.The comment clearly explains what this setting does, making it easy for server admins to understand.
42-47: Well-documented chance setting.Good explanation of how the drop chance works, with clear examples and boundary values.
54-60: Good use of placeholder documentation.The comment clearly shows what placeholders are available and provides a helpful example.
61-69: Well-structured default lore configuration.Good default values that make sense for the feature, with clear comments about placeholder usage.
eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/drop/DropController.java (2)
33-73: Good implementation of priority-based event handling.The code correctly handles all event priorities by creating separate handlers that check against the configured priority. This gives users fine control over when drop processing happens.
81-110: Well-implemented player head drop feature.The code correctly implements the configurable head drop feature with:
- Proper chance calculation
- Combat status check
- Player and killer name placeholders
- Custom display name and lore
…agController#cannotBeTagged
…re is a bug where you can still can fly if you are already flying when getting tagged.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (1)
eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/controller/FightActionBlockerController.java (1)
131-132: Remove extra empty linesThese empty lines aren't needed and can be removed to keep the code cleaner.
} } - - @EventHandler
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/controller/FightActionBlockerController.java(2 hunks)eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/controller/FightTagController.java(4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/controller/FightTagController.java
🔇 Additional comments (2)
eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/controller/FightActionBlockerController.java (2)
21-21: Good addition of the necessary importThe import for PlayerMoveEvent is correctly added to support the new functionality.
113-129: Good implementation of Elytra restriction during movementThis handler nicely complements the existing
onToggleGlidemethod by actively checking and disabling gliding during player movement. The code follows the same pattern as other event handlers in this class with proper early returns and clear logic.
Rollczi
left a comment
There was a problem hiding this comment.
Hi thanks for your PR! Checkout my "request changes" and commit with event related changes.
Please describe the changes made by this PR and why they need to be merged: