Skip to content
Permalink
Browse files

Move floatAt logic to AbstractPlayer, add isAllowedToFly and setFlying.

  • Loading branch information...
wizjany committed Jul 12, 2019
1 parent 04bb677 commit 567174bed57bd1657363bb0d83fd3c1800bdbf9f
@@ -185,14 +185,13 @@ public Player getPlayer() {
}

@Override
public void floatAt(int x, int y, int z, boolean alwaysGlass) {
if (alwaysGlass || !player.getAllowFlight()) {
super.floatAt(x, y, z, alwaysGlass);
return;
}
public boolean isAllowedToFly() {
return player.getAllowFlight();
}

setPosition(Vector3.at(x + 0.5, y, z + 0.5));
player.setFlying(true);
@Override
public void setFlying(boolean flying) {
player.setFlying(flying);
}

@Override
@@ -187,6 +187,24 @@
*/
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.
*
@@ -313,13 +313,17 @@ public boolean ascendUpwards(int distance, boolean alwaysGlass) {

@Override
public void floatAt(int x, int y, int z, boolean alwaysGlass) {
BlockVector3 spot = BlockVector3.at(x, y - 1, z);
final World world = (World) getLocation().getExtent();
if (!world.getBlock(spot).getBlockType().getMaterial().isMovementBlocker()) {
try (EditSession session = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, 1, this)) {
session.setBlock(spot, BlockTypes.GLASS.getDefaultState());
} catch (MaxChangedBlocksException ignored) {
if (alwaysGlass || !isAllowedToFly()) {
BlockVector3 spot = BlockVector3.at(x, y - 1, z);
final World world = (World) getLocation().getExtent();
if (!world.getBlock(spot).getBlockType().getMaterial().isMovementBlocker()) {
try (EditSession session = WorldEdit.getInstance().getEditSessionFactory().getEditSession(world, 1, this)) {
session.setBlock(spot, BlockTypes.GLASS.getDefaultState());
} catch (MaxChangedBlocksException ignored) {
}
}
} else {
setFlying(true);
}
setPosition(Vector3.at(x + 0.5, y, z + 0.5));
}
@@ -189,15 +189,14 @@ public boolean hasPermission(String perm) {
}

@Override
public void floatAt(int x, int y, int z, boolean alwaysGlass) {
if (alwaysGlass || !player.abilities.allowFlying) {
super.floatAt(x, y, z, alwaysGlass);
return;
}
public boolean isAllowedToFly() {
return player.abilities.allowFlying;
}

setPosition(Vector3.at(x + 0.5, y, z + 0.5));
if (!player.abilities.flying) {
player.abilities.flying = true;
@Override
public void setFlying(boolean flying) {
if (player.abilities.flying != flying) {
player.abilities.flying = flying;
player.sendAbilitiesUpdate();
}
}
@@ -190,15 +190,14 @@ public boolean hasPermission(String perm) {
}

@Override
public void floatAt(int x, int y, int z, boolean alwaysGlass) {
if (alwaysGlass || !player.abilities.allowFlying) {
super.floatAt(x, y, z, alwaysGlass);
return;
}
public boolean isAllowedToFly() {
return player.abilities.allowFlying;
}

setPosition(Vector3.at(x + 0.5, y, z + 0.5));
if (!player.abilities.isFlying) {
player.abilities.isFlying = true;
@Override
public void setFlying(boolean flying) {
if (player.abilities.isFlying != flying) {
player.abilities.isFlying = flying;
player.sendPlayerAbilities();
}
}
@@ -204,14 +204,13 @@ public void setGameMode(GameMode gameMode) {
}

@Override
public void floatAt(int x, int y, int z, boolean alwaysGlass) {
if (alwaysGlass || !player.get(Keys.CAN_FLY).orElse(false)) {
super.floatAt(x, y, z, alwaysGlass);
return;
}
public boolean isAllowedToFly() {
return player.get(Keys.CAN_FLY).orElse(super.isAllowedToFly());
}

setPosition(Vector3.at(x + 0.5, y, z + 0.5));
player.offer(Keys.IS_FLYING, true);
@Override
public void setFlying(boolean flying) {
player.offer(Keys.IS_FLYING, flying);
}

@Override

0 comments on commit 567174b

Please sign in to comment.
You can’t perform that action at this time.