mirror of
https://github.com/TotalFreedomMC/TF-ProjectKorra.git
synced 2025-02-12 03:59:06 +00:00
Remove unnecessary checks in Flight
This commit is contained in:
parent
0a1595f96c
commit
eb9d7f9cbf
1 changed files with 23 additions and 33 deletions
|
@ -1,6 +1,5 @@
|
||||||
package com.projectkorra.projectkorra.util;
|
package com.projectkorra.projectkorra.util;
|
||||||
|
|
||||||
import com.projectkorra.projectkorra.ability.AvatarState;
|
|
||||||
import com.projectkorra.projectkorra.airbending.AirScooter;
|
import com.projectkorra.projectkorra.airbending.AirScooter;
|
||||||
import com.projectkorra.projectkorra.airbending.AirSpout;
|
import com.projectkorra.projectkorra.airbending.AirSpout;
|
||||||
import com.projectkorra.projectkorra.airbending.Tornado;
|
import com.projectkorra.projectkorra.airbending.Tornado;
|
||||||
|
@ -21,10 +20,10 @@ public class Flight {
|
||||||
private static ConcurrentHashMap<Player, Flight> instances = new ConcurrentHashMap<Player, Flight>();
|
private static ConcurrentHashMap<Player, Flight> instances = new ConcurrentHashMap<Player, Flight>();
|
||||||
private static long duration = 5000;
|
private static long duration = 5000;
|
||||||
|
|
||||||
private Player player = null, source = null;
|
private Player player;
|
||||||
|
private Player source;
|
||||||
private boolean couldFly = false, wasFlying = false;
|
private boolean couldFly = false;
|
||||||
|
private boolean wasFlying = false;
|
||||||
private long time;
|
private long time;
|
||||||
|
|
||||||
public Flight(Player player) {
|
public Flight(Player player) {
|
||||||
|
@ -38,11 +37,11 @@ public class Flight {
|
||||||
instances.replace(player, flight);
|
instances.replace(player, flight);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
couldFly = player.getAllowFlight();
|
this.couldFly = player.getAllowFlight();
|
||||||
wasFlying = player.isFlying();
|
this.wasFlying = player.isFlying();
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.source = source;
|
this.source = source;
|
||||||
time = System.currentTimeMillis();
|
this.time = System.currentTimeMillis();
|
||||||
instances.put(player, this);
|
instances.put(player, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -59,14 +58,13 @@ public class Flight {
|
||||||
if (instances.containsKey(player)) {
|
if (instances.containsKey(player)) {
|
||||||
return instances.get(player).source;
|
return instances.get(player).source;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void handle() {
|
public static void handle() {
|
||||||
ArrayList<Player> players = new ArrayList<Player>();
|
ArrayList<Player> players = new ArrayList<Player>();
|
||||||
ArrayList<Player> newflyingplayers = new ArrayList<Player>();
|
ArrayList<Player> newflyingplayers = new ArrayList<Player>();
|
||||||
ArrayList<Player> avatarstateplayers = new ArrayList<Player>();
|
//ArrayList<Player> avatarstateplayers = new ArrayList<Player>();
|
||||||
ArrayList<Player> airscooterplayers = new ArrayList<Player>();
|
ArrayList<Player> airscooterplayers = new ArrayList<Player>();
|
||||||
ArrayList<Player> waterspoutplayers = new ArrayList<Player>();
|
ArrayList<Player> waterspoutplayers = new ArrayList<Player>();
|
||||||
ArrayList<Player> airspoutplayers = new ArrayList<Player>();
|
ArrayList<Player> airspoutplayers = new ArrayList<Player>();
|
||||||
|
@ -76,7 +74,7 @@ public class Flight {
|
||||||
// players.addAll(Speed.getPlayers());
|
// players.addAll(Speed.getPlayers());
|
||||||
players.addAll(FireJet.getPlayers());
|
players.addAll(FireJet.getPlayers());
|
||||||
players.addAll(Catapult.getPlayers());
|
players.addAll(Catapult.getPlayers());
|
||||||
avatarstateplayers = AvatarState.getPlayers();
|
//avatarstateplayers = AvatarState.getPlayers();
|
||||||
airscooterplayers = AirScooter.getPlayers();
|
airscooterplayers = AirScooter.getPlayers();
|
||||||
waterspoutplayers = WaterSpout.getPlayers();
|
waterspoutplayers = WaterSpout.getPlayers();
|
||||||
airspoutplayers = AirSpout.getPlayers();
|
airspoutplayers = AirSpout.getPlayers();
|
||||||
|
@ -112,15 +110,8 @@ public class Flight {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (flight.source == null) {
|
flight.revert();
|
||||||
flight.revert();
|
flight.remove();
|
||||||
flight.remove();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (System.currentTimeMillis() > flight.time + duration) {
|
|
||||||
flight.revert();
|
|
||||||
flight.remove();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -128,11 +119,10 @@ public class Flight {
|
||||||
public static void removeAll() {
|
public static void removeAll() {
|
||||||
for (Player player : instances.keySet()) {
|
for (Player player : instances.keySet()) {
|
||||||
Flight flight = instances.get(player);
|
Flight flight = instances.get(player);
|
||||||
if (player == null || flight == null) {
|
if (flight == null) {
|
||||||
instances.remove(player);
|
instances.remove(player);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
//if (flight.source != null)
|
|
||||||
flight.revert();
|
flight.revert();
|
||||||
flight.remove();
|
flight.remove();
|
||||||
}
|
}
|
||||||
|
@ -145,21 +135,21 @@ public class Flight {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void remove() {
|
public void remove() {
|
||||||
if (player == null) {
|
// if (player == null) {
|
||||||
for (Player player : instances.keySet()) {
|
// for (Player player : instances.keySet()) {
|
||||||
if (instances.get(player).equals(this)) {
|
// if (instances.get(player).equals(this)) {
|
||||||
instances.remove(player);
|
// instances.remove(player);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
instances.remove(player);
|
instances.remove(player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void revert() {
|
public void revert() {
|
||||||
if (player == null) {
|
// if (player == null) {
|
||||||
return;
|
// return;
|
||||||
}
|
// }
|
||||||
player.setAllowFlight(couldFly);
|
player.setAllowFlight(couldFly);
|
||||||
player.setFlying(wasFlying);
|
player.setFlying(wasFlying);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue