Move floatAt logic to AbstractPlayer, add isAllowedToFly and setFlying.

Dieser Commit ist enthalten in:
wizjany 2019-07-11 20:27:05 -04:00
Ursprung 8545417b3a
Commit 2cc6a367c6
6 geänderte Dateien mit 54 neuen und 36 gelöschten Zeilen

Datei anzeigen

@ -185,14 +185,13 @@ public class BukkitPlayer extends AbstractPlayerActor {
}
@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

Datei anzeigen

@ -187,6 +187,24 @@ public interface Player extends Entity, Actor {
*/
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.
*

Datei anzeigen

@ -313,14 +313,18 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
@Override
public void floatAt(int x, int y, int z, boolean alwaysGlass) {
if (alwaysGlass || !isAllowedToFly()) {
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()) {
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));
}

Datei anzeigen

@ -189,15 +189,14 @@ public class FabricPlayer extends AbstractPlayerActor {
}
@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();
}
}

Datei anzeigen

@ -190,15 +190,14 @@ public class ForgePlayer extends AbstractPlayerActor {
}
@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();
}
}

Datei anzeigen

@ -204,14 +204,13 @@ public class SpongePlayer extends AbstractPlayerActor {
}
@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