This repository was archived by the owner on Jan 21, 2026. It is now read-only.
forked from Patrikkk/DieMob
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPluginCommands.cs
More file actions
159 lines (148 loc) · 6.56 KB
/
PluginCommands.cs
File metadata and controls
159 lines (148 loc) · 6.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
using CSF;
using CSF.TShock;
using System.Threading.Tasks;
using TShockAPI;
namespace DieMob
{
[RequirePermission("diemob.use")]
class PluginCommands : TSModuleBase<TSCommandContext>
{
[Command("diemob", "dm")]
[Description("DieMob base command")]
public async Task<IResult> DieMobCommand(string sub = "", string args1 = "", string args2 = "")
{
switch (sub.ToLower())
{
case "reload":
Plugin.api.ReloadDieMob();
return Success("DieMob config reloaded independantly.");
case "wipe":
case "clear":
{
var regions = await Plugin.api.RetrieveAllRegions();
foreach (DieMobRegion r in regions)
{
await Plugin.api.DeleteDiemob(r.Region);
}
return Success("All DieMob regions cleared.");
}
case "list":
{
var regions = await Plugin.api.RetrieveAllRegions();
foreach (DieMobRegion r in regions)
{
if (TShock.Regions.GetRegionByName(r.Region) == null)
await Plugin.api.DeleteDiemob(r.Region);
}
int pageNumber;
if (string.IsNullOrWhiteSpace(args1))
pageNumber = 1;
else
{
try
{
pageNumber = int.Parse(args1);
}
catch
{
return Error(
"Couldn't parse page number, please make sure you are entering a valid number!");
}
}
PaginationTools.SendPage(Context.Player, pageNumber, PaginationTools.BuildLinesFromTerms(regions),
new PaginationTools.Settings
{
HeaderFormat = "DieMob Regions ({0}/{1}):",
FooterFormat = "Type /diemob list {0} for more.",
NothingToDisplayString = "There are currently no diemob regions!"
});
return ExecuteResult.FromSuccess();
}
case "create":
case "add":
{
if (!string.IsNullOrEmpty(args1))
{
if (!TShock.Regions.GetRegionByName(args1).Equals(null))
{
if (await Plugin.api.RetrieveRegion(args1) == null)
{
await Plugin.api.CreateDieMobRegion(args1);
return Success($"DieMob region {args1} added.");
}
else return Error($"DieMob region {args1} already exists.");
}
else return Error("That is not a defined TShock region!");
}
else return Error("Please enter a valid region name!");
}
case "delete":
case "remove":
case "rem":
case "del":
{
if (!string.IsNullOrEmpty(args1))
{
if (!TShock.Regions.GetRegionByName(args1).Equals(null))
{
await Plugin.api.DeleteDiemob(args1);
return Success($"You successfully deleted {args1} from diemob!");
}
else return Error("Please enter a valid region name!");
}
else return Error("Please enter a valid region name!");
}
case "type":
{
if (string.IsNullOrWhiteSpace(args1))
{
return Error("Please enter a valid region name!");
}
if (string.IsNullOrWhiteSpace(args2))
{
return Error("Please enter a valid region type: 'normal', or 'repel'.");
}
if (!TShock.Regions.GetRegionByName(args1).Equals(null))
{
var diemobRegion = await Plugin.api.RetrieveRegion(args1);
if (diemobRegion == null)
{
return Error("That region is not a DieMob region.");
}
if (args2.ToLower() == "normal")
{
diemobRegion.Type = RegionType.Kill;
await Plugin.api.SQL.UpdateAsync(diemobRegion);
return Success($"Region {args1} is now a normal DieMob region.");
}
else if (args2.ToLower() == "repel")
{
diemobRegion.Type = RegionType.Repel;
await Plugin.api.SQL.UpdateAsync(diemobRegion);
return Success($"Region {args1} is now a repel DieMob region.");
}
else
{
return Error("Please enter a valid region type: 'normal', or 'repel'.");
}
}
return ExecuteResult.FromSuccess();
}
case "":
case "help":
{
Info("Diemob Commands");
Info("/diemob add <region> - adds a region to diemob");
Info("/diemob clear - clears all diemob regions");
Info("/diemob del <region> - removes a region from diemob");
Info("/diemob help - displays this page");
Info("/diemob list <page> - gets a list of diemob regions");
Info("/diemob type <region> <type> - sets the type of a region to 'normal' or 'repel'");
return Info("/diemob reload - reloads the DieMob configuration.");
}
default:
return Error("Invalid subcommand. Type /diemob help for a list of subcommands.");
}
}
}
}