Skip to content

Commit

Permalink
Added bypass for fly checkers
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan923 committed Sep 17, 2020
1 parent b4d6aca commit 0e04edc
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private boolean checkNearbyPlayers(Player player, FPlayer fplayer) {
boolean canFly = true;

FPlayers fpInstance = FPlayers.getInstance();
for (Player nearbyPlayer : getNearbyPlayers(player, settings.getInt("Hooks.Factions.Auto-Disable Near Enemies.Check Radius"))) {
for (Player nearbyPlayer : getNearbyPlayers(player, settings.getInt("Hooks.Factions.Auto-Disable Near Enemies.Check Radius"), instance)) {
if (fplayer.getRelationTo(fpInstance.getByPlayer(nearbyPlayer)) == com.massivecraft.factions.struct.Relation.ENEMY) {
if (nearbyPlayer.getAllowFlight()) {
instance.getUser(nearbyPlayer).setFlight(false, CheckResult.NEARBY_ENEMIES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private boolean checkNearbyPlayers(Player player, FPlayer fplayer) {
boolean canFly = true;

FPlayers fpInstance = FPlayers.getInstance();
for (Player nearbyPlayer : getNearbyPlayers(player, settings.getInt("Hooks.Factions.Auto-Disable Near Enemies.Check Radius"))) {
for (Player nearbyPlayer : getNearbyPlayers(player, settings.getInt("Hooks.Factions.Auto-Disable Near Enemies.Check Radius"), instance)) {
if (fplayer.getRelationTo(fpInstance.getByPlayer(nearbyPlayer)) == Relation.ENEMY) {
if (nearbyPlayer.getAllowFlight()) {
instance.getUser(nearbyPlayer).setFlight(false, CheckResult.NEARBY_ENEMIES);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.stefan923.perfectflight.utils;

import me.stefan923.perfectflight.PerfectFlight;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;

Expand All @@ -8,14 +9,15 @@

public interface PlayerUtils {

default List<Player> getNearbyPlayers(Player player, int distance) {
default List<Player> getNearbyPlayers(Player player, int distance, PerfectFlight instance) {
List<Player> list = new ArrayList<>();

for (Entity entity : player.getNearbyEntities(distance, distance, distance)) {
if (entity instanceof Player) {
Player nearbyPlayer = (Player) entity;
User nearbyUser = instance.getUser(nearbyPlayer);

if (nearbyPlayer.canSee(player) && player.canSee(nearbyPlayer))
if (!nearbyUser.isBypassing() && nearbyPlayer.canSee(player) && player.canSee(nearbyPlayer))
list.add(nearbyPlayer);
}
}
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/me/stefan923/perfectflight/utils/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ public class User implements MessageUtils {
private final Player player;

private boolean enableFly;
private boolean isBypassing;
private long noFallDamageDuration;

public User(PerfectFlight instance, Player player) {
this.instance = instance;
this.player = player;
this.enableFly = true;
this.isBypassing = false;
this.noFallDamageDuration = 0;

instance.getUsers().put(player, this);
Expand All @@ -31,6 +33,14 @@ public boolean getFly() {
return enableFly;
}

public boolean isBypassing() {
return isBypassing;
}

public void setBypassing(boolean bypassing) {
isBypassing = bypassing;
}

public long getNoFallDamageDuration() {
return noFallDamageDuration;
}
Expand Down Expand Up @@ -104,6 +114,10 @@ public void checkFly() {
}

public CheckResult canFly() {
if (isBypassing) {
return CheckResult.ALLOWED;
}

for (AbstractChecker checker : instance.getCheckers()) {
CheckResult checkResult = checker.canFlyAtLocation(player);
if (checkResult != CheckResult.ALLOWED) {
Expand All @@ -112,5 +126,4 @@ public CheckResult canFly() {
}
return CheckResult.ALLOWED;
}

}

0 comments on commit 0e04edc

Please sign in to comment.