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 savedPositions = new Dictionary(); 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>(DataFileName) ?? new Dictionary(); } 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($"{entry.Key}: {entry.Value}"); } } [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 { ["NoPermission"] = "You do not have permission to use this command.", ["SavePosUsage"] = "Usage: /savepos [name]", ["PositionExists"] = "A position with the name '{1}' already exists. Use a different name.", ["PositionSaved"] = "Position '{1}' saved at coordinates: {2}", ["ListPosUsage"] = "Usage: /listpos", ["SavedPositions"] = "Saved positions:", ["NoPositions"] = "No positions have been saved yet.", ["DelPosUsage"] = "Usage: /delpos [name]", ["PositionNotFound"] = "No position found with the name '{1}'.", ["PositionDeleted"] = "Position '{1}' has been deleted.", ["HelpHeader"] = "Available Commands:", ["HelpSavePos"] = "/savepos [name] - Save your current position with a specific name.", ["HelpListPos"] = "/listpos - List all saved positions.", ["HelpDelPos"] = "/delpos [name] - 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); } } }