Иконка ресурса

FREE PositionSaver : 1.2.0 1.2.0

Нет прав для скачивания
C#:
using Oxide.Core;
using Oxide.Core.Plugins;
using System.Collections.Generic;
using UnityEngine;

namespace Oxide.Plugins
{
    [Info("PositionSaver", "✯Mr.Kingpin✯", "1.2.0")]
    [Description("A plugin for saving the coordinates of your current location with a custom name.")]

    public class PositionSaver : RustPlugin
    {
        private Dictionary<string, string> savedPositions = new Dictionary<string, string>();
        private const string DataFileName = "saved_positions";
        private const string PermissionUse = "positionsaver.saveposition.use";

        
        private void Init()
        {
            ShowLogo();
            permission.RegisterPermission(PermissionUse, this);
            savedPositions = Interface.Oxide.DataFileSystem.ReadObject<Dictionary<string, string>>(DataFileName) ?? new Dictionary<string, string>();
        }

        
        private void SaveData()
        {
            Interface.Oxide.DataFileSystem.WriteObject(DataFileName, savedPositions);
        }

        
        private bool HasPermission(BasePlayer player)
        {
            if (player == null || player.IsAdmin) return true;
            return permission.UserHasPermission(player.UserIDString, PermissionUse);
        }

        
        [ChatCommand("savepos")]
        private void SavePosCommand(BasePlayer player, string command, string[] args)
        {
            if (!HasPermission(player))
            {
                player.ChatMessage(Lang("NoPermission", player.UserIDString, "#FF6666"));
                return;
            }

            if (args.Length != 1)
            {
                player.ChatMessage(Lang("SavePosUsage", player.UserIDString, "#FFD966"));
                return;
            }

            string name = args[0].ToLower();
            Vector3 position = player.transform.position;

            if (savedPositions.ContainsKey(name))
            {
                player.ChatMessage(Lang("PositionExists", player.UserIDString, "#FFA500", name));
                return;
            }

            string positionString = $"{position.x},{position.y},{position.z}";
            savedPositions[name] = positionString;

            player.ChatMessage(Lang("PositionSaved", player.UserIDString, "#00FF7F", name, positionString));
            SaveData();
        }

        
        [ChatCommand("listpos")]
        private void ListPosCommand(BasePlayer player, string command, string[] args)
        {
            if (!HasPermission(player))
            {
                player.ChatMessage(Lang("NoPermission", player.UserIDString, "#FF6666"));
                return;
            }

            if (savedPositions.Count == 0)
            {
                player.ChatMessage(Lang("NoPositions", player.UserIDString, "#FFA07A"));
                return;
            }

            player.ChatMessage(Lang("SavedPositions", player.UserIDString, "#6495ED"));
            foreach (var entry in savedPositions)
            {
                player.ChatMessage($"<color=#FFD700>{entry.Key}</color>: <color=#FFFFFF>{entry.Value}</color>");
            }
        }

        
        [ChatCommand("delpos")]
        private void DelPosCommand(BasePlayer player, string command, string[] args)
        {
            if (!HasPermission(player))
            {
                player.ChatMessage(Lang("NoPermission", player.UserIDString, "#FF6666"));
                return;
            }

            if (args.Length != 1)
            {
                player.ChatMessage(Lang("DelPosUsage", player.UserIDString, "#FFD966"));
                return;
            }

            string name = args[0].ToLower();

            if (!savedPositions.ContainsKey(name))
            {
                player.ChatMessage(Lang("PositionNotFound", player.UserIDString, "#FFA500", name));
                return;
            }

            savedPositions.Remove(name);
            player.ChatMessage(Lang("PositionDeleted", player.UserIDString, "#00FF7F", name));
            SaveData();
        }

        
        [ChatCommand("pshelp")]
        private void HelpCommand(BasePlayer player, string command, string[] args)
        {
            if (!HasPermission(player))
            {
                player.ChatMessage(Lang("NoPermission", player.UserIDString, "#FF6666"));
                return;
            }

            player.ChatMessage(Lang("HelpHeader", player.UserIDString, "#6495ED"));
            player.ChatMessage(Lang("HelpSavePos", player.UserIDString, "#FFD700"));
            player.ChatMessage(Lang("HelpListPos", player.UserIDString, "#FFD700"));
            player.ChatMessage(Lang("HelpDelPos", player.UserIDString, "#FFD700"));
        }

        private void ShowLogo()
        {
            Puts(@"      ____                _  __   _                      _____                           ");
            Puts(@"     / __ \ ____   _____ (_)/ /_ (_)____   ____         / ___/ ____ _ _   __ ___   _____ ");
            Puts(@"    / /_/ // __ \ / ___// // __// // __ \ / __ \ ______ \__ \ / __ `/| | / // _ \ / ___/ ");
            Puts(@"   / ____// /_/ /(__  )/ // /_ / // /_/ // / / //_____/___/ // /_/ / | |/ //  __// /     ");
            Puts(@"  /_/     \____//____//_/ \__//_/ \____//_/ /_/       /____/ \__,_/  |___/ \___//_/      ");
            Puts(@"                      PositionSaver v1.2.0               By: ✯Mr.Kingpin✯               ");
        }

        protected override void LoadDefaultMessages()
        {
            lang.RegisterMessages(new Dictionary<string, string>
            {
                ["NoPermission"] = "<color={0}>You do not have permission to use this command.</color>",
                ["SavePosUsage"] = "<color={0}>Usage:</color> /savepos [name]",
                ["PositionExists"] = "<color={0}>A position with the name '{1}' already exists. Use a different name.</color>",
                ["PositionSaved"] = "<color={0}>Position '{1}' saved</color> at coordinates: <color={0}>{2}</color>",
                ["ListPosUsage"] = "<color={0}>Usage:</color> /listpos",
                ["SavedPositions"] = "<color={0}>Saved positions:</color>",
                ["NoPositions"] = "<color={0}>No positions have been saved yet.</color>",
                ["DelPosUsage"] = "<color={0}>Usage:</color> /delpos [name]",
                ["PositionNotFound"] = "<color={0}>No position found with the name '{1}'.</color>",
                ["PositionDeleted"] = "<color={0}>Position '{1}' has been deleted.</color>",
                ["HelpHeader"] = "<color={0}>Available Commands:</color>",
                ["HelpSavePos"] = "<color={0}>/savepos [name]</color> - Save your current position with a specific name.",
                ["HelpListPos"] = "<color={0}>/listpos</color> - List all saved positions.",
                ["HelpDelPos"] = "<color={0}>/delpos [name]</color> - Delete a saved position by name."
            }, this);
        }

        private string Lang(string key, string userId = null, params object[] args)
        {
            return string.Format(lang.GetMessage(key, this, userId), args);
        }
    }
}

Автор
15FPS
Скачиваний
0
Просмотры
1
Первый выпуск
Обновление
Оценка
0.00 звёзд 0 оценок
Сверху