Lobby Help!

Discussion in 'Plugin Development' started by mkezar, Aug 4, 2014.

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

    mkezar

    Hi. I am working on a lobby and i got the basics down. When i go to a different world (nether) it gets how many people are on that world. and if X amount of people are there, it says a message. What im having trouble with is if i use for example, Multiverse-Core, it makes different worlds (which i want) but, how would i make it so a player teleports to that world with an Event Trigger?
     
  2. Offline

    The Fancy Whale

    PlayerTeleportEvent?
     
  3. Offline

    mkezar

    can that be used in teleporting to a world?
     
  4. Offline

    _LB

    It's not a matter of whether it can be used, the fact is that it is called when you use .teleport() for a player. That's the only way to get them to a different world.
     
  5. Offline

    mkezar

    Could i use this?

    Code:java
    1. entity.teleport(new Location(getServer().getWorld(WORLDNAME),x,y,z);


    _LB the code i posted sux. this is better. so would this work?
    Code:java
    1. p.getLocation().setWorld(world);


    EDIT: since the worlds i have in my server folder arent on eclipse, how would i declare this world "world_the_end" in my code?
    Code:java
    1. player.getLocation().setWorld(world_the_end);


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

    Skionz

    I'm not really sure what your asking. Are you trying to check when the player teleports to a certain world?
     
  7. Offline

    iMurder

    mkezar Declare the world you are using, as a string.
    Code:java
    1. player.getLocation().setWorld("world_the_end");
     
  8. Offline

    bombom3000

    1. About that quote - Just input your world as a string and it will work and I believe you need to teleport the player directly and it gives you more control over where they spawn.
    2. Just use the PlayerTeleportEvent and in there have an if statement with your player.getLoc... etc. Just make sure you change player to the parmeter you set in the class not the player directly.

    There may be other ways, but I don't have access to my compiter right now to experiment.

    I hope that made sense, it was written at 00:00 on my tablet.

    Feel free to ask me to explain.

    Charlie
     
  9. Offline

    mkezar

    bombom3000 ok. heres my code:

    Code:java
    1. World the_end = this.getServer().getWorld("world_the_end");
    2. player.getLocation().setWorld(the_end);


    and it dosnt work. how do i make it a string? do i make it

    Code:java
    1. World the_end = this.getServer().getWorld("world_the_end");
    2. player.getLocation().setWorld("world_the_end");
     
  10. Offline

    The Fancy Whale

    If you want to teleport a player to a world:
    Location loc = new Location(Bukkit.getServer().getWorld("World_Name"), x,y,z);
    player.teleport(loc);
     
  11. Offline

    artish1

    mkezar
    Usually what i do when i create a 'Lobby', or even saving ANY sort of location (that i need to keep when server is off/reloading/stopping), is add the X,Y,Z and the worlds NAME in YAML file. Usually if it's just one location, you can put it into the config.yml, but if there are many you might want to organize and make a seperate YAML file (named locations.yml or something).


    Here is a setter and getter method i made myself (to save time):
    Code:
    public void addLocation(Location loc, String name){
            plugin.getConfig().addDefault(name + ".X", loc.getX());
            plugin.getConfig().addDefault(name + ".Y", loc.getY());
            plugin.getConfig().addDefault(name + ".Z", loc.getZ());
            plugin.getConfig().addDefault(name + ".Pitch", loc.getPitch());
            plugin.getConfig().addDefault(name + ".Yaw", loc.getYaw());
            plugin.getConfig().addDefault(name + ".World", loc.getWorld().getName());
            plugin.saveConfig(); //Or you can use plugin.getConfig().set(Path,Value);
     
        }
        public Location getLocation(String name){
            Location loc = new Location(Bukkit.getWorld(plugin.getConfig().getString(name + ".World")),
                    plugin.getConfig().getDouble(name + ".X"),
                    plugin.getConfig().getDouble(name + ".Y"),
                    plugin.getConfig().getDouble(name + ".Z"));
       
            loc.setPitch(plugin.getConfig().getInt(name + ".Pitch"));
            loc.setYaw(plugin.getConfig().getInt(name + ".Yaw"));
       
            return loc;
        }
        
    You can see it not only stores the x, y and z, But also the World Name (which is needed), and the Pitch & Yaw(Which can be used to make players look at a specific angle).

    Note: You can always change the path, so if you are making a game with Arenas and each have different locations, you can always change the path to: "Arenas." + ArenaName + "." + name+ ".X", and etc, you can customize it any how u want it
     
  12. Offline

    bombom3000

    Well, you got the String part right, what I was trying to say was to do what The Fancy Whale has posted:
    Which does work as I've done it before.

    Charlie
     
  13. Offline

    mkezar

    bombom3000 ok. I got it working. Now im having quite a bit of trouble by trying to teleport a player to a specific XYZ coord. Heres what im trying,

    Code:java
    1.  
    2. double x = 100;
    3. double y = 100;
    4. double z = 100;
    5.  
    6.  
    7. Location l = new Location(World."world_the_nether", x, y, z);
    8. player1.teleport(100,100,100);


    but its not liking the teleport part.

    Code:java
    1. .teleport(100,100,100);


    where am i going wrong

    It also dosnt like the
    Code:java
    1. World.
    Part.
    Heres the entire code if you need it
    Code:java
    1. package plugins.mkezar;
    2.  
    3. import java.util.Collection;
    4.  
    5. import org.bukkit.Bukkit;
    6. import org.bukkit.ChatColor;
    7. import org.bukkit.Location;
    8. import org.bukkit.Material;
    9. import org.bukkit.Sound;
    10. import org.bukkit.World;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.event.EventHandler;
    13. import org.bukkit.event.Listener;
    14. import org.bukkit.event.player.PlayerChangedWorldEvent;
    15. import org.bukkit.event.player.PlayerMoveEvent;
    16. import org.bukkit.inventory.ItemStack;
    17. import org.bukkit.plugin.java.JavaPlugin;
    18.  
    19. public class TeamZombieFight extends JavaPlugin implements Listener {
    20.  
    21. @Override
    22. public void onEnable() {
    23. Bukkit.getServer().getPluginManager().registerEvents(this, this);
    24. }
    25. @EventHandler
    26. public void onPlayerChangeWorld(PlayerChangedWorldEvent e) {
    27. World world = e.getPlayer().getWorld();
    28. Player player = e.getPlayer();
    29. if(world.getPlayers().size() == 1) {
    30. Collection <Player> c = world.getPlayers();
    31. if(c.size() == 1) {
    32.  
    33. Bukkit.broadcastMessage(ChatColor.YELLOW + "The Game Will Begin In " + ChatColor.RED + "30" + ChatColor.YELLOW + " Seconds!");
    34. final Player player1 = e.getPlayer();
    35. System.out.println("There Are " + c.size() + " Players Playing Now");
    36.  
    37. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    38. public void run() {
    39. Bukkit.broadcastMessage(ChatColor.YELLOW + "The Game Will Begin In " + ChatColor.RED + "10" + ChatColor.YELLOW + " Seconds!");
    40. }
    41. }, 300L);
    42.  
    43. Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() {
    44. public void run() {
    45. double x = 100;
    46. double y = 100;
    47. double z = 100;
    48.  
    49.  
    50. Location l = new Location(World."world_the_nether", x, y, z);
    51. player1.teleport(100,100,100);
    52. }
    53. }, 600L);
    54.  
    55. //l.setWorld(the_end);
    56.  
    57. //player.getLocation().setWorld(the_end);
    58.  
    59.  
    60.  
    61.  
    62. }
    63.  
    64. }
    65.  
    66. }
    67. }
    68.  
     
  14. Offline

    bombom3000

    You're almost there, I'll write a working example quickly:
    Code:java
    1. Location l = new Location(Bukkit.getWorld("world_the_nether"), 0, 0, 0); // 0, 0, 0 is equivalent to x, y, z coordinates
    2. player1.teleport(l); // Just specify the location 'l' I created above, this will teleport the player to 0, 0, 0 in 'world_the_nether'.
    3.  

    It was where you said player1.teleport(100, 100, 100) where you went wrong, there is only one parameter for teleport and that is type Location, so you have to put your location already defined in there.

    Also, from experience, use Bukkit.getWorld("world_name") to specify a specific world.

    And if you want to specify the coordinates from outside the Location, just define them as an integer and change the the 0, 0, 0 at the end of my Location example to x, y, z:
    Code:java
    1. int x = 100;
    2. int y = 100;
    3. int z = 100;
    4.  
    5. Location l = new Location(Bukkit.getWorld("world_the_nether"), x, y, z);
    6. player1.teleport(l);

    These could also be values from an equation, etc.

    I hope you understand this and it helps you!

    Charlie :)
     
  15. Offline

    mkezar

    bombom3000 ok thanks! Quick question, do you know how when I go to the lobby (a different world) it triggers the event that starts the game. When the game ends, it needs to teleport you to the lobby (a different world). This creates 1 giant loop. Is there a way that when the game ends it can cancel the event?
     
  16. Offline

    bombom3000

    mkezar I believe you can use a WorldJoinEvent and then check the world, I can't check right now as I have my mac in windows with no eclipse.

    I hope your plugin is going well :)
     
Thread Status:
Not open for further replies.

Share This Page