[ create a new paste ] login | about

Link: http://codepad.org/KJFspuUr    [ raw code | fork ]

Plain Text, pasted on Mar 9:
	@Override
	public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args){
		String commandName = command.getName();
		Player player;
		Integer x1 = Integer.valueOf(args[0]);
		Integer z1 = Integer.valueOf(args[1]);
		Integer x2 = Integer.valueOf(args[2]);
		Integer z2 = Integer.valueOf(args[3]);
		
		if (sender instanceof Player)
		{
			player = (Player) sender;
		}
		else
		{
			return false;
		}
		
		player.sendMessage(" X1: " + args[0] + " Z1: " + args[1] + " X2: " + args[2] + " Z2: " + args[3]);
		
		float d2d = Distance(new Vector(x1, 0, z1), new Vector(x2, 0, z2));
	    float distanceFinal = (float)Math.sqrt(Math.pow((double)d2d, 2.0) + Math.pow((double)(0), 2.0));	   
	    Vector vector1 = new Vector(x1, 0, z1);
	    float heading = Heading(new Vector(x1, 0, z1), new Vector(x2, 0, z2));
	    
	    // OMG!
	    player.getVehicle().setVelocity(Reposition(vector1, heading, distanceFinal)); 
	    
		return true;
	}
	
	public static float Distance(Vector Pos1, Vector Pos2)	
	{
		return (float)Math.sqrt(Math.pow((double)(Pos2.getX() - Pos1.getX()), 2.0) + Math.pow((double)(Pos2.getZ() - Pos1.getZ()), 2.0));
	}
	
	public static Vector Reposition(Vector Pos, float Ang, float Hyp)
	{
		float r = (float)Math.toRadians(Ang);
		float a = (float)(Math.sin(r)) * Hyp;
		float b = (float)(Math.cos(r)) * Hyp;
		return new Vector((double)(Pos.getX() + b), 2, (double)(Pos.getZ() + a));
	}	

	public static float Heading(Vector Origin, Vector Dest)
	{
		double ang = (double)Math.atan2((Dest.getZ() - Origin.getZ()), (Dest.getX() - Origin.getX()));
		return (float)Math.toDegrees(ang);
	}


Create a new paste based on this one


Comments: