mirror of
https://github.com/MassiveCraft/Factions.git
synced 2024-12-02 15:13:33 +01:00
Don't take fall damage after flying
This commit is contained in:
parent
055adf2e9e
commit
07eb3756e4
@ -55,6 +55,10 @@ public interface FPlayer extends EconomyParticipator {
|
||||
|
||||
public void setRole(Role role);
|
||||
|
||||
public boolean shouldTakeFallDamage();
|
||||
|
||||
public void setTakeFallDamage(boolean fallDamage);
|
||||
|
||||
public double getPowerBoost();
|
||||
|
||||
public void setPowerBoost(double powerBoost);
|
||||
|
@ -111,6 +111,12 @@ public class FactionsEntityListener implements Listener {
|
||||
} else if (Conf.safeZonePreventAllDamageToPlayers && isPlayerInSafeZone(event.getEntity())) {
|
||||
// Players can not take any damage in a Safe Zone
|
||||
event.setCancelled(true);
|
||||
} else if (event.getCause() == EntityDamageEvent.DamageCause.FALL && event.getEntity() instanceof Player) {
|
||||
Player player = (Player) event.getEntity();
|
||||
FPlayer fPlayer = FPlayers.getInstance().getByPlayer(player);
|
||||
if (fPlayer != null && !fPlayer.shouldTakeFallDamage()) {
|
||||
event.setCancelled(true); // Falling after /f fly
|
||||
}
|
||||
}
|
||||
|
||||
// entity took generic damage?
|
||||
|
@ -72,6 +72,7 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
protected transient boolean autoWarZoneEnabled;
|
||||
protected transient boolean loginPvpDisabled;
|
||||
protected transient long lastFrostwalkerMessage;
|
||||
protected transient boolean shouldTakeFallDamage = true;
|
||||
|
||||
public void login() {
|
||||
this.kills = getPlayer().getStatistic(Statistic.PLAYER_KILLS);
|
||||
@ -891,14 +892,36 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
}
|
||||
|
||||
public void setFFlying(boolean fly, boolean damage) {
|
||||
getPlayer().setAllowFlight(fly);
|
||||
getPlayer().setFlying(fly);
|
||||
Player player = getPlayer();
|
||||
if (player != null) {
|
||||
player.setAllowFlight(fly);
|
||||
player.setFlying(fly);
|
||||
}
|
||||
|
||||
if (!damage) {
|
||||
msg(TL.COMMAND_FLY_CHANGE, fly ? "enabled" : "disabled");
|
||||
} else {
|
||||
msg(TL.COMMAND_FLY_DAMAGE);
|
||||
}
|
||||
|
||||
// If leaving fly mode, don't let them take fall damage for x seconds.
|
||||
if (!fly) {
|
||||
int cooldown = P.p.getConfig().getInt("fly-falldamage-cooldown", 3);
|
||||
|
||||
// If the value is 0 or lower, make them take fall damage.
|
||||
// Otherwise, start a timer and have this cancel after a few seconds.
|
||||
// Short task so we're just doing it in method. Not clean but eh.
|
||||
if (cooldown > 0) {
|
||||
this.shouldTakeFallDamage = false;
|
||||
Bukkit.getScheduler().runTaskLater(P.p, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
shouldTakeFallDamage = true;
|
||||
}
|
||||
}, 20L * cooldown);
|
||||
}
|
||||
}
|
||||
|
||||
isFlying = fly;
|
||||
}
|
||||
|
||||
@ -919,6 +942,14 @@ public abstract class MemoryFPlayer implements FPlayer {
|
||||
return access != null && access == Access.ALLOW;
|
||||
}
|
||||
|
||||
public boolean shouldTakeFallDamage() {
|
||||
return this.shouldTakeFallDamage;
|
||||
}
|
||||
|
||||
public void setTakeFallDamage(boolean fallDamage) {
|
||||
this.shouldTakeFallDamage = fallDamage;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// Message Sending Helpers
|
||||
// -------------------------------------------- //
|
||||
|
@ -62,6 +62,11 @@ warp-cost:
|
||||
# Enable Faction Fly:
|
||||
enable-faction-flight: true
|
||||
|
||||
# If a player leaves fly (out of territory or took damage)
|
||||
# how long should they not take fall damage for?
|
||||
# Set to 0 to have them always take fall damage.
|
||||
fly-falldamage-cooldown: 3
|
||||
|
||||
# Pistons
|
||||
# Should we disable pistons in Faction territory? This will prevent people from doing something like:
|
||||
# http://i.gyazo.com/6a1a31222e58a5d60ff341c13f6a8404.gif
|
||||
|
Loading…
Reference in New Issue
Block a user