Solved Teleportation to the same spot :/

Discussion in 'Spigot Plugin Development' started by Creatos137, May 7, 2017.

  1. Hey,

    So I tried to make something small but when I run the command it keeps teleporting me to the first position.

    Thank you for your time.

    - Creatos
  2. bumb, can please someone help
    • Optimistic Optimistic x 1
  3. You first check if the lenght of the arg array is 0(which means it is empty). If this is true, you want to check the first arg of this array?
    This will never be true. Check for an arg-array length of 1 instead of 0.
    And btw. i recommend you to call the Location constructor directly instead of using a method which does this. You save space/have less methods.
    I also would use an if-else if clause instead of two ifs.
    And as last i would recommend you to return true after teleporting the Player, or you will get the command usage even after you got teleported.
  4. Hey, thank you for responding.

    The reason why I used a method is because I just learned it in the Java course I am taking and I wanted to try it out.

    As for the arg lenght, if I put it to 1 it just comes with an error whenever I try to execute the command.
  5. For the future provide error-reports in your posts here. they have a sense.
    In case of a command i would recommend you to check if arg isnt null.
    Also what do you type ingame?
  6. I would do it something like this:
    Code (Text):
    if(arg==null) return false;
    if(arg.length == 1) {
        if(arg[0].equalsIgnoreCase("red")) {
            player.teleport(new Location(player.getWorld(), 249.5, 78, 261.5));
        } else if (arg[0].equalsIgnoreCase("blue")) {
            player.teleport(new Location(player.getWorld(), 267.5, 78, 261.5));
        player.sendMessage("Wrong Usage. /command [blue|red]");
    As you can see i added a null check. So if arg is null, we return false and stop the processing.
    If it isnt null, we continue and look if the length of the arg is equals 1. if it is equals 1, check which color the player has specified. if it isnt, return the right usage.
  7. Thanks, I see what I did wrong now, I frogot it started counting at 0!

    Thank you for your time!
  8. No Problem! Thats what this forum is for, even if many people start yelling learn java, but i did it the same way like you, so why shouldn´t i help :)