Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate transaction slots #6304

Open
wants to merge 16 commits into
base: minor-next
Choose a base branch
from

Conversation

ShockedPlot7560
Copy link
Member

@ShockedPlot7560 ShockedPlot7560 commented Mar 24, 2024

Introduction

At present, we can place an item in any slot in an inventory (except in exceptional cases).

It is now necessary to provide a system for verifying transactions in order to guarantee a stable internal state for each inventory.

To maintain compatibility and avoid changing the Inventory interface. A new interface has been created, introducing a new notion of : "slot safe".
I named an inventory slot safe when we are guaranteed that the internal state is consistent with what it should do. So it's up to the core (for inventory implemented by pmmp) and plugin developers to make sure they implement the right validation logic.

Relevant issues

Changes

API changes

  • Add SlotSafeInventory
  • Add SlotValidator

Behavioural changes

  • ArmorInventory checked now correctly their slots.

Backwards compatibility

Enforced by the SlotSafeInventory

Follow-up

As proof of concept, I only implement the ArmorInventory logics. There is many inventory which need to check their slot.

@ShockedPlot7560 ShockedPlot7560 added Category: API Related to the plugin API Category: Core Related to internal functionality Type: Enhancement Contributes features or other improvements to PocketMine-MP labels Mar 24, 2024
Copy link
Member

@dktapps dktapps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could also be done with closures

src/inventory/ArmorInventory.php Outdated Show resolved Hide resolved
src/inventory/SlotSafeInventory.php Outdated Show resolved Hide resolved
Copy link
Member

@dktapps dktapps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Concept looks fine.

However, as previously discussed on Discord, I think that all validators should accept the item in order to allow the transaction to proceed, as opposed to the current behaviour of only one. The current behaviour does not make sense to me - I think it's more likely that people will want to add extra restrictions instead of overriding existing ones

src/inventory/ArmorInventory.php Outdated Show resolved Hide resolved
src/inventory/BaseInventory.php Outdated Show resolved Hide resolved
src/inventory/BaseInventory.php Outdated Show resolved Hide resolved
src/inventory/SlotSafeInventory.php Show resolved Hide resolved
src/inventory/SlotSafeInventory.php Outdated Show resolved Hide resolved
src/inventory/SlotSafeInventory.php Outdated Show resolved Hide resolved
src/inventory/SlotSafeInventory.php Outdated Show resolved Hide resolved
src/inventory/transaction/action/SlotChangeAction.php Outdated Show resolved Hide resolved
src/inventory/transaction/action/SlotChangeAction.php Outdated Show resolved Hide resolved
@ShockedPlot7560
Copy link
Member Author

Alright, I think we are done with this.

Copy link
Member

@dktapps dktapps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall, minus a couple of nits and suggestions

src/inventory/ArmorInventory.php Outdated Show resolved Hide resolved
src/inventory/transaction/action/SlotChangeAction.php Outdated Show resolved Hide resolved
Co-authored-by: ipad54 <63200545+ipad54@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: API Related to the plugin API Category: Core Related to internal functionality Type: Enhancement Contributes features or other improvements to PocketMine-MP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants