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

Merged
merged 21 commits into from
Sep 9, 2024
Merged

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 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/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
github-actions[bot]
github-actions bot previously approved these changes Aug 22, 2024
github-actions[bot]
github-actions bot previously approved these changes Aug 22, 2024
github-actions[bot]
github-actions bot previously approved these changes Aug 22, 2024
dktapps
dktapps previously approved these changes Aug 22, 2024
src/inventory/ArmorInventory.php Outdated Show resolved Hide resolved
src/inventory/ArmorInventory.php Outdated Show resolved Hide resolved
github-actions[bot]
github-actions bot previously approved these changes Aug 26, 2024
dktapps
dktapps previously approved these changes Aug 26, 2024
@dries-c dries-c dismissed stale reviews from dktapps and GitHub Actions via e8adc49 August 29, 2024 22:35
Copy link
Contributor

@ipad54 ipad54 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@IvanCraft623 IvanCraft623 left a comment

Choose a reason for hiding this comment

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

LGTM, Feel free to merge it

@ShockedPlot7560 ShockedPlot7560 merged commit f6e2a1e into minor-next Sep 9, 2024
27 checks passed
@ShockedPlot7560 ShockedPlot7560 deleted the validate-transaction-slots branch September 9, 2024 07:48
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.

6 participants