Skip to content

API CanI > canPlace canBreak canInteract canAttack ... #10397

@Anarchick

Description

@Anarchick

Is your feature request related to a problem?

I suggest an API to know if an entity or plugin can do some action. This can be useful when a server use a protection or anti-cheat plugin.

The advantage of this API is that it allows you to ignore which plugin is preventing the action. No more need to implement each plugin in maven/gradle + less known plugins will benefit from this API

Describe the solution you'd like.

/**
	 * Used to know if the given entity can place a block at this location.
	 * Some protection plugins can disalow this action. 
	 * @param plugin Your plugin
	 * @param entity The entity or null.
	 * @param block The block location you try to place
	 * @param blockdata The block data to place
	 * @param hand Main hand or Off hand or null
	 * @param ignoreDistance some protection plugins can restrict the placement to a max distance.
	 * @return
	 */
	public InteractResponse canPlace(@NotNull Plugin plugin, @Nullable Entity entity, @NotNull Block block, @NotNull BlockData blockdata, @Nullable EquipmentSlot hand, boolean ignoreDistance)
	public InteractResponse canBreak(@NotNull Plugin plugin, @Nullable Entity entity, @NotNull Block block, @Nullable ItemStack tool, @Nullable EquipmentSlot hand, boolean ignoreDistance)
	public InteractResponse canInteract(@NotNull Plugin plugin, @Nullable Entity entity, @NotNull Block block, @Nullable ItemStack tool, @Nullable EquipmentSlot hand, boolean ignoreDistance)
	public InteractResponse canAttack(@NotNull Plugin plugin, @Nullable Entity entity, @NotNull Entity victim, @Nullable ItemStack tool, @Nullable EquipmentSlot hand, boolean ignoreDistance)
	public InteractResponse canWalkOn(@NotNull Plugin plugin, @NotNull Entity entity, @NotNull Block block)
	public InteractResponse canBeAt(@NotNull Plugin plugin, @NotNull Entity entity, @NotNull Location loc)

More method can be added over time : canKill , canUseItem, canTeleport, canOpen, canSpectate ...

calling one of this method will call an Event (must be sync), others plugin which does not allow the action have to do event.disallow(plugin).

The InteractResponse tell if yes or no we can perform the action + know each plugin which have disallow

Describe alternatives you've considered.

If it's not implement in Paper, the alternative is a free library plugin .

in fact, it is even an obligation for the support of versions prior to the creation of the paper api

Other

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    type: featureRequest for a new Feature.
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions