Skip to content

Non-matching hook names #545

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open

Non-matching hook names #545

wants to merge 1 commit into from

Conversation

IIIaKa
Copy link
Contributor

@IIIaKa IIIaKa commented Feb 4, 2025

After reviewing the entire list of hooks (for OxideMod/Oxide.Core#103 ), I discovered that some hooks have names that do not correspond correctly to their purpose.
This pull request is intended to resolve these inconsistencies before they turn into a confusing mess. The sooner this is addressed, the fewer plugins will be affected. All new names have been verified, do not exist and will not cause conflicts.

1. Can hooks that are actually On hooks.

Can hooks(bool) essentially ask plugins whether an action is allowed or not and based on the returned true or false, the action is either performed or denied(only considering non-null values). The methods that invoke these hooks contain no additional logic beyond checking the return value. This distinguishes them from On(non-object) hooks, which also expect a bool return but serve a different purpose.
However, for some reason, certain hooks use Can instead of On, which creates confusion.

  1. CanBuild → OnBuild
  2. CanCreateWorldProjectile → OnCreateWorldProjectile
  3. CanAssignBed → OnSleepingBagAssign
  4. CanLock → OnLock(for CodeLock and KeyLock), ModularCarCodeLock remains unchanged
  5. CanUnlock → OnUnlock(for CodeLock and KeyLock), ModularCarCodeLock remains unchanged
  6. CanChangeCode → OnCodeChange
  7. CanSetBedPublic → OnSleepingBagPublic
  8. CanMoveItem → OnItemMove
  9. CanSeeStash → OnStashReveal
  10. CanHideStash → OnStashHide
  11. CanCombineDroppedItem → OnDroppedItemCombine
  12. CanPickupLock → OnLockPickup
  13. CanUseHelicopter → OnEntityMount(CH47HelicopterAIController)
  14. CanMountEntity → OnEntityMount(BaseMountable)
  15. CanDismountEntity → OnEntityDismount
  16. CanLootEntity → OnTryLootEntity(LootableCorpse, ResourceContainer, DroppedItemContainer, StorageContainer, ContainerIOEntity, IndustrialCrafter and WorldItem)
  17. CanHackCrate → OnCrateHack(existing OnCrateHack renamed to OnCrateHackStart since there is also OnCrateHackEnd)
  18. CanRenameBed → OnSleepingBagRename
  19. CanDeployItem → OnItemDeploy
  20. CanSamSiteShoot → OnSamSiteShoot
  21. CanSpectateTarget → OnUpdateSpectateTarget
  22. CanTakeCutting → OnTakeClones
  23. CanUseFuel → OnFuelUse
  24. CanSetRelationship → OnSetRelationship
  25. CanPurchaseItem → OnPurchaseItem

2. On hooks that are actually Can hooks.

  1. OnHelicopterOutOfCrates → CanHelicopterBeOutOfCrates
  2. OnEntityControl → CanEntityControl(AutoTurret, PoweredRemoteControlEntity and RemoteControlEntity)
  3. OnVehicleLockableCheck → CanVehicleHaveALock
  4. OnVehicleModuleMove → CanMoveVehicleModule
  5. OnSleepingBagValidCheck → CanSleepingBagBeValid
  6. OnTreeMarkerHit → CanHitTreeMarker
  7. OnItemFilter → CanContainerAcceptItem
  8. OnBoomboxStationValidate → CanBoomboxStationBeValid

3. Simple renaming of hooks for better understanding of their purpose.

  1. OnFuelAmountCheck → OnFuelGetAmount
  2. OnCrateHack → OnCrateHackStart(due to the change of CanHackCrate)
  3. OnStashExposed → OnStashRevealed(due to the addition of OnStashReveal)

4. Changes to ReturnBehavior.

From ExitWhenValidType to ExitWhenNonNull.
For hooks that are in void methods:

  1. OnPlayerSpectate

For hooks that are in bool methods, allowing the method to exit on any non-null value:

  1. OnWireClear
  2. OnHorseHitch

5. Other changes.

The OnItemResearch hook has been moved to the place of the CanResearchItem hook and the CanResearchItem hook has been removed, as it is essentially a regular On object hook. Having both hooks was simply duplicating the call.

The CanLockerAcceptItem hook has been removed because it is immediately followed by the CanContainerAcceptItem(OnItemFilter) hook in the ItemFilter method, which uses the same arguments.

@IIIaKa
Copy link
Contributor Author

IIIaKa commented Feb 4, 2025

I think with the release of the primitive mode, many plugins will need to be updated anyway and the changes in hook names are quite timely.
Also, I spent quite a bit of time on both of these pull requests, I hope it wasn't in vain.

@IIIaKa IIIaKa reopened this Feb 25, 2025
@MrBlue MrBlue force-pushed the develop branch 5 times, most recently from 342e2fb to ed689a6 Compare April 2, 2025 05:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant