cn.nukkit.AdventureSettings.Type Java Examples

The following examples show how to use cn.nukkit.AdventureSettings.Type. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Player.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean attack(EntityDamageEvent source) {
    if (!this.isAlive()) {
        return false;
    }

    if (this.isSpectator() || (this.isCreative() && source.getCause() != DamageCause.SUICIDE)) {
        //source.setCancelled();
        return false;
    } else if (this.getAdventureSettings().get(Type.ALLOW_FLIGHT) && source.getCause() == DamageCause.FALL) {
        //source.setCancelled();
        return false;
    } else if (source.getCause() == DamageCause.FALL) {
        if (this.getLevel().getBlock(this.getPosition().floor().add(0.5, -1, 0.5)).getId() == Block.SLIME_BLOCK) {
            if (!this.isSneaking()) {
                //source.setCancelled();
                this.resetFallDistance();
                return false;
            }
        }
    }

    if (super.attack(source)) { //!source.isCancelled()
        if (this.getLastDamageCause() == source && this.spawned) {
            if (source instanceof EntityDamageByEntityEvent) {
                Entity damager = ((EntityDamageByEntityEvent) source).getDamager();
                if (damager instanceof Player) {
                    ((Player) damager).getFoodData().updateFoodExpLevel(0.3);
                }
            }
            EntityEventPacket pk = new EntityEventPacket();
            pk.eid = this.id;
            pk.event = EntityEventPacket.HURT_ANIMATION;
            this.dataPacket(pk);
        }
        return true;
    } else {
        return false;
    }
}
 
Example #2
Source File: Player.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Deprecated
public void setAllowFlight(boolean value) {
    this.getAdventureSettings().set(Type.ALLOW_FLIGHT, value);
    this.getAdventureSettings().update();
}
 
Example #3
Source File: Player.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Deprecated
public boolean getAllowFlight() {
    return this.getAdventureSettings().get(Type.ALLOW_FLIGHT);
}
 
Example #4
Source File: Player.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public void setAllowModifyWorld(boolean value) {
    this.getAdventureSettings().set(Type.WORLD_IMMUTABLE, !value);
    this.getAdventureSettings().set(Type.BUILD_AND_MINE, value);
    this.getAdventureSettings().set(Type.WORLD_BUILDER, value);
    this.getAdventureSettings().update();
}
 
Example #5
Source File: Player.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public void setAllowInteract(boolean value, boolean containers) {
    this.getAdventureSettings().set(Type.WORLD_IMMUTABLE, !value);
    this.getAdventureSettings().set(Type.DOORS_AND_SWITCHED, value);
    this.getAdventureSettings().set(Type.OPEN_CONTAINERS, containers);
    this.getAdventureSettings().update();
}
 
Example #6
Source File: Player.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Deprecated
public void setAutoJump(boolean value) {
    this.getAdventureSettings().set(Type.AUTO_JUMP, value);
    this.getAdventureSettings().update();
}
 
Example #7
Source File: Player.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Deprecated
public boolean hasAutoJump() {
    return this.getAdventureSettings().get(Type.AUTO_JUMP);
}
 
Example #8
Source File: Player.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Deprecated
public void setAllowFlight(boolean value) {
    this.getAdventureSettings().set(Type.ALLOW_FLIGHT, value);
    this.getAdventureSettings().update();
}
 
Example #9
Source File: Player.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Deprecated
public boolean getAllowFlight() {
    return this.getAdventureSettings().get(Type.ALLOW_FLIGHT);
}
 
Example #10
Source File: Player.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public void setAllowModifyWorld(boolean value) {
    this.getAdventureSettings().set(Type.WORLD_IMMUTABLE, !value);
    this.getAdventureSettings().set(Type.BUILD_AND_MINE, value);
    this.getAdventureSettings().set(Type.WORLD_BUILDER, value);
    this.getAdventureSettings().update();
}
 
Example #11
Source File: Player.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
public void setAllowInteract(boolean value, boolean containers) {
    this.getAdventureSettings().set(Type.WORLD_IMMUTABLE, !value);
    this.getAdventureSettings().set(Type.DOORS_AND_SWITCHED, value);
    this.getAdventureSettings().set(Type.OPEN_CONTAINERS, containers);
    this.getAdventureSettings().update();
}
 
Example #12
Source File: Player.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Deprecated
public void setAutoJump(boolean value) {
    this.getAdventureSettings().set(Type.AUTO_JUMP, value);
    this.getAdventureSettings().update();
}
 
Example #13
Source File: Player.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Deprecated
public boolean hasAutoJump() {
    return this.getAdventureSettings().get(Type.AUTO_JUMP);
}
 
Example #14
Source File: Player.java    From Nukkit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onUpdate(int currentTick) {
    if (!this.loggedIn) {
        return false;
    }

    int tickDiff = currentTick - this.lastUpdate;

    if (tickDiff <= 0) {
        return true;
    }

    this.messageCounter = 2;

    this.lastUpdate = currentTick;

    if (!this.isAlive() && this.spawned) {
        ++this.deadTicks;
        if (this.deadTicks >= 10) {
            this.despawnFromAll();
        }
        return true;
    }

    if (this.spawned) {
        this.processMovement(tickDiff);

        this.entityBaseTick(tickDiff);

        if (this.getServer().getDifficulty() == 0 && this.level.getGameRules().getBoolean(GameRule.NATURAL_REGENERATION)) {
            if (this.getHealth() < this.getMaxHealth() && this.ticksLived % 20 == 0) {
                this.heal(1);
            }

            PlayerFood foodData = this.getFoodData();

            if (foodData.getLevel() < 20 && this.ticksLived % 10 == 0) {
                foodData.addFoodLevel(1, 0);
            }
        }

        if (this.isOnFire() && this.lastUpdate % 10 == 0) {
            if (this.isCreative() && !this.isInsideOfFire()) {
                this.extinguish();
            } else if (this.getLevel().isRaining()) {
                if (this.getLevel().canBlockSeeSky(this)) {
                    this.extinguish();
                }
            }
        }

        if (!this.isSpectator() && this.speed != null) {
            if (this.onGround) {
                if (this.inAirTicks != 0) {
                    this.startAirTicks = 5;
                }
                this.inAirTicks = 0;
                this.highestPosition = this.y;
            } else {
                if (!this.isGliding() && !server.getAllowFlight() && !this.getAdventureSettings().get(Type.ALLOW_FLIGHT) && this.inAirTicks > 10 && !this.isSleeping() && !this.isImmobile()) {
                    double expectedVelocity = (-this.getGravity()) / ((double) this.getDrag()) - ((-this.getGravity()) / ((double) this.getDrag())) * Math.exp(-((double) this.getDrag()) * ((double) (this.inAirTicks - this.startAirTicks)));
                    double diff = (this.speed.y - expectedVelocity) * (this.speed.y - expectedVelocity);

                    if (!this.hasEffect(Effect.JUMP) && diff > 0.6 && expectedVelocity < this.speed.y) {
                        if (this.inAirTicks < 100) {
                            //this.sendSettings();
                            this.setMotion(new Vector3(0, expectedVelocity, 0));
                        } else if (this.kick(PlayerKickEvent.Reason.FLYING_DISABLED, "Flying is not enabled on this server")) {
                            return false;
                        }
                    }
                }

                if (this.y > highestPosition) {
                    this.highestPosition = this.y;
                }

                if (this.isGliding()) this.resetFallDistance();

                ++this.inAirTicks;

            }

            if (this.isSurvival() || this.isAdventure()) {
                if (this.getFoodData() != null) this.getFoodData().update(tickDiff);
            }
        }
    }

    this.checkTeleportPosition();
    this.checkInteractNearby();

    if (this.spawned && this.dummyBossBars.size() > 0 && currentTick % 100 == 0) {
        this.dummyBossBars.values().forEach(DummyBossBar::updateBossEntityPosition);
    }

    return true;
}