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?
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.
Could i use this? Code:java 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 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 player.getLocation().setWorld(world_the_end); EDIT by Moderator: merged posts, please use the edit button instead of double posting.
I'm not really sure what your asking. Are you trying to check when the player teleports to a certain world?
mkezar Declare the world you are using, as a string. Code:java player.getLocation().setWorld("world_the_end");
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
bombom3000 ok. heres my code: Code:java World the_end = this.getServer().getWorld("world_the_end");player.getLocation().setWorld(the_end); and it dosnt work. how do i make it a string? do i make it Code:java World the_end = this.getServer().getWorld("world_the_end");player.getLocation().setWorld("world_the_end");
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);
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
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
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 double x = 100;double y = 100;double z = 100; Location l = new Location(World."world_the_nether", x, y, z);player1.teleport(100,100,100); but its not liking the teleport part. Code:java .teleport(100,100,100); where am i going wrong It also dosnt like the Code:java World. Part. Heres the entire code if you need it Code:java package plugins.mkezar; import java.util.Collection; import org.bukkit.Bukkit;import org.bukkit.ChatColor;import org.bukkit.Location;import org.bukkit.Material;import org.bukkit.Sound;import org.bukkit.World;import org.bukkit.entity.Player;import org.bukkit.event.EventHandler;import org.bukkit.event.Listener;import org.bukkit.event.player.PlayerChangedWorldEvent;import org.bukkit.event.player.PlayerMoveEvent;import org.bukkit.inventory.ItemStack;import org.bukkit.plugin.java.JavaPlugin; public class TeamZombieFight extends JavaPlugin implements Listener { @Override public void onEnable() { Bukkit.getServer().getPluginManager().registerEvents(this, this); } @EventHandler public void onPlayerChangeWorld(PlayerChangedWorldEvent e) { World world = e.getPlayer().getWorld(); Player player = e.getPlayer(); if(world.getPlayers().size() == 1) { Collection <Player> c = world.getPlayers(); if(c.size() == 1) { Bukkit.broadcastMessage(ChatColor.YELLOW + "The Game Will Begin In " + ChatColor.RED + "30" + ChatColor.YELLOW + " Seconds!"); final Player player1 = e.getPlayer(); System.out.println("There Are " + c.size() + " Players Playing Now"); Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() { public void run() { Bukkit.broadcastMessage(ChatColor.YELLOW + "The Game Will Begin In " + ChatColor.RED + "10" + ChatColor.YELLOW + " Seconds!"); } }, 300L); Bukkit.getServer().getScheduler().scheduleSyncDelayedTask(this, new Runnable() { public void run() { double x = 100; double y = 100; double z = 100; Location l = new Location(World."world_the_nether", x, y, z); player1.teleport(100,100,100); } }, 600L); //l.setWorld(the_end); //player.getLocation().setWorld(the_end); } } }}
You're almost there, I'll write a working example quickly: Code:java Location l = new Location(Bukkit.getWorld("world_the_nether"), 0, 0, 0); // 0, 0, 0 is equivalent to x, y, z coordinatesplayer1.teleport(l); // Just specify the location 'l' I created above, this will teleport the player to 0, 0, 0 in 'world_the_nether'. 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 int x = 100;int y = 100;int z = 100; Location l = new Location(Bukkit.getWorld("world_the_nether"), x, y, z);player1.teleport(l); These could also be values from an equation, etc. I hope you understand this and it helps you! Charlie
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?
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