{HELP} REACH DISTANCE!

Discussion in 'Plugin Development' started by Bc1151, Aug 11, 2012.

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

    Bc1151

    i want to make a command for my plugin called reach but i have no idea where to start...

    {} = optional [] = mandatory
    EX. /reach [DISTANCE] {PLAYER}

    thanks in advanced,

    -Bc1151
     
  2. Offline

    travja

    I believe you can use the p.getTargetBlock method... but I'm not quite sure how to do this either...
     
  3. Offline

    ThijsD

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if (!(sender instanceof Player)) {
                plugin.getLogger().info("This command has to be called by a player");
                return true;
            }
     
        if (cmd.getName().equalsIgnoreCase("reach")) {
            if (args.length > 0) {
                if (args.length > 1) {
                    //Optional Argument
                }else{
                    //Only the mendatory one
                }
            }else{
                //It's not long enough
            }
        }
    }
    Or did you mean the actual reach code?
     
  4. Offline

    Bc1151

    i meant the code that sets the reach distance
     
  5. Offline

    ThijsD

    Well you can check what block is targeted with for example the interact event. Then get the player X and Z and the block X and Z

    sqrt((PlayerZ - BlockZ)^2 + (PlayerX - BlockX)^2) should get the distance betwean you and the block (So the reach length) If this exceeds a value you should cancel the event.

    ([​IMG])
     
  6. Offline

    Cowboys1919


    Actually, Location has a distance() method that accepts another location.
     
  7. Offline

    Phil2812

    I guess you could also get the player's (using Player.getLocation()) and the block's Location and use the Location class's distance method. Like Player.getLocation().distance(Block.getLocation()) or something like that.
    Edit: Cowboys was faster ;)
     
  8. Offline

    ThijsD

    Never knew this :) Always good to learn ^^
     
Thread Status:
Not open for further replies.

Share This Page