public void Register(string cmd, ICommandBlock timer, long fId = Constants.noFactionId) { Dictionary <string, HashSet <ICommandBlock> > faction; if (timers.TryGetValue(fId, out faction)) { HashSet <ICommandBlock> timers; if (faction.TryGetValue(cmd, out timers)) { timers.Add(timer); } else { faction[cmd] = new HashSet <ICommandBlock>() { timer }; } } else { timers[fId] = new Dictionary <string, HashSet <ICommandBlock> >() { { cmd, new HashSet <ICommandBlock>() { timer } } }; } }
public CommandExecutor(ICommandBlock block) { string cmd = block.ContentString; string[] p = parameterize(cmd).Where(s => s != null).ToArray(); ExecutableName = p [0]; Params = p.Skip(1).ToArray(); }
async Task ExecuteCommandBlock(ICommandBlock block) { try { if (!string.IsNullOrWhiteSpace(block.ContentString)) { Log.Debug("Execute: \"", block.ContentString, "\""); CommandExecutor commandExecutor = new CommandExecutor(block); await commandExecutor.ExecuteAsync(env : Environment); } } catch (Exception ex) { Log.Error(ex); Environment.IsFatalError = true; } }
public void Unregister(string cmd, ICommandBlock timer, long fId = Constants.noFactionId) { Dictionary <string, HashSet <ICommandBlock> > faction; if (timers.TryGetValue(fId, out faction)) { HashSet <ICommandBlock> timers; if (faction.TryGetValue(cmd, out timers)) { timers.Remove(timer); if (timers.Count == 0) { faction.Remove(cmd); } if (faction.Count == 0) { this.timers.Remove(fId); } } } }
public override void Init(MyObjectBuilder_EntityBase objectBuilder) { block = (IMyTerminalBlock)Entity; cmdBlock = GetCommandBlock(block); NeedsUpdate = MyEntityUpdateEnum.BEFORE_NEXT_FRAME; }