当前位置: 首页>>代码示例>>C#>>正文


C# MyCubeBlock.GetType方法代码示例

本文整理汇总了C#中Sandbox.Game.Entities.MyCubeBlock.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# MyCubeBlock.GetType方法的具体用法?C# MyCubeBlock.GetType怎么用?C# MyCubeBlock.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Sandbox.Game.Entities.MyCubeBlock的用法示例。


在下文中一共展示了MyCubeBlock.GetType方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ProcessEnforcement

        private static void ProcessEnforcement( MyCubeBlock newBlock = null)
        {
            if ( !PluginSettings.Instance.PlayerBlockEnforcementEnabled )
                return;

            if ( _processing )
                return;

            _processing = true;

            if ( DateTime.Now - _lastRun < TimeSpan.FromMilliseconds( 100 ) )
            {
                _processing = false;
                return;
            }

            _lastRun = DateTime.Now;

            Task.Run( () =>
                      {
                          //Essentials.Log.Debug( "process enforcement" );
                          foreach ( var item in PluginSettings.Instance.PlayerBlockEnforcementItems )
                          {
                              string blockSearch;
                              bool searchSubType;
                              switch ( item.Mode )
                              {
                                  case SettingsBlockEnforcementItem.EnforcementMode.Off:
                                      continue;

                                  case SettingsBlockEnforcementItem.EnforcementMode.BlockSubtypeId:
                                      blockSearch = item.BlockSubtypeId;
                                      searchSubType = true;
                                      break;

                                  case SettingsBlockEnforcementItem.EnforcementMode.BlockTypeId:
                                      blockSearch = item.BlockTypeId;
                                      searchSubType = false;
                                      break;

                                  default:
                                      Essentials.Log.Debug( "exit" );
                                      return;
                              }

                              if ( item.MaxPerGrid == 0 )
                              {
                                  foreach ( var player in MySession.Static.Players.GetOnlinePlayers() )
                                  {
                                      if ( item.AdminExempt && player.IsAdmin )
                                          continue;

                                      Communication.DisableGMenu( player.Client.SteamUserId, blockSearch, searchSubType, false );
                                      disabledPlayers[player.Client.SteamUserId].Add( blockSearch );
                                  }
                              }

                              var ownedBlocks = new Dictionary<long, int>();
                              var entities = new HashSet<MyEntity>();
                              var razeBlocks = new HashSet<MyCubeBlock>();
                              Wrapper.GameAction( () => entities = MyEntities.GetEntities() );
                              MyEntity[] entitiesCopy = new MyEntity[entities.Count];
                              entities.CopyTo( entitiesCopy );

                              foreach ( var entity in entitiesCopy )
                              {
                                  var grid = entity as MyCubeGrid;
                                  if ( grid?.Physics == null || grid.Closed )
                                      continue;

                                  foreach ( var cubeBlock in grid.GetFatBlocks() )
                                  {
                                      if ( cubeBlock.Closed )
                                          continue;

                                      if ( ( searchSubType && cubeBlock.BlockDefinition.Id.SubtypeId.ToString().Contains( blockSearch ) )
                                           || ( !searchSubType && cubeBlock.BlockDefinition.Id.TypeId.ToString().Contains( blockSearch ) ) )
                                      {
                                          //Essentials.Log.Debug( $"found block: {cubeBlock.BlockDefinition.Id.SubtypeName}" );

                                          if ( MySession.Static.Players.IdentityIsNpc( cubeBlock.OwnerId ) )
                                          {
                                              //Essentials.Log.Debug( "not processing NPC owned block" );
                                              continue;
                                          }

                                          if ( ownedBlocks.ContainsKey( cubeBlock.OwnerId ) )
                                              ownedBlocks[cubeBlock.OwnerId]++;
                                          else
                                              ownedBlocks.Add( cubeBlock.OwnerId, 1 );

                                          foreach ( var entry in ownedBlocks )
                                          {
                                              if ( entry.Key != cubeBlock.OwnerId )
                                                  continue;

                                              if ( entry.Value > item.MaxPerGrid )
                                              {
                                                  if ( newBlock != null && newBlock.GetType() == cubeBlock.GetType() && !razeBlocks.Contains( newBlock ) )
                                                      razeBlocks.Add( newBlock );
//.........这里部分代码省略.........
开发者ID:rexxar-tc,项目名称:EssentialsPlugin,代码行数:101,代码来源:PlayerBlockEnforcement.cs


注:本文中的Sandbox.Game.Entities.MyCubeBlock.GetType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。