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

FREE xNoFallDamage : 1.1.0 1.1.0

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

namespace Oxide.Plugins
{
    [Info("xNoFallDamage", "xNullPointer95", "1.1.0")]
    [Description("Discord: https://discord.gg/rGm7VS5ERc")]
    public class xNoFallDamage : RustPlugin
    {
        const string permNoFall = "xnofalldamage.use";
        readonly HashSet<ulong> _allowedPlayers = new HashSet<ulong>();

        void Init()
        {
            permission.RegisterPermission(permNoFall, this);
        }

        void OnServerInitialized()
        {
            RebuildOnlinePermissionCache();
        }

        void OnPlayerConnected(BasePlayer player)
        {
            RefreshPlayerCache(player);
        }

        void OnPlayerDisconnected(BasePlayer player, string reason)
        {
            if (player == null)
                return;

            _allowedPlayers.Remove(player.userID);
        }

        void OnUserPermissionGranted(string userId, string perm)
        {
            if (perm != permNoFall)
                return;

            if (ulong.TryParse(userId, out var user))
                _allowedPlayers.Add(user);
        }

        void OnUserPermissionRevoked(string userId, string perm)
        {
            if (perm != permNoFall)
                return;

            if (ulong.TryParse(userId, out var user))
                _allowedPlayers.Remove(user);
        }

        void OnUserGroupAdded(string userId, string groupName)
        {
            RefreshPlayerCache(userId);
        }

        void OnUserGroupRemoved(string userId, string groupName)
        {
            RefreshPlayerCache(userId);
        }

        void OnGroupPermissionGranted(string groupName, string perm)
        {
            if (perm != permNoFall)
                return;

            RebuildOnlinePermissionCache();
        }

        void OnGroupPermissionRevoked(string groupName, string perm)
        {
            if (perm != permNoFall)
                return;

            RebuildOnlinePermissionCache();
        }

        object OnPlayerLand(BasePlayer player, float severity)
        {
            if (player == null)
                return null;

            if (!HasNoFallPermission(player))
                return null;

            return true;
        }

        bool HasNoFallPermission(BasePlayer player)
        {
            if (_allowedPlayers.Contains(player.userID))
                return true;

            if (!permission.UserHasPermission(player.UserIDString, permNoFall))
                return false;

            _allowedPlayers.Add(player.userID);
            return true;
        }

        void RefreshPlayerCache(BasePlayer player)
        {
            if (player == null)
                return;

            RefreshPlayerCache(player.UserIDString);
        }

        void RefreshPlayerCache(string userId)
        {
            if (!ulong.TryParse(userId, out var user))
                return;

            if (permission.UserHasPermission(userId, permNoFall))
                _allowedPlayers.Add(user);
            else
                _allowedPlayers.Remove(user);
        }

        void RebuildOnlinePermissionCache()
        {
            _allowedPlayers.Clear();

            for (int i = 0; i < BasePlayer.activePlayerList.Count; i++)
            {
                var player = BasePlayer.activePlayerList[i];
                if (player == null)
                    continue;

                if (permission.UserHasPermission(player.UserIDString, permNoFall))
                    _allowedPlayers.Add(player.userID);
            }
        }
    }
}

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