How do I load maps from diffrent files ?

Discussion in 'Spigot Plugin Development' started by NacOJerk, Jul 27, 2015.

  1. NacOJerk

    Supporter

    Well I got this code :
    Code (Text):
        @EventHandler
        public void chatEvent(AsyncPlayerChatEvent e){
            if(e.getMessage().contains("Maps")){
                e.getPlayer().sendMessage(ChatColor.GOLD + "" + ChatColor.BOLD + "Maps loaded :");
                for(String s : getFileNames("Maps")){
                    e.getPlayer().sendMessage(ChatColor.GOLD + s);
                }
                return;
            }
            if(e.getMessage().contains("Map")){
                String map = e.getMessage().replace("Map ", "");
                if(!getFileNames("Maps").contains(map)){
                    e.getPlayer().sendMessage(ChatColor.RED + "Map Doesnt Exists");
                    return;
                }
                World w = Bukkit.createWorld(new WorldCreator(getDataFolder().getPath() + "\\Maps\\" + map));
                e.getPlayer().teleport(new Location(w, 0, 20, 0));
            }
        }
     
    Each time I run it I get this error :
    Code (Text):
    [16:28:14 ERROR]: Could not pass event AsyncPlayerChatEvent to Castle_wars v1
    org.bukkit.event.EventException
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:310) ~[craftbukkit.jar:git-Spigot-d2856ae-8f0f4ed]
            at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.jav
    a:62) ~[craftbukkit.jar:git-Spigot-d2856ae-8f0f4ed]
            at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.j
    ava:502) [craftbukkit.jar:git-Spigot-d2856ae-8f0f4ed]
            at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.j
    ava:484) [craftbukkit.jar:git-Spigot-d2856ae-8f0f4ed]
            at net.minecraft.server.v1_8_R3.PlayerConnection.chat(PlayerConnection.j
    ava:1057) [craftbukkit.jar:git-Spigot-d2856ae-8f0f4ed]
            at net.minecraft.server.v1_8_R3.PlayerConnection.a(PlayerConnection.java
    :995) [craftbukkit.jar:git-Spigot-d2856ae-8f0f4ed]
            at net.minecraft.server.v1_8_R3.PacketPlayInChat$1.run(PacketPlayInChat.
    java:39) [craftbukkit.jar:git-Spigot-d2856ae-8f0f4ed]
            at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [
    ?:1.8.0_25]
            at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_25]
            at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) [?:
    1.8.0_25]
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [?
    :1.8.0_25]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_25]
    Caused by: java.lang.IllegalStateException: Asynchronous player tracker clear!
            at org.spigotmc.AsyncCatcher.catchOp(AsyncCatcher.java:14) ~[craftbukkit
    .jar:git-Spigot-d2856ae-8f0f4ed]
            at net.minecraft.server.v1_8_R3.EntityTrackerEntry.clear(EntityTrackerEn
    try.java:544) ~[craftbukkit.jar:git-Spigot-d2856ae-8f0f4ed]
            at net.minecraft.server.v1_8_R3.EntityTracker.untrackPlayer(EntityTracke
    r.java:237) ~[craftbukkit.jar:git-Spigot-d2856ae-8f0f4ed]
            at net.minecraft.server.v1_8_R3.PlayerList.moveToWorld(PlayerList.java:5
    07) ~[craftbukkit.jar:git-Spigot-d2856ae-8f0f4ed]
            at org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer.teleport(CraftPlaye
    r.java:476) ~[craftbukkit.jar:git-Spigot-d2856ae-8f0f4ed]
            at org.bukkit.craftbukkit.v1_8_R3.entity.CraftEntity.teleport(CraftEntit
    y.java:223) ~[craftbukkit.jar:git-Spigot-d2856ae-8f0f4ed]
            at com.kirelcodes.CastleWars.chatEvent(CastleWars.java:60) ~[?:?]
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0
    _25]
            at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[?:1.8.0
    _25]
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:1
    .8.0_25]
            at java.lang.reflect.Method.invoke(Unknown Source) ~[?:1.8.0_25]
            at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.ja
    va:306) ~[craftbukkit.jar:git-Spigot-d2856ae-8f0f4ed]
            ... 11 more
    I already checked online like many times and I cant seem to find a way to do it :(
     
  2. You're making a call to Bukkit API (Bukkit.createWorld()) in an async method (well... technically another thread, but ya.) :(
     
  3. NacOJerk

    Supporter

    so Basicly (Sorry for being an idiot) if I do it like with an other way for example command it will work ? (At the end it wont even be via a command)
     
  4. If you do it via a command you should get rid of that IllegalStateException :) You're correct!
     
  5. NacOJerk

    Supporter

    Thx :)
     
  6. Happy to help, let me know how that goes!
     
  7. Ya like this guys said just use a command to load the world
     
  8. NacOJerk

    Supporter

    Thx Worked for me :)
     
  9. NacOJerk

    Supporter

    NVM it recreats for me the map :( ?
     
  10. NacOJerk

    Supporter

    NVM it doesnt :)
     
  11. no problem ;)