Teleport help

Discussion in 'Plugin Development' started by Rehmedy, Jul 30, 2012.

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

    Rehmedy

    I am making a plugin, and I want to make a plugin for an event. But I cant figure out how to make it where you can set a spawnpoint and you can /goto or something to go there. I want the setspawn command to be /tc setspawn, and the command to teleport there to be /tc join. How would I do this? And where would i put the code under, what code would i put under the /tc setspawn part and what code would i put under the /tc join part. Sorry for the trouble, kind of a newb at this :p. Thanks.
     
  2. Offline

    sd5

    Code:
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if(command.getName().equalsIgnoreCase("tc")) {
            if(args.length >= 1) {
                if(args[0].equalsIgnoreCase("setspawn")) {
                    if(args.length == 4) {
                        int x = Integer.parseInt(args[1]);
                        int y = Integer.parseInt(args[2]);
                        int z = Integer.parseInt(args[3]);
                    }
                }
                if(args[0].equalsIgnoreCase("join")) {
                    //Teleport the player to the coordinates...
                }
            }
        }
    }
    remember that you must add the command to your plugin.yml

    EDIT: Hmm, I didn't want to write the whole code for you, because then you can't learn on your own, but now it's too late....
     
  3. Offline

    Rehmedy

    Will that set the spawn directly under wherever the player is standing? So if you are standing at x:10 y:64 z:10, it would set the spawn there? That's what I want to do. And how do i teleport the player to that location?
     
  4. Offline

    sd5

    Code:
    Location spawn = null;
     
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if(command.getName().equalsIgnoreCase("tc")) {
            if(args.length >= 1) {
                if(args[0].equalsIgnoreCase("setspawn")) {
                    if(sender instanceof Player) {
                        spawn = ((Player) sender).getLocation();
                    } else {
                        sender.sendMessage("You have to be a player to perform this command!");
                    }
                }
                if(args[0].equalsIgnoreCase("join")) {
                    if(sender instanceof Player) {
                        if(spawn != null) {
                            ((Player) sender).teleport(spawn);
                        } else {
                            sender.sendMessage("Can't teleport because spawn is not set!");
                        }
                    } else {
                        sender.sendMessage("You have to be a player to perform this command!");
                    }
                }
            }
        }
    }
     
  5. Offline

    Rehmedy

    And this won't set the server spawn correct? So if I had essentials and i /setspawn'ed, the server-wide spawn would still be there, and the only way to get to the tc spawn is by /tc join. Sorry, I am really new at this.
     
  6. Offline

    aokue

    Will that set the spawn directly under wherever the player is standing?[​IMG]
     
  7. Offline

    sd5

    The server's spawn point won't be changed, but the tc spawn is only temporary. If you want to have it the same all the time, you have to save it in a config and read it out every time you start the server...

    And yes the spawn will be directly wherever the player is...
     
Thread Status:
Not open for further replies.

Share This Page