public bool ChangeGroup(object Player, object Group) { TShockAPI.TSPlayer p = null; TShockAPI.DB.User u = new TShockAPI.DB.User(); string g = ""; if ((p = GetPlayer(Player)) == null) { return(false); } if (Group is string) { g = Group as string; } else if (Group is TShockAPI.Group) { g = (Group as TShockAPI.Group).Name; } if (string.IsNullOrEmpty(g) == true) { return(false); } try { u.Name = p.User.Name; TShockAPI.TShock.Users.SetUserGroup(u, g); } catch (Exception ex) { ScriptLog.ErrorFormat("tshock_change_group", "Group change failed: {0}", ex.Message); return(false); } return(true); }
protected void oneSecondTimer_Elapsed(object sender, ElapsedEventArgs e) { for (int i = 0; i < recurList.Count; i++) { RecurringFunction func; lock (syncRoot) { func = recurList.ElementAtOrDefault(i); } if (func == null) { continue; } try { func.ExecuteAndRecur(); } catch (Exception ex) { ScriptLog.ErrorFormat("recurring", "Error on recurring rule: " + ex.Message); } } for (int i = 0; i < runAtList.Count; i++) { RunAt at; lock (syncRoot) { at = runAtList.ElementAtOrDefault(i); } if (at == null || engine == null || Terraria.Main.time <= at.AtTime || at.ExecutedInIteration == true) { continue; } try { engine.CallFunction(at.Func, at); } catch (Exception ex) { ScriptLog.ErrorFormat("recurring", "Error on recurring rule: " + ex.Message); } finally { at.ExecutedInIteration = true; } } }
/// <summary> /// Executes the function in this recurring rule if it's /// time to, and updates the next run time to the next /// recurance. /// </summary> public void ExecuteAndRecur() { if (DateTime.UtcNow < this.NextRunTime || Jist.JistPlugin.Instance == null) { return; } try { JistPlugin.Instance.CallFunction(Function, this); } catch (Exception ex) { ScriptLog.ErrorFormat("recurring", "Error occured on a recurring task function: " + ex.Message); } finally { Recur(); } }
public bool ExecuteCommandSilent(object Player, object Command) { TShockAPI.TSPlayer p = null; string commandToExecute = ""; if ((p = GetPlayer(Player)) == null) { return(false); } try { if (Command is List <string> ) { List <string> cmdList = Command as List <string>; foreach (var param in cmdList.Skip(1)) { commandToExecute += " " + param; } } else if (Command is string) { commandToExecute = Command.ToString(); } if (string.IsNullOrEmpty((commandToExecute = commandToExecute.Trim())) == true) { return(false); } p.PermissionlessInvoke(commandToExecute, true); return(true); } catch (Exception) { ScriptLog.ErrorFormat("tshock_exec_silent", "The command \"{0}\" failed.", commandToExecute.Trim()); return(false); } }