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

FREE SurveyReport : 1.1.0 1.1.0

Нет прав для скачивания
C#:
using System.Collections.Generic;
using System.Text;
using Newtonsoft.Json;

namespace Oxide.Plugins
{
    [Info("SurveyReport", "breakglasstech", "1.1.0")]
    [Description("Broadcasts the resource results of a Survey Charge to the player who threw it.")]
    public class SurveyReport : RustPlugin
    {
        #region Config
        private Configuration config;
        private class Configuration
        {
            [JsonProperty("Require permission (surveyreport.use) to see results")]
            public bool RequirePermission = true;

            [JsonProperty("Also print in server console")]
            public bool LogToConsole = false;
        }
        protected override void LoadDefaultConfig() => config = new Configuration();
        protected override void SaveConfig() => Config.WriteObject(config);
        protected override void LoadConfig()
        {
            base.LoadConfig();
            try { config = Config.ReadObject<Configuration>() ?? new Configuration(); }
            catch { PrintError("Invalid config, using defaults."); config = new Configuration(); }
            SaveConfig();
        }
        #endregion

        #region Localization
        protected override void LoadDefaultMessages() => lang.RegisterMessages(new Dictionary<string, string>
        {
            ["Header"]      = "<color=#f0c674>Survey results:</color>",
            ["Line"]        = "  {0}: {1}",
            ["NoResources"] = "Survey found no notable resources here.",
        }, this);
        private string L(string key, string userId = null) => lang.GetMessage(key, this, userId);
        #endregion

        #region Init
        private const string PermUse = "surveyreport.use";
        private void Init() => permission.RegisterPermission(PermUse, this);
        private void OnServerInitialized(bool initial) =>
            Puts("SurveyReport loaded — survey charge results will be shown to the thrower.");
        #endregion

        // Read the resource deposit when a Survey Charge lands and report it to the thrower.
        // NOTE: the OnSurveyGather hook never fires in current Rust, so we hook the charge's spawn instead.
        #region Core: OnEntitySpawned -> SurveyCharge (verified in playtest)
        private void OnEntitySpawned(BaseNetworkable entity)
        {
            if (!(entity is SurveyCharge charge)) return;

            BasePlayer player = charge.creatorEntity as BasePlayer;
            if (player == null) return;

            if (config.RequirePermission && !permission.UserHasPermission(player.UserIDString, PermUse))
                return;

            ResourceDepositManager.ResourceDeposit deposit =
                ResourceDepositManager.GetOrCreate(charge.transform.position);

            if (deposit?._resources == null || deposit._resources.Count == 0)
            {
                player.ChatMessage(L("NoResources", player.UserIDString));
                return;
            }

            var sb = new StringBuilder();
            sb.AppendLine(L("Header", player.UserIDString));
            foreach (ResourceDepositManager.ResourceDeposit.ResourceDepositEntry entry in deposit._resources)
            {
                if (entry?.type == null) continue;
                string name = entry.type.displayName?.english ?? entry.type.shortname;
                sb.AppendLine(string.Format(L("Line", player.UserIDString), name, entry.amount));
            }

            string report = sb.ToString();
            player.ChatMessage(report);
            if (config.LogToConsole) Puts($"{player.displayName} surveyed: {report.Replace("\n", " ")}");
        }
        #endregion
    }
}

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