Skip to content

Commit

Permalink
Add extra permission to nick for ability to change your own nick
Browse files Browse the repository at this point in the history
This allows /nick to be used to change bot names but not your own name, removing the need for custom commands such as NA2's /botnick
  • Loading branch information
Goodlyay committed Apr 27, 2023
1 parent 1d703bb commit 7244fa2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
12 changes: 9 additions & 3 deletions MCGalaxy/Commands/Chat/CmdNick.cs
Expand Up @@ -26,8 +26,13 @@ public class CmdNick : EntityPropertyCmd
public override string type { get { return CommandTypes.Chat; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }
public override CommandPerm[] ExtraPerms {
get { return new[] { new CommandPerm(LevelPermission.Operator, "can change the nick of others"),
new CommandPerm(LevelPermission.Operator, "can change the nick of bots") }; }
get { return
new[] {
new CommandPerm(LevelPermission.Operator, "can change the nick of others"),
new CommandPerm(LevelPermission.Guest, "can change the nick of bots"),
new CommandPerm(LevelPermission.Guest, "can change their own nick"),
};
}
}
public override CommandAlias[] Aliases {
get { return new CommandAlias[] { new CommandAlias("xnick", "-own") }; }
Expand Down Expand Up @@ -56,7 +61,8 @@ public class CmdNick : EntityPropertyCmd
BotsFile.Save(p.level);
}

protected override void SetPlayerData(Player p, string target, string nick) {
protected override void SetPlayerData(Player p, CommandData data, string target, string nick) {
if (!CheckExtraPerm(p, data, 3)) return;
PlayerOperations.SetNick(p, target, nick);
}

Expand Down
6 changes: 5 additions & 1 deletion MCGalaxy/Commands/EntityPropertyCmd.cs
Expand Up @@ -17,6 +17,9 @@
*/

namespace MCGalaxy.Commands {
/// <summary>
/// Extra permission number 1 is hardcoded as "can edit other player" and extra permission number 2 is hardcoded as "can edit bot"
/// </summary>
public abstract class EntityPropertyCmd : Command2 {

protected void UseBotOrOnline(Player p, CommandData data, string message, string type) {
Expand Down Expand Up @@ -73,11 +76,12 @@ public abstract class EntityPropertyCmd : Command2 {

LevelPermission rank = Group.GroupIn(target).Permission;
if (!CheckRank(p, data, target, rank, "change the " + type + " of", true)) return;
SetPlayerData(p, target, args.Length > 1 ? args[1] : "");
SetPlayerData(p, data, target, args.Length > 1 ? args[1] : "");
}

protected virtual void SetBotData(Player p, PlayerBot bot, string args) { }
protected virtual void SetOnlineData(Player p, Player who, string args) { }
protected virtual void SetPlayerData(Player p, string target, string args) { }
protected virtual void SetPlayerData(Player p, CommandData data, string target, string args) { SetPlayerData(p, target, args); }
}
}

0 comments on commit 7244fa2

Please sign in to comment.