Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@ACaiCat
Copy link
Contributor

@ACaiCat ACaiCat commented May 24, 2025

Adds a virtual Call method with params object[] args parameter to allow plugins to implement custom method invocation functionality without referencing their types or namespaces.

Example

Called Plugin (eg. A rank plugin)

public override object Call(params object[] args)
{
  if (args.Length < 2)
      return null;
  
  var command = args[0] as string;
  var player = args[0] as TSPlayer;

  switch (command)
  {
      case "GetRankData":
        return GetRankData(player);
      case "ResetRankData":
        return ResetRankData(player);
      default:
        return null;
  }
}

Calling Plugin

var rankPlugin = ServerApi.Plugins.FirstOrDefault(p => p.Plugin.Name == "RankPlugin");

if (rankPlugin == null)
{
    player.SendErrorMessage("Rank plugin not available!");
    return;
}

var rankData = rankPlugin?.Plugin.Call("GetRankData", player) as string;
player.SendSuccessMessage(rankData);

Adds a virtual Call method with params object[] args parameter to allow
plugins to implement custom method invocation functionality.
@Arthri
Copy link
Contributor

Arthri commented May 24, 2025

Pardon my ignorance. What problem does the proposed Call method solve?

@sgkoishi
Copy link
Member

Probably this is trying to do some kind of cross-plugin interaction just like how tMod did. Not sure how useful it would be since you can already do ((WhateverPlugin) rankPlugin).TheirMethod()?

@hakusaro hakusaro merged commit 2b81ac7 into Pryaxis:general-devel May 24, 2025
5 of 6 checks passed
@ACaiCat
Copy link
Contributor Author

ACaiCat commented May 24, 2025

Pardon my ignorance. What problem does the proposed Call method solve?

The proposed Call method eliminates the need for hard references between plugins. For example, when Plugin A needs to use certain features from Plugin B but must still function normally when Plugin B isn't installed, the Call method enables this flexible interaction. (Sorry for my weak English)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants