Skip to content

Commit 2b289f7

Browse files
committed
Fixed issue with give, added staff chat
* Fixed issue with give that would give the item you requested by one off * Fixed issue with giving items through the functionUI * Added staff chat! Players can now type /staffchat (can be changed, of course) to enable staff chat. All admins that didn't disable receiving staff messages by typing /disablestaffchat (/dsc) will get that message. * It now shows how many IDs are loaded in! whooo
1 parent 75a016c commit 2b289f7

File tree

9 files changed

+160
-10
lines changed

9 files changed

+160
-10
lines changed

source/BP-Essentials/BP-Essentials.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@
6161
<Compile Include="Chat\Commands\Admin\Restrain.cs" />
6262
<Compile Include="Chat\Commands\Admin\Say.cs" />
6363
<Compile Include="Chat\Commands\Admin\Search.cs" />
64+
<Compile Include="Chat\Commands\Admin\ToggleReceiveStaffChat.cs" />
65+
<Compile Include="Chat\Commands\Admin\ToggleStaffChat.cs" />
6466
<Compile Include="Chat\Commands\Admin\_SetJob.cs" />
6567
<Compile Include="Chat\Commands\Admin\Slap.cs" />
6668
<Compile Include="Chat\Commands\Admin\Strip.cs" />
@@ -118,6 +120,7 @@
118120
<Compile Include="Methods\misc\SavePeriodically.cs" />
119121
<Compile Include="Methods\GameMethods\SendToJail.cs" />
120122
<Compile Include="Methods\misc\SendChatMessage.cs" />
123+
<Compile Include="Methods\misc\SendChatMessageToAdmins.cs" />
121124
<Compile Include="Methods\misc\SetTimeStamp.cs" />
122125
<Compile Include="Methods\FileHandler\WriteIpToFile.cs" />
123126
</ItemGroup>

source/BP-Essentials/Chat/Commands/Admin/Give.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,24 +25,24 @@ public static bool Run(object oPlayer, string message)
2525
return true;
2626
}
2727
int arg1int, arg2int;
28-
bool Parsed = Int32.TryParse(arg1, out arg1int);
28+
bool Parsed = int.TryParse(arg1, out arg1int);
2929
Parsed = int.TryParse(arg2, out arg2int);
3030
if (Parsed)
3131
{
32-
if (arg1int > 1 && arg1int <= IDs.Length -1)
32+
if (arg1int > 0 && arg1int <= IDs.Length)
3333
{
34-
foreach (var shPlayer in UnityEngine.Object.FindObjectsOfType<ShPlayer>())
34+
foreach (var shPlayer in FindObjectsOfType<ShPlayer>())
3535
if (shPlayer.svPlayer == player && shPlayer.IsRealPlayer())
3636
{
3737
if (arg1.Length > 4)
3838
shPlayer.TransferItem(1, arg1int, arg2int, true);
3939
else
40-
shPlayer.TransferItem(1, IDs[arg1int], arg2int, true);
40+
shPlayer.TransferItem(1, IDs[arg1int - 1], arg2int, true);
4141
player.SendToSelf(Channel.Unsequenced, ClPacket.GameMessage, $"<color={infoColor}>Giving you item ID: </color><color={argColor}>{arg1}</color>");
4242
}
4343
}
4444
else
45-
player.SendToSelf(Channel.Unsequenced, ClPacket.GameMessage, $"<color={errorColor}>Error: The ID must be between 1 and {IDs.Length -1}.</color>");
45+
player.SendToSelf(Channel.Unsequenced, ClPacket.GameMessage, $"<color={errorColor}>Error: The ID must be between 1 and {IDs.Length}.</color>");
4646
}
4747
else
4848
player.SendToSelf(Channel.Unsequenced, ClPacket.GameMessage, $"<color={errorColor}>Error: Is that a valid number you provided as argument?</color>");
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using UnityEngine;
6+
using static BP_Essentials.EssentialsVariablesPlugin;
7+
using static BP_Essentials.EssentialsMethodsPlugin;
8+
9+
namespace BP_Essentials.Commands
10+
{
11+
class ToggleReceiveStaffChat : EssentialsChatPlugin
12+
{
13+
public static bool Run(object oPlayer, string message)
14+
{
15+
var player = (SvPlayer)oPlayer;
16+
if (HasPermission.Run(player, CmdStaffChatMessagesExecutableBy))
17+
{
18+
var shplayer = GetShBySv.Run(player);
19+
if (playerList[shplayer.ID].receiveStaffChat)
20+
{
21+
playerList[shplayer.ID].receiveStaffChat = false;
22+
player.SendToSelf(Channel.Unsequenced, ClPacket.GameMessage, $"<color={infoColor}>Staff chat messages disabled. You'll not receive any staff chat messages anymore.</color>");
23+
}
24+
else
25+
{
26+
playerList[shplayer.ID].receiveStaffChat = true;
27+
player.SendToSelf(Channel.Unsequenced, ClPacket.GameMessage, $"<color={infoColor}>Staff chat message enabled. You'll now receive staff messages.</color>");
28+
}
29+
}
30+
else
31+
player.SendToSelf(Channel.Unsequenced, ClPacket.GameMessage, MsgNoPerm);
32+
return true;
33+
}
34+
}
35+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using UnityEngine;
6+
using static BP_Essentials.EssentialsVariablesPlugin;
7+
using static BP_Essentials.EssentialsMethodsPlugin;
8+
using System.Text.RegularExpressions;
9+
10+
namespace BP_Essentials.Commands
11+
{
12+
class ToggleStaffChat : EssentialsChatPlugin
13+
{
14+
public static bool Run(object oPlayer, string message)
15+
{
16+
try
17+
{
18+
var player = (SvPlayer)oPlayer;
19+
if (HasPermission.Run(player, CmdStaffChatExecutableBy))
20+
{
21+
var arg1 = GetArgument.Run(1, false, true, message);
22+
var shplayer = GetShBySv.Run(player);
23+
if (string.IsNullOrEmpty(arg1))
24+
{
25+
if (playerList[shplayer.ID].staffChatEnabled)
26+
{
27+
playerList[shplayer.ID].staffChatEnabled = false;
28+
player.SendToSelf(Channel.Unsequenced, ClPacket.GameMessage, $"<color={infoColor}>Staff chat disabled.</color>");
29+
}
30+
else
31+
{
32+
playerList[shplayer.ID].staffChatEnabled = true;
33+
player.SendToSelf(Channel.Unsequenced, ClPacket.GameMessage, $"<color={infoColor}>Staff chat enabled.</color>");
34+
}
35+
}
36+
else
37+
{
38+
if (playerList[shplayer.ID].staffChatEnabled)
39+
{
40+
_msg = AdminChatMessage;
41+
_msg = _msg.Replace("{username}", new Regex("(<)").Replace(player.playerData.username, "<<b></b>"));
42+
_msg = _msg.Replace("{message}", new Regex("(<)").Replace(Chat.LangAndChatBlock.Run(player, arg1), "<<b></b>"));
43+
SendChatMessageToAdmins.Run(_msg);
44+
}
45+
else
46+
player.SendToSelf(Channel.Unsequenced, ClPacket.GameMessage, $"<color={warningColor}>You must enable staff chat first before you can send a message.</color>");
47+
}
48+
}
49+
else
50+
player.SendToSelf(Channel.Unsequenced, ClPacket.GameMessage, MsgNoPerm);
51+
}
52+
catch (Exception ex)
53+
{
54+
ErrorLogging.Run(ex);
55+
}
56+
return true;
57+
}
58+
}
59+
}

source/BP-Essentials/EssentialsChat.cs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,18 @@ public static bool SvGlobalChatMessage(SvPlayer player, ref string message)
203203
return Commands.ToggleChat.Run(player);
204204
else
205205
{ player.SendToSelf(Channel.Unsequenced, ClPacket.GameMessage, DisabledCommand); return true; }
206+
else if (message.StartsWith(CmdStaffChat) || message.StartsWith(CmdStaffChat2))
207+
if (!CmdStaffChatDisabled)
208+
return Commands.ToggleStaffChat.Run(player, message);
209+
else
210+
{ player.SendToSelf(Channel.Unsequenced, ClPacket.GameMessage, DisabledCommand); return true; }
211+
else if (message.StartsWith(CmdStaffChatMessages) || message.StartsWith(CmdStaffChatMessages2))
212+
if (!CmdStaffChatMessagesDisabled)
213+
return Commands.ToggleReceiveStaffChat.Run(player, message);
214+
else
215+
{ player.SendToSelf(Channel.Unsequenced, ClPacket.GameMessage, DisabledCommand); return true; }
216+
217+
206218
if (MsgUnknownCommand)
207219
{
208220
player.SendToSelf(Channel.Unsequenced, ClPacket.GameMessage, $"<color={errorColor}>Unknown command. Type</color><color={argColor}> {CmdCommandCharacter}essentials cmds </color><color={errorColor}>for more info.</color>");
@@ -221,11 +233,20 @@ public static bool SvGlobalChatMessage(SvPlayer player, ref string message)
221233
player.SendToSelf(Channel.Unsequenced, ClPacket.GameMessage, PlayerIsAFK);
222234
return true;
223235
}
224-
if (!playerList[GetShBySv.Run(player).ID].chatEnabled)
236+
var shplayer = GetShBySv.Run(player);
237+
if (!playerList[shplayer.ID].chatEnabled)
225238
{
226239
player.SendToSelf(Channel.Unsequenced, ClPacket.GameMessage, $"<color={warningColor}>Please enable your chat again by typing</color> <color={argColor}>{CmdToggleChat}</color><color={warningColor}>.</color>");
227240
return true;
228241
}
242+
if (playerList[shplayer.ID].staffChatEnabled)
243+
{
244+
_msg = AdminChatMessage;
245+
_msg = _msg.Replace("{username}", new Regex("(<)").Replace(shplayer.username, "<<b></b>"));
246+
_msg = _msg.Replace("{message}", new Regex("(<)").Replace(Chat.LangAndChatBlock.Run(player, message), "<<b></b>"));
247+
SendChatMessageToAdmins.Run(_msg);
248+
return true;
249+
}
229250
// Will improve this someday..
230251
foreach (KeyValuePair<string, _Group> curr in Groups)
231252
{

source/BP-Essentials/EssentialsVariables.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace BP_Essentials
77
{
88
public class EssentialsVariablesPlugin : EssentialsCorePlugin
99
{
10-
public const string Version = "2.3.0";
10+
public const string Version = "2.4.0";
1111

1212
// Generic Constants
1313
public const string FileDirectory = "Essentials/";
@@ -76,6 +76,7 @@ public class EssentialsVariablesPlugin : EssentialsCorePlugin
7676
public static string AdminSearchingInv;
7777
public static string PlayerMessage;
7878
public static string AdminMessage;
79+
public static string AdminChatMessage;
7980

8081
public static string infoColor, errorColor, warningColor, argColor;
8182
// Strings
@@ -132,6 +133,8 @@ public class EssentialsVariablesPlugin : EssentialsCorePlugin
132133
public static string CmdReload, CmdReload2;
133134
public static string CmdClearChat, CmdClearChat2;
134135
public static string CmdReport, CmdReport2;
136+
public static string CmdStaffChat, CmdStaffChat2, CmdStaffChatExecutableBy;
137+
public static string CmdStaffChatMessages, CmdStaffChatMessages2, CmdStaffChatMessagesExecutableBy;
135138
public static string CmdHelp;
136139
public static string CmdCommandCharacter;
137140
public static bool CmdClearChatDisabled;
@@ -161,6 +164,8 @@ public class EssentialsVariablesPlugin : EssentialsCorePlugin
161164
public static bool CmdJailDisabled;
162165
public static bool CmdKnockoutDisabled;
163166
public static bool CmdToggleChatDisabled;
167+
public static bool CmdStaffChatDisabled;
168+
public static bool CmdStaffChatMessagesDisabled;
164169
#endregion
165170

166171
// Ints
@@ -192,9 +197,10 @@ public class EssentialsVariablesPlugin : EssentialsCorePlugin
192197
};
193198
public static int[] CommonIDs =
194199
{
195-
1530892865, // Pistol Ammo
200+
// need a better way of doing this
201+
493970259, // Pistol Ammo
196202
-479434394, // Handcuffs
197-
-1113305847, // Taser Ammo
203+
-906852676, // Taser Ammo
198204
-700261193, //License Boating
199205
1695812550, //License Drivers
200206
499504400, //License Gun
@@ -975,6 +981,8 @@ public class _PlayerList
975981
public ShPlayer reportedPlayer { get; set; }
976982
public string reportedReason;
977983
public bool chatEnabled = true;
984+
public bool staffChatEnabled;
985+
public bool receiveStaffChat = true;
978986
}
979987

980988
public class _Group

source/BP-Essentials/Methods/FileHandler/ReadFile.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public class _Messages
4141
public string AdminSearchingInv { get; set; }
4242
public string PlayerMessage { get; set; }
4343
public string AdminMessage { get; set; }
44+
public string AdminChatMessage { get; set; }
4445
}
4546
[Serializable]
4647
public class MessageColors
@@ -137,6 +138,7 @@ public static void Run(string fileName)
137138
AdminSearchingInv = $"<color={errorColor}>{m.Messages.AdminSearchingInv}</color>";
138139
PlayerMessage = m.Messages.PlayerMessage;
139140
AdminMessage = m.Messages.AdminMessage;
141+
AdminChatMessage = m.Messages.AdminChatMessage;
140142

141143
AccessMoneyMenu = m.FunctionUI.AccessMoneyMenu;
142144
AccessItemMenu = m.FunctionUI.AccessItemMenu;

source/BP-Essentials/Methods/misc/GetIdList.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static bool Run(bool silent)
2525
Debug.Log("[OK] ID list downloaded");
2626
Debug.Log("Reloading ID list..");
2727
ReadFile.Run(IdListFile);
28-
Debug.Log("[OK] Downloaded newest ID list and reloaded it!");
28+
Debug.Log($"[OK] Downloaded newest ID list and reloaded it! ({IDs.Length} entries loaded in.)");
2929
}
3030
return true;
3131
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using UnityEngine;
6+
using static BP_Essentials.EssentialsVariablesPlugin;
7+
using static BP_Essentials.EssentialsMethodsPlugin;
8+
using System.IO;
9+
using System.Threading;
10+
using System.Reflection;
11+
12+
namespace BP_Essentials
13+
{
14+
class SendChatMessageToAdmins : EssentialsChatPlugin
15+
{
16+
public static void Run(string message)
17+
{
18+
foreach (var player in playerList.Where(x =>x.Value.receiveStaffChat && HasPermission.Run(x.Value.shplayer.svPlayer, CmdStaffChatExecutableBy)))
19+
player.Value.shplayer.svPlayer.SendToSelf(Channel.Unsequenced, ClPacket.GameMessage, message);
20+
}
21+
}
22+
}

0 commit comments

Comments
 (0)