Added Command Callback support
This commit is contained in:
parent
f22ee0c09d
commit
51e1991643
2 changed files with 27 additions and 0 deletions
|
|
@ -195,6 +195,7 @@ namespace TShockAPI
|
||||||
add(Permissions.cfg, WorldInfo, "world");
|
add(Permissions.cfg, WorldInfo, "world");
|
||||||
add(Permissions.savessi, SaveSSI, "savessi");
|
add(Permissions.savessi, SaveSSI, "savessi");
|
||||||
add(Permissions.savessi, OverrideSSI, "overridessi", "ossi");
|
add(Permissions.savessi, OverrideSSI, "overridessi", "ossi");
|
||||||
|
add(null, TestCallbackCommand, "test");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool HandleCommand(TSPlayer player, string text)
|
public static bool HandleCommand(TSPlayer player, string text)
|
||||||
|
|
@ -212,6 +213,13 @@ namespace TShockAPI
|
||||||
|
|
||||||
if (cmd == null)
|
if (cmd == null)
|
||||||
{
|
{
|
||||||
|
if( player.AwaitingResponse.ContainsKey(cmdName))
|
||||||
|
{
|
||||||
|
Action<CommandArgs> call = player.AwaitingResponse[cmdName];
|
||||||
|
player.AwaitingResponse.Remove(cmdName);
|
||||||
|
call( new CommandArgs(cmdText, player, args));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
player.SendErrorMessage("Invalid command entered. Type /help for a list of valid commands.");
|
player.SendErrorMessage("Invalid command entered. Type /help for a list of valid commands.");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
@ -312,6 +320,13 @@ namespace TShockAPI
|
||||||
return c == ' ' || c == '\t' || c == '\n';
|
return c == ' ' || c == '\t' || c == '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void TestCallbackCommand(CommandArgs args)
|
||||||
|
{
|
||||||
|
Action<CommandArgs> a = (s) => args.Player.Spawn();
|
||||||
|
args.Player.AddResponse( "yes", a);
|
||||||
|
args.Player.SendInfoMessage( "Type yes to spawn." );
|
||||||
|
}
|
||||||
|
|
||||||
#region Account commands
|
#region Account commands
|
||||||
|
|
||||||
public static void AttemptLogin(CommandArgs args)
|
public static void AttemptLogin(CommandArgs args)
|
||||||
|
|
|
||||||
|
|
@ -43,6 +43,7 @@ namespace TShockAPI
|
||||||
public DateTime LastPvpChange;
|
public DateTime LastPvpChange;
|
||||||
public Point[] TempPoints = new Point[2];
|
public Point[] TempPoints = new Point[2];
|
||||||
public int AwaitingTempPoint { get; set; }
|
public int AwaitingTempPoint { get; set; }
|
||||||
|
public Dictionary<string, Action<CommandArgs>> AwaitingResponse;
|
||||||
public bool AwaitingName { get; set; }
|
public bool AwaitingName { get; set; }
|
||||||
public DateTime LastThreat { get; set; }
|
public DateTime LastThreat { get; set; }
|
||||||
public DateTime LastTileChangeNotify { get; set; }
|
public DateTime LastTileChangeNotify { get; set; }
|
||||||
|
|
@ -212,6 +213,7 @@ namespace TShockAPI
|
||||||
Index = index;
|
Index = index;
|
||||||
Group = new Group(TShock.Config.DefaultGuestGroupName);
|
Group = new Group(TShock.Config.DefaultGuestGroupName);
|
||||||
IceTiles = new List<Point>();
|
IceTiles = new List<Point>();
|
||||||
|
AwaitingResponse = new Dictionary<string, Action<CommandArgs>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected TSPlayer(String playerName)
|
protected TSPlayer(String playerName)
|
||||||
|
|
@ -522,6 +524,16 @@ namespace TShockAPI
|
||||||
|
|
||||||
return TShock.SendBytes(Netplay.serverSock[Index], data);
|
return TShock.SendBytes(Netplay.serverSock[Index], data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void AddResponse( string name, Action<CommandArgs> callback)
|
||||||
|
{
|
||||||
|
if( AwaitingResponse.ContainsKey(name))
|
||||||
|
{
|
||||||
|
AwaitingResponse.Remove(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
AwaitingResponse.Add(name, callback);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class TSRestPlayer : TSServerPlayer
|
public class TSRestPlayer : TSServerPlayer
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue