-
-
Notifications
You must be signed in to change notification settings - Fork 9
GH-345 Fix enforcing region knockback for mounted combat players #345
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -9,12 +9,15 @@ | |||
| import java.util.Optional; | ||||
| import org.bukkit.Location; | ||||
| import org.bukkit.Server; | ||||
| import org.bukkit.entity.Entity; | ||||
| import org.bukkit.entity.Player; | ||||
| import org.bukkit.event.EventHandler; | ||||
| import org.bukkit.event.EventPriority; | ||||
| import org.bukkit.event.Listener; | ||||
| import org.bukkit.event.player.PlayerMoveEvent; | ||||
| import org.bukkit.event.player.PlayerTeleportEvent; | ||||
| import org.bukkit.event.vehicle.VehicleMoveEvent; | ||||
| import org.spigotmc.event.entity.EntityMountEvent; | ||||
|
|
||||
| public class KnockbackRegionController implements Listener { | ||||
|
|
||||
|
|
@@ -89,6 +92,68 @@ void onPlayerTeleport(PlayerTeleportEvent event) { | |||
| } | ||||
| } | ||||
|
|
||||
| @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) | ||||
| 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(); | ||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Already in |
||||
| if (region.contains(locationFrom)) { | ||||
| this.knockbackService.knockback(region, player); | ||||
| this.knockbackService.forceKnockbackLater(player, region); | ||||
| } else { | ||||
| this.knockbackService.knockbackLater(region, player, Duration.ofMillis(50)); | ||||
| } | ||||
|
Comment on lines
+122
to
+127
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. maybe this could be exctracted? or even optimized |
||||
|
|
||||
| this.noticeService.create() | ||||
| .player(player.getUniqueId()) | ||||
| .notice(config -> config.messagesSettings.cantEnterOnRegion) | ||||
| .send(); | ||||
| } | ||||
| } | ||||
Jakubk15 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||
|
|
||||
| @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(); | ||||
| } | ||||
|
Comment on lines
+96
to
+155
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current implementation lacks handling for |
||||
|
|
||||
| @EventHandler(ignoreCancelled = true, priority = EventPriority.HIGHEST) | ||||
| void onTag(FightTagEvent event) { | ||||
| Player player = this.server.getPlayer(event.getPlayer()); | ||||
|
|
||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to method?