Oxide.Rust icon indicating copy to clipboard operation
Oxide.Rust copied to clipboard

Non-matching hook names

Open IIIaKa opened this issue 11 months ago • 1 comments

After reviewing the entire list of hooks (for https://github.com/OxideMod/Oxide.Core/pull/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 avatar Feb 04 '25 11:02 IIIaKa

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 avatar Feb 04 '25 12:02 IIIaKa