Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Commit

Permalink
Language-standard naming.
Browse files Browse the repository at this point in the history
Added a mode switch for block type processing.
Now can process enforcement based on either block type or block subtype.
  • Loading branch information
dodexahedron committed Apr 8, 2015
1 parent 5076369 commit d990e0d
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 44 deletions.
6 changes: 3 additions & 3 deletions EssentialsPlugin/AssemblyFileVersion.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//2363
//2381
//
// This code was generated by a tool. Any changes made manually will be lost
// the next time this code is regenerated.
//

using System.Reflection;

[assembly: AssemblyFileVersion("1.10.0.2363")]
[assembly: AssemblyVersion("1.10.0.2363")]
[assembly: AssemblyFileVersion("1.11.0.2381")]
[assembly: AssemblyVersion("1.11.0.2381")]
4 changes: 2 additions & 2 deletions EssentialsPlugin/AssemblyFileVersion.tt
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@

using System.Reflection;

[assembly: AssemblyFileVersion("1.10.0.<#= revisionNumber #>")]
[assembly: AssemblyVersion("1.10.0.<#= revisionNumber #>")]
[assembly: AssemblyFileVersion("1.11.0.<#= revisionNumber #>")]
[assembly: AssemblyVersion("1.11.0.<#= revisionNumber #>")]
66 changes: 44 additions & 22 deletions EssentialsPlugin/ProcessHandlers/ProcessBlockEnforcement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private void ScanForBlockItems( )
{
MyAPIGateway.Entities.GetEntities( entities );
}
catch(Exception ex)
catch ( Exception ex )
{
Log.Error( "Entity list busy, skipping scan.", ex );
}
Expand All @@ -64,21 +64,31 @@ private void ScanForBlockItems( )
IMyCubeGrid grid = (IMyCubeGrid)entity;
Sandbox.ModAPI.Ingame.IMyGridTerminalSystem gridTerminal = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid( grid );

Dictionary<string, int> blocks = new Dictionary<string, int>( );
Dictionary<SettingsBlockEnforcementItem, int> blocks = new Dictionary<SettingsBlockEnforcementItem, int>( );
foreach ( Sandbox.ModAPI.Ingame.IMyTerminalBlock myTerminalBlock in gridTerminal.Blocks )
{
Sandbox.ModAPI.Ingame.IMyTerminalBlock block = myTerminalBlock;
foreach ( SettingsBlockEnforcementItem item in PluginSettings.Instance.BlockEnforcementItems )
{
if ( !item.Enabled )
if ( item.Mode == SettingsBlockEnforcementItem.EnforcementMode.Off )
continue;

if ( block.BlockDefinition.TypeId.ToString( ).Contains( item.BlockType ) )
if ( item.Mode == SettingsBlockEnforcementItem.EnforcementMode.BlockSubtypeId
&& !string.IsNullOrEmpty( block.BlockDefinition.SubtypeId )
&& block.BlockDefinition.SubtypeId.Contains( item.BlockTypeId ) )
{
if ( blocks.ContainsKey( item ) )
blocks[ item ] += 1;
else
blocks.Add( item, 1 );
}

if ( item.Mode == SettingsBlockEnforcementItem.EnforcementMode.BlockId && block.BlockDefinition.TypeIdString.Contains( item.BlockTypeId ) )
{
if ( blocks.ContainsKey( item.BlockType ) )
blocks[ item.BlockType ] += 1;
if ( blocks.ContainsKey( item ) )
blocks[ item ] += 1;
else
blocks.Add( item.BlockType, 1 );
blocks.Add( item, 1 );
}
}
}
Expand All @@ -96,46 +106,46 @@ private void ScanForBlockItems( )
if (!item.Enabled)
continue;
if (block.GetId().ToString().Contains(item.BlockType))
if (block.GetId().ToString().Contains(item.BlockTypeId))
{
if (blocks.ContainsKey(item.BlockType))
blocks[item.BlockType] += 1;
if (blocks.ContainsKey(item.BlockTypeId))
blocks[item.BlockTypeId] += 1;
else
blocks.Add(item.BlockType, 1);
blocks.Add(item.BlockTypeId, 1);
}
}
}
*/

foreach ( SettingsBlockEnforcementItem item in PluginSettings.Instance.BlockEnforcementItems )
{
if ( !item.Enabled )
if ( item.Mode== SettingsBlockEnforcementItem.EnforcementMode.Off )
continue;

if ( !blocks.ContainsKey( item.BlockType ) )
if ( !blocks.ContainsKey( item ) )
continue;

if ( blocks[ item.BlockType ] > item.MaxPerGrid )
if ( blocks[ item ] > item.MaxPerGrid )
{
//foreach(long playerId in CubeGrids.GetBigOwners(gridBuilder))
foreach ( long playerId in grid.BigOwners )
{
ulong steamId = PlayerMap.Instance.GetSteamIdFromPlayerId( playerId );
if ( steamId > 0 )
{
//Communication.SendPrivateInformation(steamId, string.Format("You have exceeded the max block count of {0} on the ship '{1}'. We are removing {2} blocks to enforce this block limit.", item.BlockType, gridBuilder.DisplayName, blocks[item.BlockType] - item.MaxPerGrid));
Communication.SendPrivateInformation( steamId, string.Format( "You have exceeded the max block count of {0} on the ship '{1}'. We are removing {2} blocks to enforce this block limit.", item.BlockType, grid.DisplayName, blocks[ item.BlockType ] - item.MaxPerGrid ) );
//Communication.SendPrivateInformation(steamId, string.Format("You have exceeded the max block count of {0} on the ship '{1}'. We are removing {2} blocks to enforce this block limit.", item.BlockTypeId, gridBuilder.DisplayName, blocks[item.BlockTypeId] - item.MaxPerGrid));
Communication.SendPrivateInformation( steamId, string.Format( "You have exceeded the max block count of {0} on the ship '{1}'. We are removing {2} blocks to enforce this block limit.", item.BlockTypeId, grid.DisplayName, blocks[ item ] - item.MaxPerGrid ) );
}
}

//DeleteReverse(item.BlockType, blocks[item.BlockType] - item.MaxPerGrid, grid, gridBuilder);
DeleteReverse( item.BlockType, blocks[ item.BlockType ] - item.MaxPerGrid, grid );
//DeleteReverse(item.BlockTypeId, blocks[item.BlockTypeId] - item.MaxPerGrid, grid, gridBuilder);
DeleteReverse( item, blocks[ item ] - item.MaxPerGrid, grid );
}
}
}
}

private void DeleteReverse( string id, int remove, IMyCubeGrid grid )
private void DeleteReverse( SettingsBlockEnforcementItem blockEnforcementSetting, int remove, IMyCubeGrid grid )
{
int count = 0;
Sandbox.ModAPI.Ingame.IMyGridTerminalSystem gridTerminal = MyAPIGateway.TerminalActionsHelper.GetTerminalSystemForGrid( grid );
Expand All @@ -144,10 +154,22 @@ private void DeleteReverse( string id, int remove, IMyCubeGrid grid )
for ( int r = gridTerminal.Blocks.Count - 1; r >= 0; r-- )
{
IMyTerminalBlock block = (IMyTerminalBlock)gridTerminal.Blocks[ r ];
if ( block.BlockDefinition.TypeId.ToString( ).Contains( id ) )
switch ( blockEnforcementSetting.Mode )
{
blocksToRemove.Add( block );
count++;
case SettingsBlockEnforcementItem.EnforcementMode.BlockSubtypeId:
if ( !string.IsNullOrEmpty( block.BlockDefinition.SubtypeId ) && block.BlockDefinition.SubtypeId.Contains( blockEnforcementSetting.BlockSubtypeId ) )
{
blocksToRemove.Add( block );
count++;
}
break;
case SettingsBlockEnforcementItem.EnforcementMode.BlockId:
if ( block.BlockDefinition.TypeIdString.Contains( blockEnforcementSetting.BlockTypeId ) )
{
blocksToRemove.Add( block );
count++;
}
break;
}

if ( count == remove )
Expand Down
58 changes: 41 additions & 17 deletions EssentialsPlugin/Settings/SettingsBlockEnforcementItem.cs
Original file line number Diff line number Diff line change
@@ -1,40 +1,64 @@
namespace EssentialsPlugin.Settings
{
using System;

public class SettingsBlockEnforcementItem
{
private bool enabled;
public bool Enabled
public enum EnforcementMode
{
Off = 0,
BlockId = 1,
BlockSubtypeId = 2
}

private string _blockTypeId;
public string BlockTypeId
{
get { return enabled; }
set { enabled = value; }
get { return _blockTypeId; }
set { _blockTypeId = value; }
}

private string blockType;
public string BlockType
private string _blockSubtypeId;

public string BlockSubtypeId
{
get { return blockType; }
set { blockType = value; }
get { return _blockSubtypeId; }
set { _blockSubtypeId = value; }
}

private int maxPerGrid;
private int _maxPerGrid;
public int MaxPerGrid
{
get { return maxPerGrid; }
set { maxPerGrid = value; }
get { return _maxPerGrid; }
set { _maxPerGrid = value; }
}

private string maxReachWarning;
private string _maxReachWarning;
public string MaxReachWarning
{
get { return maxReachWarning; }
set { maxReachWarning = value; }
get { return _maxReachWarning; }
set { _maxReachWarning = value; }
}

private string maxExceedWarning;
private string _maxExceedWarning;
private EnforcementMode _mode;

public string MaxExceedWarning
{
get { return maxExceedWarning; }
set { maxExceedWarning = value; }
get { return _maxExceedWarning; }
set { _maxExceedWarning = value; }
}

public EnforcementMode Mode
{
get { return _mode; }
set { _mode = value; }
}

public override int GetHashCode( )
{
return ( string.IsNullOrEmpty( _blockSubtypeId ) ? string.Empty : _blockSubtypeId ).GetHashCode( )
+ ( string.IsNullOrEmpty( _blockTypeId ) ? string.Empty : _blockTypeId ).GetHashCode( );
}
}
}

0 comments on commit d990e0d

Please sign in to comment.