Search in sources :

Example 1 with UnbreakableProperty

use of org.spongepowered.api.data.property.block.UnbreakableProperty in project LanternServer by LanternPowered.

the class LanternWorld method getBlockDigTimeWith.

public int getBlockDigTimeWith(int x, int y, int z, @Nullable GameProfile profile, @Nullable ItemStack itemStack) {
    // Check if the user has the creative game mode
    if (profile != null) {
        final Optional<User> optUser = Lantern.getGame().getUserStorageService().get(profile);
        if (optUser.isPresent()) {
            final User user = optUser.get();
            if (user.get(Keys.GAME_MODE).orElse(GameModes.NOT_SET) == GameModes.CREATIVE) {
                return 0;
            }
        }
    }
    final Optional<UnbreakableProperty> optUnbreakableProperty = getProperty(x, y, z, UnbreakableProperty.class);
    if (optUnbreakableProperty.isPresent() && optUnbreakableProperty.get().getValue() == Boolean.TRUE) {
        return -1;
    }
    final Optional<HardnessProperty> optHardnessProperty = getProperty(x, y, z, HardnessProperty.class);
    if (optHardnessProperty.isPresent()) {
        final Double value = optHardnessProperty.get().getValue();
        double hardness = value == null ? 0 : value;
        // TODO: Calculate the duration
        return hardness <= 0 ? 0 : 1;
    }
    return 0;
}
Also used : User(org.spongepowered.api.entity.living.player.User) HardnessProperty(org.spongepowered.api.data.property.block.HardnessProperty) UnbreakableProperty(org.spongepowered.api.data.property.block.UnbreakableProperty)

Aggregations

HardnessProperty (org.spongepowered.api.data.property.block.HardnessProperty)1 UnbreakableProperty (org.spongepowered.api.data.property.block.UnbreakableProperty)1 User (org.spongepowered.api.entity.living.player.User)1