Refactor snowball event handling for better readability.
Renamed method for clarity and improved team player checks. Added debug logs for unsupported scenarios and ensured no actions occur when players hit teammates. These changes enhance code maintainability and prevent unintended behavior.
This commit is contained in:
parent
172f9a29a2
commit
55b88a950d
|
|
@ -48,7 +48,7 @@ public class SnowballEvent implements Listener {
|
||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onSnowballHitBySnowball(ProjectileLaunchEvent event) {
|
public void onSnowballThrown(ProjectileLaunchEvent event) {
|
||||||
handleSnowballThrown(event, (shooter, shooterTeamPlayer) -> {
|
handleSnowballThrown(event, (shooter, shooterTeamPlayer) -> {
|
||||||
GameClass shooterClass = shooterTeamPlayer.getGameClass();
|
GameClass shooterClass = shooterTeamPlayer.getGameClass();
|
||||||
shooter.setCooldown(Material.SNOWBALL, shooterClass.getThrowTickSpeed());
|
shooter.setCooldown(Material.SNOWBALL, shooterClass.getThrowTickSpeed());
|
||||||
|
|
@ -105,11 +105,22 @@ public class SnowballEvent implements Listener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<TeamPlayer> teamPlayer = gameManager.getTeamPlayer(shooter.getUniqueId());
|
Optional<TeamPlayer> teamPlayerShooter = gameManager.getTeamPlayer(shooter.getUniqueId());
|
||||||
if (teamPlayer.isEmpty()) {
|
if (teamPlayerShooter.isEmpty()) {
|
||||||
log.debug("The shooter that hit a player with a snowball was not a team player");
|
log.debug("The shooter that hit a player with a snowball was not a team player");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
consumer.apply(hitPlayer, shooter, teamPlayer.get());
|
|
||||||
|
Optional<TeamPlayer> teamPlayerHit = gameManager.getTeamPlayer(hitPlayer.getUniqueId());
|
||||||
|
if (teamPlayerHit.isEmpty()) {
|
||||||
|
log.debug("The shooter that hit a player with a snowball was not a team player");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (teamPlayerHit.get().getTeam().getId() == teamPlayerShooter.get().getTeam().getId()) {
|
||||||
|
log.debug("The shooter hit a member of their own team");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
consumer.apply(hitPlayer, shooter, teamPlayerHit.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user