mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
/list command improvements
Coding style, Guid, interface, Fallback Command
This commit is contained in:
parent
5d1aee46c2
commit
f82041288d
4 changed files with 72 additions and 49 deletions
|
|
@ -20,6 +20,7 @@ namespace MinecraftClient
|
|||
private static List<string> cmd_names = new List<string>();
|
||||
private static Dictionary<string, Command> cmds = new Dictionary<string, Command>();
|
||||
private List<ChatBot> bots = new List<ChatBot>();
|
||||
private Dictionary<Guid, string> onlinePlayers = new Dictionary<Guid,string>();
|
||||
private static List<ChatBots.Script> scripts_on_hold = new List<ChatBots.Script>();
|
||||
public void BotLoad(ChatBot b) { b.SetHandler(this); bots.Add(b); b.Initialize(); Settings.SingleCommand = ""; }
|
||||
public void BotUnLoad(ChatBot b) { bots.RemoveAll(item => object.ReferenceEquals(item, b)); }
|
||||
|
|
@ -33,8 +34,6 @@ namespace MinecraftClient
|
|||
private string uuid;
|
||||
private string sessionid;
|
||||
|
||||
public Dictionary<string, string> players;
|
||||
|
||||
public int getServerPort() { return port; }
|
||||
public string getServerHost() { return host; }
|
||||
public string getUsername() { return username; }
|
||||
|
|
@ -58,7 +57,6 @@ namespace MinecraftClient
|
|||
public McTcpClient(string username, string uuid, string sessionID, int protocolversion, string server_ip, ushort port)
|
||||
{
|
||||
StartClient(username, uuid, sessionID, server_ip, port, protocolversion, false, "");
|
||||
players = new Dictionary<string, string>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -391,19 +389,6 @@ namespace MinecraftClient
|
|||
else return handler.SendChatMessage(text);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Display a list of players
|
||||
/// </summary>
|
||||
/// <returns>True if the players can be listed</returns>
|
||||
|
||||
public bool ListPlayers()
|
||||
{
|
||||
ConsoleIO.WriteLine ("Player List");
|
||||
foreach (string player in players.Values)
|
||||
ConsoleIO.WriteLine (player);
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Allow to respawn after death
|
||||
/// </summary>
|
||||
|
|
@ -411,16 +396,38 @@ namespace MinecraftClient
|
|||
|
||||
public bool SendRespawnPacket()
|
||||
{
|
||||
return handler.SendRespawnPacket ();
|
||||
return handler.SendRespawnPacket();
|
||||
}
|
||||
|
||||
public void addPlayer(string uuid, string name) {
|
||||
players[uuid] = name;
|
||||
/// <summary>
|
||||
/// Triggered when a new player joins the game
|
||||
/// </summary>
|
||||
/// <param name="uuid">UUID of the player</param>
|
||||
/// <param name="name">Name of the player</param>
|
||||
|
||||
public void OnPlayerJoin(Guid uuid, string name)
|
||||
{
|
||||
onlinePlayers[uuid] = name;
|
||||
}
|
||||
public void removePlayer(string uuid){
|
||||
players.Remove (uuid);
|
||||
|
||||
/// <summary>
|
||||
/// Triggered when a player has left the game
|
||||
/// </summary>
|
||||
/// <param name="uuid">UUID of the player</param>
|
||||
|
||||
public void OnPlayerLeave(Guid uuid)
|
||||
{
|
||||
onlinePlayers.Remove(uuid);
|
||||
}
|
||||
|
||||
public HashSet<string> getPlayers() { return new HashSet<string>(players.Values); }
|
||||
/// <summary>
|
||||
/// Get a set of online player names
|
||||
/// </summary>
|
||||
/// <returns>Online player names</returns>
|
||||
|
||||
public string[] getOnlinePlayers()
|
||||
{
|
||||
return onlinePlayers.Values.Distinct().ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue