Search in sources :

Example 1 with IPermissionContainer

use of io.github.flemmli97.flan.claim.IPermissionContainer in project Flan by Flemmli97.

the class BlockInteractEvents method useBlocks.

// Right click block
public static ActionResult useBlocks(PlayerEntity p, World world, Hand hand, BlockHitResult hitResult) {
    if (world.isClient)
        return ActionResult.PASS;
    ServerPlayerEntity player = (ServerPlayerEntity) p;
    ItemStack stack = player.getStackInHand(hand);
    if (stack.getItem() == ConfigHandler.config.claimingItem) {
        ItemInteractEvents.claimLandHandling(player, hitResult.getBlockPos());
        return ActionResult.SUCCESS;
    }
    if (stack.getItem() == ConfigHandler.config.inspectionItem) {
        ItemInteractEvents.inspect(player, hitResult.getBlockPos());
        return ActionResult.SUCCESS;
    }
    ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
    IPermissionContainer claim = storage.getForPermissionCheck(hitResult.getBlockPos());
    if (claim != null) {
        boolean emptyHand = !player.getMainHandStack().isEmpty() || !player.getOffHandStack().isEmpty();
        boolean cancelBlockInteract = player.shouldCancelInteraction() && emptyHand;
        if (!cancelBlockInteract) {
            BlockState state = world.getBlockState(hitResult.getBlockPos());
            Identifier id = Registry.BLOCK.getId(state.getBlock());
            BlockEntity blockEntity = world.getBlockEntity(hitResult.getBlockPos());
            if (alwaysAllowBlock(id, blockEntity))
                return ActionResult.PASS;
            ClaimPermission perm = ObjectToPermissionMap.getFromBlock(state.getBlock());
            if (perm == PermissionRegistry.PROJECTILES)
                perm = PermissionRegistry.OPENCONTAINER;
            // Pressureplate handled elsewhere
            if (perm != null && perm != PermissionRegistry.PRESSUREPLATE) {
                if (claim.canInteract(player, perm, hitResult.getBlockPos(), true))
                    return ActionResult.PASS;
                if (state.getBlock() instanceof DoorBlock) {
                    DoubleBlockHalf half = state.get(DoorBlock.HALF);
                    if (half == DoubleBlockHalf.LOWER) {
                        BlockState other = world.getBlockState(hitResult.getBlockPos().up());
                        player.networkHandler.sendPacket(new BlockUpdateS2CPacket(hitResult.getBlockPos().up(), other));
                    } else {
                        BlockState other = world.getBlockState(hitResult.getBlockPos().down());
                        player.networkHandler.sendPacket(new BlockUpdateS2CPacket(hitResult.getBlockPos().down(), other));
                    }
                }
                PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
                return ActionResult.FAIL;
            }
            if (blockEntity != null) {
                if (blockEntity instanceof LecternBlockEntity) {
                    if (claim.canInteract(player, PermissionRegistry.LECTERNTAKE, hitResult.getBlockPos(), false))
                        return ActionResult.PASS;
                    if (state.get(LecternBlock.HAS_BOOK))
                        LockedLecternScreenHandler.create(player, (LecternBlockEntity) blockEntity);
                    return ActionResult.FAIL;
                }
                if (!ConfigHandler.config.lenientBlockEntityCheck || blockEntity instanceof Inventory || blockEntity instanceof InventoryProvider) {
                    if (claim.canInteract(player, PermissionRegistry.OPENCONTAINER, hitResult.getBlockPos(), true))
                        return ActionResult.PASS;
                    PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
                    return ActionResult.FAIL;
                }
            }
        }
    }
    return ActionResult.PASS;
}
Also used : BlockUpdateS2CPacket(net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) InventoryProvider(net.minecraft.block.InventoryProvider) BlockState(net.minecraft.block.BlockState) Identifier(net.minecraft.util.Identifier) ClaimStorage(io.github.flemmli97.flan.claim.ClaimStorage) DoubleBlockHalf(net.minecraft.block.enums.DoubleBlockHalf) ItemStack(net.minecraft.item.ItemStack) ClaimPermission(io.github.flemmli97.flan.api.ClaimPermission) IPermissionContainer(io.github.flemmli97.flan.claim.IPermissionContainer) LecternBlockEntity(net.minecraft.block.entity.LecternBlockEntity) Inventory(net.minecraft.inventory.Inventory) BlockEntity(net.minecraft.block.entity.BlockEntity) LecternBlockEntity(net.minecraft.block.entity.LecternBlockEntity) DoorBlock(net.minecraft.block.DoorBlock)

Example 2 with IPermissionContainer

use of io.github.flemmli97.flan.claim.IPermissionContainer in project Flan by Flemmli97.

the class BlockInteractEvents method breakBlocks.

public static boolean breakBlocks(World world, PlayerEntity p, BlockPos pos, BlockState state, BlockEntity tile) {
    if (world.isClient || p.isSpectator())
        return true;
    ServerPlayerEntity player = (ServerPlayerEntity) p;
    ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
    IPermissionContainer claim = storage.getForPermissionCheck(pos);
    if (claim != null) {
        Identifier id = Registry.BLOCK.getId(state.getBlock());
        if (alwaysAllowBlock(id, world.getBlockEntity(pos)))
            return true;
        if (!claim.canInteract(player, PermissionRegistry.BREAK, pos, true)) {
            PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
            return false;
        }
    }
    return true;
}
Also used : Identifier(net.minecraft.util.Identifier) ClaimStorage(io.github.flemmli97.flan.claim.ClaimStorage) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) IPermissionContainer(io.github.flemmli97.flan.claim.IPermissionContainer)

Example 3 with IPermissionContainer

use of io.github.flemmli97.flan.claim.IPermissionContainer in project Flan by Flemmli97.

the class BlockInteractEvents method preventFallOn.

public static boolean preventFallOn(Entity entity, double heightDifference, boolean onGround, BlockState landedState, BlockPos landedPosition) {
    if (entity.world.isClient)
        return false;
    if (entity instanceof ServerPlayerEntity) {
        ClaimPermission perm = ObjectToPermissionMap.getFromBlock(landedState.getBlock());
        if (perm != PermissionRegistry.TRAMPLE)
            return false;
        ClaimStorage storage = ClaimStorage.get((ServerWorld) entity.world);
        IPermissionContainer claim = storage.getForPermissionCheck(landedPosition);
        if (claim == null)
            return false;
        return !claim.canInteract((ServerPlayerEntity) entity, perm, landedPosition, true);
    } else if (entity instanceof ProjectileEntity) {
        Entity owner = ((ProjectileEntity) entity).getOwner();
        if (owner instanceof ServerPlayerEntity) {
            ClaimPermission perm = ObjectToPermissionMap.getFromBlock(landedState.getBlock());
            if (perm != PermissionRegistry.TRAMPLE)
                return false;
            ClaimStorage storage = ClaimStorage.get((ServerWorld) entity.world);
            IPermissionContainer claim = storage.getForPermissionCheck(landedPosition);
            return !claim.canInteract((ServerPlayerEntity) owner, perm, landedPosition, true);
        }
    }
    return false;
}
Also used : ServerWorld(net.minecraft.server.world.ServerWorld) ProjectileEntity(net.minecraft.entity.projectile.ProjectileEntity) BlockEntity(net.minecraft.block.entity.BlockEntity) ItemEntity(net.minecraft.entity.ItemEntity) Entity(net.minecraft.entity.Entity) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ProjectileEntity(net.minecraft.entity.projectile.ProjectileEntity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) LecternBlockEntity(net.minecraft.block.entity.LecternBlockEntity) ClaimStorage(io.github.flemmli97.flan.claim.ClaimStorage) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) ClaimPermission(io.github.flemmli97.flan.api.ClaimPermission) IPermissionContainer(io.github.flemmli97.flan.claim.IPermissionContainer)

Example 4 with IPermissionContainer

use of io.github.flemmli97.flan.claim.IPermissionContainer in project Flan by Flemmli97.

the class EntityInteractEvents method attackSimple.

public static ActionResult attackSimple(PlayerEntity p, Entity entity, boolean message) {
    if (p.world.isClient || p.isSpectator() || canInteract(entity))
        return ActionResult.PASS;
    if (entity instanceof Monster)
        return ActionResult.PASS;
    ServerPlayerEntity player = (ServerPlayerEntity) p;
    ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
    BlockPos pos = entity.getBlockPos();
    IPermissionContainer claim = storage.getForPermissionCheck(pos);
    if (claim != null) {
        if (!(entity instanceof LivingEntity))
            return claim.canInteract(player, PermissionRegistry.BREAKNONLIVING, pos, message) ? ActionResult.PASS : ActionResult.FAIL;
        if (entity instanceof PlayerEntity)
            return claim.canInteract(player, PermissionRegistry.HURTPLAYER, pos, message) ? ActionResult.PASS : ActionResult.FAIL;
        return claim.canInteract(player, PermissionRegistry.HURTANIMAL, pos, message) ? ActionResult.PASS : ActionResult.FAIL;
    }
    return ActionResult.PASS;
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) Monster(net.minecraft.entity.mob.Monster) ClaimStorage(io.github.flemmli97.flan.claim.ClaimStorage) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) BlockPos(net.minecraft.util.math.BlockPos) IPermissionContainer(io.github.flemmli97.flan.claim.IPermissionContainer) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity)

Example 5 with IPermissionContainer

use of io.github.flemmli97.flan.claim.IPermissionContainer in project Flan by Flemmli97.

the class EntityInteractEvents method canCollideWith.

public static boolean canCollideWith(PlayerEntity player, Entity entity) {
    if (player instanceof ServerPlayerEntity) {
        ServerPlayerEntity sPlayer = (ServerPlayerEntity) player;
        if (entity instanceof ItemEntity) {
            IOwnedItem ownedItem = (IOwnedItem) entity;
            if (ownedItem.getDeathPlayer() != null && ConfigHandler.config.lockDrops) {
                ServerPlayerEntity other = sPlayer.getServer().getPlayerManager().getPlayer(ownedItem.getDeathPlayer());
                if (other == null)
                    return false;
                return ownedItem.getDeathPlayer().equals(player.getUuid()) || PlayerClaimData.get(other).deathItemsUnlocked();
            }
            if (sPlayer.getUuid().equals(ownedItem.getPlayerOrigin()))
                return true;
            ClaimStorage storage = ClaimStorage.get(sPlayer.getServerWorld());
            BlockPos pos = sPlayer.getBlockPos();
            IPermissionContainer claim = storage.getForPermissionCheck(pos);
            if (claim != null)
                return claim.canInteract(sPlayer, PermissionRegistry.PICKUP, pos, false);
        }
    }
    return true;
}
Also used : ItemEntity(net.minecraft.entity.ItemEntity) ClaimStorage(io.github.flemmli97.flan.claim.ClaimStorage) IOwnedItem(io.github.flemmli97.flan.player.IOwnedItem) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) BlockPos(net.minecraft.util.math.BlockPos) IPermissionContainer(io.github.flemmli97.flan.claim.IPermissionContainer)

Aggregations

IPermissionContainer (io.github.flemmli97.flan.claim.IPermissionContainer)21 ClaimStorage (io.github.flemmli97.flan.claim.ClaimStorage)20 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)14 BlockPos (net.minecraft.util.math.BlockPos)13 ClaimPermission (io.github.flemmli97.flan.api.ClaimPermission)6 ServerWorld (net.minecraft.server.world.ServerWorld)6 ItemEntity (net.minecraft.entity.ItemEntity)5 PlayerEntity (net.minecraft.entity.player.PlayerEntity)5 BlockState (net.minecraft.block.BlockState)4 BlockEntity (net.minecraft.block.entity.BlockEntity)4 LecternBlockEntity (net.minecraft.block.entity.LecternBlockEntity)4 Entity (net.minecraft.entity.Entity)4 ProjectileEntity (net.minecraft.entity.projectile.ProjectileEntity)4 Claim (io.github.flemmli97.flan.claim.Claim)2 LivingEntity (net.minecraft.entity.LivingEntity)2 ArmorStandEntity (net.minecraft.entity.decoration.ArmorStandEntity)2 ItemFrameEntity (net.minecraft.entity.decoration.ItemFrameEntity)2 TameableEntity (net.minecraft.entity.passive.TameableEntity)2 VillagerEntity (net.minecraft.entity.passive.VillagerEntity)2 AbstractMinecartEntity (net.minecraft.entity.vehicle.AbstractMinecartEntity)2