Plugin bugs and performance issuesSolved

Hello, nice concept but the plugin has many issues. 1.0.5 should not be available for download. I have not checked prior versions

All hooks should be unsubscribed in Init() hook and subscribed once initialization is complete to avoid exceptions being thrown during server startup. This is a common problem with the OnEntitySpawned hook

Null checks should be using IsValid() instead of entity != null as it will throw an exception when entity.net is null. Example: if (priv != null) should be if (priv.IsValid())

OnTick and OnPlayerTick hooks:

(12:27:16) | Calling 'OnPlayerTick' on 'ScrapRaidProtection v1.0.5' took average 1243ms

(12:27:26) | Calling 'OnPlayerTick' on 'ScrapRaidProtection v1.0.5' took average 1151ms

(12:27:36) | Calling 'OnEntityTakeDamage' on 'ScrapRaidProtection v1.0.5' took average 1135ms

(12:27:46) | Calling 'OnPlayerTick' on 'ScrapRaidProtection v1.0.5' took average 1125ms

These hooks are badly optimized and cause serious server lag. Also, the server this is running on is top of the line so it's not a limitation of the machine

OnTick should be replaced with a timer since you are using it at specific times. This is a heavy hook and should not be used for its current implementation 

OnEntitySpawned - this hook does not have a null check in the timer callback and will throw an exception

OnEntityDeath - this hook is missing and should be used in combination with OnEntityKill. void OnEntityDeath(BuildingPrivilege priv, HitInfo hitInfo) => OnEntityKill(priv); will fix this bug

calling LoadAllTcs in Init() is throwing a KeyNotFoundException on line 878. calling AddProtectedTc in OnCupboardAuthorize() is throwing the same exception from the same line. both of these issues are fixed by deleting the config file, so the update notes should reflect that this is required. You can avoid this issue in the future by using a standard configuration. https://umod.org/plugins/water-works has a great example of this, in the region Configuration.

I can look at the file again once you've addressed these issues

Hi, thank you for your indepth analysis and extremely helpful suggestions.

Quite clearly I'm new to making plugins for Rust, so I appreciate the guidance. With that being said I went and implemented your suggestions in the brand new 1.1.1 update. Let me know what you think of the plugin now that these issues are resolved.

nice np

when I said initialization i was referring to the server. OnServerInitialized is where you would subscribe

also you need to clean up static members in the Unload() hook

void Unload()
{
    ProtectedCupboard.viewingTc.Clear();
    ProtectedCupboard.indicatorShown.Clear();
}​

otherwise they will persist through a reload or remain in memory during an unload

the example didn't include this, but you need to include object handling for your collections in the config

            [JsonProperty(PropertyName = "Custom unprotected entities", ObjectCreationHandling = ObjectCreationHandling.Replace)]
            public List<string> UnprotectedEntities { get; set; } = new List<string>();


this needs to be added to every collection

everything else appears to be in order. well done

I've implemented these changes as well, thanks again

Locked automatically