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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations