Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 47 additions & 22 deletions Essentials/Commands/AdminModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void Statistics()
Stats.Timing.WriteTo(sb);

if (Context?.Player?.SteamUserId > 0)
ModCommunication.SendMessageTo(new DialogMessage("Statistics", null, sb.ToString()) , Context.Player.SteamUserId);
ModCommunication.SendMessageTo(new DialogMessage("Statistics", null, sb.ToString()), Context.Player.SteamUserId);
else
Context.Respond(sb.ToString());
}
Expand All @@ -58,7 +58,7 @@ public void PlayerCount(int count = -1)
[Permission(MyPromoteLevel.Admin)]
public void ListPlayers()
{
if(MySession.Static.Players.GetOnlinePlayerCount() == 0)
if (MySession.Static.Players.GetOnlinePlayerCount() == 0)
{
Context.Respond("No players online");
return;
Expand All @@ -72,7 +72,7 @@ public void ListPlayers()
}

sb.AppendLine($"Found {players.Count} Players on server");
foreach(var player in players)
foreach (var player in players)
{
sb.AppendLine($"{player.DisplayName}");
sb.AppendLine($">PlayerId: {player.Identity.IdentityId}");
Expand Down Expand Up @@ -119,7 +119,7 @@ public void EndAuto(string commandName)
[Permission(MyPromoteLevel.Admin)]
public void EndByOrder(int commandNumber = 0)
{
var commands = new List<AutoCommand>(EssentialsPlugin.Instance.Config.AutoCommands.Where(x=>x.IsRunning()));
var commands = new List<AutoCommand>(EssentialsPlugin.Instance.Config.AutoCommands.Where(x => x.IsRunning()));

if (commands.Count == 0)
{
Expand Down Expand Up @@ -164,15 +164,15 @@ public void ListAuto()

else
{
ModCommunication.SendMessageTo(new DialogMessage("Current AutoCommands",$"Found {commands.Count} Commands",sb.ToString()), Context.Player.SteamUserId);
ModCommunication.SendMessageTo(new DialogMessage("Current AutoCommands", $"Found {commands.Count} Commands", sb.ToString()), Context.Player.SteamUserId);
}
}

[Command("listrunningauto", "Lists all running autocommands ")]
[Permission(MyPromoteLevel.Admin)]
public void ListAutoRunning()
{
var commands = new List<AutoCommand>(EssentialsPlugin.Instance.Config.AutoCommands.Where(x=>x.IsRunning()));
var commands = new List<AutoCommand>(EssentialsPlugin.Instance.Config.AutoCommands.Where(x => x.IsRunning()));

if (commands.Count == 0)
{
Expand All @@ -196,7 +196,7 @@ public void ListAutoRunning()

else
{
ModCommunication.SendMessageTo(new DialogMessage("Current AutoCommands",$"Found {commands.Count} Commands",sb.ToString()), Context.Player.SteamUserId);
ModCommunication.SendMessageTo(new DialogMessage("Current AutoCommands", $"Found {commands.Count} Commands", sb.ToString()), Context.Player.SteamUserId);
}
}

Expand Down Expand Up @@ -250,7 +250,7 @@ public void ReserveSlot(string playerNameOrId)
{
ulong.TryParse(playerNameOrId, out var id);
id = Utilities.GetPlayerByNameOrId(playerNameOrId)?.SteamUserId ?? id;

if (id == 0)
{
Context.Respond($"Player '{playerNameOrId}' not found or ID is invalid.");
Expand All @@ -262,7 +262,7 @@ public void ReserveSlot(string playerNameOrId)
Context.Respond($"ID {id} is already reserved.");
return;
}

MySandboxGame.ConfigDedicated.Reserved.Add(id);
MySandboxGame.ConfigDedicated.Save();
Context.Respond($"ID {id} added to reserved slots.");
Expand All @@ -274,19 +274,19 @@ public void UnreserveSlot(string playerNameOrId)
{
ulong.TryParse(playerNameOrId, out var id);
id = Utilities.GetPlayerByNameOrId(playerNameOrId)?.SteamUserId ?? id;

if (id == 0)
{
Context.Respond($"Player '{playerNameOrId}' not found or ID is invalid.");
return;
}

if (!MySandboxGame.ConfigDedicated.Reserved.Contains(id))
{
Context.Respond($"ID {id} is already unreserved.");
return;
}

MySandboxGame.ConfigDedicated.Reserved.Remove(id);
MySandboxGame.ConfigDedicated.Save();
Context.Respond($"ID {id} removed from reserved slots.");
Expand Down Expand Up @@ -320,7 +320,7 @@ public void MuteUser(string user, int timeout = 0)

bool res = ChatManager.MuteUser(p.SteamUserId);

if(!res)
if (!res)
Context.Respond($"Failed to mute user {user}. They are already muted.");
else
Context.Respond($"Muted user {p.DisplayName}");
Expand All @@ -339,7 +339,7 @@ private void _muteTimer_Elapsed(object sender, ElapsedEventArgs e)
{
foreach (var p in _muted)
{
if(p.Value > DateTime.Now)
if (p.Value > DateTime.Now)
continue;

_removeCache.Add(p.Key);
Expand Down Expand Up @@ -387,11 +387,11 @@ public void ListMute()
foreach (var m in ChatManager.MutedUsers)
{
var s = MySession.Static.Players.TryGetIdentityNameFromSteamId(m);
if(string.IsNullOrEmpty(s))
if (string.IsNullOrEmpty(s))
s = m.ToString();
bool f = false;
DateTime t = default(DateTime);
if(_muted != null)
if (_muted != null)
lock (_muted)
f = _muted.TryGetValue(m, out t);

Expand All @@ -409,33 +409,58 @@ public void ListMute()

[Command("give", "Insert an item with a specific quanity into a players inventory")]
[Permission(MyPromoteLevel.Admin)]
public void give(string playerName, string itemType, string item, int quantity) {
public void give(string playerName, string itemType, string item, int quantity)
{
string type = "MyObjectBuilder_" + itemType;
VRage.Game.MyDefinitionId.TryParse(type, item, out VRage.Game.MyDefinitionId defID);

if (defID.ToString().Contains("null")) {
if (defID.ToString().Contains("null"))
{
Context.Respond("Invalid item type");
return;
}

if (playerName != "*") {
if (playerName != "*")
{
var p = Utilities.GetPlayerByNameOrId(playerName);
if (p == null) {
if (p == null)
{
Context.Respond("Player not found");
return;
}
Sandbox.Game.MyVisualScriptLogicProvider.AddToPlayersInventory(p.IdentityId, defID, quantity);
ModCommunication.SendMessageTo(new NotificationMessage($"You have been given {quantity} {item} {itemType}", 5000, "Blue"), p.SteamUserId);
}

else {
foreach (var p in MySession.Static.Players.GetOnlinePlayers()) {
else
{
foreach (var p in MySession.Static.Players.GetOnlinePlayers())
{
var player = Utilities.GetPlayerByNameOrId(p.DisplayName);
Sandbox.Game.MyVisualScriptLogicProvider.AddToPlayersInventory(p.Identity.IdentityId, defID, quantity);
ModCommunication.SendMessageTo(new NotificationMessage($"You have been given {quantity} {item} {itemType}", 5000, "Blue"), player.SteamUserId);
}
}
Context.Respond("Item(s) given!");
}

[Command("playervote", "[playervote Enable] to allow players to start votes, [playervote disable] to disable stop players from starting votes.")]
[Permission(MyPromoteLevel.Admin)]
public void playerVote(string DisEnable)
{
switch (DisEnable.ToUpper())
{
case "ENABLE":
EssentialsPlugin.Instance.Config.EnableVote = true;
Context.Respond("Player vote is now enabled");
return;

case "DISABLE":
EssentialsPlugin.Instance.Config.EnableVote = false;
Context.Respond("Player vote is now disabled");
return;
}

}
}
}
6 changes: 6 additions & 0 deletions Essentials/Commands/VotingModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ public enum Status
[Permission(MyPromoteLevel.None)]
public void Vote(string name)
{
if (EssentialsPlugin.Instance.Config.EnableVote == false)
{
Context.Respond("Voting has been disabled");
return;
}

if (Context.Player == null)
{
Context.Respond("This is an in-game command");
Expand Down
4 changes: 4 additions & 0 deletions Essentials/EssentialsConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ public bool MarkerShowPosition
set => SetValue(ref _markerShowPosition, value);
}

private bool _enableVote = true;
[Display(Name = "Enable player use of Vote", Description = "Large factions can abuse the restart, refresh, and other commands with votes. Disabling this will prevent any possible vote abuse.")]
public bool EnableVote { get => _enableVote; set => SetValue(ref _enableVote, value); }

private int _backpackLimit = 1;
[Display(Name = "Backpack Limit", Description = "Sets the number of backpacks that can belong to any player. Empty backpacks are deleted after 30 seconds, and backpacks which break the limit are deleted in order spawned. Set -1 for no limit.")]
public int BackpackLimit
Expand Down