Skip to content
This repository was archived by the owner on Jun 23, 2023. It is now read-only.

Commit cb5f5f4

Browse files
committed
Rework help chat commands
1 parent dacbe22 commit cb5f5f4

File tree

5 files changed

+281
-252
lines changed

5 files changed

+281
-252
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
//366
1+
//386
22
//
33
// This code was generated by a tool. Any changes made manually will be lost
44
// the next time this code is regenerated.
55
//
66

77
using System.Reflection;
88

9-
[assembly: AssemblyFileVersion("1.13.7.366")]
10-
[assembly: AssemblyVersion("1.13.7.366")]
9+
[assembly: AssemblyFileVersion("1.13.7.386")]
10+
[assembly: AssemblyVersion("1.13.7.386")]

EssentialsPlugin/ChatHandlers/Admin/HandleAdminTest.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,36 @@ public override bool HandleCommand( ulong userId, string[ ] words )
189189
}
190190
break;
191191
}
192+
case "seated":
193+
{
194+
bool set = words.Length > 1 && words[1].ToLower( ).Equals( "on" );
195+
MyEntity[] ents = new MyEntity[0];
196+
Wrapper.GameAction( ( ) => ents = MyEntities.GetEntities( ).ToArray( ) );
197+
198+
foreach (var ent in ents)
199+
{
200+
var grid = ent as MyCubeGrid;
201+
if (grid == null)
202+
continue;
203+
204+
var blocks = grid.GetBlocks( );
205+
206+
foreach (var block in blocks)
207+
{
208+
var cockpit = block?.FatBlock as MyCockpit;
209+
if (cockpit?.Pilot == null)
210+
continue;
211+
212+
Essentials.Log.Info( cockpit.Pilot.DisplayName );
213+
214+
if (set)
215+
MyEntities.RegisterForUpdate( cockpit.Pilot );
216+
else
217+
MyEntities.UnregisterForUpdate( cockpit.Pilot );
218+
}
219+
}
220+
break;
221+
}
192222
case "component":
193223
{
194224
MyEntity[] ents = new MyEntity[0];

EssentialsPlugin/ChatHandlers/ChatHandlerBase.cs

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,28 +35,28 @@ public virtual Boolean CanHandle(ulong steamId, String[] words, ref int commandC
3535
}
3636

3737
// Check if this command has multiple commands that do the same thing
38-
if (GetMultipleCommandText().Length < 1)
39-
{
38+
//if (GetMultipleCommandText().Length < 1)
39+
//{
4040
commandCount = GetCommandText().Split(new char[] { ' ' }).Count();
4141
if (words.Length > commandCount - 1)
4242
return String.Join(" ", words).ToLower().StartsWith(GetCommandText());
43-
}
44-
else
45-
{
46-
bool found = false;
47-
foreach (string command in GetMultipleCommandText())
48-
{
49-
commandCount = command.Split(new char[] { ' ' }).Count();
50-
if (words.Length > commandCount - 1)
51-
{
52-
found = String.Join(" ", words).ToLower().StartsWith(command);
53-
if (found)
54-
break;
55-
}
56-
}
43+
//}
44+
//else
45+
//{
46+
// bool found = false;
47+
// foreach (string command in GetMultipleCommandText())
48+
// {
49+
// commandCount = command.Split(new char[] { ' ' }).Count();
50+
// if (words.Length > commandCount - 1)
51+
// {
52+
// found = String.Join(" ", words).ToLower().StartsWith(command);
53+
// if (found)
54+
// break;
55+
// }
56+
// }
5757

58-
return found;
59-
}
58+
// return found;
59+
//}
6060

6161
return false;
6262
}
@@ -73,10 +73,7 @@ public virtual Communication.ServerDialogItem GetHelpDialog( )
7373
return DialogItem;
7474
}
7575

76-
public virtual String GetCommandText()
77-
{
78-
return "";
79-
}
76+
public abstract string GetCommandText( );
8077

8178
public virtual string[] GetMultipleCommandText()
8279
{
@@ -98,9 +95,6 @@ public virtual bool IsClientOnly()
9895
return false;
9996
}
10097

101-
public virtual bool HandleCommand(ulong userId, String[] words)
102-
{
103-
return false;
104-
}
98+
public abstract bool HandleCommand( ulong userId, string[] words );
10599
}
106100
}
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
namespace EssentialsPlugin.ChatHandlers
2+
{
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using SEModAPIInternal.API.Common;
7+
using Utility;
8+
9+
public class HandleHelp : ChatHandlerBase
10+
{
11+
public override string GetHelp( )
12+
{
13+
return "If you're here, I can't help you.";
14+
}
15+
16+
public override string GetCommandText( )
17+
{
18+
return "/help";
19+
}
20+
21+
public override bool AllowedInConsole( )
22+
{
23+
return true;
24+
}
25+
26+
public override bool HandleCommand( ulong userId, string[] words )
27+
{
28+
if (userId == 0)
29+
HandleCommand( userId, words );
30+
else if (( words.Length > 0 ) && ( words[0] == "chat" ))
31+
HandleHelpCommand( userId, words.Skip( 1 ).ToArray( ) );
32+
else
33+
HandleHelpDialog( userId, words );
34+
35+
return true;
36+
}
37+
38+
/// <summary>
39+
/// This function displays available help for all the functionality of this plugin
40+
/// </summary>
41+
/// <param name="remoteUserId"></param>
42+
/// <param name="commandParts"></param>
43+
private void HandleHelpCommand( ulong remoteUserId, IReadOnlyCollection<string> commandParts )
44+
{
45+
if (commandParts.Count == 0)
46+
{
47+
List<string> commands = new List<string>( );
48+
foreach (ChatHandlerBase handler in Essentials.ChatHandlers)
49+
if (handler.GetMultipleCommandText( ).Length < 1)
50+
{
51+
string commandBase = handler.GetCommandText( ).Split( new[] {" "}, StringSplitOptions.RemoveEmptyEntries ).First( );
52+
if (!commands.Contains( commandBase ) && !handler.IsClientOnly( ) && ( !handler.IsAdminCommand( ) || ( handler.IsAdminCommand( ) && ( PlayerManager.Instance.IsUserAdmin( remoteUserId ) || ( remoteUserId == 0 ) ) ) ))
53+
commands.Add( commandBase );
54+
}
55+
else
56+
{
57+
foreach (string cmd in handler.GetMultipleCommandText( ))
58+
{
59+
string commandBase = cmd.Split( new[] {" "}, StringSplitOptions.RemoveEmptyEntries ).First( );
60+
if (!commands.Contains( commandBase ) && !handler.IsClientOnly( ) && ( !handler.IsAdminCommand( ) || ( handler.IsAdminCommand( ) && ( PlayerManager.Instance.IsUserAdmin( remoteUserId ) || ( remoteUserId == 0 ) ) ) ))
61+
commands.Add( commandBase );
62+
}
63+
}
64+
65+
string commandList = string.Join( ", ", commands );
66+
string info = $"Dedicated Server Essentials v{Essentials.Instance.Version}. Available Commands: {commandList}";
67+
Communication.SendPrivateInformation( remoteUserId, info );
68+
}
69+
else
70+
{
71+
string helpTarget = string.Join( " ", commandParts );
72+
bool found = false;
73+
foreach (ChatHandlerBase handler in Essentials.ChatHandlers)
74+
if (handler.GetMultipleCommandText( ).Length < 1)
75+
{
76+
if (string.Equals( handler.GetCommandText( ), helpTarget, StringComparison.CurrentCultureIgnoreCase ))
77+
{
78+
Communication.SendPrivateInformation( remoteUserId, handler.GetHelp( ) );
79+
found = true;
80+
}
81+
}
82+
else
83+
{
84+
foreach (string cmd in handler.GetMultipleCommandText( ))
85+
if (string.Equals( cmd, helpTarget, StringComparison.CurrentCultureIgnoreCase ))
86+
{
87+
Communication.SendPrivateInformation( remoteUserId, handler.GetHelp( ) );
88+
found = true;
89+
}
90+
}
91+
92+
if (!found)
93+
{
94+
List<string> helpTopics = new List<string>( );
95+
96+
foreach (ChatHandlerBase handler in Essentials.ChatHandlers)
97+
{
98+
// Again, cleanup to one function
99+
string[] multipleCommandText = handler.GetMultipleCommandText( );
100+
if (multipleCommandText.Length == 0)
101+
{
102+
if (handler.GetCommandText( ).ToLower( ).StartsWith( helpTarget.ToLower( ) ) && ( !handler.IsAdminCommand( ) || ( handler.IsAdminCommand( ) && ( PlayerManager.Instance.IsUserAdmin( remoteUserId ) || ( remoteUserId == 0 ) ) ) ))
103+
helpTopics.Add( handler.GetCommandText( ).ToLower( ).Replace( helpTarget.ToLower( ), string.Empty ) );
104+
}
105+
else
106+
{
107+
foreach (string cmd in multipleCommandText)
108+
if (cmd.ToLower( ).StartsWith( helpTarget.ToLower( ) ) && ( !handler.IsAdminCommand( ) || ( handler.IsAdminCommand( ) && ( PlayerManager.Instance.IsUserAdmin( remoteUserId ) || ( remoteUserId == 0 ) ) ) ))
109+
helpTopics.Add( cmd.ToLower( ).Replace( helpTarget.ToLower( ), string.Empty ) );
110+
}
111+
}
112+
113+
if (helpTopics.Any( ))
114+
{
115+
Communication.SendPrivateInformation( remoteUserId, $"Help topics for command '{helpTarget.ToLower( )}': {string.Join( ",", helpTopics.ToArray( ) )}" );
116+
found = true;
117+
}
118+
}
119+
120+
if (!found)
121+
Communication.SendPrivateInformation( remoteUserId, "Unknown command" );
122+
}
123+
}
124+
125+
/// <summary>
126+
/// This function displays available help for all the functionality of this plugin in a dialog window
127+
/// </summary>
128+
/// <param name="remoteUserId"></param>
129+
/// <param name="commandParts"></param>
130+
private void HandleHelpDialog( ulong remoteUserId, IReadOnlyCollection<string> commandParts )
131+
{
132+
if (commandParts.Count == 0)
133+
{
134+
List<string> commands = new List<string>( );
135+
foreach (ChatHandlerBase handler in Essentials.ChatHandlers)
136+
if (handler.GetMultipleCommandText( ).Length < 1)
137+
{
138+
string commandBase = handler.GetCommandText( ).Split( new[] {" "}, StringSplitOptions.RemoveEmptyEntries ).First( );
139+
if (!commands.Contains( commandBase ) && !handler.IsClientOnly( ) && ( !handler.IsAdminCommand( ) || ( handler.IsAdminCommand( ) && ( PlayerManager.Instance.IsUserAdmin( remoteUserId ) || ( remoteUserId == 0 ) ) ) ))
140+
commands.Add( commandBase );
141+
}
142+
else
143+
{
144+
foreach (string cmd in handler.GetMultipleCommandText( ))
145+
{
146+
string commandBase = cmd.Split( new[] {" "}, StringSplitOptions.RemoveEmptyEntries ).First( );
147+
if (!commands.Contains( commandBase ) && !handler.IsClientOnly( ) && ( !handler.IsAdminCommand( ) || ( handler.IsAdminCommand( ) && ( PlayerManager.Instance.IsUserAdmin( remoteUserId ) || ( remoteUserId == 0 ) ) ) ))
148+
commands.Add( commandBase );
149+
}
150+
}
151+
152+
string commandList = string.Join( ", ", commands );
153+
//take our list of commands, put line breaks between all the entries and stuff it into a dialog winow
154+
155+
Communication.DisplayDialog( remoteUserId, "Help", "Available commands", commandList + "{0}||Type '/help dialog <command>' for more info.", "close" );
156+
}
157+
else
158+
{
159+
string helpTarget = string.Join( " ", commandParts);
160+
bool found = false;
161+
foreach (ChatHandlerBase handler in Essentials.ChatHandlers)
162+
if (handler.GetMultipleCommandText( ).Length < 1)
163+
{
164+
if (string.Equals( handler.GetCommandText( ), helpTarget, StringComparison.CurrentCultureIgnoreCase ))
165+
{
166+
Communication.DisplayDialog( remoteUserId, handler.GetHelpDialog( ) );
167+
found = true;
168+
}
169+
}
170+
else
171+
{
172+
foreach (string cmd in handler.GetMultipleCommandText( ))
173+
if (string.Equals( cmd, helpTarget, StringComparison.CurrentCultureIgnoreCase ))
174+
{
175+
Communication.DisplayDialog( remoteUserId, handler.GetHelpDialog( ) );
176+
found = true;
177+
}
178+
}
179+
180+
if (!found)
181+
{
182+
List<string> helpTopics = new List<string>( );
183+
184+
foreach (ChatHandlerBase handler in Essentials.ChatHandlers)
185+
{
186+
// Again, cleanup to one function
187+
string[] multipleCommandText = handler.GetMultipleCommandText( );
188+
if (multipleCommandText.Length == 0)
189+
{
190+
if (handler.GetCommandText( ).ToLower( ).StartsWith( helpTarget.ToLower( ) ) && ( !handler.IsAdminCommand( ) || ( handler.IsAdminCommand( ) && ( PlayerManager.Instance.IsUserAdmin( remoteUserId ) || ( remoteUserId == 0 ) ) ) ))
191+
helpTopics.Add( handler.GetCommandText( ).ToLower( ).Replace( helpTarget.ToLower( ), string.Empty ) );
192+
}
193+
else
194+
{
195+
foreach (string cmd in multipleCommandText)
196+
if (cmd.ToLower( ).StartsWith( helpTarget.ToLower( ) ) && ( !handler.IsAdminCommand( ) || ( handler.IsAdminCommand( ) && ( PlayerManager.Instance.IsUserAdmin( remoteUserId ) || ( remoteUserId == 0 ) ) ) ))
197+
helpTopics.Add( cmd.ToLower( ).Replace( helpTarget.ToLower( ), string.Empty ) );
198+
}
199+
}
200+
201+
if (helpTopics.Any( ))
202+
{
203+
Communication.DisplayDialog( remoteUserId, "Help", helpTarget.ToLower( ), string.Format( "Help topics for command '{0}': {1}", helpTarget.ToLower( ), string.Join( ",", helpTopics.ToArray( ) ) ) );
204+
found = true;
205+
}
206+
}
207+
208+
if (!found)
209+
Communication.SendPrivateInformation( remoteUserId, "Unknown command" );
210+
}
211+
}
212+
}
213+
}

0 commit comments

Comments
 (0)