mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-22 17:27:38 +00:00
Move floatAt logic to AbstractPlayer, add isAllowedToFly and setFlying.
This commit is contained in:
parent
8545417b3a
commit
2cc6a367c6
@ -185,14 +185,13 @@ public class BukkitPlayer extends AbstractPlayerActor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void floatAt(int x, int y, int z, boolean alwaysGlass) {
|
public boolean isAllowedToFly() {
|
||||||
if (alwaysGlass || !player.getAllowFlight()) {
|
return player.getAllowFlight();
|
||||||
super.floatAt(x, y, z, alwaysGlass);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setPosition(Vector3.at(x + 0.5, y, z + 0.5));
|
@Override
|
||||||
player.setFlying(true);
|
public void setFlying(boolean flying) {
|
||||||
|
player.setFlying(flying);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -187,6 +187,24 @@ public interface Player extends Entity, Actor {
|
|||||||
*/
|
*/
|
||||||
void floatAt(int x, int y, int z, boolean alwaysGlass);
|
void floatAt(int x, int y, int z, boolean alwaysGlass);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the player is allowed to fly.
|
||||||
|
*
|
||||||
|
* @return true if allowed flight
|
||||||
|
*/
|
||||||
|
default boolean isAllowedToFly() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set whether the player is currently flying.
|
||||||
|
*
|
||||||
|
* @param flying true to fly
|
||||||
|
*/
|
||||||
|
default void setFlying(boolean flying) {
|
||||||
|
throw new UnsupportedOperationException("setFlying unimplemented but isAllowedToFly was true (or unchecked)");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the point of the block that is being stood in.
|
* Get the point of the block that is being stood in.
|
||||||
*
|
*
|
||||||
|
@ -313,14 +313,18 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void floatAt(int x, int y, int z, boolean alwaysGlass) {
|
public void floatAt(int x, int y, int z, boolean alwaysGlass) {
|
||||||
|
if (alwaysGlass || !isAllowedToFly()) {
|
||||||
BlockVector3 spot = BlockVector3.at(x, y - 1, z);
|
BlockVector3 spot = BlockVector3.at(x, y - 1, z);
|
||||||
final World world = (World) getLocation().getExtent();
|
final World world = getWorld();
|
||||||
if (!world.getBlock(spot).getBlockType().getMaterial().isMovementBlocker()) {
|
if (!world.getBlock(spot).getBlockType().getMaterial().isMovementBlocker()) {
|
||||||
try (EditSession session = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, 1, this)) {
|
try (EditSession session = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, 1, this)) {
|
||||||
session.setBlock(spot, BlockTypes.GLASS.getDefaultState());
|
session.setBlock(spot, BlockTypes.GLASS.getDefaultState());
|
||||||
} catch (MaxChangedBlocksException ignored) {
|
} catch (MaxChangedBlocksException ignored) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
setFlying(true);
|
||||||
|
}
|
||||||
setPosition(Vector3.at(x + 0.5, y, z + 0.5));
|
setPosition(Vector3.at(x + 0.5, y, z + 0.5));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,15 +189,14 @@ public class FabricPlayer extends AbstractPlayerActor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void floatAt(int x, int y, int z, boolean alwaysGlass) {
|
public boolean isAllowedToFly() {
|
||||||
if (alwaysGlass || !player.abilities.allowFlying) {
|
return player.abilities.allowFlying;
|
||||||
super.floatAt(x, y, z, alwaysGlass);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setPosition(Vector3.at(x + 0.5, y, z + 0.5));
|
@Override
|
||||||
if (!player.abilities.flying) {
|
public void setFlying(boolean flying) {
|
||||||
player.abilities.flying = true;
|
if (player.abilities.flying != flying) {
|
||||||
|
player.abilities.flying = flying;
|
||||||
player.sendAbilitiesUpdate();
|
player.sendAbilitiesUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -190,15 +190,14 @@ public class ForgePlayer extends AbstractPlayerActor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void floatAt(int x, int y, int z, boolean alwaysGlass) {
|
public boolean isAllowedToFly() {
|
||||||
if (alwaysGlass || !player.abilities.allowFlying) {
|
return player.abilities.allowFlying;
|
||||||
super.floatAt(x, y, z, alwaysGlass);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setPosition(Vector3.at(x + 0.5, y, z + 0.5));
|
@Override
|
||||||
if (!player.abilities.isFlying) {
|
public void setFlying(boolean flying) {
|
||||||
player.abilities.isFlying = true;
|
if (player.abilities.isFlying != flying) {
|
||||||
|
player.abilities.isFlying = flying;
|
||||||
player.sendPlayerAbilities();
|
player.sendPlayerAbilities();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -204,14 +204,13 @@ public class SpongePlayer extends AbstractPlayerActor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void floatAt(int x, int y, int z, boolean alwaysGlass) {
|
public boolean isAllowedToFly() {
|
||||||
if (alwaysGlass || !player.get(Keys.CAN_FLY).orElse(false)) {
|
return player.get(Keys.CAN_FLY).orElse(super.isAllowedToFly());
|
||||||
super.floatAt(x, y, z, alwaysGlass);
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setPosition(Vector3.at(x + 0.5, y, z + 0.5));
|
@Override
|
||||||
player.offer(Keys.IS_FLYING, true);
|
public void setFlying(boolean flying) {
|
||||||
|
player.offer(Keys.IS_FLYING, flying);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user