using System.Collections; using System; using System.Collections.Generic; using Facepunch; using UnityEngine; namespace Oxide.Plugins { [Info("Null Save List", "ViolationHandler", "0.0.1")] [Description("Removes nulls on Save List via command.")] public class NullSaveList : RustPlugin { [ConsoleCommand("clearnullsave")] private void ClearNullSaveCommand(ConsoleSystem.Arg arg) { HashSet saveList = BaseEntity.saveList; List list = Pool.GetList(); BasePlayer player = arg?.Connection?.player as BasePlayer; if (!arg.IsRcon || (player != null && player?.net?.connection.authLevel < 2)) { player.ChatMessage("No Perms."); return; } try { foreach (BaseEntity entity in saveList) { if (entity == null || entity.IsDestroyed) list.Add(entity); } foreach (BaseEntity entity in list) { saveList.Remove(entity); } string reply; if(list.Count == 0) reply = "There were 0 null entities in Save List."; else reply = $"Sucessfully removed {list.Count} null entites from Save List."; if (arg.IsRcon) { Debug.Log(reply); return; } player.ChatMessage(reply); } catch (Exception e) { Debug.LogError(e); return; } finally { Pool.FreeList(ref list); } } } }