Bukkit teleport - nullPointerException

元气小坏坏 提交于 2019-12-02 10:08:30

It seems like this world is not loaded yet. You have to load it first.

This snippets checks if the world is null. If it is null, it loads(if the world already exists) or creates(if the world doesn't exist yet) the world.

@EventHandler
public static void onPortalTravel(PlayerPortalEvent event) throws Exception {
    if (event.getCause() == PlayerPortalEvent.TeleportCause.END_PORTAL) {
        int x = event.getPlayer().getLocation().getBlockX();
        int y = event.getPlayer().getLocation().getBlockY();
        int z = event.getPlayer().getLocation().getBlockZ();

        String[] data = getPageData("http://example.com/game.php?type=getRealm&location="+x+":"+y+":"+z).split(":"); // THIS RETURNS <username>:<oldblockid>
        String realm = data[0];
        int oldID = Integer.parseInt(data[1].trim());

        Bukkit.getServer().getWorld("world").getBlockAt(x, y, z).setTypeId(oldID);
        World world = Bukkit.getWorld("realms/" + realm);
        if(world == null){
            //Loads a world with the name given in the constructor
            WorldCreator wc = new WorldCreator("realms/" + realm);
            world = Bukkit.createWorld(wc);

        }
        event.getPlayer().teleport(new Location(world, 1, 65,16.5));
    }

}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!