EXILED
EXILED copied to clipboard
[WIP] [BREAKING CHANGES] - REQUIRES TESTING -- Eventargs interfaces
All EventArg classes have been moved into folders corresponding to what type of event they are, in line with how those events are laid out in the Patches folder.
Additionally, event args used by EXILED are now all based on the IExiledEvent
interface, instead of System.EventArgs
.
This allows us to create even more Interfaces for commonly used properties, such as ev.Player, ev.Target, ev.DamageHandler, ev.Item, ev.Firearm and so on.
These properties now belong to their appropriate interface, and the EventArgs classes used by events will inherit the interfaces it needs, then add whatever other properties the event needs ontop of those.
For most plugin devs, aside from all events having standardized property naming and new namespaces (yes, this will break just about every plugin using Exiled.Events), they won't even know the difference between the old and new EventArgs system.
However for those of us who occasionally have to go through this hell:
protected override void SubscribeEvents()
{
Exiled.Events.Handlers.Player.InteractingElevator += OnInteractingElevator;
Exiled.Events.Handlers.Player.InteractingDoor += OnInteractingDoor;
Exiled.Events.Handlers.Player.InteractingLocker += OnInteractingLocker;
Exiled.Events.Handlers.Player.InteractingScp330 += OnInteractingScp330;
Exiled.Events.Handlers.Player.InteractingShootingTarget += OnInteractingShootingTarget;
Exiled.Events.Handlers.Player.PickingUpItem += OnPickingUpItem;
Exiled.Events.Handlers.Player.EnteringFemurBreaker += OnEnteringFemurBreaker;
Exiled.Events.Handlers.Player.Shooting += OnShooting;
Exiled.Events.Handlers.Player.Hurting += OnHurting;
Exiled.Events.Handlers.Scp096.AddingTarget += OnAddingTarget;
Exiled.Events.Handlers.Scp106.Containing += OnContaining;
Exiled.Events.Handlers.Scp914.Activating += OnActivating914;
Exiled.Events.Handlers.Scp914.UpgradingPlayer += OnUpgradingPlayer;
Exiled.Events.Handlers.Scp914.UpgradingInventoryItem += OnUpgradingInventoryItem;
Exiled.Events.Handlers.Player.PickingUpAmmo += OnPickingUpAmmo;
Exiled.Events.Handlers.Player.PickingUpArmor += OnPickingUpArmor;
base.SubscribeEvents();
}
private void OnPickingUpArmor(PickingUpArmorEventArgs ev)
{
if (Check(ev.Player))
ev.IsAllowed = false;
}
private void OnPickingUpAmmo(PickingUpAmmoEventArgs ev)
{
if (Check(ev.Player))
ev.IsAllowed = false;
}
private void OnUpgradingInventoryItem(UpgradingInventoryItemEventArgs ev)
{
if (Check(ev.Player))
ev.IsAllowed = false;
}
private void OnUpgradingPlayer(UpgradingPlayerEventArgs ev)
{
if (Check(ev.Player))
ev.IsAllowed = false;
}
private void OnActivating914(ActivatingEventArgs ev)
{
if (Check(ev.Player))
ev.IsAllowed = false;
}
...
To do things like, make someone unable to interact with the game world in any way, instead, we can do something like this:
protected override void SubscribeEvents()
{
Exiled.Events.Handlers.Player.InteractingElevator += OnPlayerEvent;
Exiled.Events.Handlers.Player.InteractingDoor += OnPlayerEvent;
Exiled.Events.Handlers.Player.InteractingLocker += OnPlayerEvent;
Exiled.Events.Handlers.Player.InteractingScp330 += OnPlayerEvent;
Exiled.Events.Handlers.Player.InteractingShootingTarget += OnPlayerEvent;
Exiled.Events.Handlers.Player.PickingUpItem += OnPlayerEvent;
Exiled.Events.Handlers.Player.EnteringFemurBreaker += OnPlayerEvent;
Exiled.Events.Handlers.Player.Shooting += OnPlayerEvent;
Exiled.Events.Handlers.Player.Hurting += OnPlayerEvent;
Exiled.Events.Handlers.Scp096.AddingTarget += OnPlayerEvent;
Exiled.Events.Handlers.Scp106.Containing += OnPlayerEvent;
Exiled.Events.Handlers.Scp914.Activating += OnPlayerEvent;
Exiled.Events.Handlers.Scp914.UpgradingPlayer += OnPlayerEvent;
Exiled.Events.Handlers.Scp914.UpgradingInventoryItem += OnPlayerEvent;
Exiled.Events.Handlers.Player.PickingUpAmmo += OnPlayerEvent;
Exiled.Events.Handlers.Player.PickingUpArmor += OnPlayerEvent;
base.SubscribeEvents();
}
private void OnPlayerEvent(IExiledEvent eventArgs)
{
if (eventArgs is IPlayerEvent and IDeniableEvent ev)
if (Check(ev.Player))
ev.IsAllowed = false;
}
This also forces standardization of property naming for events using similar properties. Devs will know that any event involving a player, will have ev.Player Any event related to a gun will have ev.Firearm etc.
In my very limited testing, with a custom build of DevTools to switch from EventArgs to IExiledEvent, events still seem to fire and their property values are what's expected, however I have not yet done any throughout testing to make sure changing the values still works, etc.
Tested SCPStats and WaitAndChillReborn (with a modification almost exactly like the example) with @Michal78900, and everything seems to work fine.
Omg!!!!