Skip to content

Commit

Permalink
1.3 files
Browse files Browse the repository at this point in the history
  • Loading branch information
SebasCapo authored Mar 24, 2020
1 parent 11dc5b3 commit c63fafa
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 26 deletions.
84 changes: 70 additions & 14 deletions LightsPlugin/LightsPlugin/EventHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@
using System.Collections.Generic;
using System.Linq;
using EXILED;
using EXILED.Extensions;
using MEC;
using Log = EXILED.Log;

namespace Lights {

public class EventHandlers {
public Plugin plugin;
public int count;

public EventHandlers( Plugin plugin ) {
this.plugin = plugin;
}

public void OnRoundStart() {
if(plugin.DoFirstBlackout)
Timing.RunCoroutine(StartTimer(generateRandomNumber(plugin.FirstBlackoutTimerMin, plugin.FirstBlackoutTimerMax)));
}

Expand All @@ -23,15 +27,65 @@ public void OnCommand( ref RACommandEvent ev ) {
try {
if ( ev.Command.Contains("REQUEST_DATA PLAYER_LIST SILENT") ) return;
string [] args = ev.Command.Split(' ');
ReferenceHub sender = ev.Sender.SenderId == "SERVER CONSOLE" || ev.Sender.SenderId == "GAME CONSOLE" ? Plugin.GetPlayer(PlayerManager.localPlayer) : Plugin.GetPlayer(ev.Sender.SenderId);
if ( args [ 0 ].ToLower() == "lights_reload" ) {
ReferenceHub sender = ev.Sender.SenderId == "SERVER CONSOLE" || ev.Sender.SenderId == "GAME CONSOLE" ? Player.GetPlayer(PlayerManager.localPlayer) : Player.GetPlayer(ev.Sender.SenderId);
if ( args [ 0 ].ToLower() == "lightsconfig" ) {
ev.Allow = false;
if ( !checkPermission(ev, sender, "reload") ) {
if ( !checkPermission(ev, sender, "config") ) {
ev.Sender.RAMessage(plugin.AccessDenied);
return;
}
plugin.reloadConfig();
ev.Sender.RAMessage("<color=red>Configuration variables reloaded.</color>");
if(args.Length >= 2) {
if(args[1].ToLower() == "set") {
if(!checkPermission(ev, sender, "set")) return;
if(args.Length >= 4) {
if(args[2].ToLower().StartsWith("lights_")) {
Plugin.Config.SetString(args[2].ToLower(), ev.Command.Substring(ev.Command.LastIndexOf(args[3])));
ev.Sender.RAMessage($"<color=yellow>{args[2].ToLower()}</color> <color=green>has been set to:</color> <color=yellow>{args[3]}</color><color=green>.</color>");
return;
}
}
} else if(args[1].ToLower() == "reload") {
if(!checkPermission(ev, sender, "reload")) return;
plugin.reloadConfig();
ev.Sender.RAMessage("<color=green>Configuration variables reloaded.</color>");
return;
} else if(args[1].ToLower() == "variables") {
ev.Sender.RAMessage(
"<color=red>Each color shows the type of each variable.</color>\n" +
"<color=yellow>String</color> - <color=green>Integer</color> - <color=red>Float</color> - <color=#ff00ffff>Boolean</color>\n" +
"<color=yellow>lights_command -</color>" +
"<color=yellow>lights_alias -</color>" +
"<color=yellow>lights_true_arguments -</color>" +
"<color=#ff00ffff>lights_announce -</color>" +
"<color=green>lights_announce_duration -</color>" +
"<color=yellow>lights_announce_text -</color>" +
"<color=yellow>lights_message_access_denied -</color>" +
"<color=yellow>lights_message_help -</color>" +
"<color=yellow>lights_message_not_recognized -</color>" +
"<color=yellow>lights_message_success -</color>" +
"<color=yellow>lights_cassie_announcement_hcz -</color>" +
"<color=yellow>lights_cassie_announcement_both -</color>" +
"<color=#ff00ffff>lights_cassie_announceforhcz -</color>" +
"<color=#ff00ffff>lights_cassie_announceforboth -</color>" +
"<color=#ff00ffff>lights_cassie_makenoise -</color>" +
"<color=#ff00ffff>lights_startblackout_toggle -</color>" +
"<color=red>lights_startblackout_delay_max -</color>" +
"<color=red>lights_startblackout_delay_min -</color>" +
"<color=#ff00ffff>lights_multipleblackout_toggle -</color>" +
"<color=red>lights_multipleblackout_duration_max -</color>" +
"<color=red>lights_multipleblackout_duration_min -</color>" +
"<color=red>lights_multipleblackout_timebetween_max -</color>" +
"<color=red>lights_multipleblackout_timebetween_min -</color>" +
"<color=green>lights_multipleblackout_maxamount -</color>" +
"<color=yellow>lights_cassie_announcement_auto -</color>" +
"<color=#ff00ffff>lights_cassie_announceauto</color>");
return;
}
}
ev.Sender.RAMessage("<color=red>Please try one of the following:</color> " +
"\n<color=#f29f05>\"lightsconfig set <config_variable> <value>\" -> Change the value of a config variable of the plugin.</color>" +
"\n<color=#f29f05>\"lightsconfig variables\" -> Gives you a list of all variables available.</color>" +
"\n<color=#f29f05>\"lightsconfig reload\" -> Reloads config variables.</color>");
return;
}

Expand All @@ -43,13 +97,11 @@ public void OnCommand( ref RACommandEvent ev ) {
return;
}
if ( args.Length < 2 ) {
ev.Sender.RAMessage(plugin.HelpOne.Replace("%cmd", args [ 0 ]));
ev.Sender.RAMessage(plugin.HelpTwo);
ev.Sender.RAMessage(plugin.HelpMessage.Replace("%cmd", args [ 0 ]));
return;
} else if ( args.Length >= 2 ) {
if ( !args [ 1 ].All(char.IsDigit) ) {
ev.Sender.RAMessage(plugin.HelpOne.Replace("%cmd", args [ 0 ]));
ev.Sender.RAMessage(plugin.HelpTwo);
ev.Sender.RAMessage(plugin.HelpMessage.Replace("%cmd", args [ 0 ]));
return;
}
bool OnlyHCZ = false;
Expand All @@ -60,7 +112,7 @@ public void OnCommand( ref RACommandEvent ev ) {
}
ev.Sender.RAMessage(plugin.Success.Replace("%s", args [ 1 ]).Replace("%value" , OnlyHCZ + ""));
if ( plugin.DoAnnouncement ) {
foreach ( ReferenceHub h in Plugin.GetHubs() )
foreach ( ReferenceHub h in Player.GetHubs() )
h.Broadcast(plugin.AnnounceDuration, plugin.Announcement.Replace("%player", ev.Sender.Nickname).Replace("%s", args[1]));
}

Expand Down Expand Up @@ -89,14 +141,18 @@ public bool checkPermission( RACommandEvent ev , ReferenceHub sender , string pe

public IEnumerator<float> StartTimer( float s ) {
yield return Timing.WaitForSeconds(s);
lightsOff(generateRandomNumber(plugin.FirstBlackoutMinDuration, plugin.FirstBlackoutMaxDuration), false);
if(plugin.DoMultipleBlackouts) Timing.RunCoroutine(StartTimers(plugin.TimeBetween));
float _tmp = generateRandomNumber(plugin.FirstBlackoutMinDuration, plugin.FirstBlackoutMaxDuration);
lightsOff(_tmp, false);
if(plugin.DoMultipleBlackouts) Timing.RunCoroutine(StartTimers(_tmp + generateRandomNumber(plugin.TimeBetweenMin, plugin.TimeBetweenMax)));
}

public IEnumerator<float> StartTimers( float s ) {
yield return Timing.WaitForSeconds(s);
lightsOff(generateRandomNumber(plugin.FirstBlackoutMinDuration, plugin.FirstBlackoutMaxDuration), false);
Timing.RunCoroutine(StartTimers(plugin.TimeBetween));
float _tmp = generateRandomNumber(plugin.BlackoutMinDuration, plugin.BlackoutMaxDuration);
lightsOff(_tmp, false);
if(count <= plugin.maxAmount)
Timing.RunCoroutine(StartTimers(_tmp + generateRandomNumber(plugin.TimeBetweenMin, plugin.TimeBetweenMax)));
count++;
}

public void lightsOff(float time, bool hczonly) {
Expand Down
27 changes: 15 additions & 12 deletions LightsPlugin/LightsPlugin/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ public class Plugin : EXILED.Plugin {
// Text
public bool debugMode;
public string AccessDenied;
public string HelpOne;
public string HelpTwo;
public string HelpMessage;
public string NotRecognized;
public string Success;

Expand All @@ -26,9 +25,11 @@ public class Plugin : EXILED.Plugin {
public float FirstBlackoutMinDuration;

public bool DoMultipleBlackouts;
public float TimeBetween;
public float BlackoutMaxDurations;
public float BlackoutMinDurations;
public float TimeBetweenMin;
public float TimeBetweenMax;
public float BlackoutMaxDuration;
public float BlackoutMinDuration;
public int maxAmount;

// Command
public string CmdName;
Expand Down Expand Up @@ -90,22 +91,24 @@ public void reloadConfig() {
// Text
debugMode = Config.GetBool("lights_debug", true);
AccessDenied = Config.GetString("lights_message_access_denied", "<color=red>Access Denied.</color>");
HelpOne = Config.GetString("lights_message_help", "<color=red>Command usage: " + '"' + "</color><color=yellow>%cmd <seconds> </color><color=#ab0be6>[true/yes] </color><color=red>" + '"' + "</color>");
HelpTwo = Config.GetString("lights_message_help2", "<color=red><> is necessary -- [] is optional.</color>");
HelpMessage = Config.GetString("lights_message_help", "<color=red>Command usage: " + '"' + "</color><color=yellow>%cmd <seconds> </color><color=#ab0be6>[true/yes] </color><color=red>" + '"' + "</color>" +
"\n<color=red><> is necessary -- [] is optional.</color>");
NotRecognized = Config.GetString("lights_message_not_recognized", "<color=red>Argument " + '"' + "%arg" + '"' + " can't be recognized, using default value.</color>");
Success = Config.GetString("lights_message_success", "<color=#13c706>Lights have been turned off for:<b> %ss </b>(HCZ Only? : <b>%value</b>)</color>");

// Timers
DoFirstBlackout = Config.GetBool("lights_startblackout_toggle", false);
FirstBlackoutTimerMax = Config.GetFloat("lights_startblackout_delay_max", 60f);
FirstBlackoutTimerMax = Config.GetFloat("lights_startblackout_delay_min", 60f);
FirstBlackoutTimerMin = Config.GetFloat("lights_startblackout_delay_min", 50f);
FirstBlackoutMaxDuration = Config.GetFloat("lights_startblackout_duration_max", 15f);
FirstBlackoutMinDuration = Config.GetFloat("lights_startblackout_duration_min", 10f);

DoMultipleBlackouts = Config.GetBool("lights_multipleblackout_toggle", false);
TimeBetween = Config.GetFloat("lights_multipleblackout_timebetween", 5f);
BlackoutMaxDurations = Config.GetFloat("lights_multipleblackout_duration_max", 8f);
BlackoutMinDurations = Config.GetFloat("lights_multipleblackout_duration_min", 5f);
TimeBetweenMin = Config.GetFloat("lights_multipleblackout_timebetween_min", 20f);
TimeBetweenMax = Config.GetFloat("lights_multipleblackout_timebetween_max", 35f);
BlackoutMaxDuration = Config.GetFloat("lights_multipleblackout_duration_max", 25f);
BlackoutMinDuration = Config.GetFloat("lights_multipleblackout_duration_min", 21f);
maxAmount = Config.GetInt("lights_multipleblackout_maxamount", 2);

// Command
CmdName = Config.GetString("lights_command", "lights");
Expand All @@ -129,6 +132,6 @@ public void reloadConfig() {
#endregion
}

public override string getName { get; } = "LightsPlugin 1.3 - SebasCapo";
public override string getName { get; } = "LightsPlugin 1.3.3 - SebasCapo";
}
}

0 comments on commit c63fafa

Please sign in to comment.