• The move of Eco-Mods.com has taken place and the merge of our old officials forums is currently ongoing, read more here.

How to block executing of events

mampf

Moderator
Mod Dev
Eco-Mods.com Founder
Messages
115
Reaction score
72
Add this method to your code:

C#:
public static void AddActionPreventer<T>(PlayerActionManager<T> pPlayerActionManager, IActionPreventer<T> pActionPreventer) where T : IPlayerAction, new()
{
    FieldInfo fi = pPlayerActionManager.GetType().BaseType.GetField("actionPreventers", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
    IActionPreventer<T>[] actionPreventers = (IActionPreventer<T>[])fi.GetValue(pPlayerActionManager);
    var preventers = actionPreventers.ToList();
    preventers.Add(pActionPreventer);
    fi.SetValue(pPlayerActionManager, preventers.ToArray());
}

Call it like this to register your "Event Listener":

C#:
AddActionPreventer(PlayerActions.Message, new MyMessagePreventer());

Now you can create an ActionPreventer (A Factorty of IAtomicActions)

C#:
  public class MyMessagePreventer : IActionPreventer<MessageAction>
  {
      public IAtomicAction CreateAtomicAction(MessageAction action)
      {
          return new FailedAtomicAction(new LocString("Blocked!"));
      }
  }
Because MessageAction does not contain the real message, it's not possible to block messages based on the content.
(With this way)

Also it's possible to implement your own Action ;)


Have fun :p


Thanks to Kronox for help ;)
 
Last edited:
Top Bottom