Skip to content

Commit 3ef3f30

Browse files
committed
Add option to require permission for starting certain votes closes #9
1 parent 6324894 commit 3ef3f30

8 files changed

Lines changed: 19 additions & 8 deletions

File tree

Commands/CommandCallVote.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ public void Execute(IRocketPlayer caller, string[] command)
6161

6262
try
6363
{
64+
if (vote.Settings.RequirePermission && !player.HasPermission($"callvote.{vote.Settings.Name}"))
65+
throw new VoteStartException("NO_PERMISSION");
66+
6467
var arguments = command.Skip(1).ToList();
6568

6669
vote.Start(arguments);

Configuration.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ public void LoadDefaults()
2424
new VoteSettings("NoSnow", "ns", "/weather none"),
2525
new VoteSettings("HealAll", "ha", "/healall"),
2626
new VoteSettings("Airdrop", "a", "/airdrop"),
27-
new VoteSettings("AirdropAll", "aa", "/airdropall"),
28-
new VoteSettings("VehicleAll", "va", "/vehicleall"),
29-
new VoteSettings("MaxSkills", "ms", "/maxskills"),
30-
new VoteSettings("ItemAll", "ia", "/itemall")
27+
new VoteSettings("AirdropAll", "aa", "/airdropall", requirePermission: true),
28+
new VoteSettings("VehicleAll", "va", "/vehicleall", requirePermission: true),
29+
new VoteSettings("MaxSkills", "ms", "/maxskills", requirePermission: true),
30+
new VoteSettings("ItemAll", "ia", "/itemall", requirePermission: true)
3131
};
3232
}
3333
}

IVote.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namespace Arechi.CallVote
55
{
66
public interface IVote
77
{
8-
VoteSettings Settings { get; set; }
8+
IVoteSettings Settings { get; set; }
99

1010
List<string> Arguments { get; set; }
1111

IVoteSettings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,7 @@ public interface IVoteSettings
2323
int Timer { get; set; }
2424

2525
int CooldownTime { get; set; }
26+
27+
bool RequirePermission { get; set; }
2628
}
2729
}

Plugin.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ protected override void Unload()
3232
{ "COOLING_DOWN", "This vote is cooling down!: {0}s" },
3333
{ "NOT_ENOUGH_ARGUMENTS", "You need at least {0} arguments to start this vote!" },
3434
{ "NOT_ENOUGH_PLAYERS", "You need at least {0} players to start this vote!" },
35+
{ "NO_PERMISSION", "You are missing the required permission to start this vote!" },
3536
{ "RESULT", "{0}% | Required: {1}% | Vote with /cv {2}" },
3637
{ "FAILURE", "Failed!" },
3738
{ "SUCCESS", "Successful!" },

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ Each vote can be customized even further:
3333
- required percent
3434
- timer
3535
- cooldown time
36+
- whether a permission is required to start it (callvote.\<name>)
3637

3738
The plugin includes default values for these.

Vote.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Arechi.CallVote
1212
{
1313
public class Vote : IVote
1414
{
15-
public VoteSettings Settings { get; set; }
15+
public IVoteSettings Settings { get; set; }
1616

1717
public List<string> Arguments { get; set; }
1818

@@ -26,7 +26,7 @@ public class Vote : IVote
2626

2727
private Coroutine _cooldownCoroutine;
2828

29-
public Vote(VoteSettings settings)
29+
public Vote(IVoteSettings settings)
3030
{
3131
Settings = settings;
3232
}

VoteSettings.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@ public class VoteSettings : IVoteSettings
3737
[XmlAttribute("CooldownTime")]
3838
public int CooldownTime { get; set; }
3939

40+
[XmlAttribute("RequirePermission")]
41+
public bool RequirePermission { get; set; }
42+
4043
public VoteSettings() { }
4144

4245
public VoteSettings(string name, string alias, string command, int minArgs = 0, string color = "#fff333", string icon = "",
43-
bool enabled = true, int minPlayers = 1, int reqPercent = 50, int timer = 60, int cooldown = 300)
46+
bool enabled = true, int minPlayers = 1, int reqPercent = 50, int timer = 60, int cooldown = 300, bool requirePermission = false)
4447
{
4548
Name = name;
4649
Alias = alias;
@@ -53,6 +56,7 @@ public VoteSettings(string name, string alias, string command, int minArgs = 0,
5356
RequiredPercent = reqPercent;
5457
Timer = timer;
5558
CooldownTime = cooldown;
59+
RequirePermission = requirePermission;
5660
}
5761
}
5862
}

0 commit comments

Comments
 (0)