Commit c6092c8fbb8ca596ab9d0fe9c02e81266f9269da
1 parent
3fba94f0
Pass key to container when fetching mod descriptions
Showing
1 changed file
with
212 additions
and
203 deletions
java/common/com/mumfrey/liteloader/core/Mod.java
1 | -package com.mumfrey.liteloader.core; | ||
2 | - | ||
3 | -import com.mumfrey.liteloader.LiteMod; | ||
4 | -import com.mumfrey.liteloader.interfaces.LoadableMod; | ||
5 | - | ||
6 | -/** | ||
7 | - * ModInfo for an active mod instance | ||
8 | - * | ||
9 | - * @author Adam Mummery-Smith | ||
10 | - */ | ||
11 | -class Mod extends ModInfo<LoadableMod<?>> | ||
12 | -{ | ||
13 | - /** | ||
14 | - * Mod class | ||
15 | - */ | ||
16 | - private final Class<? extends LiteMod> modClass; | ||
17 | - | ||
18 | - /** | ||
19 | - * Mod's key identifier, usually the class simplename | ||
20 | - */ | ||
21 | - private final String key; | ||
22 | - | ||
23 | - /** | ||
24 | - * Mod's identifier (from metadata) | ||
25 | - */ | ||
26 | - private final String identifier; | ||
27 | - | ||
28 | - /** | ||
29 | - * Mod instance | ||
30 | - */ | ||
31 | - private LiteMod instance; | ||
32 | - | ||
33 | - /** | ||
34 | - * Mod display name, initially read from metadata then replaced with real name once instanced | ||
35 | - */ | ||
36 | - private String name; | ||
37 | - | ||
38 | - /** | ||
39 | - * Mod display name, initially read from version then replaced with real version once instanced | ||
40 | - */ | ||
41 | - private String version; | ||
42 | - | ||
43 | - /** | ||
44 | - * @param container | ||
45 | - * @param modClass | ||
46 | - */ | ||
47 | - public Mod(LoadableMod<?> container, Class<? extends LiteMod> modClass) | ||
48 | - { | ||
49 | - this(container, modClass, container != null ? container.getIdentifier() : LiteLoaderEnumerator.getModClassName(modClass)); | ||
50 | - } | ||
51 | - | ||
52 | - /** | ||
53 | - * @param container | ||
54 | - * @param modClass | ||
55 | - * @param identifier | ||
56 | - */ | ||
57 | - public Mod(LoadableMod<?> container, Class<? extends LiteMod> modClass, String identifier) | ||
58 | - { | ||
59 | - super(container != null ? container : LoadableMod.NONE, true); | ||
60 | - | ||
61 | - this.modClass = modClass; | ||
62 | - this.key = modClass.getSimpleName(); | ||
63 | - this.identifier = identifier.toLowerCase(); | ||
64 | - this.name = this.container.getDisplayName(); | ||
65 | - this.version = this.container.getVersion(); | ||
66 | - } | ||
67 | - | ||
68 | - /** | ||
69 | - * Called by the mod manager to instance the mod | ||
70 | - * | ||
71 | - * @throws InstantiationException | ||
72 | - * @throws IllegalAccessException | ||
73 | - */ | ||
74 | - LiteMod newInstance() throws InstantiationException, IllegalAccessException | ||
75 | - { | ||
76 | - if (this.instance != null) | ||
77 | - { | ||
78 | - throw new InstantiationException("Attempted to create an instance of " + this.key + " but the instance was already created"); | ||
79 | - } | ||
80 | - | ||
81 | - this.instance = this.modClass.newInstance(); | ||
82 | - | ||
83 | - String name = this.instance.getName(); | ||
84 | - if (name != null) this.name = name; | ||
85 | - | ||
86 | - String version = this.instance.getVersion(); | ||
87 | - if (version != null) this.version = version; | ||
88 | - | ||
89 | - return this.instance; | ||
90 | - } | ||
91 | - | ||
92 | - /* (non-Javadoc) | ||
93 | - * @see com.mumfrey.liteloader.core.ModInfo#isToggleable() | ||
94 | - */ | ||
95 | - @Override | ||
96 | - public boolean isToggleable() | ||
97 | - { | ||
98 | - return true; | ||
99 | - } | ||
100 | - | ||
101 | - /* (non-Javadoc) | ||
102 | - * @see com.mumfrey.liteloader.core.ModInfo#getMod() | ||
103 | - */ | ||
104 | - @Override | ||
105 | - public LiteMod getMod() | ||
106 | - { | ||
107 | - return this.instance; | ||
108 | - } | ||
109 | - | ||
110 | - /* (non-Javadoc) | ||
111 | - * @see com.mumfrey.liteloader.core.ModInfo#getModClass() | ||
112 | - */ | ||
113 | - @Override | ||
114 | - public Class<? extends LiteMod> getModClass() | ||
115 | - { | ||
116 | - return this.modClass; | ||
117 | - } | ||
118 | - | ||
119 | - /* (non-Javadoc) | ||
120 | - * @see com.mumfrey.liteloader.core.ModInfo#getDisplayName() | ||
121 | - */ | ||
122 | - @Override | ||
123 | - public String getDisplayName() | ||
124 | - { | ||
125 | - return this.name; | ||
126 | - } | ||
127 | - | ||
128 | - /* (non-Javadoc) | ||
129 | - * @see com.mumfrey.liteloader.core.ModInfo#getVersion() | ||
130 | - */ | ||
131 | - @Override | ||
132 | - public String getVersion() | ||
133 | - { | ||
134 | - return this.version; | ||
135 | - } | ||
136 | - | ||
137 | - /* (non-Javadoc) | ||
138 | - * @see com.mumfrey.liteloader.core.ModInfo#getModClassName() | ||
139 | - */ | ||
140 | - @Override | ||
141 | - public String getModClassName() | ||
142 | - { | ||
143 | - return this.modClass.getName(); | ||
144 | - } | ||
145 | - | ||
146 | - /* (non-Javadoc) | ||
147 | - * @see com.mumfrey.liteloader.core.ModInfo#getModClassSimpleName() | ||
148 | - */ | ||
149 | - @Override | ||
150 | - public String getModClassSimpleName() | ||
151 | - { | ||
152 | - return this.key; | ||
153 | - } | ||
154 | - | ||
155 | - /* (non-Javadoc) | ||
156 | - * @see com.mumfrey.liteloader.core.ModInfo#getIdentifier() | ||
157 | - */ | ||
158 | - @Override | ||
159 | - public String getIdentifier() | ||
160 | - { | ||
161 | - return this.identifier; | ||
162 | - } | ||
163 | - | ||
164 | - /** | ||
165 | - * Get whether any of the valid identifiers match the supplied name | ||
166 | - * | ||
167 | - * @param name | ||
168 | - */ | ||
169 | - public boolean matchesName(String name) | ||
170 | - { | ||
171 | - return (name.equalsIgnoreCase(this.instance.getName()) || name.equalsIgnoreCase(this.identifier) || name.equalsIgnoreCase(this.key)); | ||
172 | - } | ||
173 | - | ||
174 | - /** | ||
175 | - * Get whether ths mod identifier matches the supplied identifier | ||
176 | - * | ||
177 | - * @param identifier | ||
178 | - */ | ||
179 | - public boolean matchesIdentifier(String identifier) | ||
180 | - { | ||
181 | - return identifier.equalsIgnoreCase(this.identifier); | ||
182 | - } | ||
183 | - | ||
184 | - /* (non-Javadoc) | ||
185 | - * @see java.lang.Object#equals(java.lang.Object) | ||
186 | - */ | ||
187 | - @Override | ||
188 | - public boolean equals(Object other) | ||
189 | - { | ||
190 | - if (other == null) return false; | ||
191 | - if (!(other instanceof Mod)) return false; | ||
192 | - return ((Mod)other).key.equals(this.key); | ||
193 | - } | ||
194 | - | ||
195 | - /* (non-Javadoc) | ||
196 | - * @see java.lang.Object#hashCode() | ||
197 | - */ | ||
198 | - @Override | ||
199 | - public int hashCode() | ||
200 | - { | ||
201 | - return this.key.hashCode(); | ||
202 | - } | ||
203 | -} | 1 | +package com.mumfrey.liteloader.core; |
2 | + | ||
3 | +import com.mumfrey.liteloader.LiteMod; | ||
4 | +import com.mumfrey.liteloader.interfaces.LoadableMod; | ||
5 | + | ||
6 | +/** | ||
7 | + * ModInfo for an active mod instance | ||
8 | + * | ||
9 | + * @author Adam Mummery-Smith | ||
10 | + */ | ||
11 | +class Mod extends ModInfo<LoadableMod<?>> | ||
12 | +{ | ||
13 | + /** | ||
14 | + * Mod class | ||
15 | + */ | ||
16 | + private final Class<? extends LiteMod> modClass; | ||
17 | + | ||
18 | + /** | ||
19 | + * Mod's key identifier, usually the class simplename | ||
20 | + */ | ||
21 | + private final String key; | ||
22 | + | ||
23 | + /** | ||
24 | + * Mod's identifier (from metadata) | ||
25 | + */ | ||
26 | + private final String identifier; | ||
27 | + | ||
28 | + /** | ||
29 | + * Mod instance | ||
30 | + */ | ||
31 | + private LiteMod instance; | ||
32 | + | ||
33 | + /** | ||
34 | + * Mod display name, initially read from metadata then replaced with real name once instanced | ||
35 | + */ | ||
36 | + private String name; | ||
37 | + | ||
38 | + /** | ||
39 | + * Mod display name, initially read from version then replaced with real version once instanced | ||
40 | + */ | ||
41 | + private String version; | ||
42 | + | ||
43 | + /** | ||
44 | + * @param container | ||
45 | + * @param modClass | ||
46 | + */ | ||
47 | + public Mod(LoadableMod<?> container, Class<? extends LiteMod> modClass) | ||
48 | + { | ||
49 | + this(container, modClass, container != null ? container.getIdentifier() : LiteLoaderEnumerator.getModClassName(modClass)); | ||
50 | + } | ||
51 | + | ||
52 | + /** | ||
53 | + * @param container | ||
54 | + * @param modClass | ||
55 | + * @param identifier | ||
56 | + */ | ||
57 | + public Mod(LoadableMod<?> container, Class<? extends LiteMod> modClass, String identifier) | ||
58 | + { | ||
59 | + super(container != null ? container : LoadableMod.NONE, true); | ||
60 | + | ||
61 | + this.modClass = modClass; | ||
62 | + this.key = modClass.getSimpleName(); | ||
63 | + this.identifier = identifier.toLowerCase(); | ||
64 | + this.name = this.container.getDisplayName(); | ||
65 | + this.version = this.container.getVersion(); | ||
66 | + } | ||
67 | + | ||
68 | + /** | ||
69 | + * Called by the mod manager to instance the mod | ||
70 | + * | ||
71 | + * @throws InstantiationException | ||
72 | + * @throws IllegalAccessException | ||
73 | + */ | ||
74 | + LiteMod newInstance() throws InstantiationException, IllegalAccessException | ||
75 | + { | ||
76 | + if (this.instance != null) | ||
77 | + { | ||
78 | + throw new InstantiationException("Attempted to create an instance of " + this.key + " but the instance was already created"); | ||
79 | + } | ||
80 | + | ||
81 | + this.instance = this.modClass.newInstance(); | ||
82 | + | ||
83 | + String name = this.instance.getName(); | ||
84 | + if (name != null) this.name = name; | ||
85 | + | ||
86 | + String version = this.instance.getVersion(); | ||
87 | + if (version != null) this.version = version; | ||
88 | + | ||
89 | + return this.instance; | ||
90 | + } | ||
91 | + | ||
92 | + /* (non-Javadoc) | ||
93 | + * @see com.mumfrey.liteloader.core.ModInfo#isToggleable() | ||
94 | + */ | ||
95 | + @Override | ||
96 | + public boolean isToggleable() | ||
97 | + { | ||
98 | + return true; | ||
99 | + } | ||
100 | + | ||
101 | + /* (non-Javadoc) | ||
102 | + * @see com.mumfrey.liteloader.core.ModInfo#getMod() | ||
103 | + */ | ||
104 | + @Override | ||
105 | + public LiteMod getMod() | ||
106 | + { | ||
107 | + return this.instance; | ||
108 | + } | ||
109 | + | ||
110 | + /* (non-Javadoc) | ||
111 | + * @see com.mumfrey.liteloader.core.ModInfo#getModClass() | ||
112 | + */ | ||
113 | + @Override | ||
114 | + public Class<? extends LiteMod> getModClass() | ||
115 | + { | ||
116 | + return this.modClass; | ||
117 | + } | ||
118 | + | ||
119 | + /* (non-Javadoc) | ||
120 | + * @see com.mumfrey.liteloader.core.ModInfo#getDisplayName() | ||
121 | + */ | ||
122 | + @Override | ||
123 | + public String getDisplayName() | ||
124 | + { | ||
125 | + return this.name; | ||
126 | + } | ||
127 | + | ||
128 | + /** | ||
129 | + * Get the mod description | ||
130 | + */ | ||
131 | + @Override | ||
132 | + public String getDescription() | ||
133 | + { | ||
134 | + return this.container.getDescription(this.key); | ||
135 | + } | ||
136 | + | ||
137 | + /* (non-Javadoc) | ||
138 | + * @see com.mumfrey.liteloader.core.ModInfo#getVersion() | ||
139 | + */ | ||
140 | + @Override | ||
141 | + public String getVersion() | ||
142 | + { | ||
143 | + return this.version; | ||
144 | + } | ||
145 | + | ||
146 | + /* (non-Javadoc) | ||
147 | + * @see com.mumfrey.liteloader.core.ModInfo#getModClassName() | ||
148 | + */ | ||
149 | + @Override | ||
150 | + public String getModClassName() | ||
151 | + { | ||
152 | + return this.modClass.getName(); | ||
153 | + } | ||
154 | + | ||
155 | + /* (non-Javadoc) | ||
156 | + * @see com.mumfrey.liteloader.core.ModInfo#getModClassSimpleName() | ||
157 | + */ | ||
158 | + @Override | ||
159 | + public String getModClassSimpleName() | ||
160 | + { | ||
161 | + return this.key; | ||
162 | + } | ||
163 | + | ||
164 | + /* (non-Javadoc) | ||
165 | + * @see com.mumfrey.liteloader.core.ModInfo#getIdentifier() | ||
166 | + */ | ||
167 | + @Override | ||
168 | + public String getIdentifier() | ||
169 | + { | ||
170 | + return this.identifier; | ||
171 | + } | ||
172 | + | ||
173 | + /** | ||
174 | + * Get whether any of the valid identifiers match the supplied name | ||
175 | + * | ||
176 | + * @param name | ||
177 | + */ | ||
178 | + public boolean matchesName(String name) | ||
179 | + { | ||
180 | + return (name.equalsIgnoreCase(this.instance.getName()) || name.equalsIgnoreCase(this.identifier) || name.equalsIgnoreCase(this.key)); | ||
181 | + } | ||
182 | + | ||
183 | + /** | ||
184 | + * Get whether ths mod identifier matches the supplied identifier | ||
185 | + * | ||
186 | + * @param identifier | ||
187 | + */ | ||
188 | + public boolean matchesIdentifier(String identifier) | ||
189 | + { | ||
190 | + return identifier.equalsIgnoreCase(this.identifier); | ||
191 | + } | ||
192 | + | ||
193 | + /* (non-Javadoc) | ||
194 | + * @see java.lang.Object#equals(java.lang.Object) | ||
195 | + */ | ||
196 | + @Override | ||
197 | + public boolean equals(Object other) | ||
198 | + { | ||
199 | + if (other == null) return false; | ||
200 | + if (!(other instanceof Mod)) return false; | ||
201 | + return ((Mod)other).key.equals(this.key); | ||
202 | + } | ||
203 | + | ||
204 | + /* (non-Javadoc) | ||
205 | + * @see java.lang.Object#hashCode() | ||
206 | + */ | ||
207 | + @Override | ||
208 | + public int hashCode() | ||
209 | + { | ||
210 | + return this.key.hashCode(); | ||
211 | + } | ||
212 | +} |