Skip to content

Commit 75e8e9d

Browse files
committed
Added wait time based on groups
1 parent 31c7588 commit 75e8e9d

File tree

7 files changed

+74
-22
lines changed

7 files changed

+74
-22
lines changed

Zamirathe_HomeCommand/CommandHome.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,6 @@ public void Execute(CSteamID playerid, string bed)
3636
object[] cont = HomeCommand.CheckConfig(player, playerid, homeplayer);
3737
if (!(bool)cont[0]) return;
3838
// A bed was found, so let's run a few checks.
39-
if (HomeCommand.Instance.Configuration.TeleportWait)
40-
{
41-
// Admin want the player to have to wait before they can teleport. Now do they have to stay still too?
42-
if (HomeCommand.Instance.Configuration.MovementRestriction)
43-
{
44-
// Admin wants them not to move either. So let's send the appropriate msg and start the timer.
45-
RocketChatManager.Say(playerid, String.Format(HomeCommand.Instance.Configuration.FoundBedWaitNoMoveMsg, player.name, HomeCommand.Instance.Configuration.TeleportWaitTime));
46-
}
47-
else
48-
{
49-
// Admin just wants them to wait but they can move.
50-
RocketChatManager.Say(playerid, String.Format(HomeCommand.Instance.Configuration.FoundBedNowWaitMsg, player.name, HomeCommand.Instance.Configuration.TeleportWaitTime));
51-
}
52-
}
5339
homeplayer.GoHome((Vector3)cont[1], (byte)cont[2], player);
5440
}
5541
}

Zamirathe_HomeCommand/HomeCommand.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using Rocket.RocketAPI;
34
using SDG;
45
using UnityEngine;
@@ -10,11 +11,19 @@ public class HomeCommand : RocketPlugin<HomeCommandConfiguration>
1011
{
1112
public static bool running;
1213
public static DateTime start;
14+
public Dictionary<string, byte> WaitGroups = new Dictionary<string, byte>();
1315
public static HomeCommand Instance;
1416

1517
protected override void Load()
1618
{
1719
HomeCommand.Instance = this;
20+
if (Loaded)
21+
{
22+
foreach (HomeGroup hg in this.Configuration.WaitGroups)
23+
{
24+
WaitGroups.Add(hg.Id, hg.Wait);
25+
}
26+
}
1827
}
1928
// All we are doing here is checking the config to see if anything like restricted movement or time restriction is enforced.
2029
public static object[] CheckConfig(Player player, CSteamID playerid, HomePlayer homeplayer)

Zamirathe_HomeCommand/HomeCommandConfiguration.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
using Rocket.RocketAPI;
2+
using System;
3+
using System.Collections.Generic;
24

35
namespace Zamirathe_HomeCommand
46
{
@@ -9,7 +11,7 @@ public class HomeCommandConfiguration : RocketConfiguration
911
public string NoBedMsg;
1012
public string NoVehicleMsg;
1113
public bool TeleportWait;
12-
public byte TeleportWaitTime;
14+
public List<HomeGroup> WaitGroups;
1315
public string TeleportMsg;
1416
public string FoundBedNowWaitMsg;
1517
public bool MovementRestriction;
@@ -28,7 +30,12 @@ public RocketConfiguration DefaultConfiguration
2830
NoBedMsg = "I'm sorry {0}, but I could not find your bed.",
2931
NoVehicleMsg = "I'm sorry {0}, but you can't be teleported while inside a vehicle.",
3032
TeleportWait = false,
31-
TeleportWaitTime = 5,
33+
WaitGroups = new List<HomeGroup>() {
34+
new HomeGroup{Id = "all", Wait = 5},
35+
new HomeGroup{Id = "admin", Wait = 0},
36+
new HomeGroup{Id = "moderator", Wait = 3},
37+
new HomeGroup{Id = "default", Wait = 5}
38+
},
3239
TeleportMsg = "You were sent back to your bed.",
3340
FoundBedNowWaitMsg = "I have located your bed {0}, please wait for {1} seconds to be teleported.",
3441
MovementRestriction = false,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Xml.Serialization;
4+
5+
namespace Zamirathe_HomeCommand
6+
{
7+
public class HomeGroup
8+
{
9+
[XmlAttribute]
10+
public string Id { get; set; }
11+
[XmlAttribute]
12+
public byte Wait { get; set; }
13+
}
14+
}

Zamirathe_HomeCommand/HomePlayer.cs

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using Rocket.Components;
22
using Rocket.RocketAPI;
3+
using Rocket.Logging;
34
using SDG;
45
using Steamworks;
56
using UnityEngine;
67
using System;
8+
using System.Collections.Generic;
79

810
namespace Zamirathe_HomeCommand
911
{
@@ -28,19 +30,52 @@ private void Load()
2830
public void GoHome(Vector3 bedPos, byte bedRot, Player player)
2931
{
3032
this.waitrestricted = HomeCommand.Instance.Configuration.TeleportWait;
31-
this.waittime = HomeCommand.Instance.Configuration.TeleportWaitTime;
3233
this.movementrestricted = HomeCommand.Instance.Configuration.MovementRestriction;
3334
this.p = player;
3435
this.bedPos = Vector3.up + bedPos;
3536
this.bedRot = bedRot;
3637

3738
if (this.waitrestricted)
3839
{
39-
// We have to wait to teleport.
40+
// We have to wait to teleport now find out how long
4041
this.LastCalledHomeCommand = DateTime.Now;
42+
if (HomeCommand.Instance.WaitGroups.ContainsKey("all"))
43+
{
44+
HomeCommand.Instance.WaitGroups.TryGetValue("all", out this.waittime);
45+
}
46+
else
47+
{
48+
if (player.SteamChannel.SteamPlayer.IsAdmin && HomeCommand.Instance.WaitGroups.ContainsKey("admin"))
49+
{
50+
HomeCommand.Instance.WaitGroups.TryGetValue("admin", out this.waittime);
51+
}
52+
else
53+
{
54+
// Either not an admin or they don't get special wait restrictions.
55+
List<Group> hg = player.GetGroups();
56+
byte[] time2 = new byte[hg.Count];
57+
for (byte g=0;g<hg.Count;g++)
58+
{
59+
Group hgr = hg[g];
60+
HomeCommand.Instance.WaitGroups.TryGetValue(hgr.Id, out time2[g]);
61+
if (time2[g] <= 0)
62+
{
63+
time2[g] = 60;
64+
}
65+
}
66+
Array.Sort(time2);
67+
// Take the lowest time.
68+
this.waittime = time2[0];
69+
}
70+
}
4171
if (this.movementrestricted)
4272
{
4373
this.LastCalledHomePos = this.transform.position;
74+
RocketChatManager.Say(player.SteamChannel.SteamPlayer.SteamPlayerID.CSteamID, String.Format(HomeCommand.Instance.Configuration.FoundBedWaitNoMoveMsg, player.name, this.waittime));
75+
}
76+
else
77+
{
78+
RocketChatManager.Say(player.SteamChannel.SteamPlayer.SteamPlayerID.CSteamID, String.Format(HomeCommand.Instance.Configuration.FoundBedNowWaitMsg, player.name, this.waittime));
4479
}
4580
}
4681
else

Zamirathe_HomeCommand/Properties/AssemblyInfo.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
[assembly: AssemblyTitle("Zamirathe_HomeCommand")]
99
[assembly: AssemblyDescription("")]
1010
[assembly: AssemblyConfiguration("")]
11-
[assembly: AssemblyCompany("Hewlett-Packard")]
11+
[assembly: AssemblyCompany("")]
1212
[assembly: AssemblyProduct("Zamirathe_HomeCommand")]
13-
[assembly: AssemblyCopyright("Copyright © Hewlett-Packard 2015")]
13+
[assembly: AssemblyCopyright("Copyright © 2015")]
1414
[assembly: AssemblyTrademark("")]
1515
[assembly: AssemblyCulture("")]
1616

@@ -32,5 +32,5 @@
3232
// You can specify all the values or you can default the Build and Revision Numbers
3333
// by using the '*' as shown below:
3434
// [assembly: AssemblyVersion("1.0.*")]
35-
[assembly: AssemblyVersion("2.0.0.2")]
36-
[assembly: AssemblyFileVersion("2.0.0.2")]
35+
[assembly: AssemblyVersion("2.1.0.0")]
36+
[assembly: AssemblyFileVersion("2.1.0.0")]

Zamirathe_HomeCommand/Zamirathe_HomeCommand.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
<Compile Include="CommandHome.cs" />
5959
<Compile Include="HomeCommand.cs" />
6060
<Compile Include="HomeCommandConfiguration.cs" />
61+
<Compile Include="HomeGroups.cs" />
6162
<Compile Include="HomePlayer.cs" />
6263
<Compile Include="Properties\AssemblyInfo.cs" />
6364
</ItemGroup>

0 commit comments

Comments
 (0)