using Oxide.Core.Plugins; using Oxide.Core; using System.Collections.Generic; using UnityEngine; namespace Oxide.Plugins { [Info("LadderDestruction", "LLC", "1.0.4")] [Description("Execute a cleanup every 5 minutes to check for ladders that are not owned by a player in a building zone.")] public class LadderDestruction : RustPlugin { private const string PrefabLadder = "assets/prefabs/building/ladder.wall.wood/ladder.wooden.wall.prefab"; private Dictionary ladderTimers = new Dictionary(); private void OnEntityBuilt(Planner planner, GameObject go) { BasePlayer player = planner.GetOwnerPlayer(); BaseEntity entity = go.ToBaseEntity(); if (entity == null || player == null || entity.PrefabName != PrefabLadder) return; BuildingPrivlidge priv = GetBuildingPrivilege(entity.transform.position); if (priv != null) { if (IsAuthorized(player, priv)) return; } else return; NetworkableId entityID = entity.net.ID; ladderTimers[entityID] = timer.Once(300f, () => DestroyLadder(entityID)); } private void DestroyLadder(NetworkableId entityID) { BaseNetworkable ladder = BaseNetworkable.serverEntities.Find(entityID); if (ladder != null) ladder.Kill(); if (ladderTimers.ContainsKey(entityID)) { ladderTimers[entityID].Destroy(); ladderTimers.Remove(entityID); } } private BuildingPrivlidge GetBuildingPrivilege(Vector3 position) { BuildingBlock buildingBlock = GetBuildingBlock(position); if (buildingBlock != null) return buildingBlock.GetBuildingPrivilege(); return null; } private BuildingBlock GetBuildingBlock(Vector3 position) { List buildingBlocks = new List(); Vis.Entities(position, 3f, buildingBlocks, Rust.Layers.Solid); foreach (var block in buildingBlocks) { if (block.IsValid()) return block; } return null; } private bool IsAuthorized(BasePlayer player, BuildingPrivlidge priv) { if (priv.IsAuthed(player)) return true; var team = RelationshipManager.ServerInstance?.FindTeam(player.currentTeam); if (team == null) return false; foreach (ulong memberId in team.members) { if (priv.IsAuthed(memberId)) return true; } return false; } private void Unload() { foreach (var timer in ladderTimers.Values) timer.Destroy(); ladderTimers.Clear(); } } }