OrangeGuidanceTomestone/client/Commands.cs

109 lines
3.8 KiB
C#
Raw Permalink Normal View History

2022-09-05 09:33:36 +00:00
using System.Text;
2022-09-04 03:23:19 +00:00
using Dalamud.Game.Command;
2022-09-05 08:02:34 +00:00
using Dalamud.Utility;
using Lumina.Excel.GeneratedSheets;
2022-09-04 03:23:19 +00:00
2022-09-04 19:19:38 +00:00
namespace OrangeGuidanceTomestone;
2022-09-04 03:23:19 +00:00
internal class Commands : IDisposable {
2022-09-05 09:33:36 +00:00
private const string CommandName = "/ogt";
2022-09-04 03:23:19 +00:00
private Plugin Plugin { get; }
internal Commands(Plugin plugin) {
this.Plugin = plugin;
2022-09-05 09:33:36 +00:00
this.Plugin.CommandManager.AddHandler(CommandName, new CommandInfo(this.OnCommand) {
HelpMessage = $"Toggle UI - try {CommandName} help",
2022-09-04 19:19:38 +00:00
});
2022-09-04 03:23:19 +00:00
}
public void Dispose() {
2022-09-05 09:33:36 +00:00
this.Plugin.CommandManager.RemoveHandler(CommandName);
2022-09-04 03:23:19 +00:00
}
2022-09-04 19:19:38 +00:00
2022-09-04 03:23:19 +00:00
private void OnCommand(string command, string arguments) {
2022-09-04 23:43:58 +00:00
switch (arguments) {
2022-09-05 08:02:34 +00:00
case "ban": {
var name = this.Plugin.DataManager.GetExcelSheet<TerritoryType>()?.GetRow(this.Plugin.ClientState.TerritoryType)
?.PlaceName
.Value
?.Name
?.ToDalamudString()
.TextValue;
if (this.Plugin.Config.BannedTerritories.Contains(this.Plugin.ClientState.TerritoryType)) {
this.Plugin.ChatGui.Print($"{name} is already on the ban list.");
return;
}
2022-09-04 23:43:58 +00:00
this.Plugin.Config.BannedTerritories.Add(this.Plugin.ClientState.TerritoryType);
this.Plugin.SaveConfig();
2022-09-05 08:02:34 +00:00
this.Plugin.ChatGui.Print($"Added {name} to the ban list.");
2022-09-13 21:26:54 +00:00
this.Plugin.Framework.RunOnFrameworkThread(() => {
this.Plugin.Messages.RemoveVfx();
this.Plugin.Messages.Clear();
});
2022-09-04 23:43:58 +00:00
break;
2022-09-05 08:02:34 +00:00
}
case "unban": {
var name = this.Plugin.DataManager.GetExcelSheet<TerritoryType>()?.GetRow(this.Plugin.ClientState.TerritoryType)
?.PlaceName
.Value
?.Name
?.ToDalamudString()
.TextValue;
if (!this.Plugin.Config.BannedTerritories.Contains(this.Plugin.ClientState.TerritoryType)) {
this.Plugin.ChatGui.Print($"{name} is not on the ban list.");
return;
}
2022-09-04 23:43:58 +00:00
this.Plugin.Config.BannedTerritories.Remove(this.Plugin.ClientState.TerritoryType);
this.Plugin.SaveConfig();
2022-09-05 08:02:34 +00:00
this.Plugin.ChatGui.Print($"Removed {name} from the ban list.");
2022-09-04 23:43:58 +00:00
this.Plugin.Messages.SpawnVfx();
break;
2022-09-05 08:02:34 +00:00
}
2022-09-04 23:43:58 +00:00
case "refresh":
this.Plugin.Messages.SpawnVfx();
break;
2022-09-05 09:33:36 +00:00
case "viewer":
this.Plugin.Ui.Viewer.Visible ^= true;
break;
case "help": {
var sb = new StringBuilder("\n");
sb.Append(CommandName);
sb.Append(" - open the main interface");
sb.Append('\n');
sb.Append(CommandName);
sb.Append(" ban - bans the current zone, hiding messages");
sb.Append('\n');
sb.Append(CommandName);
sb.Append(" unban - unbans the current zone, allowing messages to appear");
sb.Append('\n');
sb.Append(CommandName);
sb.Append(" refresh - refreshes the messages in the current zone");
sb.Append('\n');
sb.Append(CommandName);
sb.Append(" viewer - toggle the message viewer window");
sb.Append('\n');
sb.Append(CommandName);
sb.Append(" help - show this help");
this.Plugin.ChatGui.Print(sb.ToString());
break;
}
2022-09-04 23:43:58 +00:00
default:
this.Plugin.Ui.MainWindow.Visible ^= true;
break;
}
2022-09-04 03:23:19 +00:00
}
}