Skip to content

Commit 75976a6

Browse files
committed
[F] Server: Fix blacklist loading
1 parent fb192f8 commit 75976a6

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

src/main/java/org/hydev/mcpm/server/crawlers/SpigetCrawler.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.hydev.mcpm.utils.PluginJarFile;
1010
import org.hydev.mcpm.utils.StoredHashMap;
1111
import org.hydev.mcpm.utils.TemporaryDir;
12+
import org.yaml.snakeyaml.error.YAMLException;
1213

1314
import java.io.File;
1415
import java.io.IOException;
@@ -38,7 +39,7 @@ public class SpigetCrawler
3839
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36";
3940
private final long mtDelay = 1000;
4041
private final File dataDir;
41-
private final StoredHashMap<Long, String> blacklist;
42+
private final StoredHashMap<String, String> blacklist;
4243

4344
public SpigetCrawler(File dataDir)
4445
{
@@ -170,7 +171,7 @@ private File getLatestPath(SpigetResource res)
170171
private void checkUpdate(SpigetResource res)
171172
{
172173
// Plugin is in the blacklist, skip
173-
if (blacklist.containsKey(res.id())) return;
174+
if (blacklist.containsKey("" + res.id())) return;
174175

175176
// Latest version already exists in local fs, skip
176177
var fp = getLatestPath(res);
@@ -202,7 +203,7 @@ private void checkUpdate(SpigetResource res)
202203
{
203204
// Cannot read plugin.yml, that means it's not a standard plugin, add to blacklist
204205
System.out.printf("Cannot read plugin.yml (%s: %s)\n", res.id(), res.name());
205-
blacklist.put(res.id(), "Cannot read plugin.yml");
206+
blacklist.put("" + res.id(), "Cannot read plugin.yml");
206207
return;
207208
}
208209

@@ -221,15 +222,15 @@ private void checkUpdate(SpigetResource res)
221222
{
222223
// Not found
223224
if (e.getMessage().contains("404"))
224-
blacklist.put(res.id(), "HTTP 404: Not found");
225+
blacklist.put("" + res.id(), "HTTP 404: Not found");
225226

226227
// "External resource cannot be downloaded"
227228
else if (e.getMessage().contains("400"))
228-
blacklist.put(res.id(), "HTTP 400: Probably external resource");
229+
blacklist.put("" + res.id(), "HTTP 400: Probably external resource");
229230

230231
// Blocked by cloudflare
231232
else if (e.getMessage().contains("520"))
232-
blacklist.put(res.id(), "HTTP 520: External site, blocked by CloudFlare");
233+
blacklist.put("" + res.id(), "HTTP 520: External site, blocked by CloudFlare");
233234

234235
// This happens when the server has an error (e.g. when a plugin doesn't have files to download)
235236
//else if (e.getMessage().contains("502")) return;
@@ -274,11 +275,11 @@ public void links()
274275
linkPath.getParentFile().mkdirs();
275276
createSymbolicLink(linkPath.toPath(), linkPath.getParentFile().toPath().relativize(ver.toPath()));
276277
}
277-
catch (IOException e)
278+
catch (IOException | YAMLException | NullPointerException e)
278279
{
279280
// TODO: Better error handling
280281
//e.printStackTrace();
281-
throw new RuntimeException(e);
282+
System.out.printf("Cannot read plugin.yml for %s: %s\n", ver, e);
282283
}
283284
});
284285
});
@@ -292,7 +293,7 @@ public void links()
292293
public static void main(String[] args)
293294
{
294295
var crawler = new SpigetCrawler(new File(".mcpm"));
295-
var res = crawler.crawlAllResources(false).stream()
296+
var res = crawler.crawlAllResources(true).stream()
296297
.filter(it -> it.downloads() > 100 && !it.external()).toList();
297298

298299
System.out.println(res.size());

0 commit comments

Comments
 (0)