[SOLVED] Teleportation to an unloaded and potentially ungenerated chunk of another world.

Discussion in 'Plugin Development' started by Derthmonuter, Jun 11, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    Derthmonuter

    Hello everyone.

    I am trying to accomplish the above. The teleporation works fine, but my server crashes frequently.
    My code for teleporting is as follows:

    Location below = new Location(world, x, 266, z);
    world.loadChunk(world.getChunkAt(below));
    player.teleport(below);

    However, I am recieving the following error and a crash to my server:

    2012-06-11 18:22:58 [SEVERE] java.util.ConcurrentModificationException
    2012-06-11 18:22:58 [SEVERE] at java.util.HashMap$HashIterator.nextEntry(HashMap.java:806)
    2012-06-11 18:22:58 [SEVERE] at java.util.HashMap$KeyIterator.next(HashMap.java:841)
    2012-06-11 18:22:58 [SEVERE] Unexpected exception
    java.util.ConcurrentModificationException
    at java.util.HashMap$HashIterator.nextEntry(HashMap.java:806)
    at java.util.HashMap$KeyIterator.next(HashMap.java:841)
    at net.minecraft.server.EntityTracker.updatePlayers(EntityTracker.java:130)
    at net.minecraft.server.MinecraftServer.w(MinecraftServer.java:556)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:449)
    at net.minecraft.server.ThreadServerApplication.run(SourceFile:492)
    2012-06-11 18:23:15 [INFO] Connection reset

    Any help on the matter would be appreciated.
     
  2. Offline

    zachoooo

    A concurrent modification exception means that 2 things are trying to modify a single thing at the same time. Maybe you can add a check to see if the chunk below is already loaded or not.
    Code:
    Location below = new Location (world, x, 266, z);
    Chunk chunk = world.getChunkAt(below));
    if (!chunk.isLoaded()) {
    world.loadChunk(chunk);
    }
    player.teleport(below);
     
  3. Offline

    CorrieKay

    >.>

    <.<

    Just teleport to the location. You'll derp around in the unloaded chunk while it gens/loads, but it should be fine.
     
  4. Offline

    zachoooo

    Yeah I was over complicating things.
     
  5. Offline

    Derthmonuter

    That did not work.

    I am still having the same problems with this.

    In case it helps, here is my full method:

    @EventHandler
    public void onPlayerFall(PlayerVelocityEvent event) {
    Player player = event.getPlayer();
    if (player.getWorld().getName().equals("Skylands")) {
    if (player.getLocation().getY() < 0) {
    int x = (int) player.getLocation().getX();
    int z = (int) player.getLocation().getZ();
    int worldKey = (int) Math.random() * 3;
    //Because you are a fuckup at naming worlds, TEST is Neos, temp is Protos, and world is Paleos
    String[] worlds = {"world", "TEST", "temp"};
    World world = Bukkit.getWorld(worlds[worldKey]);
    //World world = Bukkit.getWorld("world");
    Location below = new Location(world, x, 260, z);
    //world.loadChunk(world.getChunkAt(below).getX(), world.getChunkAt(below).getZ());
    player.teleport(below);
    }
    }
    }

    Edit: I think I've stumbled onto something.
    If I change the event from a PlayerVelocityEvent to a simple PlayerInteract, it works.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 26, 2016
  6. Offline

    Njol

    Try PlayerMoveEvent and use event.setTo() to teleport to the new world.
    My guess why the error occurrs is that teleport() directly removes the player from the current world's entity list (or HashMap) and adds him to the teleported world. The code that calls PlayerVelocityEvent however is included in a loop through all entities of a world, thus a CuncurrentModificationException is thrown.
     
  7. Offline

    Derthmonuter

    Spot on! Using a PlayerMoveEvent instead of a PlayerVelocityEvent works. Thank you!
     
Thread Status:
Not open for further replies.

Share This Page