Solved How to teleport a player to specific coordinates

Discussion in 'Spigot Plugin Development' started by superblaze27, Mar 1, 2020.

  1. Solved:
    How to teleport a player to specific coordinates

    Code (Java):
    public void onPlayerJoin(PlayerJoinEvent event) {
        Location loc = new Location(Bukkit.getWorld("world"), -16.5, 67, -22.5, 0, 0);

    Code (Text):
    Location loc = new Location(Bukkit.getWorld("WORLDNAME"), x, y, z, y, p);
    WORLDNAME = Name of world you want to teleport the player to
    X = X coordinate
    Y = Y coordinate
    Z = Z coordinate
    Y = Yaw
    P = Pitch

    How to teleport player to specific location
    How to teleport player to specific coordinate
    How to teleport player to specific coordinates
    How to teleport player to a specific location
    How to teleport player to a specific coordinate
    How to teleport player to a specific coordinates
    How to teleport a player to specific location
    How to teleport a player to specific coordinate
    How to teleport a player to specific coordinates
    How to teleport a player to a specific location
    How to teleport a player to a specific coordinate
    How to teleport a player to a specific coordinates

    Old post:
    Sorry but this forum is no help at all. Minecraftforum is literally the only forum that keeps is clean. And what I mean by that is they don't allow replies that are useless and won't be helpful years later. Their forum is great to use as a knowledge base. These threads become useless less than a year later. I'm digging and digging for answers and I can't find what I'm looking for. So here's another question.

    How can I teleport a player to a location?
    And DO NOT say that the answer is in the forums. ITS NOT. I've been searching for 30 minutes. And if it is, it clearly isn't user friendly to find. After I'm done with this question, I'll rename this thread to something so people can look it up later.

    Code (Java):
    Player player = event.getPlayer();
    Location loc = new Location(event.getWorld(), -17, 67, -22, 0, 0);
    What am I doing wrong. I've tried about a billion things in the world area. I have more code. I just need to fix the format of Location()

    Can someone for the love of god teach me how to use the javadocs? It's ridiculous that nobody on youtube can explain it. I can't even find an actual explanation here. How can I use it and apply it?

    Thank you. Sorry for posting so many threads, it's just so stupid that we have to have this section. This forum would be a lot less spam if someone actually explained how to use these tools.

    Also, why do people use plugin.getConfig at the start of
    String test = plugin.getConfig().getString("group.test");

    instead of this.getConfig?

    When I use plugin.getConfig it doesn't work.
    #1 superblaze27, Mar 1, 2020
    Last edited: Mar 1, 2020
    • Optimistic Optimistic x 1
  2. Plugin is a variable, it's normally used as an instance of your main class. So your instance may be different, can't just copy plugin.getConfig and expect it to work. Also, getConfig can only be accessed from your main class, so this.getConfig can only be used in the main class, as the "this" keyword refers to the class you're in.

    Also the teleport code should work fine? Have you registered your listener? Added event handler? Debugged?
    • Agree Agree x 1
  3. First of, calm down. It ain't nobody's fault if you do not know how to read JavaDoc. JavaDoc is as easy as reading a book. So if we look over here: we can see how entity.teleport works. For creating a new location: you can see how the constructor works here. What is wrong in your code? It should definitely be working unless you're using in some sort of event. We need more code in order to help you.

    People use plugin.getConfig() cause their events and commands aren't located in the main class just like you did. It's what we called project management.
    #3 Maxx_Qc, Mar 1, 2020
    Last edited: Mar 1, 2020
    • Agree Agree x 1
  4. Also I just wanna add that this is spigot plugin development, which means that you should know how to code and use javadocs at least a minimum before getting crazy over such thing. Learn coding before trying to use a coding API. Go on coding forums if you wanna learn how to read javadocs (even though you literally just have to read it, it's self-explanatory)
    • Agree Agree x 2
  5. I know what I did wrong. I have 2 if then statements from an event that were pointing to different lines of code.

    I changed my code to:

    Location loc = new Location(Bukkit.getWorld("world"), -16.5, 67, -22.5, 0, 0);

    And it works perfectly
  6. If you wanna teleport to the main world of the server you can use Bukkit.getWorlds()[0]
    • Like Like x 1
  7. It's solved? Well then, one of the things this non-perfect in every way forum has which can be used to help people in the future, is a nifty little tool that allows you to put the prefix: SOLVED
    before the title.... and I would also recommend changing the title to something along the lines of: Help with player/entity teleportation.

    That would definitely help future coders that run into a problem similar to yours, granted you did not really explain your actual problem, you just ripped on the spigot forums and then posted a bit of code with no context as to whether there were errors or not. This is especially proven in your solution where you point out something that was never mentioned in the question.
    • Agree Agree x 1
  8. I’d be interested to see concrete examples of this being the case.

    So ask your question. Maybe no one has had your problem before.


    Yes it is. This is the first result when you look for “how to teleport player spigot” -

    The first comment explains how you use a Location object and how the OP can use the teleport method with it.

    The code snippet you posted appears to have nothing wrong with it. You need to give more context. What do you expect to happen? What is happening right now? What is the code leading up to your snippet? Have you tried debugging your code using System.out.println() to ensure it even runs in the first place?

    Teach you what about the JavaDocs? They’re simply listings of every single constructor/field/method available from a certain class. If you’re looking for a function for a specific instance of, say, a Player, the JavaDoc page for Player tells you what functions you can call and what those methods do.

    Why should you? This isn’t a Java programming forum. JavaDocs are a generic tool available to all Java APIs, so it is expected of you, as a Java developer, to understand how to use the Java API and the tools available to you as a prerequisite to the using the Spigot API.

    Why is that?

    Once again, the JavaDocs are not a tool exclusive to the Spigot API, it’s a generic Java development tool. Ironically, some (if not most) people consider questions on Java-specific topics (as you seem to be attributing your issue with) to be spam.

    You can’t call a method out of thin air, it has to come from somewhere. The “plugin” and the “this” tells which instance of the main class to call the getConfig() method from.

    More code context is needed to answer this question. What do you expect it to do? What do you mean by it doesn’t work? Does it throw an exception? Does your code not compile?
    • Agree Agree x 2