Advertisement
Vlad-00003

[RUST] DiscordRoles: Fix for unliking OnDiscordPlayerUnlinked hook.

Aug 11th, 2022 (edited)
1,187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 4.13 KB | None | 0 0
  1. From 10847757a882a7659e0324518f2c1ed6c333bfed Mon Sep 17 00:00:00 2001
  2. From: Vlad-00003 <Vlad-00003@mail.ru>
  3. Date: Thu, 11 Aug 2022 15:09:58 +0300
  4. Subject: [PATCH] DiscordRoles: Fix for unliking OnDiscordPlayerUnlinked hook.
  5.  At this point discord link already was removed and calling GetDiscordUserId
  6.  would always result in null.
  7.  
  8. ---
  9. .../ASKED/DiscordRoles/DiscordRoles.cs        | 28 +++++++++++++------
  10.  1 file changed, 20 insertions(+), 8 deletions(-)
  11.  
  12. diff --git a/DiscordRoles/DiscordRoles.cs b/DiscordRoles/DiscordRoles.cs
  13. index 26c6ba0..312fd30 100644
  14. --- a/DiscordRoles/DiscordRoles.cs 
  15. +++ b/DiscordRoles/DiscordRoles.cs 
  16. @@ -311,7 +311,7 @@ namespace Oxide.Plugins
  17.              }
  18.              
  19.              Debug(DebugEnum.Info, $"{nameof(OnUserConnected)} Added {player.Name}({player.Id}) to be processed");
  20. -            ProcessChange(player.Id, false, SyncEvent.PlayerConnected);
  21. +            ProcessChange(player.Id, SyncEvent.PlayerConnected);
  22.          }
  23.  
  24.          private void OnUserGroupAdded(string id, string groupName)
  25. @@ -323,7 +323,7 @@ namespace Oxide.Plugins
  26.              }
  27.              
  28.              Debug(DebugEnum.Info, $"{nameof(OnUserGroupAdded)} Added ({id}) to be processed because added to group {groupName}");
  29. -            ProcessChange(id, false, SyncEvent.ServerGroupChanged);
  30. +            ProcessChange(id, SyncEvent.ServerGroupChanged);
  31.          }
  32.  
  33.          private void OnUserGroupRemoved(string id, string groupName)
  34. @@ -335,7 +335,7 @@ namespace Oxide.Plugins
  35.              }
  36.              
  37.              Debug(DebugEnum.Info, $"{nameof(OnUserGroupRemoved)} Added ({id}) to be processed because removed from group {groupName}");
  38. -            ProcessChange(id, false, SyncEvent.ServerGroupChanged);
  39. +            ProcessChange(id, SyncEvent.ServerGroupChanged);
  40.          }
  41.  
  42.          [HookMethod(DiscordExtHooks.OnDiscordPlayerLinked)]
  43. @@ -348,7 +348,7 @@ namespace Oxide.Plugins
  44.              }
  45.              
  46.              Debug(DebugEnum.Info, $"{nameof(OnDiscordPlayerLinked)} Added Player {player.Name}({player.Id}) Discord: {user.Username}#{user.Discriminator}({user.Id}) to be processed");
  47. -            ProcessChange(player.Id, false, SyncEvent.PlayerLinkedChanged);
  48. +            ProcessChange(player.Id, SyncEvent.PlayerLinkedChanged);
  49.          }
  50.  
  51.          [HookMethod(DiscordExtHooks.OnDiscordPlayerUnlinked)]
  52. @@ -361,7 +361,7 @@ namespace Oxide.Plugins
  53.              }
  54.              
  55.              Debug(DebugEnum.Info, $"{nameof(OnDiscordPlayerUnlinked)} Added Player {player.Name}({player.Id}) Discord: {user.Username}#{user.Discriminator}({user.Id}) to be processed");
  56. -            ProcessChange(player.Id, true, SyncEvent.PlayerLinkedChanged);
  57. +            ProcessLeaving(player.Id, user.Id, SyncEvent.PlayerLinkedChanged);
  58.          }
  59.  
  60.          [HookMethod(DiscordExtHooks.OnDiscordGuildMemberAdded)]
  61. @@ -512,10 +512,10 @@ namespace Oxide.Plugins
  62.              StartChecker();
  63.          }
  64.  
  65. -        private void ProcessChange(string playerId, bool isLeaving, SyncEvent syncEvent)
  66. +        private void ProcessChange(string playerId, SyncEvent syncEvent)
  67.          {
  68.              _processIds.RemoveAll(p => p.Player.Id == playerId);
  69. -
  70. +            
  71.              IPlayer player = players.FindPlayerById(playerId);
  72.              if (player == null)
  73.              {
  74. @@ -527,8 +527,20 @@ namespace Oxide.Plugins
  75.              {
  76.                  return;
  77.              }
  78. +            _processIds.Insert(0, new PlayerSync(player, discordId, false, syncEvent));
  79.  
  80. -            _processIds.Insert(0, new PlayerSync(player, discordId, isLeaving, syncEvent));
  81. +            StartChecker();
  82. +        }
  83. +        private void ProcessLeaving(string playerId, Snowflake discordId, SyncEvent syncEvent)
  84. +        {
  85. +            _processIds.RemoveAll(p => p.Player.Id == playerId);
  86. +
  87. +            IPlayer player = players.FindPlayerById(playerId);
  88. +            if (player == null || !discordId.IsValid())
  89. +            {
  90. +                return;
  91. +            }
  92. +            _processIds.Insert(0, new PlayerSync(player, discordId, true, syncEvent));
  93.  
  94.              StartChecker();
  95.          }
  96. --
  97. 2.33.0.windows.1
  98.  
  99.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement