use of net.glowstone.util.library.LibraryManager in project Glowstone by GlowstoneMC.
the class GlowServer method start.
/**
* Starts this server.
*/
public void start() {
// Determine console mode and start reading input
consoleManager.startConsole(config.getBoolean(Key.USE_JLINE));
consoleManager.startFile(config.getString(Key.LOG_FILE));
if (getProxySupport()) {
if (getOnlineMode()) {
ConsoleMessages.Info.Proxy.ONLINE.log();
} else {
ConsoleMessages.Info.PROXY.log();
}
} else if (!getOnlineMode()) {
ConsoleMessages.Warn.OFFLINE.log();
}
int openClMajor = 1;
int openClMinor = 2;
if (doesUseGraphicsCompute()) {
int maxGpuFlops = 0;
int maxIntelFlops = 0;
int maxCpuFlops = 0;
CLPlatform bestPlatform = null;
CLPlatform bestIntelPlatform = null;
CLPlatform bestCpuPlatform = null;
// gets the max flops device across platforms on the computer
for (CLPlatform platform : CLPlatform.listCLPlatforms()) {
if (platform.isAtLeast(openClMajor, openClMinor) && platform.isExtensionAvailable("cl_khr_fp64")) {
// NON-NLS
for (CLDevice device : platform.listCLDevices()) {
if (device.getType() == CLDevice.Type.GPU) {
int flops = device.getMaxComputeUnits() * device.getMaxClockFrequency();
ConsoleMessages.Info.Opencl.FOUND_DEVICE.log(device, flops);
if (device.getVendor().contains("Intel")) {
// NON-NLS
if (flops > maxIntelFlops) {
maxIntelFlops = flops;
ConsoleMessages.Info.Opencl.BEST.log(platform);
bestIntelPlatform = platform;
} else if (flops == maxIntelFlops) {
if (bestIntelPlatform != null && bestIntelPlatform.getVersion().compareTo(platform.getVersion()) < 0) {
maxIntelFlops = flops;
ConsoleMessages.Info.Opencl.BEST_VERSION_TIEBREAKER.log(platform);
bestIntelPlatform = platform;
}
}
} else {
if (flops > maxGpuFlops) {
maxGpuFlops = flops;
ConsoleMessages.Info.Opencl.BEST.log(platform);
bestPlatform = platform;
} else if (flops == maxGpuFlops) {
if (bestPlatform != null && bestPlatform.getVersion().compareTo(platform.getVersion()) < 0) {
maxGpuFlops = flops;
ConsoleMessages.Info.Opencl.BEST_VERSION_TIEBREAKER.log(platform);
bestPlatform = platform;
}
}
}
} else {
int flops = device.getMaxComputeUnits() * device.getMaxClockFrequency();
ConsoleMessages.Info.Opencl.FOUND_DEVICE.log(device, flops);
if (flops > maxCpuFlops) {
maxCpuFlops = flops;
ConsoleMessages.Info.Opencl.BEST.log(platform);
bestCpuPlatform = platform;
} else if (flops == maxCpuFlops) {
if (bestCpuPlatform != null && bestCpuPlatform.getVersion().compareTo(platform.getVersion()) < 0) {
maxCpuFlops = flops;
ConsoleMessages.Info.Opencl.BEST_VERSION_TIEBREAKER.log(platform);
bestCpuPlatform = platform;
}
}
}
}
}
}
if (config.getBoolean(Key.GRAPHICS_COMPUTE_ANY_DEVICE)) {
if (maxGpuFlops - maxIntelFlops < 0 && maxCpuFlops - maxIntelFlops <= 0) {
bestPlatform = bestIntelPlatform;
} else if (maxGpuFlops - maxCpuFlops < 0 && maxIntelFlops - maxCpuFlops < 0) {
bestPlatform = bestCpuPlatform;
}
} else {
if (maxGpuFlops == 0) {
if (maxIntelFlops == 0) {
ConsoleMessages.Info.Opencl.CPU.log();
bestPlatform = bestCpuPlatform;
} else {
ConsoleMessages.Info.Opencl.INTEL_GPU.log();
bestPlatform = bestIntelPlatform;
}
}
}
if (bestPlatform == null) {
isGraphicsComputeAvailable = false;
ConsoleMessages.Info.Opencl.NO_DEVICE.log();
ConsoleMessages.Info.Opencl.REQUIRED_VERSION.log(openClMajor, openClMinor);
ConsoleMessages.Info.Opencl.REQUIRED_EXTENSIONS.log();
} else {
OpenCompute.initContext(bestPlatform);
}
}
// Load player lists
opsList.load();
whitelist.load();
nameBans.load();
ipBans.load();
setPort(config.getInt(Key.SERVER_PORT));
setIp(config.getString(Key.SERVER_IP));
try {
LootingManager.load();
} catch (Exception e) {
ConsoleMessages.Error.LOOTING_MANAGER.log();
e.printStackTrace();
}
// Start loading plugins
String repository = config.getString(Key.LIBRARY_REPOSITORY_URL);
String libraryFolder = config.getString(Key.LIBRARIES_FOLDER);
Set<Library> libraries = aggregateLibraries(repository, libraryFolder);
new LibraryManager(repository, libraryFolder, config.getBoolean(Key.LIBRARY_CHECKSUM_VALIDATION), config.getInt(Key.LIBRARY_DOWNLOAD_ATTEMPTS), libraries).run();
loadPlugins();
enablePlugins(PluginLoadOrder.STARTUP);
// Create worlds
String seedString = config.getString(Key.LEVEL_SEED);
WorldType type = WorldType.getByName(getWorldType());
if (type == null) {
type = WorldType.NORMAL;
}
long seed = new Random().nextLong();
if (!seedString.isEmpty()) {
try {
long parsed = Long.parseLong(seedString);
if (parsed != 0) {
seed = parsed;
}
} catch (NumberFormatException ex) {
seed = seedString.hashCode();
}
}
if (storageProviderFactory == null) {
storageProviderFactory = (worldName) -> new AnvilWorldStorageProvider(new File(getWorldContainer(), worldName));
}
String name = config.getString(Key.LEVEL_NAME);
boolean structs = getGenerateStructures();
createWorld(WorldCreator.name(name).environment(Environment.NORMAL).seed(seed).type(type).generateStructures(structs));
if (getAllowNether()) {
checkTransfer(name, "_nether", Environment.NETHER);
createWorld(// NON-NLS
WorldCreator.name(name + "_nether").environment(Environment.NETHER).seed(seed).type(type).generateStructures(structs));
}
if (getAllowEnd()) {
checkTransfer(name, "_the_end", Environment.THE_END);
createWorld(// NON-NLS
WorldCreator.name(name + "_the_end").environment(Environment.THE_END).seed(seed).type(type).generateStructures(structs));
}
// Finish loading plugins
enablePlugins(PluginLoadOrder.POSTWORLD);
commandMap.registerServerAliases();
scheduler.start();
}
Aggregations