-
Notifications
You must be signed in to change notification settings - Fork 138
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
Flight Fixes #963
Flight Fixes #963
Conversation
WaterArms and FireWheel fixes (#950) Merge
|
||
public class FlightMultiAbility extends FlightAbility implements MultiAbility{ | ||
|
||
public static Map<UUID, UUID> requestedMap = new HashMap<>(); | ||
public static Map<UUID, Long> requestTime = new HashMap<>(); | ||
|
||
private static Set<UUID> flying = new HashSet<>(); | ||
private boolean canFly, hadFly, hadGlide; | ||
private boolean hadGlide; | ||
private Flight flight; |
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.
You should never store an instance of Flight yourself. FlightHandler will manage all of this.
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.
In the FlightMultiAbility I set the states of flying various times depending on the mode. In the ending mode, I want them to have whatever the state of flying was before using the ability or starting to fly. I store it so I can access those stored states whenever they go to ending mode (since it's a mutliability, they can switch between binds whenever, need to check every iteration of progress). I do this because FlightHandler doesn't manage it in the way I said, not when I need it to. So yes I do need to store the instance of Flight, or else why does the createInstance method return Flight at all, if I'm not intended to store it?
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.
In the FlightMultiAbility I set the states of flying various times depending on the mode.
That's fine, though you shouldn't be doing that from the Flight instance. FlightHandler works by storing a player's flight state for multiple identifiers and does not reverting until all instances have been removed. If you were want to give them flight, use the createInstance method and then do whatever you want with the player (setFlying(true/false), setAllowFlight(true/false)). Then when you're done, call the removeInstance method. If they have no other instances of Flight outstanding, and only if that is true, it will revert their flight state back to what it was when you (or their first flight instance) called createFlight. If you are manually setting their flight back when their FlightMultiAbility is removed, that will also prematurely revert their flight for another ability.
Eg. A player is hit by AirSwipe, Tornado, AirBlast, etc. just before their FlightMultiAbility ends. Keep in mind that the whole point of FlightHandler, and the reason we had so many fly glitches before, was because abilities did not communicate player's flight states correctly. FlightHandler is designed to save a player's fly state, and then when ALL abilities are done using flight, revert it back to what it was. You're completely defeating the purpose of using FlightHandler by manually reverting it.
or else why does the createInstance method return Flight at all, if I'm not intended to store it?
It doesn't actually need to return the Flight instance, and I'll change that in a future PR.
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.
If you are manually setting their flight back when their FlightMultiAbility is removed, that will also prematurely revert their flight for another ability.
This doesn't make sense. It shouldn't revert flight for other abilities if I just change their flying states, even if it is back to what it was before the flight. Nowhere would the code cause other abilities flight to prematurely revert.
It doesn't actually need to return the Flight instance, and I'll change that in a future PR.
I think this should be left how it is, because it is useful to access flight (since you can't actually change anything about the flight itself)
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.
It shouldn't revert flight for other abilities if I just change their flying states, even if it is back to what it was before the flight. Nowhere would the code cause other abilities flight to prematurely revert.
If another ability has someone set flying and you turn it off, or vice verse, you are prematurely reverting that abilities flight.
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.
And it should be? FlightMultiAbility should take priority
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.
No it shouldn't. If someone is hit with AirBlast a moment before ending their FlightMultiAbility, doing what you're doing will also remove AirBlast's Flight instance, likely causing the player to get kicked for flying.
MultiAbilityManager.bindMultiAbility(player, "Flight"); | ||
hadFly = player.isFlying(); | ||
canFly = player.getAllowFlight(); | ||
flight = ProjectKorra.flightHandler.createInstance(player, "FlightMultiAbility"); |
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.
Use getName() or store a final String with the value of "FlightMultiAbility" instead
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.
Doesn't make much difference what identifier I use tbh, but sure I'll change it
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.
Yeah, I just think it's more aesthetically pleasing, and since it's being used in multiple locations it makes sense to do so imo
@@ -215,8 +243,8 @@ public void run() { | |||
player.setFlying(true); | |||
} else if (mode == FlightMode.ENDING) { | |||
player.setGliding(hadGlide); | |||
player.setAllowFlight(canFly); | |||
player.setFlying(hadFly); | |||
player.setAllowFlight(flight.getCouldFly()); |
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.
Again, FlightHandler will manage the reversion of a player's flight state. These lines need to be removed.
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.
Refer to first comment
@@ -289,8 +317,7 @@ public void remove() { | |||
if (player.isOnline() && !player.isDead()) { | |||
player.eject(); | |||
} | |||
player.setAllowFlight(canFly); | |||
player.setFlying(hadFly); | |||
ProjectKorra.flightHandler.removeInstance(player, "FlightMultiAbility"); |
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.
This line will manage the player's flight state, but again change "FlightMultiAbility" to getName() or a final String with the same value.
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.
Refer to second comment
@@ -199,6 +199,14 @@ public Player getPlayer() { | |||
public Player getSource() { | |||
return source; | |||
} | |||
|
|||
public boolean getCouldFly() { |
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.
All of these changes can go given my previous comments.
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.
These should stay regardless. It is now and could be useful in the future.
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.
Given the top comment, there's no need a third party would need to access this information. Like how I have createInstance returning a Flight instance where it shouldn't be stored, these methods are asking for people to access them when they don't need to.
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.
But there is no harm in them accessing them, since they can't change them.
Requested changes have been completed
@@ -128,6 +148,11 @@ public void progress() { | |||
return; | |||
} | |||
|
|||
if (!bPlayer.hasElement(Element.AIR)) { |
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.
This check is not necessary as of #964.
Not necessary after #964.
Fixes
Misc. Changes