mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2025-06-11 20:13:55 +00:00
Move floatAt logic to AbstractPlayer, add isAllowedToFly and setFlying.
This commit is contained in:
@ -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.
|
||||
*
|
||||
|
@ -313,13 +313,17 @@ public abstract class AbstractPlayerActor implements Actor, Player, Cloneable {
|
||||
|
||||
@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 = 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));
|
||||
}
|
||||
|
Reference in New Issue
Block a user