This repository has been archived by the owner on Mar 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
315 lines (304 loc) · 14.9 KB
/
Program.cs
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
using System;
using System.IO;
using System.Net;
using Newtonsoft.Json;
namespace KygekTermDownload
{
class Program
{
public static readonly string userAgent = "kygektermdownload";
public static readonly string PREFIX = "[KygekTermDownload]: ";
public static int Main(string[] args)
{
if (args.Length == 0)
{
SendHelpMessage();
}
else if (args[0].ToLower() == "help")
{
SendHelpMessage();
}
else if (args[0].ToLower() == "pm4")
{
if (args.Length >= 2)
{
if (args[1].ToLower() == "help")
{
SendPM4HelpMessage();
}
else if (args[1].ToLower() == "windows")
{
var client = new WebClient();
Console.WriteLine(PREFIX + "Downloading PHP");
client.DownloadFile("https://jenkins.kygek.team/job/PMMP-4-PHP-Binary/lastSuccessfulBuild/artifact/Windows/PHP_Windows-x86_64.zip", "php.zip");
Console.WriteLine(PREFIX + "Downloading PM4");
client.DownloadFile("https://jenkins.kygek.team/job/PocketMine-MP-4/lastSuccessfulBuild/artifact/PocketMine-MP.phar", "pmmp.phar");
Console.WriteLine(PREFIX + "Downloading Command Prompt start script");
client.DownloadFile("https://jenkins.kygek.team/job/PocketMine-MP-4/lastSuccessfulBuild/artifact/start.cmd", "start.cmd");
Console.WriteLine(PREFIX + "Downloading PowerShell start script");
client.DownloadFile("https://jenkins.kygek.team/job/PocketMine-MP-4/lastSuccessfulBuild/artifact/start.ps1", "start.ps1");
Console.WriteLine(PREFIX + "Finished downloading!");
}
else if (args[1].ToLower() == "mac")
{
var client = new WebClient();
Console.WriteLine(PREFIX + "Downloading PHP");
client.DownloadFile("https://jenkins.kygek.team/job/PMMP-4-PHP-Binary/lastSuccessfulBuild/artifact/Mac/PHP_MacOS-x86_64.tar.gz", "php.tar.gz");
Console.WriteLine(PREFIX + "Downloading PM4");
client.DownloadFile("https://jenkins.kygek.team/job/PocketMine-MP-4/lastSuccessfulBuild/artifact/PocketMine-MP.phar", "pmmp.phar");
Console.WriteLine(PREFIX + "Downloading start script");
client.DownloadFile("https://jenkins.kygek.team/job/PocketMine-MP-4/lastSuccessfulBuild/artifact/start.cmd", "start.sh");
Console.WriteLine(PREFIX + "Finished downloading!");
}
else if (args[1].ToLower() == "linux")
{
var client = new WebClient();
Console.WriteLine(PREFIX + "Downloading PHP");
client.DownloadFile("https://jenkins.kygek.team/job/PMMP-4-PHP-Binary/lastSuccessfulBuild/artifact/Linux/PHP_Linux-x86_64.tar.gz", "php.tar.gz");
Console.WriteLine(PREFIX + "Downloading PM4");
client.DownloadFile("https://jenkins.kygek.team/job/PocketMine-MP-4/lastSuccessfulBuild/artifact/PocketMine-MP.phar", "pmmp.phar");
Console.WriteLine(PREFIX + "Downloading start script");
client.DownloadFile("https://jenkins.kygek.team/job/PocketMine-MP-4/lastSuccessfulBuild/artifact/start.cmd", "start.sh");
Console.WriteLine(PREFIX + "Finished downloading!");
}
else
{
SendPM4HelpMessage();
}
}
else
{
SendPM4HelpMessage();
}
}
else if (args[0].ToLower() == "list")
{
SendListOfPlugins();
}
else if (args[0].ToLower() == "download")
{
if (args.Length >= 2)
{
WebClient client = new WebClient();
Stream data = client.OpenRead("https://api.kygek.team");
StreamReader reader = new StreamReader(data);
string dataString = reader.ReadToEnd();
data.Close();
reader.Close();
KygekPlugin[] plugins = JsonConvert.DeserializeObject<KygekPlugin[]>(dataString);
bool compatible = true;
KygekPlugin match = null;
bool exists = true;
if (args.Length >= 3)
{
if (args[1] == "pmmp")
{
foreach (KygekPlugin plugin in plugins)
{
if (plugin.name.ToLower() == args[2].ToLower())
{
match = plugin;
}
}
if (match == null)
{
exists = false;
}
if (exists)
{
if (match.downloads.poggit == null)
{
compatible = false;
}
if (compatible)
{
Stream data2 = client.OpenRead("https://poggit.pmmp.io/releases.json?name=" + match.name);
StreamReader reader2 = new StreamReader(data2);
string dataString2 = reader2.ReadToEnd();
data2.Close();
reader2.Close();
PoggitArtifact[] artifacts = JsonConvert.DeserializeObject<PoggitArtifact[]>(dataString2);
PoggitArtifact artifact = artifacts[0];
Console.WriteLine("Downloading " + match.name);
client.DownloadFile(artifact.artifact_url, match.name + ".phar");
}
else
{
Console.WriteLine("This plugin isn't compatible with the server type you selected.");
}
}
else
{
Console.WriteLine(PREFIX + "That plugin doesn't exist!");
}
}
else if (args[1] == "nukkit")
{
foreach (KygekPlugin plugin in plugins)
{
if (plugin.name.ToLower() == args[2].ToLower())
{
match = plugin;
}
}
if (match == null)
{
exists = false;
}
if (exists)
{
if (match.downloads.nukkit == null)
{
compatible = false;
}
if (compatible)
{
Console.WriteLine(PREFIX + "Downloading " + match.name);
client.DownloadFile(match.downloads.nukkit + "/download", match.name + ".jar");
}
else
{
Console.WriteLine("This plugin isn't compatible with the server type you selected.");
}
}
else
{
Console.WriteLine(PREFIX + "That plugin doesn't exist!");
}
}
else if (args[1] == "spigot")
{
foreach (KygekPlugin plugin in plugins)
{
if (plugin.name.ToLower() == args[2].ToLower())
{
match = plugin;
}
}
if (match == null)
{
exists = false;
}
if (exists)
{
if (match.downloads.spigot == null)
{
compatible = false;
}
if (compatible)
{
Stream data2 = client.OpenRead("https://api.spiget.org/v2/search/resources/" + match.name + "?field=name");
StreamReader reader2 = new StreamReader(data2);
string dataString2 = reader2.ReadToEnd();
data2.Close();
reader2.Close();
SpigetID[] ids = JsonConvert.DeserializeObject<SpigetID[]>(dataString2);
SpigetID id = ids[0];
Console.WriteLine("Downloading " + match.name);
client.DownloadFile("https://api.spiget.org/v2/resources/" + id.id + "/download", match.name + ".jar");
}
else
{
Console.WriteLine("This plugin isn't compatible with the server type you selected.");
}
}
else
{
Console.WriteLine(PREFIX + "That plugin doesn't exist!");
}
} else
{
Console.WriteLine(PREFIX + "Please specify a server to use!");
Console.WriteLine(PREFIX + "Valid options: pmmp, nukkit, spigot");
}
}
else
{
if (args[1].ToLower() == "pmmp" | args[1].ToLower() == "nukkit" | args[1].ToLower() == "spigot") {
Console.WriteLine(PREFIX + "Please specify a plugin to download!");
}
else
{
Console.WriteLine(PREFIX + "Two errors found:");
Console.WriteLine(" Please specify a server to use!");
Console.WriteLine(" Valid options: pmmp, nukkit, spigot");
Console.WriteLine(" Please specify a plugin to download!");
}
}
}
else
{
Console.WriteLine("Please specify a server to use!");
Console.WriteLine("Valid options: pmmp, nukkit, spigot");
}
}
else if (args[0].ToLower() == "easygamemode")
{
WebClient client = new WebClient();
Console.WriteLine("Downloading KygekEasyGamemode");
client.DownloadFile("https://kygek.team/plugins/KygekEasyGamemode_v1.1.1.phar", "KygekEasyGamemode.phar");
}
else
{
Console.WriteLine(PREFIX + "Command not found");
SendHelpMessage();
}
return 0;
}
private static void SendHelpMessage()
{
Console.WriteLine(PREFIX + "help | Read this message.");
Console.WriteLine(PREFIX + "pm4 | Download the PocketMine-MP 4 binary as well as the PHP binary for your system.");
Console.WriteLine(PREFIX + "list | Get a list of all KygekTeam plugins.");
Console.WriteLine(PREFIX + "download | Downloads a plugin from Poggit, Nukkit resources, or Spigot resources.");
Console.WriteLine(PREFIX + "easygamemode | Downloads KygekEasyGamemode for PocketMine-MP, as you cannot download it from Poggit.");
}
private static void SendPM4HelpMessage()
{
Console.WriteLine(PREFIX + "Usage: ktd pm4 <windows/mac/linux>");
Console.WriteLine(PREFIX + "This command will be slightly different on Mac or Linux.");
}
private static void SendListOfPlugins()
{
WebClient client = new WebClient();
Stream data = client.OpenRead("https://api.kygek.team");
StreamReader reader = new StreamReader(data);
string dataString = reader.ReadToEnd();
data.Close();
reader.Close();
KygekPlugin[] plugins = JsonConvert.DeserializeObject<KygekPlugin[]>(dataString);
foreach (KygekPlugin plugin in plugins)
{
Console.WriteLine(PREFIX + plugin.name + " by " + plugin.author);
Console.WriteLine(" " + plugin.description);
bool poggitExists = true;
bool nukkitExists = true;
bool spigotExists = true;
if (plugin.downloads.poggit == null)
{
poggitExists = false;
}
if (plugin.downloads.nukkit == null)
{
nukkitExists = false;
}
if (plugin.downloads.spigot == null)
{
spigotExists = false;
}
if (poggitExists)
{
Console.WriteLine(" Poggit: " + plugin.downloads.poggit);
}
if (nukkitExists)
{
Console.WriteLine(" Nukkit: " + plugin.downloads.nukkit);
}
if (spigotExists)
{
Console.WriteLine(" Spigot: " + plugin.downloads.spigot);
}
}
}
}
}