Wierd bugs with multiWorld teleporting

Discussion in 'Plugin Development' started by Snowl, Feb 7, 2011.

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

    Snowl

    Heres my code:
    Code:
    package com.Snowl.bukkit.exodusNether;
    
    import java.util.List;
    
    import org.bukkit.Location;
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.World.Environment;
    import org.bukkit.entity.Player;
    import org.bukkit.event.player.PlayerChatEvent;
    import org.bukkit.event.player.PlayerListener;
    import org.bukkit.event.player.PlayerMoveEvent;
    
    /**
     * Handle events for all Player related events
     * @author Snowl
     */
    public class exodusNetherPlayerListener extends PlayerListener {
        private final exodusNether plugin;
        exodusNether exodusNetherInstance;
    
        public exodusNetherPlayerListener(exodusNether instance) {
            plugin = instance;
        }
      
        @Override
        public void onPlayerCommand(PlayerChatEvent event) {
            String split = event.getMessage();
            String split1[] = split.split(" ");
                if (split.toLowerCase().startsWith("/goto")) {
                    //List worlds = exodusNetherInstance.getServer().getWorlds();
                    if (split.toLowerCase().equals("/goto list"))
                    {
                        int index = 0;
                           while (index < plugin.getServer().getWorlds().size()) {
                        event.getPlayer().sendMessage(plugin.getServer().getWorlds().get(index).getName());
                        index++;
                           }
                    }
                    else
                    {
                        int index = 0;
                           while (index < plugin.getServer().getWorlds().size()) {
                        if (plugin.getServer().getWorlds().get(index).getName().equalsIgnoreCase(split1[1]))
                        {
                            event.getPlayer().teleportTo(plugin.getServer().getWorlds().get(index).getSpawnLocation());
                        }
                        index = +1;
                           }
                    }
                }
                if (split.toLowerCase().startsWith("/worldcreate")) {
                    int index = 0;
                       while (index < plugin.getServer().getWorlds().size()) {
                    if (plugin.getServer().getWorlds().get(index).getName().equalsIgnoreCase(split1[1]))
                    {
                        break;
                    }
                    index = +1;
                       }
                       if (index == plugin.getServer().getWorlds().size())
                       {
                           plugin.getServer().createWorld(split1[1], Environment.NORMAL);
                       }
                }
          }
    }
    (Ignore the non yaml command)
    when I create a new world, that works fine, but once I tp to the world, it seems that if I try and tp back to my old world, it never spawns? o.o and then /goto list provides two "world" instead of one "world" and one "testworld".
    And once you restart the plugin doesn't find the extra world at all

    Does anyone know why?
     
  2. Offline

    Purre

    Try using index++ or index += 1 instead of index = +1 as that will cause index to be 1 all the time, which is not the intended behaviour.
     
  3. Offline

    Snowl

    Thanks, I dont know why I used the other one. I'll test it out now :)
     
Thread Status:
Not open for further replies.

Share This Page