LiteLoaderCoreAPI.java
5.23 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
/*
* This file is part of LiteLoader.
* Copyright (C) 2012-16 Adam Mummery-Smith
* All Rights Reserved.
*/
package com.mumfrey.liteloader.core.api;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import com.mumfrey.liteloader.api.EnumeratorModule;
import com.mumfrey.liteloader.api.LiteAPI;
import com.mumfrey.liteloader.api.MixinConfigProvider;
import com.mumfrey.liteloader.core.LiteLoaderVersion;
import com.mumfrey.liteloader.core.api.EnumeratorModuleFiles.ContainerEnvironment;
import com.mumfrey.liteloader.interfaces.ObjectFactory;
import com.mumfrey.liteloader.launch.LoaderEnvironment;
import com.mumfrey.liteloader.launch.LoaderProperties;
import com.mumfrey.liteloader.util.log.LiteLoaderLogger;
/**
* LiteLoader's API impl.
*
* @author Adam Mummery-Smith
*/
public abstract class LiteLoaderCoreAPI implements LiteAPI, MixinConfigProvider
{
protected static final String PKG_LITELOADER = "com.mumfrey.liteloader";
protected static final String PKG_LITELOADER_COMMON = LiteLoaderCoreAPI.PKG_LITELOADER + ".common";
protected LoaderEnvironment environment;
protected LoaderProperties properties;
protected boolean searchClassPath;
protected boolean searchModsFolder;
/* (non-Javadoc)
* @see com.mumfrey.liteloader.api.LiteAPI#getIdentifier()
*/
@Override
public String getIdentifier()
{
return "liteloader";
}
/* (non-Javadoc)
* @see com.mumfrey.liteloader.api.LiteAPI#getName()
*/
@Override
public String getName()
{
return "LiteLoader core API";
}
/* (non-Javadoc)
* @see com.mumfrey.liteloader.api.LiteAPI#getVersion()
*/
@Override
public String getVersion()
{
return LiteLoaderVersion.CURRENT.getLoaderVersion();
}
/* (non-Javadoc)
* @see com.mumfrey.liteloader.api.LiteAPI#getRevision()
*/
@Override
public int getRevision()
{
return LiteLoaderVersion.CURRENT.getLoaderRevision();
}
/* (non-Javadoc)
* @see com.mumfrey.liteloader.api.LiteAPI#getModClassPrefix()
*/
@Override
public String getModClassPrefix()
{
return "LiteMod";
}
/* (non-Javadoc)
* @see com.mumfrey.liteloader.api.LiteAPI#init(
* com.mumfrey.liteloader.launch.LoaderEnvironment,
* com.mumfrey.liteloader.launch.LoaderProperties)
*/
@Override
public void init(LoaderEnvironment environment, LoaderProperties properties)
{
this.environment = environment;
this.properties = properties;
}
/**
* Get the discovery settings from the properties file
*/
void readDiscoverySettings()
{
this.searchModsFolder = this.properties.getAndStoreBooleanProperty(LoaderProperties.OPTION_SEARCH_MODS, true);
this.searchClassPath = this.properties.getAndStoreBooleanProperty(LoaderProperties.OPTION_SEARCH_CLASSPATH, true);
if (!this.searchModsFolder && !this.searchClassPath)
{
LiteLoaderLogger.warning("Invalid configuration, no search locations defined. Enabling all search locations.");
this.searchModsFolder = true;
this.searchClassPath = true;
}
}
/**
* Write settings
*/
void writeDiscoverySettings()
{
this.properties.setBooleanProperty(LoaderProperties.OPTION_SEARCH_MODS, this.searchModsFolder);
this.properties.setBooleanProperty(LoaderProperties.OPTION_SEARCH_CLASSPATH, this.searchClassPath);
}
/* (non-Javadoc)
* @see com.mumfrey.liteloader.api.LiteAPI#getEnumeratorModules()
*/
@Override
public List<EnumeratorModule> getEnumeratorModules()
{
this.readDiscoverySettings();
List<EnumeratorModule> enumeratorModules = new ArrayList<EnumeratorModule>();
if (this.searchClassPath)
{
enumeratorModules.add(new EnumeratorModuleClassPath());
}
ContainerEnvironment containers = new ContainerEnvironment();
if (this.searchModsFolder)
{
File modsFolder = this.environment.getModsFolder();
enumeratorModules.add(new EnumeratorModuleFolder(this, containers, modsFolder, false));
File versionedModsFolder = this.environment.getVersionedModsFolder();
enumeratorModules.add(new EnumeratorModuleFolder(this, containers, versionedModsFolder, true));
}
String modsRepoFile = this.environment.getModsRepoFile();
if (modsRepoFile != null)
{
File modList = new File(modsRepoFile);
enumeratorModules.add(new EnumeratorModuleRepository(this, containers, this.environment.getModRepository(), modList));
}
return Collections.<EnumeratorModule>unmodifiableList(enumeratorModules);
}
/**
* Get the ObjectFactory
*/
public abstract ObjectFactory<?, ?> getObjectFactory();
@Override
public MixinConfigProvider getMixins()
{
return this;
}
@Override
public String[] getMixinConfigs()
{
return new String[] {
"mixins.liteloader.core.json"
};
}
@Override
public String[] getErrorHandlers()
{
return null;
}
}