Skip to content

Commit 30b1022

Browse files
feat: replace ability to toggle plugin with ability to remove set code
"/code remove" replaces "/code toggle"
1 parent eaec180 commit 30b1022

File tree

2 files changed

+30
-20
lines changed

2 files changed

+30
-20
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Allow players to automatically try and unlock locked code locks with their code.
1919
- `/code 1234` - Sets your code to 1234.
2020
- `/code pick` - Opens the code lock input for you to enter a code.
2121
- `/code random` - Sets your code to a random code.
22-
- `/code toggle` - Toggles this plugin on/off for you.
22+
- `/code remove` - Removes your set code.
2323

2424
## Console Commands
2525

src/AutoCode.cs

+29-19
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ void OnEntitySpawned(CodeLock codeLock)
105105

106106
Data.Structure.PlayerSettings settings = data.Inst.playerSettings[player.userID];
107107

108-
// Disabled for the player or they haven't set a code?
109-
if (settings == null || !settings.enabled || settings.code == null)
108+
// Player doesn't have a code?
109+
if (settings == null || settings.code == null)
110110
{
111111
return;
112112
}
@@ -139,8 +139,8 @@ object CanUseLockedEntity(BasePlayer player, CodeLock codeLock)
139139
{
140140
Data.Structure.PlayerSettings settings = data.Inst.playerSettings[player.userID];
141141

142-
// Player has plugin enabled and they have the code?
143-
if (settings != null && settings.enabled && codeLock.code == settings.code)
142+
// Player has the code?
143+
if (settings != null && codeLock.code == settings.code)
144144
{
145145
// Auth the player.
146146
codeLock.whitelistPlayers.Add(player.userID);
@@ -156,10 +156,9 @@ protected override void LoadDefaultMessages()
156156
lang.RegisterMessages(new Dictionary<string, string>
157157
{
158158
{ "NoPermission", "You don't have permission." },
159-
{ "Enabled", "Auto Code enabled." },
160-
{ "Disabled", "Auto Code disabled." },
161159
{ "CodeAutoLocked", "Code lock placed with code {0}." },
162160
{ "CodeUpdated", "Your new code is {0}." },
161+
{ "CodeRemoved", "You're code has been removed." },
163162
{ "InvalidArgsTooMany", "No additional arguments expected." },
164163
{ "SyntaxError", "Syntax Error: expected \"{0}\"" },
165164
{ "SpamPrevention", "Too many recent code sets. Please wait {0} and try again." },
@@ -182,10 +181,10 @@ protected override void LoadDefaultMessages()
182181
/// Get the code for the given player.
183182
/// </summary>
184183
/// <param name="player">The player to get the code for.</param>
185-
/// <returns>A string of the player's code or null if the player doesn't have a code or they have disabled this plugin.</returns>
184+
/// <returns>A string of the player's code or null if the player doesn't have a code.</returns>
186185
public string GetCode(BasePlayer player)
187186
{
188-
if (data.Inst.playerSettings.ContainsKey(player.userID) && data.Inst.playerSettings[player.userID].enabled)
187+
if (data.Inst.playerSettings.ContainsKey(player.userID))
189188
{
190189
return data.Inst.playerSettings[player.userID].code;
191190
}
@@ -280,19 +279,31 @@ public void SetCode(BasePlayer player, string code)
280279
}
281280

282281
/// <summary>
283-
/// Toggle enabled for the given player.
282+
/// This method will only toggle off, not on.
284283
/// </summary>
285-
/// <param name="player">The player to toggle this plugin for.</param>
284+
/// <param name="player"></param>
285+
[ObsoleteAttribute("This method is deprecated.", true)]
286286
public void ToggleEnabled(BasePlayer player)
287287
{
288-
// Can't toggle until player has done their first enabled.
288+
RemoveCode(player);
289+
}
290+
291+
/// <summary>
292+
/// Remove the given player's the code.
293+
/// </summary>
294+
/// <param name="player">The player to remove the code of.</param>
295+
public void RemoveCode(BasePlayer player)
296+
{
289297
if (!data.Inst.playerSettings.ContainsKey(player.userID))
290298
{
291299
return;
292300
}
293301

294-
data.Inst.playerSettings[player.userID].enabled = !data.Inst.playerSettings[player.userID].enabled;
295-
player.ChatMessage(lang.GetMessage(data.Inst.playerSettings[player.userID].enabled ? "Enabled" : "Disabled", this, player.UserIDString));
302+
// Load the player's settings.
303+
Data.Structure.PlayerSettings settings = data.Inst.playerSettings[player.userID];
304+
305+
settings.code = null;
306+
player.ChatMessage(lang.GetMessage("CodeRemoved", this, player.UserIDString));
296307
}
297308

298309
/// <summary>
@@ -636,7 +647,6 @@ public class Structure
636647
public class PlayerSettings
637648
{
638649
public string code = null;
639-
public bool enabled = true;
640650
public double lastSet = 0;
641651
public int timesSetInSpamWindow = 0;
642652
public double lockedOutUntil = 0;
@@ -697,7 +707,7 @@ private class Commands
697707
// Chat Command Arguments.
698708
public string PickCode = "pick";
699709
public string RandomCode = "random";
700-
public string ToggleEnabled = "toggle";
710+
public string RemoveCode = "remove";
701711

702712
public Commands(AutoCode plugin)
703713
{
@@ -832,16 +842,16 @@ private void HandleUse(BasePlayer player, string label, string[] args)
832842
return;
833843
}
834844

835-
// Toggle enabled?
836-
if (arg0 == ToggleEnabled)
845+
// Remove?
846+
if (arg0 == RemoveCode)
837847
{
838848
if (args.Length > 1)
839849
{
840850
player.ChatMessage(string.Format(plugin.lang.GetMessage("InvalidArgsTooMany", plugin, player.UserIDString), label));
841851
return;
842852
}
843853

844-
plugin.ToggleEnabled(player);
854+
plugin.RemoveCode(player);
845855
return;
846856
}
847857

@@ -893,7 +903,7 @@ private void SyntaxError(BasePlayer player, string label, string[] args)
893903
/// <returns></returns>
894904
private string HelpGetAllUseCommandArguments()
895905
{
896-
return string.Format("<{0}>", string.Join("|", new string[] { "1234", RandomCode, PickCode, ToggleEnabled }));
906+
return string.Format("<{0}>", string.Join("|", new string[] { "1234", RandomCode, PickCode, RemoveCode }));
897907
}
898908
}
899909

0 commit comments

Comments
 (0)