Skip to content

GH-345 Fix enforce region knockback for mounted combat players#345

Open
vLuckyyy wants to merge 1 commit intomasterfrom
vehicle-region-knockback
Open

GH-345 Fix enforce region knockback for mounted combat players#345
vLuckyyy wants to merge 1 commit intomasterfrom
vehicle-region-knockback

Conversation

@vLuckyyy
Copy link
Member

image

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @vLuckyyy, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the region-based knockback system by specifically addressing scenarios involving mounted players in combat. It ensures that players engaged in combat cannot bypass region restrictions by riding vehicles, providing a more consistent and robust enforcement of game mechanics.

Highlights

  • Mounted Combat Region Enforcement: Introduced new event listeners (VehicleMoveEvent, EntityMountEvent) in KnockbackRegionController to detect and handle players in combat attempting to enter or mount within knockback-enforced regions.
  • Knockback Application for Mounted Players: Implemented logic to dismount combat players from their vehicles and apply region-specific knockback when they attempt to move into a restricted area while mounted.
  • Vehicle Dismount on Knockback: Modified KnockbackService to ensure players are dismounted from any vehicle they are riding before applying immediate or delayed knockback, preventing unintended behavior.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/knockback/KnockbackRegionController.java
    • Added imports for Entity, VehicleMoveEvent, and EntityMountEvent.
    • Implemented onVehicleMove event handler to check if mounted combat players are moving into a restricted region, dismount them, apply knockback, and send a notice.
    • Implemented onEntityMount event handler to cancel mounting if a combat player attempts to mount an entity within a restricted region and sends a notice.
  • eternalcombat-plugin/src/main/java/com/eternalcode/combat/fight/knockback/KnockbackService.java
    • Modified forceKnockbackLater method to include a check and dismount the player from their vehicle if they are inside one before applying delayed knockback.
    • Modified knockback method to include a check and dismount the player from their vehicle if they are inside one before applying immediate knockback.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@vLuckyyy vLuckyyy changed the title fix: enforce region knockback for mounted combat players GH-345 fix: enforce region knockback for mounted combat players Feb 16, 2026
@vLuckyyy vLuckyyy changed the title GH-345 fix: enforce region knockback for mounted combat players GH-345 Fix enforce region knockback for mounted combat players Feb 16, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a fix to enforce region knockback for players in mounted combat, handling VehicleMoveEvent and EntityMountEvent to dismount and knock back players in protected regions, and preventing mounting within them. While this is a positive step, the current implementation has security gaps as it only handles VehicleMoveEvent, missing many rideable entities (e.g., horses, other players) that do not implement the Vehicle interface, potentially allowing bypasses. It also doesn't fully account for entity teleportation, which could enable further circumvention of combat region boundaries. Additionally, there is an opportunity to improve maintainability by addressing some code duplication.

Comment on lines +96 to +134
void onVehicleMove(VehicleMoveEvent event) {
Location locationTo = event.getTo();
Location locationFrom = event.getFrom();

if (locationTo.getBlockX() == locationFrom.getBlockX()
&& locationTo.getBlockY() == locationFrom.getBlockY()
&& locationTo.getBlockZ() == locationFrom.getBlockZ()) {
return;
}

Optional<Region> regionOptional = this.regionProvider.getRegion(locationTo);
if (regionOptional.isEmpty()) {
return;
}

Region region = regionOptional.get();
for (Entity passenger : event.getVehicle().getPassengers()) {
if (!(passenger instanceof Player player)) {
continue;
}

if (!this.fightManager.isInCombat(player.getUniqueId())) {
continue;
}

player.leaveVehicle();
if (region.contains(locationFrom)) {
this.knockbackService.knockback(region, player);
this.knockbackService.forceKnockbackLater(player, region);
} else {
this.knockbackService.knockbackLater(region, player, Duration.ofMillis(50));
}

this.noticeService.create()
.player(player.getUniqueId())
.notice(config -> config.messagesSettings.cantEnterOnRegion)
.send();
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

security-medium medium

The onVehicleMove listener has a security gap: it only handles entities implementing the org.bukkit.entity.Vehicle interface (e.g., Boats, Minecarts), missing many other rideable entities like Horses, Llamas, Pigs, or other Players that do not trigger VehicleMoveEvent. This allows players in combat to bypass region restrictions. To fix this, consider checking for passengers in the onPlayerMove listener or implementing a more comprehensive movement check for all rideable entities.

Furthermore, the logic within this onVehicleMove event handler, especially inside the for loop, is very similar to the onPlayerMove handler, introducing code duplication. Extracting the common logic for applying knockback and sending notifications into a private helper method would improve maintainability and reduce redundancy.

Comment on lines +96 to +155
void onVehicleMove(VehicleMoveEvent event) {
Location locationTo = event.getTo();
Location locationFrom = event.getFrom();

if (locationTo.getBlockX() == locationFrom.getBlockX()
&& locationTo.getBlockY() == locationFrom.getBlockY()
&& locationTo.getBlockZ() == locationFrom.getBlockZ()) {
return;
}

Optional<Region> regionOptional = this.regionProvider.getRegion(locationTo);
if (regionOptional.isEmpty()) {
return;
}

Region region = regionOptional.get();
for (Entity passenger : event.getVehicle().getPassengers()) {
if (!(passenger instanceof Player player)) {
continue;
}

if (!this.fightManager.isInCombat(player.getUniqueId())) {
continue;
}

player.leaveVehicle();
if (region.contains(locationFrom)) {
this.knockbackService.knockback(region, player);
this.knockbackService.forceKnockbackLater(player, region);
} else {
this.knockbackService.knockbackLater(region, player, Duration.ofMillis(50));
}

this.noticeService.create()
.player(player.getUniqueId())
.notice(config -> config.messagesSettings.cantEnterOnRegion)
.send();
}
}

@EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST)
void onEntityMount(EntityMountEvent event) {
if (!(event.getEntity() instanceof Player player)) {
return;
}

if (!this.fightManager.isInCombat(player.getUniqueId())) {
return;
}

if (!this.regionProvider.isInRegion(event.getMount().getLocation())) {
return;
}

event.setCancelled(true);
this.noticeService.create()
.player(player.getUniqueId())
.notice(config -> config.messagesSettings.cantEnterOnRegion)
.send();
}
Copy link
Contributor

Choose a reason for hiding this comment

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

security-medium medium

The current implementation lacks handling for EntityTeleportEvent and VehicleTeleportEvent. If an entity (like a horse or a boat) carrying a player in combat is teleported into a restricted region (e.g., via a portal, a command, or another plugin's feature), the player will enter the region without triggering the knockback logic. This allows players to bypass combat region restrictions. It is recommended to implement listeners for these teleportation events to ensure passengers in combat are properly knocked back when entering restricted regions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments