Solved Setting a players location

Discussion in 'Plugin Development' started by eyedjellyfish78, Nov 23, 2013.

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

    eyedjellyfish78

    I'm trying to make a plugin with basic troll commands. One of the commands is /void which is supposed to teleport a player to the void right under their location. For some reason I'm getting an error when I try to execute the command. Here's the onCommand:
    Code:java
    1. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
    2. if (cmd.getName().equalsIgnoreCase("void")){
    3.  
    4. Player target = (Bukkit.getServer().getPlayer(args[0]));
    5. if (target == null) {//Checks to see if the target is online
    6. //If the target is not online
    7. sender.sendMessage(args[0] + " is not online!");
    8. return false;
    9. }
    10. else {//If the target is online
    11. double x = target.getLocation().getX();
    12. double z = target.getLocation().getZ();
    13. Location voidUnderPlayer = null;
    14. voidUnderPlayer.setX(x);
    15. voidUnderPlayer.setZ(z);
    16. voidUnderPlayer.setY(0);
    17. target.teleport(voidUnderPlayer);
    18.  
    19. }
    20. }
    21. return false;
    22. }
     
  2. Offline

    Noxyro

    Code:java
    1. Location voidUnderPlayer = null;
    2. voidUnderPlayer.setX(x);
    3. voidUnderPlayer.setZ(z);
    4. voidUnderPlayer.setY(0);


    Are you serious? ...
    If you don't know what null means you should realy start on some basic Java Tutorials...
     
  3. Offline

    Hoolean

    Like Noxyro said, if you don't know how to use null then you should probably check out some basic Java tutorials before trying to learn the Bukkit API.

    Show Spoiler

    Change:
    Code:java
    1. Location voidUnderPlayer = null;
    2. voidUnderPlayer.setX(x);
    3. voidUnderPlayer.setZ(z);
    4. voidUnderPlayer.setY(0);

    to:
    Code:java
    1. Location voidUnderPlayer = new Location(target.getWorld(), x, 0, z);

    or even:
    Code:java
    1. Location voidUnderPlayer = target.getLocation();
    2. voidUnderPlayer.setY(0);

     
Thread Status:
Not open for further replies.

Share This Page