Mirror von
https://github.com/IntellectualSites/FastAsyncWorldEdit.git
synchronisiert 2024-11-19 09:20:08 +01:00
Move floatAt logic to AbstractPlayer, add isAllowedToFly and setFlying.
Dieser Commit ist enthalten in:
Ursprung
8545417b3a
Commit
2cc6a367c6
@ -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
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren