Search in sources :

Example 1 with ClaimStorage

use of io.github.flemmli97.flan.claim.ClaimStorage 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 ClaimStorage

use of io.github.flemmli97.flan.claim.ClaimStorage 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 ClaimStorage

use of io.github.flemmli97.flan.claim.ClaimStorage 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 ClaimStorage

use of io.github.flemmli97.flan.claim.ClaimStorage 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 ClaimStorage

use of io.github.flemmli97.flan.claim.ClaimStorage 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

ClaimStorage (io.github.flemmli97.flan.claim.ClaimStorage)35 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)26 IPermissionContainer (io.github.flemmli97.flan.claim.IPermissionContainer)21 BlockPos (net.minecraft.util.math.BlockPos)16 Claim (io.github.flemmli97.flan.claim.Claim)13 ServerWorld (net.minecraft.server.world.ServerWorld)11 ClaimPermission (io.github.flemmli97.flan.api.ClaimPermission)8 PlayerEntity (net.minecraft.entity.player.PlayerEntity)6 PlayerClaimData (io.github.flemmli97.flan.player.PlayerClaimData)5 BlockState (net.minecraft.block.BlockState)5 ItemEntity (net.minecraft.entity.ItemEntity)5 GameProfile (com.mojang.authlib.GameProfile)4 ArrayList (java.util.ArrayList)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 ItemStack (net.minecraft.item.ItemStack)4 BlockUpdateS2CPacket (net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket)3 OfflinePlayerData (io.github.flemmli97.flan.player.OfflinePlayerData)2