Beispiel #1
0
 public static void TabComplete(MinecraftClient client, MinecraftServer server, IPacket _packet)
 {
     var packet = (TabCompletePacket)_packet;
     var eventArgs = new TabCompleteEventArgs(packet.Text, client);
     server.OnTabComplete(eventArgs);
     if (eventArgs.Handled)
     {
         packet.Text = eventArgs.Text;
         client.SendPacket(packet);
     }
 }
Beispiel #2
0
 void MinecraftServer_TabComplete(object sender, TabCompleteEventArgs e)
 {
     if (TabComplete != null)
     {
         var eventArgs = new TabCompleteEventArgs(e.Text, e.Client);
         TabComplete(this, eventArgs);
         if (eventArgs.Handled)
             return;
     }
     // Handle it ourselves
     string[] matches = new string[0];
     if (e.Text.StartsWith("/"))
     {
         // Command
         if (e.Text.Contains(' '))
         {
             // Command parameter
             var name = e.Text.Substring(1, e.Text.IndexOf(' ') - 1);
             var text = e.Text.Substring(e.Text.IndexOf(' ') + 1);
             var command = Command.GetCommand(name);
             if (command.TabComplete(this, text, out matches))
                 e.Text = matches.First();
             else
                 TabCompleteUsername(e.Text, out matches);
         }
         else
         {
             var commands = new List<string>();
             foreach (var command in Command.Commands)
             {
                 commands.Add("/" + command.DefaultCommand);
                 commands.AddRange(command.Aliases.Select(s => "/" + s));
             }
             matches = commands.Where(c => c.StartsWith(e.Text, StringComparison.OrdinalIgnoreCase)).ToArray();
             if (matches.Length == 1)
                 e.Text = "/" + matches.First();
         }
     }
     else
         TabCompleteUsername(e.Text, out matches);
     if (matches.Length == 1)
     {
         e.Handled = true;
         e.Text = matches[0];
     }
     else
         e.Client.SendChat(string.Join(", ", matches));
 }
Beispiel #3
0
 protected internal void OnTabComplete(TabCompleteEventArgs e)
 {
     if (TabComplete != null) TabComplete(this, e);
 }