Skip to content

Commit

Permalink
Allow adding notes to players without warning them
Browse files Browse the repository at this point in the history
/note -- add a note to a player that anyone may see
/opnote -- add a note to a player that only ops may see
  • Loading branch information
Goodlyay committed May 6, 2024
1 parent acdb29e commit 52c7079
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 25 deletions.
14 changes: 13 additions & 1 deletion MCGalaxy/CorePlugin/ModActionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ internal static class ModActionHandler {
case ModActionType.UnbanIP: DoUnbanIP(action); break;
case ModActionType.Warned: DoWarn(action); break;
case ModActionType.Rank: DoRank(action); break;
case ModActionType.Noted: DoNote(action); break;
case ModActionType.OpNoted: DoNote(action); break;
}
}

Expand All @@ -52,7 +54,7 @@ internal static class ModActionHandler {
Chat.Message(ChatScope.Global, e.FormatMessage(targetNick, action),
null, null, true);
} else {
Chat.MessageOps(e.FormatMessage(targetNick, action));
Chat.MessageOps("To Ops: " + e.FormatMessage(targetNick, action));
}

action = Colors.StripUsed(action);
Expand Down Expand Up @@ -255,5 +257,15 @@ internal static class ModActionHandler {
string assigner = e.Actor.name;
return assigner + " " + assign + " " + expiry;
}

static void DoNote(ModAction e) {
if (!Server.Config.LogNotes) {
e.Actor.Message("Notes logging must be enabled to note players."); return;
}

// No null checking because LogAction who parameter isn't used
Player who = PlayerInfo.FindExact(e.Target);
LogAction(e, who, "&egiven a note");
}
}
}
8 changes: 6 additions & 2 deletions MCGalaxy/Events/ModActionEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ public sealed class ModAction
}

public delegate void OnModAction(ModAction action);
/// <summary> Types of moderation actions that can occur. </summary>

/// <summary> Types of moderation actions that can occur. To make a mod action logged to /notes, add a new NoteAcronym in NotesPlugin NoteAcronym. </summary>
public enum ModActionType
{
/// <summary> Player was banned. </summary>
Expand Down Expand Up @@ -119,6 +119,10 @@ public enum ModActionType
Kicked,
/// <summary> Player was reported </summary>
Reported,
/// <summary> Player was given a note </summary>
Noted,
/// <summary> Player was given a note that only operators may read </summary>
OpNoted,
}

/// <summary> Raised when a moderation action occurs. </summary>
Expand Down
1 change: 1 addition & 0 deletions MCGalaxy/MCGalaxy_.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -590,6 +590,7 @@
<Compile Include="Modules\Games\ZombieSurvival\ZSGame.Plugin.cs" />
<Compile Include="Modules\Games\ZombieSurvival\ZSGame.Round.cs" />
<Compile Include="Modules\Games\ZombieSurvival\ZSPlugin.cs" />
<Compile Include="Modules\Moderation\Notes\CmdNote.cs" />
<Compile Include="Modules\Moderation\Notes\CmdNotes.cs" />
<Compile Include="Modules\Moderation\Notes\NotesPlugin.cs" />
<Compile Include="Modules\Moderation\Review\CmdReview.cs" />
Expand Down
69 changes: 69 additions & 0 deletions MCGalaxy/Modules/Moderation/Notes/CmdNote.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
Copyright 2015 MCGalaxy
Dual-licensed under the Educational Community License, Version 2.0 and
the GNU General Public License, Version 3 (the "Licenses"); you may
not use this file except in compliance with the Licenses. You may
obtain a copy of the Licenses at
https://opensource.org/license/ecl-2-0/
https://www.gnu.org/licenses/gpl-3.0.html
Unless required by applicable law or agreed to in writing,
software distributed under the Licenses are distributed on an "AS IS"
BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the Licenses for the specific language governing
permissions and limitations under the Licenses.
*/
using MCGalaxy.Commands.Moderation;
using MCGalaxy.Events;

namespace MCGalaxy.Modules.Moderation.Notes {
public class CmdNote : Command2 {
public override string name { get { return "Note"; } }
public override string type { get { return CommandTypes.Moderation; } }
public override LevelPermission defaultRank { get { return LevelPermission.AdvBuilder; } }
protected virtual bool announce { get { return true; } }
protected virtual ModActionType modActionType { get { return ModActionType.Noted; } }
public override void Use(Player p, string message, CommandData data) {
if (!Server.Config.LogNotes) {
p.Message("Notes logging must be enabled to note players."); return;
}
if (message.Length == 0) { Help(p); return; }
string[] args = message.SplitSpaces(2);
if (args.Length == 1) { p.Message("&WYou must provide text for the note."); return; }

string note = args[1];
string target = ModActionCmd.FindName(p, "note", "/"+name, "", args[0], ref note);
if (target == null) return;

note = ModActionCmd.ExpandReason(p, note);
if (note == null) return;

Group group = ModActionCmd.CheckTarget(p, data, "note", target);
if (group == null) return;

ModAction action = new ModAction(target, p, modActionType, note);
action.Announce = announce;
OnModActionEvent.Call(action);
}

public override void Help(Player p) {
p.Message("&T/Note [player] [text]");
p.Message("&HAdds a note to [player]'s /notes");
p.Message("&HFor [text], @number can be used as a shortcut for that rule.");
}
}
public class CmdOpNote : CmdNote {
public override string name { get { return "OpNote"; } }
public override LevelPermission defaultRank { get { return LevelPermission.Operator; } }

protected override bool announce { get { return false; } }
protected override ModActionType modActionType { get { return ModActionType.OpNoted; } }
public override void Help(Player p) {
p.Message("&T/OpNote [player] [text]");
p.Message("&HAdds a note to [player]'s /notes that only ops may see.");
p.Message("&HFor [text], @number can be used as a shortcut for that rule.");
}
}
}
24 changes: 19 additions & 5 deletions MCGalaxy/Modules/Moderation/Notes/CmdNotes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,38 @@ class CmdNotes : Command2
p.Message("The server does not have notes logging enabled."); return;
}

List<string> notes = Server.Notes.FindAllExact(name);
List<string> allNotes = Server.Notes.FindAllExact(name);
List<string> visibleNotes;
if (p.group.Permission >= Chat.OpchatPerms.MinRank) {
visibleNotes = allNotes;
} else {
visibleNotes = new List<string>();

foreach (string note in allNotes) {
string[] sections = note.SplitSpaces();
if (sections.Length <= 3) continue; // Malformed note, don't include
if (sections[1] == NoteAcronym.OpNoted.Acronym) continue; // Only Ops may see this note, don't include
visibleNotes.Add(note);
}
}

string nick = p.FormatNick(name);

if (notes.Count == 0) {
if (visibleNotes.Count == 0) {
p.Message("{0} &Shas no notes.", nick); return;
} else {
p.Message(" Notes for {0}:", nick);
}

// special case "/Notes" to show latest notes by default
if (modifier.Length == 0) {
Paginator.Output(p, notes, PrintNote, cmd, "Notes",
(1 + (notes.Count - 8)).ToString());
Paginator.Output(p, visibleNotes, PrintNote, cmd, "Notes",
(1 + (visibleNotes.Count - 8)).ToString());
p.Message("To see all Notes, use &T/{0} all", cmd);
return;
}

Paginator.Output(p, notes, PrintNote,
Paginator.Output(p, visibleNotes, PrintNote,
cmd, "Notes", modifier);
}

Expand Down
33 changes: 16 additions & 17 deletions MCGalaxy/Modules/Moderation/Notes/NotesPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,26 @@
permissions and limitations under the Licenses.
*/
using System;
using System.Collections.Generic;
using MCGalaxy.Events;
using MCGalaxy.Events.ServerEvents;

namespace MCGalaxy.Modules.Moderation.Notes
{
public sealed class NotesPlugin : Plugin
{
public override string name { get { return "Notes"; } }

Command cmdNotes = new CmdNotes();
Command cmdMyNotes = new CmdMyNotes();

static Command[] cmds = new Command[] { new CmdNotes(), new CmdMyNotes(), new CmdNote(), new CmdOpNote(), };

public override void Load(bool startup) {
OnModActionEvent.Register(HandleModerationAction, Priority.Low);
Command.Register(cmdNotes);
Command.Register(cmdMyNotes);
foreach (Command cmd in cmds) { Command.Register(cmd); }
NoteAcronym.Init();
}

public override void Unload(bool shutdown) {
OnModActionEvent.Unregister(HandleModerationAction);
Command.Unregister(cmdNotes, cmdMyNotes);
Command.Unregister(cmds);
}


Expand All @@ -65,18 +62,20 @@ public sealed class NotesPlugin : Plugin
/// </summary>
public class NoteAcronym
{
readonly static NoteAcronym Warned = new NoteAcronym("W", "Warned");
readonly static NoteAcronym Kicked = new NoteAcronym("K", "Kicked");
readonly static NoteAcronym Muted = new NoteAcronym("M", "Muted");
readonly static NoteAcronym Banned = new NoteAcronym("B", "Banned");
readonly static NoteAcronym Jailed = new NoteAcronym("J", "Jailed"); //Jailing was removed, but still appears in notes for historical reasons
readonly static NoteAcronym Frozen = new NoteAcronym("F", "Frozen");
readonly static NoteAcronym TempBanned = new NoteAcronym("T", "Temp-Banned");
private readonly static NoteAcronym Warned = new NoteAcronym("W", "Warned");
private readonly static NoteAcronym Kicked = new NoteAcronym("K", "Kicked");
private readonly static NoteAcronym Muted = new NoteAcronym("M", "Muted");
private readonly static NoteAcronym Banned = new NoteAcronym("B", "Banned");
private readonly static NoteAcronym Jailed = new NoteAcronym("J", "Jailed"); // Jailing was removed, but still appears in notes for historical reasons
private readonly static NoteAcronym Frozen = new NoteAcronym("F", "Frozen");
private readonly static NoteAcronym TempBanned = new NoteAcronym("T", "Temp-Banned");
private readonly static NoteAcronym Noted = new NoteAcronym("N", "Noted");
public readonly static NoteAcronym OpNoted = new NoteAcronym("O", "OpNoted");

static NoteAcronym[] All;

internal static void Init() {
All = new NoteAcronym[] { Warned, Kicked, Muted, Banned, Jailed, Frozen, TempBanned };
All = new NoteAcronym[] { Warned, Kicked, Muted, Banned, Jailed, Frozen, TempBanned, Noted, OpNoted };
}

/// <summary>
Expand All @@ -103,8 +102,8 @@ public class NoteAcronym
return acronym;
}

readonly string Acronym;
readonly string Action;
public readonly string Acronym;
public readonly string Action;

private NoteAcronym(string acronym, string action) {
Acronym = acronym;
Expand Down

0 comments on commit 52c7079

Please sign in to comment.