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

Flight Fixes #963

Merged
merged 16 commits into from
Jul 15, 2018
Merged

Flight Fixes #963

merged 16 commits into from
Jul 15, 2018

Conversation

Simplicitee
Copy link
Member

@Simplicitee Simplicitee commented Jul 10, 2018

Fixes

  • Fixes Flight causing fly glitch w/other abilities
  • Fixes Flight persisting without Air element

Misc. Changes

  • Adds Override annotation to event methods
  • Removes accessibility to more of FlightHandler and sub-classes


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;
Copy link
Contributor

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.

Copy link
Member Author

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?

Copy link
Contributor

@jayoevans jayoevans Jul 10, 2018

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.

Copy link
Member Author

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)

Copy link
Contributor

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.

Copy link
Member Author

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

Copy link
Contributor

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");
Copy link
Contributor

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

Copy link
Member Author

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

Copy link
Contributor

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());
Copy link
Contributor

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.

Copy link
Member Author

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");
Copy link
Contributor

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.

Copy link
Member Author

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() {
Copy link
Contributor

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.

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Member Author

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.

@ChristopherWMM ChristopherWMM dismissed jayoevans’s stale review July 14, 2018 21:52

Requested changes have been completed

@@ -128,6 +148,11 @@ public void progress() {
return;
}

if (!bPlayer.hasElement(Element.AIR)) {
Copy link
Member

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.

@ChristopherWMM ChristopherWMM merged commit 1debe50 into ProjectKorra:wip Jul 15, 2018
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.

None yet

3 participants