本文整理汇总了Java中cn.nukkit.level.format.LevelProviderManager类的典型用法代码示例。如果您正苦于以下问题:Java LevelProviderManager类的具体用法?Java LevelProviderManager怎么用?Java LevelProviderManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LevelProviderManager类属于cn.nukkit.level.format包,在下文中一共展示了LevelProviderManager类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: isLevelGenerated
import cn.nukkit.level.format.LevelProviderManager; //导入依赖的package包/类
public boolean isLevelGenerated(String name) {
if (Objects.equals(name.trim(), "")) {
return false;
}
String path = this.getDataPath() + "worlds/" + name + "/";
if (this.getLevelByName(name) == null) {
if (LevelProviderManager.getProvider(path) == null) {
return false;
}
}
return true;
}
示例2: isLevelGenerated
import cn.nukkit.level.format.LevelProviderManager; //导入依赖的package包/类
public boolean isLevelGenerated(String name) {
if (Objects.equals(name.trim(), "")) {
return false;
}
String path = FastAppender.get(this.getDataPath(), "worlds/", name, "/");
if (this.getLevelByName(name) == null) {
if (LevelProviderManager.getProvider(path) == null) {
return false;
}
}
return true;
}
示例3: onRun
import cn.nukkit.level.format.LevelProviderManager; //导入依赖的package包/类
@Override
public void onRun(){
String path = Server.getInstance().getDataPath() + "worlds/" + world + "/";
Class<? extends LevelProvider > provider = LevelProviderManager.getProvider(path);
if(provider == null) {
message = TextFormat.RED + "Invalid level format";
}
}
示例4: loadLevel
import cn.nukkit.level.format.LevelProviderManager; //导入依赖的package包/类
public boolean loadLevel(String name) {
if (Objects.equals(name.trim(), "")) {
throw new LevelException("Invalid empty level name");
}
if (this.isLevelLoaded(name)) {
return true;
} else if (!this.isLevelGenerated(name)) {
this.logger.notice(this.getLanguage().translateString("nukkit.level.notFound", name));
return false;
}
String path = this.getDataPath() + "worlds/" + name + "/";
Class<? extends LevelProvider> provider = LevelProviderManager.getProvider(path);
if (provider == null) {
this.logger.error(this.getLanguage().translateString("nukkit.level.loadError", new String[]{name, "Unknown provider"}));
return false;
}
Level level;
try {
level = new Level(this, name, path, provider);
} catch (Exception e) {
this.logger.error(this.getLanguage().translateString("nukkit.level.loadError", new String[]{name, e.getMessage()}));
this.logger.logException(e);
return false;
}
this.levels.put(level.getId(), level);
level.initLevel();
this.getPluginManager().callEvent(new LevelLoadEvent(level));
level.setTickRate(this.baseTickRate);
return true;
}
示例5: generateLevel
import cn.nukkit.level.format.LevelProviderManager; //导入依赖的package包/类
public boolean generateLevel(String name, long seed, Class<? extends Generator> generator, Map<String, Object> options) {
if (Objects.equals(name.trim(), "") || this.isLevelGenerated(name)) {
return false;
}
if (!options.containsKey("preset")) {
options.put("preset", this.getPropertyString("generator-settings", ""));
}
if (generator == null) {
generator = Generator.getGenerator(this.getLevelType());
}
Class<? extends LevelProvider> provider;
String providerName;
if ((provider = LevelProviderManager.getProviderByName
(providerName = (String) this.getConfig("level-settings.default-format", "mcregion"))) == null) {
provider = LevelProviderManager.getProviderByName(providerName = "mcregion");
}
Level level;
try {
String path = this.getDataPath() + "worlds/" + name + "/";
provider.getMethod("generate", String.class, String.class, long.class, Class.class, Map.class).invoke(null, path, name, seed, generator, options);
level = new Level(this, name, path, provider);
this.levels.put(level.getId(), level);
level.initLevel();
level.setTickRate(this.baseTickRate);
} catch (Exception e) {
this.logger.error(this.getLanguage().translateString("nukkit.level.generationError", new String[]{name, e.getMessage()}));
this.logger.logException(e);
return false;
}
this.getPluginManager().callEvent(new LevelInitEvent(level));
this.getPluginManager().callEvent(new LevelLoadEvent(level));
/*this.getLogger().notice(this.getLanguage().translateString("nukkit.level.backgroundGeneration", name));
int centerX = (int) level.getSpawnLocation().getX() >> 4;
int centerZ = (int) level.getSpawnLocation().getZ() >> 4;
TreeMap<String, Integer> order = new TreeMap<>();
for (int X = -3; X <= 3; ++X) {
for (int Z = -3; Z <= 3; ++Z) {
int distance = X * X + Z * Z;
int chunkX = X + centerX;
int chunkZ = Z + centerZ;
order.put(Level.chunkHash(chunkX, chunkZ), distance);
}
}
List<Map.Entry<String, Integer>> sortList = new ArrayList<>(order.entrySet());
Collections.sort(sortList, new Comparator<Map.Entry<String, Integer>>() {
@Override
public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
return o2.getValue() - o1.getValue();
}
});
for (String index : order.keySet()) {
Chunk.Entry entry = Level.getChunkXZ(index);
level.populateChunk(entry.chunkX, entry.chunkZ, true);
}*/
return true;
}
示例6: generateLevel
import cn.nukkit.level.format.LevelProviderManager; //导入依赖的package包/类
public boolean generateLevel(String name, long seed, Class<? extends Generator> generator, Map<String, Object> options, Class<? extends LevelProvider> provider) {
if (Objects.equals(name.trim(), "") || this.isLevelGenerated(name)) {
return false;
}
if (!options.containsKey("preset")) {
options.put("preset", this.getPropertyString("generator-settings", ""));
}
if (generator == null) {
generator = Generator.getGenerator(this.getLevelType());
}
if (provider == null) {
if ((provider = LevelProviderManager.getProviderByName
((String) this.getConfig("level-settings.default-format", "anvil"))) == null) {
provider = LevelProviderManager.getProviderByName("anvil");
}
}
Level level;
try {
String path = this.getDataPath() + "worlds/" + name + "/";
provider.getMethod("generate", String.class, String.class, long.class, Class.class, Map.class).invoke(null, path, name, seed, generator, options);
level = new Level(this, name, path, provider);
this.levels.put(level.getId(), level);
level.initLevel();
level.setTickRate(this.baseTickRate);
} catch (Exception e) {
this.logger.error(this.getLanguage().translateString("nukkit.level.generationError", new String[]{name, e.getMessage()}));
this.logger.logException(e);
return false;
}
this.getPluginManager().callEvent(new LevelInitEvent(level));
this.getPluginManager().callEvent(new LevelLoadEvent(level));
/*this.getLogger().notice(this.getLanguage().translateString("nukkit.level.backgroundGeneration", name));
int centerX = (int) level.getSpawnLocation().getX() >> 4;
int centerZ = (int) level.getSpawnLocation().getZ() >> 4;
TreeMap<String, Integer> order = new TreeMap<>();
for (int X = -3; X <= 3; ++X) {
for (int Z = -3; Z <= 3; ++Z) {
int distance = X * X + Z * Z;
int chunkX = X + centerX;
int chunkZ = Z + centerZ;
order.put(Level.chunkHash(chunkX, chunkZ), distance);
}
}
List<Map.Entry<String, Integer>> sortList = new ArrayList<>(order.entrySet());
Collections.sort(sortList, new Comparator<Map.Entry<String, Integer>>() {
@Override
public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
return o2.getValue() - o1.getValue();
}
});
for (String index : order.keySet()) {
Chunk.Entry entry = Level.getChunkXZ(index);
level.populateChunk(entry.chunkX, entry.chunkZ, true);
}*/
return true;
}
示例7: loadLevel
import cn.nukkit.level.format.LevelProviderManager; //导入依赖的package包/类
public boolean loadLevel(String name) {
if (Objects.equals(name.trim(), "")) {
throw new LevelException("Invalid empty level name");
}
if (this.isLevelLoaded(name)) {
return true;
} else if (!this.isLevelGenerated(name)) {
this.logger.notice(this.getLanguage().translateString("nukkit.level.notFound", name));
return false;
}
String path;
if (name.contains("/") || name.contains("\\")) {
path = name;
} else {
path = this.getDataPath() + "worlds/" + name + "/";
}
Class<? extends LevelProvider> provider = LevelProviderManager.getProvider(path);
if (provider == null) {
this.logger.error(this.getLanguage().translateString("nukkit.level.loadError", new String[]{name, "Unknown provider"}));
return false;
}
Level level;
try {
level = new Level(this, name, path, provider);
} catch (Exception e) {
this.logger.error(this.getLanguage().translateString("nukkit.level.loadError", new String[]{name, e.getMessage()}));
this.logger.logException(e);
return false;
}
this.levels.put(level.getId(), level);
level.initLevel();
this.getPluginManager().callEvent(new LevelLoadEvent(level));
level.setTickRate(this.baseTickRate);
return true;
}
示例8: generateLevel
import cn.nukkit.level.format.LevelProviderManager; //导入依赖的package包/类
public boolean generateLevel(String name, long seed, Class<? extends Generator> generator, Map<String, Object> options, Class<? extends LevelProvider> provider) {
if (Objects.equals(name.trim(), "") || this.isLevelGenerated(name)) {
return false;
}
if (!options.containsKey("preset")) {
options.put("preset", this.getPropertyString("generator-settings", ""));
}
if (generator == null) {
generator = Generator.getGenerator(this.getLevelType());
}
if (provider == null) {
if ((provider = LevelProviderManager.getProviderByName
((String) this.getConfig("level-settings.default-format", "anvil"))) == null) {
provider = LevelProviderManager.getProviderByName("anvil");
}
}
String path;
if (name.contains("/") || name.contains("\\")) {
path = name;
} else {
path = this.getDataPath() + "worlds/" + name + "/";
}
Level level;
try {
provider.getMethod("generate", String.class, String.class, long.class, Class.class, Map.class).invoke(null, path, name, seed, generator, options);
level = new Level(this, name, path, provider);
this.levels.put(level.getId(), level);
level.initLevel();
level.getGameRules().setGameRule("spawnRadius", "" + this.getSpawnRadius());
level.setTickRate(this.baseTickRate);
} catch (Exception e) {
this.logger.error(this.getLanguage().translateString("nukkit.level.generationError", new String[]{name, e.getMessage()}));
this.logger.logException(e);
return false;
}
this.getPluginManager().callEvent(new LevelInitEvent(level));
this.getPluginManager().callEvent(new LevelLoadEvent(level));
/*this.getLogger().notice(this.getLanguage().translateString("nukkit.level.backgroundGeneration", name));
int centerX = (int) level.getSpawnLocation().getX() >> 4;
int centerZ = (int) level.getSpawnLocation().getZ() >> 4;
TreeMap<String, Integer> order = new TreeMap<>();
for (int X = -3; X <= 3; ++X) {
for (int Z = -3; Z <= 3; ++Z) {
int distance = X * X + Z * Z;
int chunkX = X + centerX;
int chunkZ = Z + centerZ;
order.put(Level.chunkHash(chunkX, chunkZ), distance);
}
}
List<Map.Entry<String, Integer>> sortList = new ArrayList<>(order.entrySet());
Collections.sort(sortList, new Comparator<Map.Entry<String, Integer>>() {
@Override
public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
return o2.getValue() - o1.getValue();
}
});
for (String index : order.keySet()) {
Chunk.Entry entry = Level.getChunkXZ(index);
level.populateChunk(entry.chunkX, entry.chunkZ, true);
}*/
return true;
}