How do you teleport players to Locations?

Title.

Ive tried alot of different methods but cant see to do alot of things through the event system.

With a lot of Gamma energy.

On another note, you wouldn’t necessarily need to listen to an event to teleport someone. Under what circumstances would you want to make them teleport?

2 Likes

@FerusGrim That completely avoided answering the question… I would be frustrated if I was the original poster.

2 Likes

I was going to answer a little more specifically, when he answered. xD

Command, when they land on a specific location, click a block, etc.

1 Like

Teleport all players to a configurable spawn point?

Yes, but what would the trigger be? A command?

1 Like

That’s not handled by an event, you should use the commands API for that.

2 Likes

A configurable countdown. Idk ahahah

But what would trigger the countdown? XD

Something has to come from something.

1 Like

The game-master will click a book and start the game.

  • Listen to BlockInteractEvent.
  • Check if the Block is a book.
  • Check if the Interact-or is a game-master.
  • Look at @gratimax’s post.
2 Likes

Perhaps excuse me for prying into this, but I don’t understand this methodology. The original poster asked a very simple question about teleporting players, and it is somehow a better idea to get the full context for the answer and explain how to do it step-by-step (essentially writing OP’s plugin for him) instead of answering directly? You opened with a joke that supposedly answered the question and then said “on another note”, indicating that you were done answering his question and wanted to know more about the context behind it.

6 Likes

Im looking for like Objects and Classes i will need to use. I figured people had figured that out by now? and i havnt been able to teleport players to custom locations.

@numbrs By “havnt been able to teleport players to custom locations”, do you mean that you tried out the method I linked or that you didn’t try it out and were looking for it? In other words, is your problem solved, or is there some other error like a runtime error or compile error?

My code simply will not teleport the player on join, and I was just looking around the api. I will look at your resource when I get home. Thanks

If you have further problems maybe show us a code example of what you have tried.

Clicking a book sounds a lot like using the TextActions from the Text API in order to make the player run a command.

You could use the Text API in order to create the books contents from a command.

https://docs.spongepowered.org/en/plugin/basics/text/text.html#text-actions

Create a command:

https://docs.spongepowered.org/en/plugin/basics/commands/index.html

Then teleport the players, either by executing the vanilla command from your plugin, or directly setting each players location using the method linked by Gratimax.

Also you can use this method.

/**
 * Sets the location of this entity using a safe one from {@link TeleportHelper#getSafeLocation(Location)}. This is equivalent to a
 * teleport and also moves this entity's passengers.
 *
 * @param location The location to set
 * @return True if location was set successfully, false if location couldn't be set as no safe location was found
 */
boolean setLocationSafely(Location location);

This is the method I was trying to use, it didn’t do anything for me.

What is it returning? True or False?

It’s not guarantee’d to do anything, it depends on what it outputs whether the teleportation was successful.

I have same problem. It return true (“Teleported”), but It don’t teleport player. I have tried to use transferToWorld function and I get same result. So where can the problem be ?

@Listener(ignoreCancelled = true)
public void onPlayerJoin(ClientConnectionEvent.Join playerJoinEvent) {
    Location<World> spawn = plugin.getGame().getServer().getWorld("world").get().getSpawnLocation();
    Player player = (Player) playerJoinEvent.getTargetEntity();
    //player.transferToWorld(spawn.getExtent().getName(), new Vector3d(spawn.getX(), spawn.getY(), spawn.getZ()))
    if (player.setLocationSafely(spawn)) {
        plugin.getLogger().error("Teleported");
    }
}