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

FREE CreativeToggle : 1.2.0 1.2.0

Нет прав для скачивания
C#:
using Oxide.Game.Rust.Cui;
using Newtonsoft.Json;


namespace Oxide.Plugins;

[Info("CreativeToggle", "Bubbafett", "1.2.0")]
[Description("Toggles creative mode for players.")]
public class CreativeToggle : RustPlugin
{
    #region Configuration
    private Configuration CreativeConfig;

    CuiElementContainer cachedCreativeUI = null;

    private sealed class Configuration
    {
        [JsonProperty(PropertyName = "ConsoleLoggingEnabled")]
        public bool ConsoleLoggingEnabled { get; set; }

        [JsonProperty(PropertyName = "ChatMessageEnabled")]
        public bool ChatMessageEnabled { get; set; }

        [JsonProperty(PropertyName = "IconEnabled")]
        public bool IconEnabled { get; set; }

        [JsonProperty(PropertyName = "IconAnchorMin")]
        public string IconAnchorMin { get; set; }

        [JsonProperty(PropertyName = "IconAnchorMax")]
        public string IconAnchorMax { get; set; }

        [JsonProperty(PropertyName = "IconImageURL")]
        public string IconImageURL { get; set; }

        [JsonProperty(PropertyName = "IconColor")]
        public string IconColor { get; set; }

        [JsonProperty(PropertyName = "Toggle Creative Permission")]
        public string CreativePermission { get; set; }

        [JsonProperty(PropertyName = "Toggle ConVars Permission")]
        public string ConVarPermission { get; set; }
    }

    private Configuration GetDefaultConfig()
    {
        return new Configuration
        {
            ConsoleLoggingEnabled = true,
            ChatMessageEnabled = true,
            IconEnabled = true,
            IconAnchorMin = "0.345 0.11",
            IconAnchorMax = "0.375 0.16",
            IconImageURL = "https://i.postimg.cc/nVvW4Smw/Creative-Mode.png",
            IconColor = "1 1 1 0.3",
            CreativePermission = "creativetoggle.use",
            ConVarPermission = "creativetoggle.convars"
        };
    }

    protected override void LoadConfig()
    {
        base.LoadConfig();
        if (!Config.Exists())
        {
            CreativeConfig = GetDefaultConfig();
            SaveConfig();
            return;
        }
        CreativeConfig = Config.ReadObject<Configuration>();
        SaveConfig();
    }

    protected override void LoadDefaultConfig()
    {
        CreativeConfig = GetDefaultConfig();
    }

    protected override void SaveConfig()
    {
        Config.WriteObject(CreativeConfig, true);
    }
    #endregion

    #region Hooks
    private void Init()
    {
        permission.RegisterPermission(CreativeConfig.CreativePermission, this);
        permission.RegisterPermission(CreativeConfig.ConVarPermission, this);
    }

    void Loaded()
    {
        if (CreativeConfig.IconEnabled)
        {
            foreach (BasePlayer player in BasePlayer.activePlayerList)
            {
                if (player.HasPlayerFlag(BasePlayer.PlayerFlags.CreativeMode))
                {
                    cachedCreativeUI = CreateCreativeUI();
                    CuiHelper.AddUi(player, cachedCreativeUI);
                }
            }
        }
    }

    void Unload()
    {
        foreach (BasePlayer player in BasePlayer.activePlayerList)
        {
            CuiHelper.DestroyUi(player, "CreativeModeUI");
        }
    }
    #endregion

    #region Commands
    [ChatCommand("creative")]
    private void CreativeCommand(BasePlayer player)
    {
        if (!permission.UserHasPermission(player.UserIDString, CreativeConfig.CreativePermission))
        {
            player.ChatMessage("You do not have permission to use this command!");
            return;
        }
        var wasCreativeMode = player.HasPlayerFlag(BasePlayer.PlayerFlags.CreativeMode);

        player.SetPlayerFlag(BasePlayer.PlayerFlags.CreativeMode, !wasCreativeMode);

        if (CreativeConfig.ChatMessageEnabled)
        {
            player.ChatMessage($"Creative mode {(wasCreativeMode ? "disabled" : "enabled")}.");
        }

        if (CreativeConfig.ConsoleLoggingEnabled)
        {
            Puts($"{player.Connection} {(wasCreativeMode ? "disabled" : "enabled")} creative mode");
        }


        if (!wasCreativeMode & CreativeConfig.IconEnabled)
        {
            cachedCreativeUI = CreateCreativeUI();
            CuiHelper.AddUi(player, cachedCreativeUI);
        }
        else
        {
            CuiHelper.DestroyUi(player, "CreativeModeUI");
        }
    }

    [ChatCommand("creativefreerepair")]
    private void CreativeFreeRepair(BasePlayer player)
    {
        if (!permission.UserHasPermission(player.UserIDString, CreativeConfig.ConVarPermission))
        {
            player.ChatMessage("You do not have permission to use this command!");
            return;
        }
        var wasFreeRepair = ConVar.Creative.freeRepair;
        ConVar.Creative.freeRepair = !ConVar.Creative.freeRepair;
        player.ChatMessage($"Creative free repair {(wasFreeRepair ? "disabled" : "enabled")}!");
    }

    [ChatCommand("creativefreebuild")]
    private void CreativeFreeBuild(BasePlayer player)
    {
        if (!permission.UserHasPermission(player.UserIDString, CreativeConfig.ConVarPermission))
        {
            player.ChatMessage("You do not have permission to use this command!");
            return;
        }
        var wasFreeBuild = ConVar.Creative.freeBuild;
        ConVar.Creative.freeBuild = !ConVar.Creative.freeBuild;
        player.ChatMessage($"Creative free build {(wasFreeBuild ? "disabled" : "enabled")}!");
    }

    [ChatCommand("creativefreeplacement")]
    private void CreativeFreePlacement(BasePlayer player)
    {
        if (!permission.UserHasPermission(player.UserIDString, CreativeConfig.ConVarPermission))
        {
            player.ChatMessage("You do not have permission to use this command!");
            return;
        }
        var wasFreePlacement = ConVar.Creative.freePlacement;
        ConVar.Creative.freePlacement = !ConVar.Creative.freePlacement;
        player.ChatMessage($"Creative free placement {(wasFreePlacement ? "disabled" : "enabled")}!");
    }

    [ChatCommand("creativeunlimitedio")]
    private void CreativeUnlimitedIO(BasePlayer player)
    {
        if (!permission.UserHasPermission(player.UserIDString, CreativeConfig.ConVarPermission))
        {
            player.ChatMessage("You do not have permission to use this command!");
            return;
        }
        var wasFreeUnlimitedIO = ConVar.Creative.unlimitedIo;
        ConVar.Creative.unlimitedIo = !ConVar.Creative.unlimitedIo;
        player.ChatMessage($"Creative free placement {(wasFreeUnlimitedIO ? "disabled" : "enabled")}!");
    }



    #endregion

    #region GUI
    private CuiElementContainer CreateCreativeUI()
    {
        CuiElementContainer elements = new CuiElementContainer();
        string panel = elements.Add(new CuiPanel
        {
            Image = {
                Color = "0 0 0 0"
            },
            RectTransform = {
                AnchorMin = CreativeConfig.IconAnchorMin,
                AnchorMax = CreativeConfig.IconAnchorMax
            }
        }, "Hud", "CreativeModeUI", "CreativeModeUI");
        elements.Add(new CuiElement
        {
            Parent = panel,
            Components =
            {
                new CuiRawImageComponent {
                    Url = CreativeConfig.IconImageURL,
                    Color = CreativeConfig.IconColor
                },
                new CuiRectTransformComponent {
                    AnchorMin = "0 0",
                    AnchorMax = "1 1"
                }
            }
        });
        return elements;
    }
    #endregion
}

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