• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java LevelInitEvent类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中cn.nukkit.event.level.LevelInitEvent的典型用法代码示例。如果您正苦于以下问题:Java LevelInitEvent类的具体用法?Java LevelInitEvent怎么用?Java LevelInitEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



LevelInitEvent类属于cn.nukkit.event.level包,在下文中一共展示了LevelInitEvent类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: generateLevel

import cn.nukkit.event.level.LevelInitEvent; //导入依赖的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;
}
 
开发者ID:Creeperface01,项目名称:NukkitGT,代码行数:75,代码来源:Server.java


示例2: generateLevel

import cn.nukkit.event.level.LevelInitEvent; //导入依赖的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;
}
 
开发者ID:NycuRO,项目名称:Apollo-OLD,代码行数:75,代码来源:Server.java


示例3: generateLevel

import cn.nukkit.event.level.LevelInitEvent; //导入依赖的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;
}
 
开发者ID:Nukkit,项目名称:Nukkit,代码行数:82,代码来源:Server.java


示例4: onWorldInit

import cn.nukkit.event.level.LevelInitEvent; //导入依赖的package包/类
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
public void onWorldInit(LevelInitEvent event) {
    handle(event.getLevel());
}
 
开发者ID:IntellectualSites,项目名称:PlotSquared,代码行数:5,代码来源:WorldEvents.java



注:本文中的cn.nukkit.event.level.LevelInitEvent类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java AttributeModifier类代码示例发布时间:2022-05-22
下一篇:
Java NormalGenerator类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap