Skip to content
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

Fix PlayerToggleFlightEvent trigger #2152

Merged
merged 2 commits into from
Oct 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 30 additions & 25 deletions src/main/java/cn/nukkit/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -2546,6 +2546,36 @@ public void onCompletion(Server server) {
}
}

if (authPacket.getInputData().contains(AuthInputAction.START_FLYING)) {
if (!server.getAllowFlight() && !this.getAdventureSettings().get(Type.ALLOW_FLIGHT)) {
this.kick(PlayerKickEvent.Reason.FLYING_DISABLED, "Flying is not enabled on this server");
break;
}
PlayerToggleFlightEvent playerToggleFlightEvent = new PlayerToggleFlightEvent(this, true);
if (this.isSpectator()) {
playerToggleFlightEvent.setCancelled();
}
this.getServer().getPluginManager().callEvent(playerToggleFlightEvent);
if (playerToggleFlightEvent.isCancelled()) {
this.getAdventureSettings().update();
} else {
this.getAdventureSettings().set(AdventureSettings.Type.FLYING, playerToggleFlightEvent.isFlying());
}
}

if (authPacket.getInputData().contains(AuthInputAction.STOP_FLYING)) {
PlayerToggleFlightEvent playerToggleFlightEvent = new PlayerToggleFlightEvent(this, false);
if (this.isSpectator()) {
playerToggleFlightEvent.setCancelled();
}
this.getServer().getPluginManager().callEvent(playerToggleFlightEvent);
PetteriM1 marked this conversation as resolved.
Show resolved Hide resolved
if (playerToggleFlightEvent.isCancelled()) {
this.getAdventureSettings().update();
} else {
this.getAdventureSettings().set(AdventureSettings.Type.FLYING, playerToggleFlightEvent.isFlying());
}
}

Vector3 clientPosition = authPacket.getPosition().asVector3()
.subtract(0, this.getEyeHeight(), 0);

Expand Down Expand Up @@ -2591,31 +2621,6 @@ public void onCompletion(Server server) {
}
}
break;
case ProtocolInfo.REQUEST_ABILITY_PACKET:
RequestAbilityPacket abilityPacket = (RequestAbilityPacket) packet;

PlayerAbility ability = abilityPacket.getAbility();
if (ability != PlayerAbility.FLYING) {
this.server.getLogger().info("[" + this.getName() + "] has tried to trigger " + ability + " ability " + (abilityPacket.isBoolValue() ? "on" : "off"));
return;
}

if (!server.getAllowFlight() && abilityPacket.isBoolValue() && !this.getAdventureSettings().get(Type.ALLOW_FLIGHT)) {
this.kick(PlayerKickEvent.Reason.FLYING_DISABLED, "Flying is not enabled on this server");
break;
}

PlayerToggleFlightEvent playerToggleFlightEvent = new PlayerToggleFlightEvent(this, abilityPacket.isBoolValue());
if (this.isSpectator()) {
playerToggleFlightEvent.setCancelled();
}
this.server.getPluginManager().callEvent(playerToggleFlightEvent);
if (playerToggleFlightEvent.isCancelled()) {
this.getAdventureSettings().update();
} else {
this.getAdventureSettings().set(Type.FLYING, playerToggleFlightEvent.isFlying());
}
break;
case ProtocolInfo.MOB_EQUIPMENT_PACKET:
if (!this.spawned || !this.isAlive()) {
break;
Expand Down