ModInfo.java
5.24 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
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
/*
* This file is part of LiteLoader.
* Copyright (C) 2012-16 Adam Mummery-Smith
* All Rights Reserved.
*/
package com.mumfrey.liteloader.core;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import com.google.common.collect.ImmutableSet;
import com.mumfrey.liteloader.LiteMod;
import com.mumfrey.liteloader.interfaces.Loadable;
import com.mumfrey.liteloader.interfaces.LoadableMod;
import com.mumfrey.liteloader.interfaces.MixinContainer;
import com.mumfrey.liteloader.interfaces.TweakContainer;
/**
* ModInfo is used to keep runtime information about a mod (or other injectable)
* together with relevant environmental information (such as startup errors) and
* its container.
*
* @author Adam Mummery-Smith
*
* @param <TContainer> type of container
*/
public abstract class ModInfo<TContainer extends Loadable<?>>
{
/**
* List of built-in APIs, used to filter for 3rd-party APIs
*/
protected static final Set<String> BUILT_IN_APIS = ImmutableSet.of("liteloader");
/**
* Container instance
*/
protected final TContainer container;
/**
* True if this mod is active/injected or not active/errored
*/
protected final boolean active;
/**
* Startup errors encountered whilst loading this mod
*/
private final List<Throwable> startupErrors = new ArrayList<Throwable>();
/**
* @param container
* @param active
*/
protected ModInfo(TContainer container, boolean active)
{
this.container = container;
this.active = active;
}
/**
* Get whether this mod is currently active
*/
public final boolean isActive()
{
return this.active;
}
/**
* Get whether this mod is valid
*/
public boolean isValid()
{
return true;
}
/**
* Get whether this mod can be toggled
*/
public boolean isToggleable()
{
return this.container.isToggleable();
}
/**
* Get whether this mod has a container
*/
public final boolean hasContainer()
{
return this.container != LoadableMod.NONE;
}
/**
* Get the container for this mod
*/
public final TContainer getContainer()
{
return this.container;
}
/**
* Callback to allow the mod manager to register a startup error
*/
void registerStartupError(Throwable th)
{
this.startupErrors.add(th);
}
/**
* Get startup errors for this instance
*/
public List<Throwable> getStartupErrors()
{
return Collections.unmodifiableList(this.startupErrors);
}
/**
* Get the display name for this mod
*/
public String getDisplayName()
{
return this.container.getDisplayName();
}
/**
* Get the mod version
*/
public String getVersion()
{
return this.container.getVersion();
}
/**
* Get the nod identifier
*/
public String getIdentifier()
{
return this.container.getIdentifier();
}
/**
* Get the mod URL
*/
public String getURL()
{
return this.container instanceof LoadableMod<?> ? ((LoadableMod<?>)this.container).getMetaValue("url", "") : null;
}
/**
* Get the mod author(s)
*/
public String getAuthor()
{
return this.container.getAuthor();
}
/**
* Get the mod description
*/
public String getDescription()
{
return this.container.getDescription(null);
}
/**
* If this container has a tweak
*/
public boolean hasTweakClass()
{
return (this.container instanceof TweakContainer && ((TweakContainer<?>)this.container).hasTweakClass());
}
/**
* If this has transformers (NOT robots in disguise, the other kind)
*/
public boolean hasClassTransformers()
{
return (this.container instanceof TweakContainer && ((TweakContainer<?>)this.container).hasClassTransformers());
}
/**
* If this has JSON event transformers
*/
public boolean hasEventTransformers()
{
return (this.container instanceof TweakContainer && ((TweakContainer<?>)this.container).hasEventTransformers());
}
/**
* If this has mixins
*/
public boolean hasMixins()
{
return (this.container instanceof MixinContainer && ((MixinContainer<?>)this.container).hasMixins());
}
/**
* Get whether this mod uses external (3rd-party) API
*/
public boolean usesAPI()
{
if (this.container instanceof LoadableMod<?>)
{
for (String requiredAPI : ((LoadableMod<?>)this.container).getRequiredAPIs())
{
if (!ModInfo.BUILT_IN_APIS.contains(requiredAPI))
{
return true;
}
}
}
return false;
}
/**
* Get the mod instance
*/
public abstract LiteMod getMod();
/**
* Get the mod class
*/
public abstract Class<? extends LiteMod> getModClass();
/**
* Get the mod class full name
*/
public abstract String getModClassName();
/**
* Get the mod class simple name
*/
public abstract String getModClassSimpleName();
}