using System.Collections.Generic; using JetBrains.Annotations; using Oxide.Core.Plugins; using ProtoBuf; using UnityEngine; namespace Oxide.Plugins; [Info("Map Markers", "Ilovepatatos", "2.0.2")] [Description("Removes all your map markers when placing a new one. Useful for admins using the 'teleport2marker' command.")] public class MapMarkers : RustPlugin { private const string CLEAR_MARKER_PERM = "mapmarkers.clear"; private const string TELEPORT_TO_MARKER_PERM = "mapmarkers.teleport"; #region Hooks [UsedImplicitly] [HookMethod(nameof(Init))] private void Init() { permission.RegisterPermission(CLEAR_MARKER_PERM, this); permission.RegisterPermission(TELEPORT_TO_MARKER_PERM, this); } [UsedImplicitly] [HookMethod(nameof(OnMapMarkerAdd))] private void OnMapMarkerAdd(BasePlayer player, MapNote marker) { if (player == null) return; if (permission.UserHasPermission(player.UserIDString, CLEAR_MARKER_PERM)) ClearMapMarkers(player); if (permission.UserHasPermission(player.UserIDString, TELEPORT_TO_MARKER_PERM)) TeleportToMapMarker(player, marker); } #endregion #region Methods private static void ClearMapMarkers(BasePlayer player) { List list = player.State?.pointsOfInterest; if (list == null) return; foreach (MapNote note in list) note?.Dispose(); list.Clear(); } private static void TeleportToMapMarker(BasePlayer player, MapNote marker) { Vector3 pos = marker.worldPosition; pos.y = GetTerrainHeightAt(pos); player.Teleport(pos); } #endregion #region Utility private static float GetTerrainHeightAt(Vector3 pos) { float height = TerrainMeta.HeightMap.GetHeight(pos); float water = TerrainMeta.WaterMap.GetHeight(pos); return Mathf.Max(height, water); } #endregion }