use of org.bukkit.WorldType in project CommandHelper by EngineHub.
the class BukkitMCWorldCreator method type.
@Override
public MCWorldCreator type(MCWorldType type) {
WorldType wt = BukkitMCWorldType.getConvertor().getConcreteEnum(type);
creator.type(wt);
return this;
}
use of org.bukkit.WorldType 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();
}
use of org.bukkit.WorldType in project Glowstone by GlowstoneMC.
the class OverworldGenerator method generateTerrainDensity.
private void generateTerrainDensity(World world, int x, int z) {
WorldType type = world.getWorldType();
// Scaling chunk x and z coordinates (4x, see below)
x <<= 2;
z <<= 2;
// Get biome grid data at lower res (scaled 4x, at this scale a chunk is 4x4 columns of
// the biome grid),
// we are loosing biome detail but saving huge amount of computation.
// We need 1 chunk (4 columns) + 1 column for later needed outer edges (1 column) and at
// least 2 columns
// on each side to be able to cover every value.
// 4 + 1 + 2 + 2 = 9 columns but the biomegrid generator needs a multiple of 2 so we ask
// 10 columns wide
// to the biomegrid generator.
// This gives a total of 81 biome grid columns to work with, and this includes the chunk
// neighborhood.
int[] biomeGrid = ((GlowWorld) world).getChunkManager().getBiomeGridAtLowerRes(x - 2, z - 2, 10, 10);
Map<String, OctaveGenerator> octaves = getWorldOctaves(world);
double[] heightNoise = ((PerlinOctaveGenerator) octaves.get("height")).getFractalBrownianMotion(x, z, 0.5D, 2.0D);
double[] roughnessNoise = ((PerlinOctaveGenerator) octaves.get("roughness")).getFractalBrownianMotion(x, 0, z, 0.5D, 2.0D);
double[] roughnessNoise2 = ((PerlinOctaveGenerator) octaves.get("roughness2")).getFractalBrownianMotion(x, 0, z, 0.5D, 2.0D);
double[] detailNoise = ((PerlinOctaveGenerator) octaves.get("detail")).getFractalBrownianMotion(x, 0, z, 0.5D, 2.0D);
int index = 0;
int indexHeight = 0;
// terrain.
for (int i = 0; i < 5; i++) {
for (int j = 0; j < 5; j++) {
double avgHeightScale = 0;
double avgHeightBase = 0;
double totalWeight = 0;
Biome biome = GlowBiome.getBiome(biomeGrid[i + 2 + (j + 2) * 10]).getType();
BiomeHeight biomeHeight = HEIGHT_MAP.getOrDefault(biome, defaultHeight);
// of the current biomegrid column.
for (int m = 0; m < 5; m++) {
for (int n = 0; n < 5; n++) {
Biome nearBiome = GlowBiome.getBiome(biomeGrid[i + m + (j + n) * 10]).getType();
BiomeHeight nearBiomeHeight = HEIGHT_MAP.getOrDefault(nearBiome, defaultHeight);
double heightBase = biomeHeightOffset + nearBiomeHeight.getHeight() * biomeHeightWeight;
double heightScale = biomeScaleOffset + nearBiomeHeight.getScale() * biomeScaleWeight;
if (type == WorldType.AMPLIFIED && heightBase > 0) {
heightBase = 1.0D + heightBase * 2.0D;
heightScale = 1.0D + heightScale * 4.0D;
}
double weight = ELEVATION_WEIGHT[m][n] / (heightBase + 2.0D);
if (nearBiomeHeight.getHeight() > biomeHeight.getHeight()) {
weight *= 0.5D;
}
avgHeightScale += heightScale * weight;
avgHeightBase += heightBase * weight;
totalWeight += weight;
}
}
avgHeightScale /= totalWeight;
avgHeightBase /= totalWeight;
avgHeightScale = avgHeightScale * 0.9D + 0.1D;
avgHeightBase = (avgHeightBase * 4.0D - 1.0D) / 8.0D;
double noiseH = heightNoise[indexHeight++] / 8000.0D;
if (noiseH < 0) {
noiseH = Math.abs(noiseH) * 0.3D;
}
noiseH = noiseH * 3.0D - 2.0D;
if (noiseH < 0) {
noiseH = Math.max(noiseH * 0.5D, -1) / 1.4D * 0.5D;
} else {
noiseH = Math.min(noiseH, 1) / 8.0D;
}
noiseH = (noiseH * 0.2D + avgHeightBase) * baseSize / 8.0D * 4.0D + baseSize;
for (int k = 0; k < 33; k++) {
// density should be lower and lower as we climb up, this gets a height value to
// subtract from the noise.
double nh = (k - noiseH) * stretchY * 128.0D / 256.0D / avgHeightScale;
if (nh < 0.0D) {
nh *= 4.0D;
}
double noiseR = roughnessNoise[index] / 512.0D;
double noiseR2 = roughnessNoise2[index] / 512.0D;
double noiseD = (detailNoise[index] / 10.0D + 1.0D) / 2.0D;
// linear interpolation
double dens = noiseD < 0 ? noiseR : noiseD > 1 ? noiseR2 : noiseR + (noiseR2 - noiseR) * noiseD;
dens -= nh;
index++;
if (k > 29) {
double lowering = (k - 29) / 3.0D;
// linear interpolation
dens = dens * (1.0D - lowering) + -10.0D * lowering;
}
density[i][j][k] = dens;
}
}
}
}
use of org.bukkit.WorldType in project Denizen-For-Bukkit by DenizenScript.
the class CreateWorldCommand method execute.
@Override
public void execute(ScriptEntry scriptEntry) {
ElementTag worldName = scriptEntry.getElement("world_name");
ElementTag generator = scriptEntry.argForPrefixAsElement("generator", null);
ElementTag worldType = scriptEntry.argForPrefixAsElement("worldtype", "NORMAL");
ElementTag environment = scriptEntry.argForPrefixAsElement("environment", "NORMAL");
ElementTag copy_from = scriptEntry.argForPrefixAsElement("copy_from", null);
ElementTag settings = scriptEntry.argForPrefixAsElement("settings", null);
ElementTag seed = scriptEntry.argForPrefixAsElement("seed", null);
ElementTag generateStructures = scriptEntry.argForPrefixAsElement("generate_structures", null);
if (scriptEntry.dbCallShouldDebug()) {
Debug.report(scriptEntry, getName(), worldName, generator, environment, copy_from, settings, worldType, seed, generateStructures);
}
if (Bukkit.getWorld(worldName.asString()) != null) {
Debug.echoDebug(scriptEntry, "CreateWorld doing nothing, world by that name already loaded.");
scriptEntry.setFinished(true);
return;
}
if (!Settings.cache_createWorldSymbols && forbiddenSymbols.containsAnyMatch(worldName.asString())) {
Debug.echoError("Cannot use world names with non-alphanumeric symbols due to security settings in Denizen/config.yml.");
scriptEntry.setFinished(true);
return;
}
final File newFolder = new File(Bukkit.getWorldContainer(), worldName.asString());
if (!Utilities.canWriteToFile(newFolder)) {
Debug.echoError("Cannot copy to that new folder path due to security settings in Denizen/config.yml.");
scriptEntry.setFinished(true);
return;
}
WorldType enumWorldType;
World.Environment enumEnvironment;
try {
enumWorldType = WorldType.valueOf(worldType.asString().toUpperCase());
enumEnvironment = World.Environment.valueOf(environment.asString().toUpperCase());
} catch (IllegalArgumentException ex) {
Debug.echoError("Invalid worldtype or environment: " + ex.getMessage());
scriptEntry.setFinished(true);
return;
}
Supplier<Boolean> copyRunnable = () -> {
try {
if (!Settings.cache_createWorldSymbols && forbiddenSymbols.containsAnyMatch(copy_from.asString())) {
Debug.echoError("Cannot use copy_from world names with non-alphanumeric symbols due to security settings in Denizen/config.yml.");
return false;
}
File folder = new File(Bukkit.getWorldContainer(), copy_from.asString().replace("w@", ""));
if (!Utilities.canReadFile(folder)) {
Debug.echoError("Cannot copy from that folder path due to security settings in Denizen/config.yml.");
return false;
}
if (!folder.exists() || !folder.isDirectory()) {
Debug.echoError(scriptEntry, "Invalid copy from world folder - does not exist!");
return false;
}
if (newFolder.exists()) {
Debug.echoError("Cannot copy to new world - that folder already exists.");
return false;
}
CoreUtilities.copyDirectory(folder, newFolder, excludedExtensionsForCopyFrom);
Debug.echoDebug(scriptEntry, "Copied " + folder.getName() + " to " + newFolder.getName());
File file = new File(Bukkit.getWorldContainer(), worldName.asString() + "/uid.dat");
if (file.exists()) {
file.delete();
}
File file2 = new File(Bukkit.getWorldContainer(), worldName.asString() + "/session.lock");
if (file2.exists()) {
file2.delete();
}
} catch (Throwable ex) {
Debug.echoError(ex);
return false;
}
return true;
};
Runnable createRunnable = () -> {
World world;
WorldCreator worldCreator = WorldCreator.name(worldName.asString()).environment(enumEnvironment).type(enumWorldType);
if (generateStructures != null) {
worldCreator.generateStructures(generateStructures.asBoolean());
}
if (generator != null) {
worldCreator.generator(generator.asString());
}
if (seed != null) {
worldCreator.seed(seed.asLong());
}
if (settings != null) {
worldCreator.generatorSettings(settings.asString());
}
world = Bukkit.getServer().createWorld(worldCreator);
if (world == null) {
Debug.echoError("World is null, something went wrong in creation!");
} else {
Debug.echoDebug(scriptEntry, "Created new world " + world.getName());
}
scriptEntry.setFinished(true);
};
if (scriptEntry.shouldWaitFor() && copy_from != null) {
Bukkit.getScheduler().runTaskAsynchronously(Denizen.getInstance(), () -> {
if (!copyRunnable.get()) {
scriptEntry.setFinished(true);
return;
}
Bukkit.getScheduler().runTask(Denizen.getInstance(), createRunnable);
});
} else {
if (copy_from != null && !copyRunnable.get()) {
return;
}
createRunnable.run();
}
}
Aggregations