ModEvents.java
2.68 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
package com.mumfrey.liteloader.transformers.event.json;
import java.io.File;
import java.net.MalformedURLException;
import java.util.HashMap;
import java.util.Map;
import net.minecraft.launchwrapper.Launch;
import com.google.common.base.Charsets;
import com.mumfrey.liteloader.api.ContainerRegistry.DisabledReason;
import com.mumfrey.liteloader.api.EnumerationObserver;
import com.mumfrey.liteloader.core.ModInfo;
import com.mumfrey.liteloader.core.api.LoadableModFile;
import com.mumfrey.liteloader.interfaces.LoadableMod;
import com.mumfrey.liteloader.interfaces.LoaderEnumerator;
import com.mumfrey.liteloader.interfaces.TweakContainer;
import com.mumfrey.liteloader.util.log.LiteLoaderLogger;
public class ModEvents implements EnumerationObserver
{
public static class ModEventDefinition
{
private final LoadableModFile file;
private final String identifier;
private final String json;
public ModEventDefinition(LoadableModFile file, String json)
{
this.file = file;
this.identifier = file.getIdentifier();
this.json = json;
}
public String getIdentifier()
{
return this.identifier;
}
public String getJson()
{
return this.json;
}
public void onEventsInjected()
{
this.file.onEventsInjected();
}
public void injectIntoClassPath()
{
try
{
this.file.injectIntoClassPath(Launch.classLoader, true);
}
catch (MalformedURLException ex)
{
ex.printStackTrace();
}
}
}
private static final String DEFINITION_FILENAME = "events.json";
private static Map<String, ModEventDefinition> events = new HashMap<String, ModEventDefinition>();
@Override
public void onRegisterEnabledContainer(LoaderEnumerator enumerator, LoadableMod<?> container)
{
if (container instanceof LoadableModFile)
{
LoadableModFile file = (LoadableModFile)container;
if (!file.exists()) return;
String json = file.getFileContents(ModEvents.DEFINITION_FILENAME, Charsets.UTF_8);
if (json == null) return;
LiteLoaderLogger.info("Registering %s for mod with id %s", ModEvents.DEFINITION_FILENAME, file.getIdentifier());
ModEvents.events.put(file.getIdentifier(), new ModEventDefinition(file, json));
}
}
@Override
public void onRegisterDisabledContainer(LoaderEnumerator enumerator, LoadableMod<?> container, DisabledReason reason)
{
}
@Override
public void onRegisterTweakContainer(LoaderEnumerator enumerator, TweakContainer<File> container)
{
}
@Override
public void onModAdded(LoaderEnumerator enumerator, ModInfo<LoadableMod<?>> mod)
{
}
static Map<String, ModEventDefinition> getEvents()
{
return events;
}
}