blob: c52f265f43b14881fac6cfea3a001fed2fe8385e (
plain)
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
|
package com.anthonyhilyard.iceberg.mixin;
import java.lang.reflect.Field;
import java.net.URL;
import java.util.ArrayList;
import java.util.Optional;
import com.anthonyhilyard.iceberg.Loader;
import org.apache.commons.lang3.exception.ExceptionUtils;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import net.minecraft.server.Main;
import net.minecraftforge.fml.loading.FMLLoader;
import net.minecraftforge.fml.loading.moddiscovery.ModInfo;
import net.minecraftforge.forgespi.language.IModInfo;
@Mixin(Main.class)
public class MainMixin
{
@SuppressWarnings("unchecked")
@Inject(method = "main", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/server/loading/ServerModLoader;load()V", remap = false), remap = false)
private static void fixUpdateURLs(String[] args, CallbackInfo info)
{
for (IModInfo mod : FMLLoader.getLoadingModList().getMods())
{
Optional<Object> authors = mod.getConfig().getConfigElement("authors");
if (!authors.isPresent())
{
continue;
}
boolean madeByGrend = false;
if (authors.get() instanceof String author)
{
madeByGrend = author.contentEquals("Grend");
}
else if (authors.get() instanceof ArrayList<?> authorList)
{
madeByGrend = authorList.contains("Grend");
}
if (madeByGrend)
{
// Found a mod I made, so patch the update URL.
// Yeah, it's a dirty hack but it lets me fix all my mods at once before I have the time to update them all properly.
ModInfo modInfo = (ModInfo)mod;
try
{
Field updateJSONURLField = ModInfo.class.getDeclaredField("updateJSONURL");
updateJSONURLField.setAccessible(true);
Optional<URL> updateJSONURL = (Optional<URL>)updateJSONURLField.get(modInfo);
if (updateJSONURL.isPresent())
{
String url = updateJSONURL.get().toString();
url = url.replace("mc-curse-update-checker.herokuapp.com", "mc-update-check.anthonyhilyard.com");
updateJSONURLField.set(modInfo, Optional.of(new URL(url)));
}
}
catch (Exception e)
{
Loader.LOGGER.debug(ExceptionUtils.getStackTrace(e));
}
}
}
}
}
|