[factions-banking] Fixed faction fly bugs
Some checks are pending
build / build (21) (push) Waiting to run
Some checks are pending
build / build (21) (push) Waiting to run
This commit is contained in:
parent
74722b465a
commit
7efeb689cb
@ -2,8 +2,8 @@ package jesse.keeblarcraft.AttributeMgr.AttributeNodes.FactionNodes;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.logging.log4j.core.jmx.Server;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
import jesse.keeblarcraft.AttributeMgr.AttributeNodes.AbstractNode;
|
||||
import jesse.keeblarcraft.FactionMgr.Callbacks.PlayerCommandFlightCallback;
|
||||
@ -22,6 +22,7 @@ public class FactionFlight extends AbstractNode {
|
||||
private float SPEED_SCALAR = 40.0f; // The value to scale this correctly to CREATIVE flight is '20.0f' however faction flight is slower than creative intentionally
|
||||
private Boolean canFly = false;
|
||||
private Boolean loginInBaseToggle = false; // Covers the unique case if player logs in inside the faction block border; in which case they need flight enabled!
|
||||
private Integer leaveTimerMs = 5000;
|
||||
|
||||
@Override
|
||||
public String GetNodeTitle() {
|
||||
@ -40,74 +41,81 @@ public class FactionFlight extends AbstractNode {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public Boolean ToggleFlight(ServerPlayerEntity player) {
|
||||
// Only bother with flight if the player can fly
|
||||
public Boolean TurnOnFlight(ServerPlayerEntity player) {
|
||||
Boolean isFlying = false;
|
||||
if (canFly) {
|
||||
PlayerAbilities abilities = player.getAbilities();
|
||||
|
||||
// Flight toggle off
|
||||
if (abilities.flying) {
|
||||
// Disable flight
|
||||
abilities.flying = false;
|
||||
abilities.allowFlying = false;
|
||||
abilities.setFlySpeed(0);
|
||||
} else {
|
||||
// Flight toggle on
|
||||
isFlying = true;
|
||||
abilities.allowFlying = true;
|
||||
abilities.setFlySpeed((float) (flightSpeed / SPEED_SCALAR)); // Dividing by 20f yields max clamp value of 0.5 since MC does 0.0-> 1.0 flight. 0.1 flight is too fast!
|
||||
}
|
||||
PlayerAbilities abilities = player.getAbilities();
|
||||
if (canFly && !abilities.allowFlying) {
|
||||
abilities.allowFlying = true;
|
||||
abilities.setFlySpeed((float) (flightSpeed / SPEED_SCALAR));
|
||||
isFlying = true;
|
||||
player.sendAbilitiesUpdate();
|
||||
}
|
||||
player.sendAbilitiesUpdate();
|
||||
|
||||
return isFlying;
|
||||
}
|
||||
|
||||
public Boolean TurnOffFlight(ServerPlayerEntity player) {
|
||||
Boolean isFlying = false;
|
||||
PlayerAbilities abilities = player.getAbilities();
|
||||
if (canFly && abilities.allowFlying) {
|
||||
abilities.allowFlying = false;
|
||||
abilities.flying = false;
|
||||
abilities.setFlySpeed(0);
|
||||
isFlying = false;
|
||||
player.sendAbilitiesUpdate();
|
||||
}
|
||||
|
||||
return isFlying;
|
||||
}
|
||||
|
||||
public void ResetPlayer(ServerPlayerEntity player) {
|
||||
// Disable flight
|
||||
PlayerAbilities abilities = player.getAbilities();
|
||||
if (abilities.flying) {
|
||||
// Disable flight
|
||||
abilities.flying = false;
|
||||
abilities.allowFlying = false;
|
||||
abilities.setFlySpeed(0);
|
||||
}
|
||||
abilities.flying = false;
|
||||
abilities.allowFlying = false;
|
||||
abilities.setFlySpeed(0);
|
||||
player.sendAbilitiesUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void RegisterCallbacks(ServerPlayerEntity playerObj, ServerWorld worldObj) {
|
||||
// PlayerInBaseCallback.EVENT.register((player, world) -> {
|
||||
// player.sendMessage(Text.of("Welcome home! Feel free to fly around!"));
|
||||
// return ActionResult.SUCCESS;
|
||||
// });
|
||||
|
||||
PlayerEnteredBaseCallback.EVENT.register((player, world) -> {
|
||||
player.sendMessage(Text.of("Faction flight enabled"));
|
||||
canFly = true;
|
||||
ServerPlayerEntity serverPlayer = (ServerPlayerEntity) player;
|
||||
ToggleFlight(serverPlayer);
|
||||
|
||||
// Toggle flight
|
||||
TurnOnFlight(serverPlayer);
|
||||
return ActionResult.SUCCESS;
|
||||
});
|
||||
|
||||
PlayerInBaseCallback.EVENT.register((player, world) -> {
|
||||
// Make sure player can fly while inside the border. We don't ever want to run this more than once!
|
||||
System.out.println("INSIDE BORDER CHECK: canFly && !loginBase: " + canFly + " " + !loginInBaseToggle);
|
||||
if (!canFly && !loginInBaseToggle) {
|
||||
player.sendMessage(Text.of("Faction flight enabled"));
|
||||
loginInBaseToggle = true;
|
||||
canFly = true;
|
||||
ServerPlayerEntity serverPlayer = (ServerPlayerEntity) player;
|
||||
ToggleFlight(serverPlayer);
|
||||
TurnOnFlight(serverPlayer);
|
||||
}
|
||||
return ActionResult.SUCCESS;
|
||||
});
|
||||
|
||||
PlayerCommandFlightCallback.EVENT.register((player, world) -> {
|
||||
ServerPlayerEntity serverPlayer = (ServerPlayerEntity) player;
|
||||
Boolean isFlying = ToggleFlight(serverPlayer);
|
||||
if(isFlying) {
|
||||
Boolean isFlying = TurnOnFlight(serverPlayer);
|
||||
// This is a toggle command; so first we get if the player is flying
|
||||
PlayerAbilities abilities = player.getAbilities();
|
||||
if (abilities.flying) {
|
||||
TurnOffFlight((ServerPlayerEntity) player);
|
||||
} else {
|
||||
TurnOnFlight((ServerPlayerEntity) player);
|
||||
}
|
||||
System.out.println("abilities.flying: " + abilities.flying);
|
||||
|
||||
if(canFly && isFlying) {
|
||||
serverPlayer.sendMessage(Text.of("Flight turned on"));
|
||||
} else if (!isFlying && canFly) {
|
||||
} else if (canFly && !isFlying) {
|
||||
// Infers toggled off
|
||||
serverPlayer.sendMessage(Text.of("Flight turned off"));
|
||||
} else {
|
||||
@ -118,10 +126,22 @@ public class FactionFlight extends AbstractNode {
|
||||
});
|
||||
|
||||
PlayerExitedBaseCallback.EVENT.register((player, world) -> {
|
||||
player.sendMessage(Text.of("Faction flight disabled"));
|
||||
Timer timer = new Timer();
|
||||
canFly = false;
|
||||
ServerPlayerEntity serverPlayer = (ServerPlayerEntity) player;
|
||||
ResetPlayer(serverPlayer);
|
||||
player.sendMessage(Text.of("You left the faction's perimeter! Flight will disable in 5 seconds..."));
|
||||
timer.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
// Cover the edge condition such that we leave the faction base (canFly = false) then
|
||||
// the timer here starts and we come back into the base (canFly = true) - we want a NO-OP here
|
||||
if (!canFly) {
|
||||
player.sendMessage(Text.of("Faction flight disabled"));
|
||||
ServerPlayerEntity serverPlayer = (ServerPlayerEntity) player;
|
||||
ResetPlayer(serverPlayer);
|
||||
}
|
||||
}
|
||||
}, leaveTimerMs);
|
||||
|
||||
return ActionResult.SUCCESS;
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user