mirror of
https://github.com/TotalFreedomMC/TF-ProjectKorra.git
synced 2025-02-11 11:40:40 +00:00
Flight: Hovering Glitch Fix and Code Cleanup
This commit is contained in:
parent
8b6ede61c6
commit
6548de6581
1 changed files with 32 additions and 35 deletions
|
@ -1,10 +1,12 @@
|
||||||
package com.projectkorra.ProjectKorra.airbending;
|
package com.projectkorra.ProjectKorra.airbending;
|
||||||
|
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
|
import com.projectkorra.ProjectKorra.Flight;
|
||||||
import com.projectkorra.ProjectKorra.Methods;
|
import com.projectkorra.ProjectKorra.Methods;
|
||||||
|
|
||||||
public class FlightAbility {
|
public class FlightAbility {
|
||||||
|
@ -13,15 +15,13 @@ public class FlightAbility {
|
||||||
private static ConcurrentHashMap<String, Integer> hits = new ConcurrentHashMap<String, Integer>();
|
private static ConcurrentHashMap<String, Integer> hits = new ConcurrentHashMap<String, Integer>();
|
||||||
private static ConcurrentHashMap<String, Boolean> hovering = new ConcurrentHashMap<String, Boolean>();
|
private static ConcurrentHashMap<String, Boolean> hovering = new ConcurrentHashMap<String, Boolean>();
|
||||||
private Player p;
|
private Player p;
|
||||||
|
private Flight flight;
|
||||||
|
|
||||||
public FlightAbility(Player player) {
|
public FlightAbility(Player player) {
|
||||||
if(!Methods.canFly(player, true, false)) return;
|
if(!Methods.canFly(player, true, false))
|
||||||
|
return;
|
||||||
player.setAllowFlight(true);
|
player.setAllowFlight(true);
|
||||||
|
|
||||||
player.setVelocity(player.getEyeLocation().getDirection().normalize());
|
player.setVelocity(player.getEyeLocation().getDirection().normalize());
|
||||||
|
|
||||||
instances.put(player.getName(), this);
|
instances.put(player.getName(), this);
|
||||||
p = player;
|
p = player;
|
||||||
}
|
}
|
||||||
|
@ -32,11 +32,20 @@ public class FlightAbility {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
p.setAllowFlight(true);
|
if(flight == null)
|
||||||
|
flight = new Flight(p);
|
||||||
|
|
||||||
|
if(isHovering(p)) {
|
||||||
|
Vector vec = p.getVelocity().clone();
|
||||||
|
vec.setY(0);
|
||||||
|
p.setVelocity(vec);
|
||||||
|
}
|
||||||
|
else {
|
||||||
p.setVelocity(p.getEyeLocation().getDirection().normalize());
|
p.setVelocity(p.getEyeLocation().getDirection().normalize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static void addHit(Player player) {
|
public static void addHit(Player player) {
|
||||||
if(instances.containsKey(player)) {
|
if(instances.containsKey(player)) {
|
||||||
if(hits.containsKey(player.getName())) {
|
if(hits.containsKey(player.getName())) {
|
||||||
|
@ -51,11 +60,7 @@ public class FlightAbility {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isHovering(Player player) {
|
public static boolean isHovering(Player player) {
|
||||||
String playername = player.getName();
|
return hovering.containsKey(player.getName());
|
||||||
|
|
||||||
if(hovering.containsKey(playername) && hovering.get(playername)) return true;
|
|
||||||
if(hovering.containsKey(playername) && hovering.get(playername)) return false; //Shouldn't happen
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setHovering(Player player, boolean bool) {
|
public static void setHovering(Player player, boolean bool) {
|
||||||
|
@ -64,13 +69,11 @@ public class FlightAbility {
|
||||||
if(bool) {
|
if(bool) {
|
||||||
if(!hovering.containsKey(playername)) {
|
if(!hovering.containsKey(playername)) {
|
||||||
hovering.put(playername, true);
|
hovering.put(playername, true);
|
||||||
player.setFlying(true);
|
player.setVelocity(new Vector(0, 0, 0));
|
||||||
player.setVelocity(new Vector(0, 0 ,0));
|
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
if(hovering.containsKey(playername)) {
|
if(hovering.containsKey(playername)) {
|
||||||
hovering.remove(playername);
|
hovering.remove(playername);
|
||||||
player.setFlying(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,30 +84,24 @@ public class FlightAbility {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
public void remove() {
|
||||||
|
String name = p.getName();
|
||||||
|
instances.remove(name);
|
||||||
|
hits.remove(name);
|
||||||
|
hovering.remove(name);
|
||||||
|
flight.revert();
|
||||||
|
}
|
||||||
|
|
||||||
public static void remove(Player player) {
|
public static void remove(Player player) {
|
||||||
if(instances.containsKey(player.getName())) {
|
if(instances.containsKey(player.getName()))
|
||||||
instances.remove(player.getName());
|
instances.get(player.getName()).remove();
|
||||||
if(hits.containsKey(player.getName())) {
|
|
||||||
hits.remove(player.getName());
|
|
||||||
}
|
|
||||||
if(hovering.containsKey(player.getName())) {
|
|
||||||
hovering.remove(player.getName());
|
|
||||||
}
|
|
||||||
if((!(player.getGameMode().getValue() == 1))) {
|
|
||||||
if(!(player.getGameMode().getValue() == 1)) {
|
|
||||||
player.setAllowFlight(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if((!(player.getGameMode().getValue() == 3))) {
|
|
||||||
if(!(player.getGameMode().getValue() == 1)) {
|
|
||||||
player.setAllowFlight(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeAll() {
|
public static void removeAll() {
|
||||||
|
Iterator<String> it = instances.keySet().iterator();
|
||||||
|
while (it.hasNext()) {
|
||||||
|
instances.get(it.next()).remove();
|
||||||
|
}
|
||||||
instances.clear();
|
instances.clear();
|
||||||
hits.clear();
|
hits.clear();
|
||||||
hovering.clear();
|
hovering.clear();
|
||||||
|
|
Loading…
Reference in a new issue